Loading apex/testing.go +2 −0 Original line number Diff line number Diff line Loading @@ -25,5 +25,7 @@ var PrepareForTestWithApexBuildComponents = android.GroupFixturePreparers( // Needed by apex. "system/core/rootdir/etc/public.libraries.android.txt": nil, "build/soong/scripts/gen_ndk_backedby_apex.sh": nil, // Needed by prebuilt_apex. "build/soong/scripts/unpack-prebuilt-apex.sh": nil, }.AddToFixture(), ) java/boot_image.go +14 −0 Original line number Diff line number Diff line Loading @@ -319,19 +319,33 @@ func (b *bootImageMemberType) CreateVariantPropertiesStruct() android.SdkMemberP type bootImageSdkMemberProperties struct { android.SdkMemberPropertiesBase // The image name Image_name *string // Contents of the bootclasspath fragment Contents []string } func (b *bootImageSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { module := variant.(*BootImageModule) b.Image_name = module.properties.Image_name if b.Image_name == nil { // Only one of image_name or contents can be specified. However, if image_name is set then the // contents property is updated to match the configuration used to create the corresponding // boot image. Therefore, contents property is only copied if the image name is not specified. b.Contents = module.properties.Contents } } func (b *bootImageSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { if b.Image_name != nil { propertySet.AddProperty("image_name", *b.Image_name) } if len(b.Contents) > 0 { propertySet.AddPropertyWithTag("contents", b.Contents, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(true)) } } var _ android.SdkMemberType = (*bootImageMemberType)(nil) Loading java/testing.go +6 −0 Original line number Diff line number Diff line Loading @@ -200,6 +200,9 @@ func FixtureConfigureBootJars(bootJars ...string) android.FixturePreparer { }), dexpreopt.FixtureSetBootJars(bootJars...), dexpreopt.FixtureSetArtBootJars(artBootJars...), // Add a fake dex2oatd module. dexpreopt.PrepareForTestWithFakeDex2oatd, ) } Loading @@ -212,6 +215,9 @@ func FixtureConfigureUpdatableBootJars(bootJars ...string) android.FixturePrepar variables.UpdatableBootJars = android.CreateTestConfiguredJarList(bootJars) }), dexpreopt.FixtureSetUpdatableBootJars(bootJars...), // Add a fake dex2oatd module. dexpreopt.PrepareForTestWithFakeDex2oatd, ) } Loading sdk/bootclasspath_fragment_sdk_test.go +149 −4 Original line number Diff line number Diff line Loading @@ -18,20 +18,56 @@ import ( "testing" "android/soong/android" "android/soong/java" ) func TestSnapshotWithBootclasspathFragment(t *testing.T) { func TestSnapshotWithBootclasspathFragment_ImageName(t *testing.T) { result := android.GroupFixturePreparers( prepareForSdkTestWithJava, prepareForSdkTestWithApex, // Some additional files needed for the art apex. android.FixtureMergeMockFs(android.MockFS{ "com.android.art.avbpubkey": nil, "com.android.art.pem": nil, "system/sepolicy/apex/com.android.art-file_contexts": nil, }), java.FixtureConfigureBootJars("com.android.art:mybootlib"), android.FixtureWithRootAndroidBp(` sdk { name: "mysdk", bootclasspath_fragments: ["mybootclasspathfragment"], java_boot_libs: ["mybootlib"], } apex { name: "com.android.art", key: "com.android.art.key", bootclasspath_fragments: [ "mybootclasspathfragment", ], updatable: false, } bootclasspath_fragment { name: "mybootclasspathfragment", image_name: "art", apex_available: ["com.android.art"], } apex_key { name: "com.android.art.key", public_key: "com.android.art.avbpubkey", private_key: "com.android.art.pem", } java_library { name: "mybootlib", srcs: ["Test.java"], system_modules: "none", sdk_version: "none", compile_dex: true, apex_available: ["com.android.art"], } `), ).RunTest(t) Loading @@ -44,9 +80,17 @@ prebuilt_bootclasspath_fragment { name: "mybootclasspathfragment", prefer: false, visibility: ["//visibility:public"], apex_available: ["//apex_available:platform"], apex_available: ["com.android.art"], image_name: "art", } java_import { name: "mybootlib", prefer: false, visibility: ["//visibility:public"], apex_available: ["com.android.art"], jars: ["java/mybootlib.jar"], } `), checkVersionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. Loading @@ -55,17 +99,118 @@ prebuilt_bootclasspath_fragment { name: "mysdk_mybootclasspathfragment@current", sdk_member_name: "mybootclasspathfragment", visibility: ["//visibility:public"], apex_available: ["//apex_available:platform"], apex_available: ["com.android.art"], image_name: "art", } java_import { name: "mysdk_mybootlib@current", sdk_member_name: "mybootlib", visibility: ["//visibility:public"], apex_available: ["com.android.art"], jars: ["java/mybootlib.jar"], } sdk_snapshot { name: "mysdk@current", visibility: ["//visibility:public"], bootclasspath_fragments: ["mysdk_mybootclasspathfragment@current"], java_boot_libs: ["mysdk_mybootlib@current"], } `), checkAllCopyRules(` .intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar `), snapshotTestPreparer(checkSnapshotPreferredWithSource, android.GroupFixturePreparers( android.FixtureAddTextFile("prebuilts/apex/Android.bp", ` prebuilt_apex { name: "com.android.art", src: "art.apex", exported_java_libs: [ "mybootlib", ], } `), android.FixtureAddFile("prebuilts/apex/art.apex", nil), ), ), ) } func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) { result := android.GroupFixturePreparers( prepareForSdkTestWithJava, android.FixtureWithRootAndroidBp(` sdk { name: "mysdk", bootclasspath_fragments: ["mybootclasspathfragment"], java_boot_libs: ["mybootlib"], } bootclasspath_fragment { name: "mybootclasspathfragment", contents: ["mybootlib"], } java_library { name: "mybootlib", srcs: ["Test.java"], system_modules: "none", sdk_version: "none", compile_dex: true, } `), ).RunTest(t) CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. prebuilt_bootclasspath_fragment { name: "mybootclasspathfragment", prefer: false, visibility: ["//visibility:public"], apex_available: ["//apex_available:platform"], contents: ["mybootlib"], } java_import { name: "mybootlib", prefer: false, visibility: ["//visibility:public"], apex_available: ["//apex_available:platform"], jars: ["java/mybootlib.jar"], } `), checkVersionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. prebuilt_bootclasspath_fragment { name: "mysdk_mybootclasspathfragment@current", sdk_member_name: "mybootclasspathfragment", visibility: ["//visibility:public"], apex_available: ["//apex_available:platform"], contents: ["mysdk_mybootlib@current"], } java_import { name: "mysdk_mybootlib@current", sdk_member_name: "mybootlib", visibility: ["//visibility:public"], apex_available: ["//apex_available:platform"], jars: ["java/mybootlib.jar"], } sdk_snapshot { name: "mysdk@current", visibility: ["//visibility:public"], bootclasspath_fragments: ["mysdk_mybootclasspathfragment@current"], java_boot_libs: ["mysdk_mybootlib@current"], } `), checkAllCopyRules("")) checkAllCopyRules(` .intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar `)) } // Test that bootclasspath_fragment works with sdk. Loading sdk/testing.go +14 −1 Original line number Diff line number Diff line Loading @@ -255,13 +255,14 @@ func CheckSnapshot(t *testing.T, result *android.TestResult, name string, dir st var runSnapshotTestWithCheckers = func(t *testing.T, testConfig snapshotTest, extraPreparer android.FixturePreparer) { customization := snapshotBuildInfo.snapshotTestCustomization(testConfig) customizedPreparers := android.GroupFixturePreparers(customization.preparers...) // TODO(b/183184375): Set Config.TestAllowNonExistentPaths = false to verify that all the // files the snapshot needs are actually copied into the snapshot. // Run the snapshot with the snapshot preparer and the extra preparer, which must come after as // it may need to modify parts of the MockFS populated by the snapshot preparer. result := android.GroupFixturePreparers(snapshotPreparer, extraPreparer). result := android.GroupFixturePreparers(snapshotPreparer, extraPreparer, customizedPreparers). ExtendWithErrorHandler(customization.errorHandler). RunTest(t) Loading Loading @@ -369,6 +370,15 @@ func checkMergeZips(expected ...string) snapshotBuildInfoChecker { type resultChecker func(t *testing.T, result *android.TestResult) // snapshotTestPreparer registers a preparer that will be used to customize the specified // snapshotTest. func snapshotTestPreparer(snapshotTest snapshotTest, preparer android.FixturePreparer) snapshotBuildInfoChecker { return func(info *snapshotBuildInfo) { customization := info.snapshotTestCustomization(snapshotTest) customization.preparers = append(customization.preparers, preparer) } } // snapshotTestChecker registers a checker that will be run against the result of processing the // generated snapshot for the specified snapshotTest. func snapshotTestChecker(snapshotTest snapshotTest, checker resultChecker) snapshotBuildInfoChecker { Loading @@ -395,6 +405,9 @@ func snapshotTestErrorHandler(snapshotTest snapshotTest, handler android.Fixture // Encapsulates information provided by each test to customize a specific snapshotTest. type snapshotTestCustomization struct { // Preparers that are used to customize the test fixture before running the test. preparers []android.FixturePreparer // Checkers that are run on the result of processing the preferred snapshot in a specific test // case. checkers []resultChecker Loading Loading
apex/testing.go +2 −0 Original line number Diff line number Diff line Loading @@ -25,5 +25,7 @@ var PrepareForTestWithApexBuildComponents = android.GroupFixturePreparers( // Needed by apex. "system/core/rootdir/etc/public.libraries.android.txt": nil, "build/soong/scripts/gen_ndk_backedby_apex.sh": nil, // Needed by prebuilt_apex. "build/soong/scripts/unpack-prebuilt-apex.sh": nil, }.AddToFixture(), )
java/boot_image.go +14 −0 Original line number Diff line number Diff line Loading @@ -319,19 +319,33 @@ func (b *bootImageMemberType) CreateVariantPropertiesStruct() android.SdkMemberP type bootImageSdkMemberProperties struct { android.SdkMemberPropertiesBase // The image name Image_name *string // Contents of the bootclasspath fragment Contents []string } func (b *bootImageSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { module := variant.(*BootImageModule) b.Image_name = module.properties.Image_name if b.Image_name == nil { // Only one of image_name or contents can be specified. However, if image_name is set then the // contents property is updated to match the configuration used to create the corresponding // boot image. Therefore, contents property is only copied if the image name is not specified. b.Contents = module.properties.Contents } } func (b *bootImageSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { if b.Image_name != nil { propertySet.AddProperty("image_name", *b.Image_name) } if len(b.Contents) > 0 { propertySet.AddPropertyWithTag("contents", b.Contents, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(true)) } } var _ android.SdkMemberType = (*bootImageMemberType)(nil) Loading
java/testing.go +6 −0 Original line number Diff line number Diff line Loading @@ -200,6 +200,9 @@ func FixtureConfigureBootJars(bootJars ...string) android.FixturePreparer { }), dexpreopt.FixtureSetBootJars(bootJars...), dexpreopt.FixtureSetArtBootJars(artBootJars...), // Add a fake dex2oatd module. dexpreopt.PrepareForTestWithFakeDex2oatd, ) } Loading @@ -212,6 +215,9 @@ func FixtureConfigureUpdatableBootJars(bootJars ...string) android.FixturePrepar variables.UpdatableBootJars = android.CreateTestConfiguredJarList(bootJars) }), dexpreopt.FixtureSetUpdatableBootJars(bootJars...), // Add a fake dex2oatd module. dexpreopt.PrepareForTestWithFakeDex2oatd, ) } Loading
sdk/bootclasspath_fragment_sdk_test.go +149 −4 Original line number Diff line number Diff line Loading @@ -18,20 +18,56 @@ import ( "testing" "android/soong/android" "android/soong/java" ) func TestSnapshotWithBootclasspathFragment(t *testing.T) { func TestSnapshotWithBootclasspathFragment_ImageName(t *testing.T) { result := android.GroupFixturePreparers( prepareForSdkTestWithJava, prepareForSdkTestWithApex, // Some additional files needed for the art apex. android.FixtureMergeMockFs(android.MockFS{ "com.android.art.avbpubkey": nil, "com.android.art.pem": nil, "system/sepolicy/apex/com.android.art-file_contexts": nil, }), java.FixtureConfigureBootJars("com.android.art:mybootlib"), android.FixtureWithRootAndroidBp(` sdk { name: "mysdk", bootclasspath_fragments: ["mybootclasspathfragment"], java_boot_libs: ["mybootlib"], } apex { name: "com.android.art", key: "com.android.art.key", bootclasspath_fragments: [ "mybootclasspathfragment", ], updatable: false, } bootclasspath_fragment { name: "mybootclasspathfragment", image_name: "art", apex_available: ["com.android.art"], } apex_key { name: "com.android.art.key", public_key: "com.android.art.avbpubkey", private_key: "com.android.art.pem", } java_library { name: "mybootlib", srcs: ["Test.java"], system_modules: "none", sdk_version: "none", compile_dex: true, apex_available: ["com.android.art"], } `), ).RunTest(t) Loading @@ -44,9 +80,17 @@ prebuilt_bootclasspath_fragment { name: "mybootclasspathfragment", prefer: false, visibility: ["//visibility:public"], apex_available: ["//apex_available:platform"], apex_available: ["com.android.art"], image_name: "art", } java_import { name: "mybootlib", prefer: false, visibility: ["//visibility:public"], apex_available: ["com.android.art"], jars: ["java/mybootlib.jar"], } `), checkVersionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. Loading @@ -55,17 +99,118 @@ prebuilt_bootclasspath_fragment { name: "mysdk_mybootclasspathfragment@current", sdk_member_name: "mybootclasspathfragment", visibility: ["//visibility:public"], apex_available: ["//apex_available:platform"], apex_available: ["com.android.art"], image_name: "art", } java_import { name: "mysdk_mybootlib@current", sdk_member_name: "mybootlib", visibility: ["//visibility:public"], apex_available: ["com.android.art"], jars: ["java/mybootlib.jar"], } sdk_snapshot { name: "mysdk@current", visibility: ["//visibility:public"], bootclasspath_fragments: ["mysdk_mybootclasspathfragment@current"], java_boot_libs: ["mysdk_mybootlib@current"], } `), checkAllCopyRules(` .intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar `), snapshotTestPreparer(checkSnapshotPreferredWithSource, android.GroupFixturePreparers( android.FixtureAddTextFile("prebuilts/apex/Android.bp", ` prebuilt_apex { name: "com.android.art", src: "art.apex", exported_java_libs: [ "mybootlib", ], } `), android.FixtureAddFile("prebuilts/apex/art.apex", nil), ), ), ) } func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) { result := android.GroupFixturePreparers( prepareForSdkTestWithJava, android.FixtureWithRootAndroidBp(` sdk { name: "mysdk", bootclasspath_fragments: ["mybootclasspathfragment"], java_boot_libs: ["mybootlib"], } bootclasspath_fragment { name: "mybootclasspathfragment", contents: ["mybootlib"], } java_library { name: "mybootlib", srcs: ["Test.java"], system_modules: "none", sdk_version: "none", compile_dex: true, } `), ).RunTest(t) CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. prebuilt_bootclasspath_fragment { name: "mybootclasspathfragment", prefer: false, visibility: ["//visibility:public"], apex_available: ["//apex_available:platform"], contents: ["mybootlib"], } java_import { name: "mybootlib", prefer: false, visibility: ["//visibility:public"], apex_available: ["//apex_available:platform"], jars: ["java/mybootlib.jar"], } `), checkVersionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. prebuilt_bootclasspath_fragment { name: "mysdk_mybootclasspathfragment@current", sdk_member_name: "mybootclasspathfragment", visibility: ["//visibility:public"], apex_available: ["//apex_available:platform"], contents: ["mysdk_mybootlib@current"], } java_import { name: "mysdk_mybootlib@current", sdk_member_name: "mybootlib", visibility: ["//visibility:public"], apex_available: ["//apex_available:platform"], jars: ["java/mybootlib.jar"], } sdk_snapshot { name: "mysdk@current", visibility: ["//visibility:public"], bootclasspath_fragments: ["mysdk_mybootclasspathfragment@current"], java_boot_libs: ["mysdk_mybootlib@current"], } `), checkAllCopyRules("")) checkAllCopyRules(` .intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar `)) } // Test that bootclasspath_fragment works with sdk. Loading
sdk/testing.go +14 −1 Original line number Diff line number Diff line Loading @@ -255,13 +255,14 @@ func CheckSnapshot(t *testing.T, result *android.TestResult, name string, dir st var runSnapshotTestWithCheckers = func(t *testing.T, testConfig snapshotTest, extraPreparer android.FixturePreparer) { customization := snapshotBuildInfo.snapshotTestCustomization(testConfig) customizedPreparers := android.GroupFixturePreparers(customization.preparers...) // TODO(b/183184375): Set Config.TestAllowNonExistentPaths = false to verify that all the // files the snapshot needs are actually copied into the snapshot. // Run the snapshot with the snapshot preparer and the extra preparer, which must come after as // it may need to modify parts of the MockFS populated by the snapshot preparer. result := android.GroupFixturePreparers(snapshotPreparer, extraPreparer). result := android.GroupFixturePreparers(snapshotPreparer, extraPreparer, customizedPreparers). ExtendWithErrorHandler(customization.errorHandler). RunTest(t) Loading Loading @@ -369,6 +370,15 @@ func checkMergeZips(expected ...string) snapshotBuildInfoChecker { type resultChecker func(t *testing.T, result *android.TestResult) // snapshotTestPreparer registers a preparer that will be used to customize the specified // snapshotTest. func snapshotTestPreparer(snapshotTest snapshotTest, preparer android.FixturePreparer) snapshotBuildInfoChecker { return func(info *snapshotBuildInfo) { customization := info.snapshotTestCustomization(snapshotTest) customization.preparers = append(customization.preparers, preparer) } } // snapshotTestChecker registers a checker that will be run against the result of processing the // generated snapshot for the specified snapshotTest. func snapshotTestChecker(snapshotTest snapshotTest, checker resultChecker) snapshotBuildInfoChecker { Loading @@ -395,6 +405,9 @@ func snapshotTestErrorHandler(snapshotTest snapshotTest, handler android.Fixture // Encapsulates information provided by each test to customize a specific snapshotTest. type snapshotTestCustomization struct { // Preparers that are used to customize the test fixture before running the test. preparers []android.FixturePreparer // Checkers that are run on the result of processing the preferred snapshot in a specific test // case. checkers []resultChecker Loading