Inherit default_visibility from parent package

Enhances the visibility mechanism to use the default_visibility
property of the closest ancestor package that has the property
specified.

Bug: 133290645
Test: m droid
Change-Id: I7248e9034a73894ac8d514f913316438c4d7c079
This commit is contained in:
Paul Duffin
2019-06-20 16:38:08 +01:00
parent e2453c705f
commit e484f47a63
4 changed files with 106 additions and 11 deletions

View File

@@ -761,6 +761,64 @@ var visibilityTests = []struct {
` visible to this module`,
},
},
{
name: "package default_visibility inherited to subpackages",
fs: map[string][]byte{
"top/Blueprints": []byte(`
package {
default_visibility: ["//outsider"],
}
mock_library {
name: "libexample",
visibility: [":__subpackages__"],
}`),
"top/nested/Blueprints": []byte(`
mock_library {
name: "libnested",
deps: ["libexample"],
}`),
"outsider/Blueprints": []byte(`
mock_library {
name: "liboutsider",
deps: ["libexample", "libnested"],
}`),
},
expectedErrors: []string{
`module "liboutsider" variant "android_common": depends on //top:libexample which is not` +
` visible to this module`,
},
},
{
name: "package default_visibility inherited to subpackages",
fs: map[string][]byte{
"top/Blueprints": []byte(`
package {
default_visibility: ["//visibility:private"],
}`),
"top/nested/Blueprints": []byte(`
package {
default_visibility: ["//outsider"],
}
mock_library {
name: "libnested",
}`),
"top/other/Blueprints": []byte(`
mock_library {
name: "libother",
}`),
"outsider/Blueprints": []byte(`
mock_library {
name: "liboutsider",
deps: ["libother", "libnested"],
}`),
},
expectedErrors: []string{
`module "liboutsider" variant "android_common": depends on //top/other:libother which is` +
` not visible to this module`,
},
},
}
func TestVisibility(t *testing.T) {