Ensure prebuilt modules have same visibility as source modules
Exports visibility and package mutator registration functions so they can be used in sdk testing. Updates sdk test to support visibility and package modules. Adds EffectiveVisibility(...)[]string function to make the effective visibility rules available to sdk snapshot creation. Extracts compositeRule.Strings() []string from compositeRule.String() method so that it can be used by above func. Adds visibility property to sdk snapshot and prebuilt modules along with a test to ensure it works properly. Adds dir parameter to CheckSnapshot so that it can check the snapshot generated for a non-root package. That is required in order to ensure that visibility of :__subpackages__ on a source module in package <pkg> is resolved to an effective visibility of //<pkg>:__subpackages__ on its corresponding prebuilt. Test: m conscrypt-module-sdk Bug: 143678475 Change-Id: Icaacac5b9c04726d28e6fec93e49715ac45df7f4
This commit is contained in:
@@ -164,7 +164,7 @@ func TestSnapshotWithCcShared(t *testing.T) {
|
||||
}
|
||||
`)
|
||||
|
||||
result.CheckSnapshot("mysdk", "android_common",
|
||||
result.CheckSnapshot("mysdk", "android_common", "",
|
||||
checkAndroidBpContents(`
|
||||
// This is auto-generated. DO NOT EDIT.
|
||||
|
||||
@@ -263,7 +263,7 @@ func TestHostSnapshotWithCcShared(t *testing.T) {
|
||||
}
|
||||
`)
|
||||
|
||||
result.CheckSnapshot("mysdk", "linux_glibc_common",
|
||||
result.CheckSnapshot("mysdk", "linux_glibc_common", "",
|
||||
checkAndroidBpContents(`
|
||||
// This is auto-generated. DO NOT EDIT.
|
||||
|
||||
|
@@ -123,7 +123,7 @@ func TestSnapshotWithJavaHeaderLibrary(t *testing.T) {
|
||||
}
|
||||
`)
|
||||
|
||||
result.CheckSnapshot("mysdk", "android_common",
|
||||
result.CheckSnapshot("mysdk", "android_common", "",
|
||||
checkAndroidBpContents(`
|
||||
// This is auto-generated. DO NOT EDIT.
|
||||
|
||||
@@ -178,7 +178,7 @@ func TestHostSnapshotWithJavaHeaderLibrary(t *testing.T) {
|
||||
}
|
||||
`)
|
||||
|
||||
result.CheckSnapshot("mysdk", "linux_glibc_common",
|
||||
result.CheckSnapshot("mysdk", "linux_glibc_common", "",
|
||||
checkAndroidBpContents(`
|
||||
// This is auto-generated. DO NOT EDIT.
|
||||
|
||||
@@ -232,7 +232,7 @@ func TestSnapshotWithJavaImplLibrary(t *testing.T) {
|
||||
}
|
||||
`)
|
||||
|
||||
result.CheckSnapshot("mysdk", "android_common",
|
||||
result.CheckSnapshot("mysdk", "android_common", "",
|
||||
checkAndroidBpContents(`
|
||||
// This is auto-generated. DO NOT EDIT.
|
||||
|
||||
@@ -287,7 +287,7 @@ func TestHostSnapshotWithJavaImplLibrary(t *testing.T) {
|
||||
}
|
||||
`)
|
||||
|
||||
result.CheckSnapshot("mysdk", "linux_glibc_common",
|
||||
result.CheckSnapshot("mysdk", "linux_glibc_common", "",
|
||||
checkAndroidBpContents(`
|
||||
// This is auto-generated. DO NOT EDIT.
|
||||
|
||||
@@ -379,7 +379,7 @@ func TestSnapshotWithDroidstubs(t *testing.T) {
|
||||
}
|
||||
`)
|
||||
|
||||
result.CheckSnapshot("mysdk", "android_common",
|
||||
result.CheckSnapshot("mysdk", "android_common", "",
|
||||
checkAndroidBpContents(`
|
||||
// This is auto-generated. DO NOT EDIT.
|
||||
|
||||
@@ -428,7 +428,7 @@ func TestHostSnapshotWithDroidstubs(t *testing.T) {
|
||||
}
|
||||
`)
|
||||
|
||||
result.CheckSnapshot("mysdk", "linux_glibc_common",
|
||||
result.CheckSnapshot("mysdk", "linux_glibc_common", "",
|
||||
checkAndroidBpContents(`
|
||||
// This is auto-generated. DO NOT EDIT.
|
||||
|
||||
|
120
sdk/sdk_test.go
120
sdk/sdk_test.go
@@ -79,3 +79,123 @@ func TestDepNotInRequiredSdks(t *testing.T) {
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
||||
// Ensure that prebuilt modules have the same effective visibility as the source
|
||||
// modules.
|
||||
func TestSnapshotVisibility(t *testing.T) {
|
||||
packageBp := `
|
||||
package {
|
||||
default_visibility: ["//other/foo"],
|
||||
}
|
||||
|
||||
sdk {
|
||||
name: "mysdk",
|
||||
visibility: [
|
||||
"//other/foo",
|
||||
// This short form will be replaced with //package:__subpackages__ in the
|
||||
// generated sdk_snapshot.
|
||||
":__subpackages__",
|
||||
],
|
||||
java_header_libs: [
|
||||
"myjavalib",
|
||||
"mypublicjavalib",
|
||||
"mydefaultedjavalib",
|
||||
],
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "myjavalib",
|
||||
// Uses package default visibility
|
||||
srcs: ["Test.java"],
|
||||
system_modules: "none",
|
||||
sdk_version: "none",
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "mypublicjavalib",
|
||||
visibility: ["//visibility:public"],
|
||||
srcs: ["Test.java"],
|
||||
system_modules: "none",
|
||||
sdk_version: "none",
|
||||
}
|
||||
|
||||
java_defaults {
|
||||
name: "myjavadefaults",
|
||||
visibility: ["//other/bar"],
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "mydefaultedjavalib",
|
||||
defaults: ["myjavadefaults"],
|
||||
srcs: ["Test.java"],
|
||||
system_modules: "none",
|
||||
sdk_version: "none",
|
||||
}
|
||||
`
|
||||
|
||||
result := testSdkWithFs(t, ``,
|
||||
map[string][]byte{
|
||||
"package/Test.java": nil,
|
||||
"package/Android.bp": []byte(packageBp),
|
||||
})
|
||||
|
||||
result.CheckSnapshot("mysdk", "android_common", "package",
|
||||
checkAndroidBpContents(`
|
||||
// This is auto-generated. DO NOT EDIT.
|
||||
|
||||
java_import {
|
||||
name: "mysdk_myjavalib@current",
|
||||
sdk_member_name: "myjavalib",
|
||||
visibility: ["//other/foo:__pkg__"],
|
||||
jars: ["java/myjavalib.jar"],
|
||||
}
|
||||
|
||||
java_import {
|
||||
name: "myjavalib",
|
||||
prefer: false,
|
||||
visibility: ["//other/foo:__pkg__"],
|
||||
jars: ["java/myjavalib.jar"],
|
||||
}
|
||||
|
||||
java_import {
|
||||
name: "mysdk_mypublicjavalib@current",
|
||||
sdk_member_name: "mypublicjavalib",
|
||||
visibility: ["//visibility:public"],
|
||||
jars: ["java/mypublicjavalib.jar"],
|
||||
}
|
||||
|
||||
java_import {
|
||||
name: "mypublicjavalib",
|
||||
prefer: false,
|
||||
visibility: ["//visibility:public"],
|
||||
jars: ["java/mypublicjavalib.jar"],
|
||||
}
|
||||
|
||||
java_import {
|
||||
name: "mysdk_mydefaultedjavalib@current",
|
||||
sdk_member_name: "mydefaultedjavalib",
|
||||
visibility: ["//other/bar:__pkg__"],
|
||||
jars: ["java/mydefaultedjavalib.jar"],
|
||||
}
|
||||
|
||||
java_import {
|
||||
name: "mydefaultedjavalib",
|
||||
prefer: false,
|
||||
visibility: ["//other/bar:__pkg__"],
|
||||
jars: ["java/mydefaultedjavalib.jar"],
|
||||
}
|
||||
|
||||
sdk_snapshot {
|
||||
name: "mysdk@current",
|
||||
visibility: [
|
||||
"//other/foo:__pkg__",
|
||||
"//package:__subpackages__",
|
||||
],
|
||||
java_header_libs: [
|
||||
"mysdk_myjavalib@current",
|
||||
"mysdk_mypublicjavalib@current",
|
||||
"mysdk_mydefaultedjavalib@current",
|
||||
],
|
||||
}
|
||||
`))
|
||||
}
|
||||
|
@@ -33,7 +33,12 @@ func testSdkContext(bp string, fs map[string][]byte) (*android.TestContext, andr
|
||||
ctx := android.NewTestArchContext()
|
||||
|
||||
// from android package
|
||||
ctx.PreArchMutators(android.RegisterPackageRenamer)
|
||||
ctx.PreArchMutators(android.RegisterVisibilityRuleChecker)
|
||||
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
|
||||
ctx.PreArchMutators(android.RegisterVisibilityRuleGatherer)
|
||||
ctx.PostDepsMutators(android.RegisterVisibilityRuleEnforcer)
|
||||
|
||||
ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
|
||||
ctx.BottomUp("prebuilts", android.PrebuiltMutator).Parallel()
|
||||
})
|
||||
@@ -41,9 +46,11 @@ func testSdkContext(bp string, fs map[string][]byte) (*android.TestContext, andr
|
||||
ctx.TopDown("prebuilt_select", android.PrebuiltSelectModuleMutator).Parallel()
|
||||
ctx.BottomUp("prebuilt_postdeps", android.PrebuiltPostDepsMutator).Parallel()
|
||||
})
|
||||
ctx.RegisterModuleType("package", android.PackageFactory)
|
||||
|
||||
// from java package
|
||||
ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory)
|
||||
ctx.RegisterModuleType("java_defaults", java.DefaultsFactory)
|
||||
ctx.RegisterModuleType("java_library", java.LibraryFactory)
|
||||
ctx.RegisterModuleType("java_import", java.ImportFactory)
|
||||
ctx.RegisterModuleType("droidstubs", java.DroidstubsFactory)
|
||||
@@ -115,7 +122,7 @@ func testSdkContext(bp string, fs map[string][]byte) (*android.TestContext, andr
|
||||
func testSdkWithFs(t *testing.T, bp string, fs map[string][]byte) *testSdkResult {
|
||||
t.Helper()
|
||||
ctx, config := testSdkContext(bp, fs)
|
||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
||||
_, errs := ctx.ParseBlueprintsFiles(".")
|
||||
android.FailIfErrored(t, errs)
|
||||
_, errs = ctx.PrepareBuildActions(config)
|
||||
android.FailIfErrored(t, errs)
|
||||
@@ -268,7 +275,7 @@ func (r *testSdkResult) pathsRelativeToBuildDir(paths android.Paths) []string {
|
||||
// Takes a list of functions which check different facets of the snapshot build rules.
|
||||
// Allows each test to customize what is checked without duplicating lots of code
|
||||
// or proliferating check methods of different flavors.
|
||||
func (r *testSdkResult) CheckSnapshot(name string, variant string, checkers ...snapshotBuildInfoChecker) {
|
||||
func (r *testSdkResult) CheckSnapshot(name string, variant string, dir string, checkers ...snapshotBuildInfoChecker) {
|
||||
r.t.Helper()
|
||||
|
||||
sdk := r.Module(name, variant).(*sdk)
|
||||
@@ -282,8 +289,11 @@ func (r *testSdkResult) CheckSnapshot(name string, variant string, checkers ...s
|
||||
|
||||
// Make sure that the generated zip file is in the correct place.
|
||||
actual := snapshotBuildInfo.outputZip
|
||||
if dir != "" {
|
||||
dir = filepath.Clean(dir) + "/"
|
||||
}
|
||||
r.AssertStringEquals("Snapshot zip file in wrong place",
|
||||
fmt.Sprintf(".intermediates/%s/%s/%s-current.zip", name, variant, name), actual)
|
||||
fmt.Sprintf(".intermediates/%s%s/%s/%s-current.zip", dir, name, variant, name), actual)
|
||||
|
||||
// Populate a mock filesystem with the files that would have been copied by
|
||||
// the rules.
|
||||
|
@@ -211,6 +211,13 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext) android.OutputPath {
|
||||
snapshotName := ctx.ModuleName() + string(android.SdkVersionSeparator) + builder.version
|
||||
snapshotModule := bpFile.newModule("sdk_snapshot")
|
||||
snapshotModule.AddProperty("name", snapshotName)
|
||||
|
||||
// Make sure that the snapshot has the same visibility as the sdk.
|
||||
visibility := android.EffectiveVisibilityRules(ctx, s)
|
||||
if len(visibility) != 0 {
|
||||
snapshotModule.AddProperty("visibility", visibility)
|
||||
}
|
||||
|
||||
addHostDeviceSupportedProperties(&s.ModuleBase, snapshotModule)
|
||||
for _, memberListProperty := range sdkMemberListProperties {
|
||||
names := memberListProperty.getter(&s.properties)
|
||||
@@ -376,6 +383,14 @@ func (s *snapshotBuilder) AddPrebuiltModule(member android.SdkMember, moduleType
|
||||
|
||||
m := s.bpFile.newModule(moduleType)
|
||||
m.AddProperty("name", name)
|
||||
|
||||
// Extract visibility information from a member variant. All variants have the same
|
||||
// visibility so it doesn't matter which one is used.
|
||||
visibility := android.EffectiveVisibilityRules(s.ctx, member.Variants()[0])
|
||||
if len(visibility) != 0 {
|
||||
m.AddProperty("visibility", visibility)
|
||||
}
|
||||
|
||||
addHostDeviceSupportedProperties(&s.sdk.ModuleBase, m)
|
||||
|
||||
s.prebuiltModules[name] = m
|
||||
|
Reference in New Issue
Block a user