Add more specific partition visibility rules
//visibility:any_system_partition, //visibility:any_vendor_partition,
etc.
Then, if a partition visibility rule is not specificed, but the module
is installed on a non-system partition via the `vendor: true` or other
properties, the visibility rule for that partition will be added by
default.
This is so that "any_partition" doesn't imply that modules could be put
on the vendor partition when they weren't designed for that, and so that
modules that do need to go on the vendor partition don't need to specify
both vendor: true and visibility:any_vendor_partition.
Eventually, the partition properties should be deprecated, and replaced
with just these visibility rules.
Bug: 321000103
Test: go tests
Change-Id: I24dba36bbc20921941f892480bf7c050e93827c6
diff --git a/android/visibility_test.go b/android/visibility_test.go
index bb43b1f..1a2eeca 100644
--- a/android/visibility_test.go
+++ b/android/visibility_test.go
@@ -1905,7 +1905,7 @@
},
},
{
- name: "any_partition visibility works",
+ name: "any_system_partition visibility works",
fs: MockFS{
"top/Android.bp": []byte(`
android_filesystem {
@@ -1916,12 +1916,12 @@
package(default_visibility=["//visibility:private"])
mock_library {
name: "bar",
- visibility: ["//visibility:any_partition"],
+ visibility: ["//visibility:any_system_partition"],
}`),
},
},
{
- name: "any_partition visibility works with the other visibility",
+ name: "any_system_partition visibility works with the other visibility",
fs: MockFS{
"top/Android.bp": []byte(`
android_filesystem {
@@ -1935,13 +1935,13 @@
name: "bar",
visibility: [
"//top2",
- "//visibility:any_partition"
+ "//visibility:any_system_partition"
],
}`),
},
},
{
- name: "any_partition visibility doesn't work for non-partitions",
+ name: "any_system_partition visibility doesn't work for non-partitions",
fs: MockFS{
"top/Android.bp": []byte(`
mock_library {
@@ -1951,11 +1951,77 @@
"top/nested/Android.bp": []byte(`
mock_library {
name: "bar",
- visibility: ["//visibility:any_partition"],
+ visibility: ["//visibility:any_system_partition"],
}`),
},
expectedErrors: []string{`module "foo" variant "android_common": depends on //top/nested:bar which is not visible to this module`},
},
+ {
+ name: "any_system_partition visibility doesn't work for vendor partitions",
+ fs: MockFS{
+ "top/Android.bp": []byte(`
+ android_filesystem {
+ name: "foo",
+ partition_type: "vendor",
+ deps: ["bar"],
+ }`),
+ "top/nested/Android.bp": []byte(`
+ package(default_visibility=["//visibility:private"])
+ mock_library {
+ name: "bar",
+ visibility: ["//visibility:any_system_partition"],
+ }`),
+ },
+ expectedErrors: []string{`module "foo" variant "android_common": depends on //top/nested:bar which is not visible to this module`},
+ },
+ {
+ name: "Vendor modules are visible to any vendor partition by default",
+ fs: MockFS{
+ "top/Android.bp": []byte(`
+ android_filesystem {
+ name: "foo",
+ partition_type: "vendor",
+ deps: ["bar"],
+ }`),
+ "top/nested/Android.bp": []byte(`
+ package(default_visibility=["//visibility:private"])
+ mock_library {
+ name: "bar",
+ vendor: true,
+ }`),
+ },
+ },
+ {
+ name: "Not visible to vendor partitions when using any_system_partiton, even if vendor: true",
+ fs: MockFS{
+ "top/Android.bp": []byte(`
+ android_filesystem {
+ name: "foo",
+ partition_type: "vendor",
+ deps: ["bar"],
+ }`),
+ "top/nested/Android.bp": []byte(`
+ package(default_visibility=["//visibility:private"])
+ mock_library {
+ name: "bar",
+ vendor: true,
+ visibility: ["//visibility:any_system_partition"],
+ }`),
+ },
+ expectedErrors: []string{`module "foo" variant "android_common": depends on //top/nested:bar which is not visible to this module`},
+ },
+ {
+ name: "unknown any_partition specs throw errors",
+ fs: MockFS{
+ "top/nested/Android.bp": []byte(`
+ package(default_visibility=["//visibility:private"])
+ mock_library {
+ name: "bar",
+ visibility: ["//visibility:any_unknown_partition"],
+ }`),
+ },
+ expectedErrors: []string{`unrecognized visibility rule "//visibility:any_unknown_partition"`},
+ },
}
func TestVisibility(t *testing.T) {
@@ -1977,8 +2043,7 @@
ctx.RegisterModuleType("mock_library", newMockLibraryModule)
ctx.RegisterModuleType("mock_parent", newMockParentFactory)
ctx.RegisterModuleType("mock_defaults", defaultsFactory)
- // For testing //visibility:any_partition. The module type doesn't matter, just that it's registered under the name "android_filesystem"
- ctx.RegisterModuleType("android_filesystem", newMockLibraryModule)
+ ctx.RegisterModuleType("android_filesystem", newMockFilesystemModule)
}),
prepareForTestWithFakePrebuiltModules,
// Add additional files to the mock filesystem
@@ -2032,6 +2097,37 @@
func (p *mockLibraryModule) GenerateAndroidBuildActions(ModuleContext) {
}
+type mockFilesystemModuleProperties struct {
+ Partition_type *string
+ Deps []string
+}
+
+type mockFilesystemModule struct {
+ ModuleBase
+ properties mockFilesystemModuleProperties
+}
+
+func (j *mockFilesystemModule) DepsMutator(ctx BottomUpMutatorContext) {
+ ctx.AddVariationDependencies(nil, dependencyTag{name: "mockdeps"}, j.properties.Deps...)
+}
+
+func (p *mockFilesystemModule) GenerateAndroidBuildActions(ModuleContext) {
+}
+
+func (p *mockFilesystemModule) PartitionType() string {
+ if p.properties.Partition_type == nil {
+ return "system"
+ }
+ return *p.properties.Partition_type
+}
+
+func newMockFilesystemModule() Module {
+ m := &mockFilesystemModule{}
+ m.AddProperties(&m.properties)
+ InitAndroidArchModule(m, DeviceSupported, MultilibCommon)
+ return m
+}
+
type mockDefaults struct {
ModuleBase
DefaultsModuleBase