From b69e89559fe02bcd010f25c3cf2449d30200a761 Mon Sep 17 00:00:00 2001 From: Jiakai Zhang Date: Tue, 11 Jul 2023 14:31:22 +0100 Subject: [PATCH 1/5] Fix some tests for dexpreopt and remove unnecessary tests. This CL is to prepare for the changes in http://r.android.com/2652081. See the description of that CL for the reasons. Some tests were set up in a fragile way and were easy to be broken when the implementation changes. This CL is a pure test change that fixes them. This CL also removes TestNoUpdatableJarsInBootImage. That test checks what should go to the ART boot image and what should go to the platform one, which does not apply today because boot images are not associated with mainline modules anymore: a boot image may take jars from multiple mainline modules and the platform, and a mainline module can contribute to multiple boot images. In practice, we have ART jars in the platform boot image, and we are going to add core-icu4j and consrypt to the ART boot image, which is now for testing only. Bug: 290583827 Test: m nothing Change-Id: I22c45cbf6f853b030b68edb51197854e9c53a02e --- apex/apex_test.go | 309 +++++-------------------- apex/bootclasspath_fragment_test.go | 114 +++++---- apex/dexpreopt_bootjars_test.go | 4 +- java/bootclasspath_fragment_test.go | 35 +++ java/dexpreopt_config_testing.go | 27 ++- sdk/bootclasspath_fragment_sdk_test.go | 32 +-- 6 files changed, 186 insertions(+), 335 deletions(-) diff --git a/apex/apex_test.go b/apex/apex_test.go index b67535a18..f7a4dea72 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -5587,6 +5587,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { checkHiddenAPIIndexFromFlagsInputs(t, ctx, ` my-bootclasspath-fragment/index.csv out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/index-from-classes.csv + out/soong/.intermediates/packages/modules/com.android.art/art-bootclasspath-fragment/android_common_apex10000/modular-hiddenapi/index.csv `) }) @@ -5664,6 +5665,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { checkHiddenAPIIndexFromFlagsInputs(t, ctx, ` my-bootclasspath-fragment/index.csv out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/index-from-classes.csv + out/soong/.intermediates/packages/modules/com.android.art/art-bootclasspath-fragment/android_common_apex10000/modular-hiddenapi/index.csv `) myApex := ctx.ModuleForTests("myapex", "android_common_myapex").Module() @@ -5758,6 +5760,28 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { t.Run("prebuilt library preferred with source", func(t *testing.T) { bp := ` + apex { + name: "myapex", + key: "myapex.key", + updatable: false, + bootclasspath_fragments: ["my-bootclasspath-fragment"], + } + + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + + bootclasspath_fragment { + name: "my-bootclasspath-fragment", + contents: ["libfoo", "libbar"], + apex_available: ["myapex"], + hidden_api: { + split_packages: ["*"], + }, + } + prebuilt_apex { name: "myapex", arch: { @@ -5773,6 +5797,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { prebuilt_bootclasspath_fragment { name: "my-bootclasspath-fragment", + prefer: true, contents: ["libfoo", "libbar"], apex_available: ["myapex"], hidden_api: { @@ -5797,6 +5822,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { name: "libfoo", srcs: ["foo/bar/MyClass.java"], apex_available: ["myapex"], + installable: true, } java_sdk_library_import { @@ -5815,6 +5841,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { srcs: ["foo/bar/MyClass.java"], unsafe_ignore_missing_latest_api: true, apex_available: ["myapex"], + compile_dex: true, } ` @@ -5827,6 +5854,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { checkHiddenAPIIndexFromFlagsInputs(t, ctx, ` my-bootclasspath-fragment/index.csv out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/index-from-classes.csv + out/soong/.intermediates/packages/modules/com.android.art/art-bootclasspath-fragment/android_common_apex10000/modular-hiddenapi/index.csv `) }) @@ -5835,8 +5863,8 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { apex { name: "myapex", key: "myapex.key", - java_libs: ["libfoo", "libbar"], updatable: false, + bootclasspath_fragments: ["my-bootclasspath-fragment"], } apex_key { @@ -5845,6 +5873,15 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { private_key: "testkey.pem", } + bootclasspath_fragment { + name: "my-bootclasspath-fragment", + contents: ["libfoo", "libbar"], + apex_available: ["myapex"], + hidden_api: { + split_packages: ["*"], + }, + } + prebuilt_apex { name: "myapex", arch: { @@ -5883,6 +5920,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { srcs: ["foo/bar/MyClass.java"], apex_available: ["myapex"], permitted_packages: ["foo"], + installable: true, } java_sdk_library_import { @@ -5900,6 +5938,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { unsafe_ignore_missing_latest_api: true, apex_available: ["myapex"], permitted_packages: ["bar"], + compile_dex: true, } ` @@ -5910,8 +5949,9 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { // Verify the correct module jars contribute to the hiddenapi index file. checkHiddenAPIIndexFromClassesInputs(t, ctx, ``) checkHiddenAPIIndexFromFlagsInputs(t, ctx, ` - my-bootclasspath-fragment/index.csv out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/index-from-classes.csv + out/soong/.intermediates/my-bootclasspath-fragment/android_common_myapex/modular-hiddenapi/index.csv + out/soong/.intermediates/packages/modules/com.android.art/art-bootclasspath-fragment/android_common_apex10000/modular-hiddenapi/index.csv `) }) @@ -5921,7 +5961,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { name: "myapex", enabled: false, key: "myapex.key", - java_libs: ["libfoo", "libbar"], + bootclasspath_fragments: ["my-bootclasspath-fragment"], } apex_key { @@ -5930,6 +5970,16 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { private_key: "testkey.pem", } + bootclasspath_fragment { + name: "my-bootclasspath-fragment", + enabled: false, + contents: ["libfoo", "libbar"], + apex_available: ["myapex"], + hidden_api: { + split_packages: ["*"], + }, + } + prebuilt_apex { name: "myapex", arch: { @@ -5959,7 +6009,6 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { java_import { name: "libfoo", - prefer: true, jars: ["libfoo.jar"], apex_available: ["myapex"], permitted_packages: ["foo"], @@ -5967,13 +6016,14 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { java_library { name: "libfoo", + enabled: false, srcs: ["foo/bar/MyClass.java"], apex_available: ["myapex"], + installable: true, } java_sdk_library_import { name: "libbar", - prefer: true, public: { jars: ["libbar.jar"], }, @@ -5984,9 +6034,11 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { java_sdk_library { name: "libbar", + enabled: false, srcs: ["foo/bar/MyClass.java"], unsafe_ignore_missing_latest_api: true, apex_available: ["myapex"], + compile_dex: true, } ` @@ -5999,6 +6051,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { checkHiddenAPIIndexFromFlagsInputs(t, ctx, ` my-bootclasspath-fragment/index.csv out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/index-from-classes.csv + out/soong/.intermediates/packages/modules/com.android.art/art-bootclasspath-fragment/android_common_apex10000/modular-hiddenapi/index.csv `) }) } @@ -8163,126 +8216,6 @@ func TestApexSetApksModuleAssignment(t *testing.T) { android.AssertArrayString(t, "extractor input", []string{"myapex.apks"}, extractedApex.Inputs.Strings()) } -func testNoUpdatableJarsInBootImage(t *testing.T, errmsg string, preparer android.FixturePreparer, fragments ...java.ApexVariantReference) { - t.Helper() - - bp := ` - java_library { - name: "some-updatable-apex-lib", - srcs: ["a.java"], - sdk_version: "current", - apex_available: [ - "some-updatable-apex", - ], - permitted_packages: ["some.updatable.apex.lib"], - min_sdk_version: "33", - } - - java_library { - name: "some-non-updatable-apex-lib", - srcs: ["a.java"], - apex_available: [ - "some-non-updatable-apex", - ], - compile_dex: true, - permitted_packages: ["some.non.updatable.apex.lib"], - } - - bootclasspath_fragment { - name: "some-non-updatable-fragment", - contents: ["some-non-updatable-apex-lib"], - apex_available: [ - "some-non-updatable-apex", - ], - hidden_api: { - split_packages: ["*"], - }, - } - - java_library { - name: "some-platform-lib", - srcs: ["a.java"], - sdk_version: "current", - installable: true, - } - - java_library { - name: "some-art-lib", - srcs: ["a.java"], - sdk_version: "current", - apex_available: [ - "com.android.art.debug", - ], - hostdex: true, - compile_dex: true, - min_sdk_version: "33", - } - - apex { - name: "some-updatable-apex", - key: "some-updatable-apex.key", - java_libs: ["some-updatable-apex-lib"], - updatable: true, - min_sdk_version: "33", - } - - apex { - name: "some-non-updatable-apex", - key: "some-non-updatable-apex.key", - bootclasspath_fragments: ["some-non-updatable-fragment"], - updatable: false, - } - - apex_key { - name: "some-updatable-apex.key", - } - - apex_key { - name: "some-non-updatable-apex.key", - } - - apex { - name: "com.android.art.debug", - key: "com.android.art.debug.key", - bootclasspath_fragments: ["art-bootclasspath-fragment"], - updatable: true, - min_sdk_version: "33", - } - - bootclasspath_fragment { - name: "art-bootclasspath-fragment", - image_name: "art", - contents: ["some-art-lib"], - apex_available: [ - "com.android.art.debug", - ], - hidden_api: { - split_packages: ["*"], - }, - } - - apex_key { - name: "com.android.art.debug.key", - } - - filegroup { - name: "some-updatable-apex-file_contexts", - srcs: [ - "system/sepolicy/apex/some-updatable-apex-file_contexts", - ], - } - - filegroup { - name: "some-non-updatable-apex-file_contexts", - srcs: [ - "system/sepolicy/apex/some-non-updatable-apex-file_contexts", - ], - } - ` - - testDexpreoptWithApexes(t, bp, errmsg, preparer, fragments...) -} - func testDexpreoptWithApexes(t *testing.T, bp, errmsg string, preparer android.FixturePreparer, fragments ...java.ApexVariantReference) *android.TestContext { t.Helper() @@ -8306,7 +8239,7 @@ func testDexpreoptWithApexes(t *testing.T, bp, errmsg string, preparer android.F result := android.GroupFixturePreparers( cc.PrepareForTestWithCcDefaultModules, java.PrepareForTestWithHiddenApiBuildComponents, - java.PrepareForTestWithJavaDefaultModules, + java.PrepareForTestWithDexpreopt, java.PrepareForTestWithJavaSdkLibraryFiles, PrepareForTestWithApexBuildComponents, preparer, @@ -8321,12 +8254,16 @@ func testDexpreoptWithApexes(t *testing.T, bp, errmsg string, preparer android.F platform_bootclasspath { name: "platform-bootclasspath", fragments: [ + {apex: "com.android.art", module: "art-bootclasspath-fragment"}, %s ], } `, insert)) } }), + // Dexpreopt for boot jars requires the ART boot image profile. + java.PrepareApexBootJarModule("com.android.art", "core-oj"), + dexpreopt.FixtureSetArtBootJars("com.android.art:core-oj"), dexpreopt.FixtureSetBootImageProfiles("art/build/boot/boot-image-profile.txt"), ). ExtendWithErrorHandler(errorHandler). @@ -8633,126 +8570,6 @@ func TestUpdatable_should_not_set_generate_classpaths_proto(t *testing.T) { ) } -func TestNoUpdatableJarsInBootImage(t *testing.T) { - // Set the BootJars in dexpreopt.GlobalConfig and productVariables to the same value. This can - // result in an invalid configuration as it does not set the ArtApexJars and allows art apex - // modules to be included in the BootJars. - prepareSetBootJars := func(bootJars ...string) android.FixturePreparer { - return android.GroupFixturePreparers( - dexpreopt.FixtureSetBootJars(bootJars...), - android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { - variables.BootJars = android.CreateTestConfiguredJarList(bootJars) - }), - ) - } - - // Set the ArtApexJars and BootJars in dexpreopt.GlobalConfig and productVariables all to the - // same value. This can result in an invalid configuration as it allows non art apex jars to be - // specified in the ArtApexJars configuration. - prepareSetArtJars := func(bootJars ...string) android.FixturePreparer { - return android.GroupFixturePreparers( - dexpreopt.FixtureSetArtBootJars(bootJars...), - dexpreopt.FixtureSetBootJars(bootJars...), - android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { - variables.BootJars = android.CreateTestConfiguredJarList(bootJars) - }), - ) - } - - t.Run("updatable jar from ART apex in the ART boot image => ok", func(t *testing.T) { - preparer := android.GroupFixturePreparers( - java.FixtureConfigureBootJars("com.android.art.debug:some-art-lib"), - java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib"), - ) - fragments := []java.ApexVariantReference{ - { - Apex: proptools.StringPtr("com.android.art.debug"), - Module: proptools.StringPtr("art-bootclasspath-fragment"), - }, - { - Apex: proptools.StringPtr("some-non-updatable-apex"), - Module: proptools.StringPtr("some-non-updatable-fragment"), - }, - } - testNoUpdatableJarsInBootImage(t, "", preparer, fragments...) - }) - - t.Run("updatable jar from ART apex in the platform bootclasspath => error", func(t *testing.T) { - err := `module "some-art-lib" from updatable apexes \["com.android.art.debug"\] is not allowed in the platform bootclasspath` - // Update the dexpreopt BootJars directly. - preparer := android.GroupFixturePreparers( - prepareSetBootJars("com.android.art.debug:some-art-lib"), - java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib"), - ) - testNoUpdatableJarsInBootImage(t, err, preparer) - }) - - t.Run("updatable jar from some other apex in the ART boot image => error", func(t *testing.T) { - err := `ArtApexJars expects this to be in apex "some-updatable-apex" but this is only in apexes.*"com.android.art.debug"` - // Update the dexpreopt ArtApexJars directly. - preparer := prepareSetArtJars("some-updatable-apex:some-updatable-apex-lib") - testNoUpdatableJarsInBootImage(t, err, preparer) - }) - - t.Run("non-updatable jar from some other apex in the ART boot image => error", func(t *testing.T) { - err := `ArtApexJars expects this to be in apex "some-non-updatable-apex" but this is only in apexes.*"com.android.art.debug"` - // Update the dexpreopt ArtApexJars directly. - preparer := prepareSetArtJars("some-non-updatable-apex:some-non-updatable-apex-lib") - testNoUpdatableJarsInBootImage(t, err, preparer) - }) - - t.Run("updatable jar from some other apex in the platform bootclasspath => error", func(t *testing.T) { - err := `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the platform bootclasspath` - preparer := android.GroupFixturePreparers( - java.FixtureConfigureBootJars("some-updatable-apex:some-updatable-apex-lib"), - java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib"), - ) - testNoUpdatableJarsInBootImage(t, err, preparer) - }) - - t.Run("non-updatable jar from some other apex in the platform bootclasspath => ok", func(t *testing.T) { - preparer := java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib") - fragment := java.ApexVariantReference{ - Apex: proptools.StringPtr("some-non-updatable-apex"), - Module: proptools.StringPtr("some-non-updatable-fragment"), - } - testNoUpdatableJarsInBootImage(t, "", preparer, fragment) - }) - - t.Run("nonexistent jar in the ART boot image => error", func(t *testing.T) { - err := `"platform-bootclasspath" depends on undefined module "nonexistent"` - preparer := java.FixtureConfigureBootJars("platform:nonexistent") - testNoUpdatableJarsInBootImage(t, err, preparer) - }) - - t.Run("nonexistent jar in the platform bootclasspath => error", func(t *testing.T) { - err := `"platform-bootclasspath" depends on undefined module "nonexistent"` - preparer := java.FixtureConfigureBootJars("platform:nonexistent") - testNoUpdatableJarsInBootImage(t, err, preparer) - }) - - t.Run("platform jar in the ART boot image => error", func(t *testing.T) { - err := `ArtApexJars is invalid as it requests a platform variant of "some-platform-lib"` - // Update the dexpreopt ArtApexJars directly. - preparer := prepareSetArtJars("platform:some-platform-lib") - testNoUpdatableJarsInBootImage(t, err, preparer) - }) - - t.Run("platform jar in the platform bootclasspath => ok", func(t *testing.T) { - preparer := android.GroupFixturePreparers( - java.FixtureConfigureBootJars("platform:some-platform-lib"), - java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib"), - ) - fragments := []java.ApexVariantReference{ - { - Apex: proptools.StringPtr("some-non-updatable-apex"), - Module: proptools.StringPtr("some-non-updatable-fragment"), - }, - } - testNoUpdatableJarsInBootImage(t, "", preparer, fragments...) - }) -} - func TestDexpreoptAccessDexFilesFromPrebuiltApex(t *testing.T) { preparer := java.FixtureConfigureApexBootJars("myapex:libfoo") t.Run("prebuilt no source", func(t *testing.T) { diff --git a/apex/bootclasspath_fragment_test.go b/apex/bootclasspath_fragment_test.go index 1b5288696..53afbb577 100644 --- a/apex/bootclasspath_fragment_test.go +++ b/apex/bootclasspath_fragment_test.go @@ -268,10 +268,10 @@ func TestBootclasspathFragmentInArtApex(t *testing.T) { name: "com.android.art", key: "com.android.art.key", bootclasspath_fragments: [ - "mybootclasspathfragment", + "art-bootclasspath-fragment", ], // bar (like foo) should be transitively included in this apex because it is part of the - // mybootclasspathfragment bootclasspath_fragment. + // art-bootclasspath-fragment bootclasspath_fragment. updatable: false, } @@ -280,42 +280,6 @@ func TestBootclasspathFragmentInArtApex(t *testing.T) { public_key: "testkey.avbpubkey", private_key: "testkey.pem", } - - java_library { - name: "foo", - srcs: ["b.java"], - installable: true, - apex_available: [ - "com.android.art", - ], - } - - java_library { - name: "bar", - srcs: ["b.java"], - installable: true, - apex_available: [ - "com.android.art", - ], - } - - java_import { - name: "foo", - jars: ["foo.jar"], - apex_available: [ - "com.android.art", - ], - compile_dex: true, - } - - java_import { - name: "bar", - jars: ["bar.jar"], - apex_available: [ - "com.android.art", - ], - compile_dex: true, - } `), ) @@ -330,7 +294,7 @@ func TestBootclasspathFragmentInArtApex(t *testing.T) { addSource := func(contents ...string) android.FixturePreparer { text := fmt.Sprintf(` bootclasspath_fragment { - name: "mybootclasspathfragment", + name: "art-bootclasspath-fragment", image_name: "art", %s apex_available: [ @@ -342,6 +306,19 @@ func TestBootclasspathFragmentInArtApex(t *testing.T) { } `, contentsInsert(contents)) + for _, content := range contents { + text += fmt.Sprintf(` + java_library { + name: "%[1]s", + srcs: ["%[1]s.java"], + installable: true, + apex_available: [ + "com.android.art", + ], + } + `, content) + } + return android.FixtureAddTextFile("art/build/boot/Android.bp", text) } @@ -357,11 +334,11 @@ func TestBootclasspathFragmentInArtApex(t *testing.T) { src: "com.android.art-arm.apex", }, }, - exported_bootclasspath_fragments: ["mybootclasspathfragment"], + exported_bootclasspath_fragments: ["art-bootclasspath-fragment"], } prebuilt_bootclasspath_fragment { - name: "mybootclasspathfragment", + name: "art-bootclasspath-fragment", image_name: "art", %s prefer: %t, @@ -369,14 +346,29 @@ func TestBootclasspathFragmentInArtApex(t *testing.T) { "com.android.art", ], hidden_api: { - annotation_flags: "mybootclasspathfragment/annotation-flags.csv", - metadata: "mybootclasspathfragment/metadata.csv", - index: "mybootclasspathfragment/index.csv", - stub_flags: "mybootclasspathfragment/stub-flags.csv", - all_flags: "mybootclasspathfragment/all-flags.csv", + annotation_flags: "hiddenapi/annotation-flags.csv", + metadata: "hiddenapi/metadata.csv", + index: "hiddenapi/index.csv", + stub_flags: "hiddenapi/stub-flags.csv", + all_flags: "hiddenapi/all-flags.csv", }, } `, contentsInsert(contents), prefer) + + for _, content := range contents { + text += fmt.Sprintf(` + java_import { + name: "%[1]s", + prefer: %[2]t, + jars: ["%[1]s.jar"], + apex_available: [ + "com.android.art", + ], + compile_dex: true, + } + `, content, prefer) + } + return android.FixtureAddTextFile("prebuilts/module_sdk/art/Android.bp", text) } @@ -399,13 +391,13 @@ func TestBootclasspathFragmentInArtApex(t *testing.T) { }) java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ + `art-bootclasspath-fragment`, `com.android.art.key`, - `mybootclasspathfragment`, }) // Make sure that the source bootclasspath_fragment copies its dex files to the predefined // locations for the art image. - module := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000") + module := result.ModuleForTests("art-bootclasspath-fragment", "android_common_apex10000") checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo") }) @@ -469,14 +461,14 @@ func TestBootclasspathFragmentInArtApex(t *testing.T) { }) java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ + `art-bootclasspath-fragment`, `com.android.art.key`, - `mybootclasspathfragment`, `prebuilt_com.android.art`, }) // Make sure that the prebuilt bootclasspath_fragment copies its dex files to the predefined // locations for the art image. - module := result.ModuleForTests("prebuilt_mybootclasspathfragment", "android_common_com.android.art") + module := result.ModuleForTests("prebuilt_art-bootclasspath-fragment", "android_common_com.android.art") checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo") }) @@ -566,7 +558,7 @@ func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) { src: "com.android.art-arm.apex", }, }, - exported_bootclasspath_fragments: ["mybootclasspathfragment"], + exported_bootclasspath_fragments: ["art-bootclasspath-fragment"], } java_import { @@ -586,7 +578,7 @@ func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) { } prebuilt_bootclasspath_fragment { - name: "mybootclasspathfragment", + name: "art-bootclasspath-fragment", image_name: "art", // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. contents: ["foo", "bar"], @@ -594,11 +586,11 @@ func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) { "com.android.art", ], hidden_api: { - annotation_flags: "mybootclasspathfragment/annotation-flags.csv", - metadata: "mybootclasspathfragment/metadata.csv", - index: "mybootclasspathfragment/index.csv", - stub_flags: "mybootclasspathfragment/stub-flags.csv", - all_flags: "mybootclasspathfragment/all-flags.csv", + annotation_flags: "hiddenapi/annotation-flags.csv", + metadata: "hiddenapi/metadata.csv", + index: "hiddenapi/index.csv", + stub_flags: "hiddenapi/stub-flags.csv", + all_flags: "hiddenapi/all-flags.csv", }, } @@ -608,7 +600,7 @@ func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) { apex_name: "com.android.art", %s src: "com.mycompany.android.art.apex", - exported_bootclasspath_fragments: ["mybootclasspathfragment"], + exported_bootclasspath_fragments: ["art-bootclasspath-fragment"], } ` @@ -617,17 +609,17 @@ func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) { java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art", []string{ `com.android.art.apex.selector`, - `prebuilt_mybootclasspathfragment`, + `prebuilt_art-bootclasspath-fragment`, }) - java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_com.android.art", []string{ + java.CheckModuleDependencies(t, result.TestContext, "art-bootclasspath-fragment", "android_common_com.android.art", []string{ `com.android.art.deapexer`, `dex2oatd`, `prebuilt_bar`, `prebuilt_foo`, }) - module := result.ModuleForTests("mybootclasspathfragment", "android_common_com.android.art") + module := result.ModuleForTests("art-bootclasspath-fragment", "android_common_com.android.art") checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo") }) diff --git a/apex/dexpreopt_bootjars_test.go b/apex/dexpreopt_bootjars_test.go index bba8bb6cb..a56d3a240 100644 --- a/apex/dexpreopt_bootjars_test.go +++ b/apex/dexpreopt_bootjars_test.go @@ -155,7 +155,7 @@ func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOu } func TestDexpreoptBootJarsWithSourceArtApex(t *testing.T) { - ruleFile := "boot.art" + ruleFile := "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art" expectedInputs := []string{ "out/soong/dexpreopt_arm64/dex_bootjars_input/core-oj.jar", @@ -192,7 +192,7 @@ func TestDexpreoptBootJarsWithSourceArtApex(t *testing.T) { // The only difference is that the ART profile should be deapexed from the prebuilt APEX. Other // inputs and outputs should be the same as above. func TestDexpreoptBootJarsWithPrebuiltArtApex(t *testing.T) { - ruleFile := "boot.art" + ruleFile := "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art" expectedInputs := []string{ "out/soong/dexpreopt_arm64/dex_bootjars_input/core-oj.jar", diff --git a/java/bootclasspath_fragment_test.go b/java/bootclasspath_fragment_test.go index 2541f14ff..888caad16 100644 --- a/java/bootclasspath_fragment_test.go +++ b/java/bootclasspath_fragment_test.go @@ -40,6 +40,12 @@ func TestBootclasspathFragment_UnknownImageName(t *testing.T) { image_name: "unknown", contents: ["foo"], } + + java_library { + name: "foo", + srcs: ["foo.java"], + installable: true, + } `) } @@ -53,6 +59,11 @@ func TestPrebuiltBootclasspathFragment_UnknownImageName(t *testing.T) { image_name: "unknown", contents: ["foo"], } + + java_import { + name: "foo", + jars: ["foo.jar"], + } `) } @@ -72,6 +83,18 @@ func TestBootclasspathFragmentInconsistentArtConfiguration_Platform(t *testing.T "apex", ], } + + java_library { + name: "foo", + srcs: ["foo.java"], + installable: true, + } + + java_library { + name: "bar", + srcs: ["bar.java"], + installable: true, + } `) } @@ -92,6 +115,18 @@ func TestBootclasspathFragmentInconsistentArtConfiguration_ApexMixture(t *testin "apex2", ], } + + java_library { + name: "foo", + srcs: ["foo.java"], + installable: true, + } + + java_library { + name: "bar", + srcs: ["bar.java"], + installable: true, + } `) } diff --git a/java/dexpreopt_config_testing.go b/java/dexpreopt_config_testing.go index 6f3aa2be8..2bef6434c 100644 --- a/java/dexpreopt_config_testing.go +++ b/java/dexpreopt_config_testing.go @@ -44,18 +44,18 @@ var PrepareApexBootJarConfigs = FixtureConfigureApexBootJars( var PrepareApexBootJarConfigsAndModules = android.GroupFixturePreparers( PrepareApexBootJarConfigs, - prepareApexBootJarModule("com.android.foo", "framework-foo"), - prepareApexBootJarModule("com.android.bar", "framework-bar"), + PrepareApexBootJarModule("com.android.foo", "framework-foo"), + PrepareApexBootJarModule("com.android.bar", "framework-bar"), ) var ApexBootJarFragmentsForPlatformBootclasspath = fmt.Sprintf(` { apex: "%[1]s", - module: "%[1]s-bootclasspathfragment", + module: "%[1]s-bootclasspath-fragment", }, { apex: "%[2]s", - module: "%[2]s-bootclasspathfragment", + module: "%[2]s-bootclasspath-fragment", }, `, "com.android.foo", "com.android.bar") @@ -64,15 +64,22 @@ var ApexBootJarDexJarPaths = []string{ "out/soong/.intermediates/packages/modules/com.android.foo/framework-foo/android_common_apex10000/aligned/framework-foo.jar", } -func prepareApexBootJarModule(apexName string, moduleName string) android.FixturePreparer { +func PrepareApexBootJarModule(apexName string, moduleName string) android.FixturePreparer { moduleSourceDir := fmt.Sprintf("packages/modules/%s", apexName) + fragmentName := apexName+"-bootclasspath-fragment" + imageNameProp := "" + if apexName == "com.android.art" { + fragmentName = "art-bootclasspath-fragment" + imageNameProp = `image_name: "art",` + } + return android.GroupFixturePreparers( android.FixtureAddTextFile(moduleSourceDir+"/Android.bp", fmt.Sprintf(` apex { name: "%[1]s", key: "%[1]s.key", bootclasspath_fragments: [ - "%[1]s-bootclasspathfragment", + "%[3]s", ], updatable: false, } @@ -84,7 +91,8 @@ func prepareApexBootJarModule(apexName string, moduleName string) android.Fixtur } bootclasspath_fragment { - name: "%[1]s-bootclasspathfragment", + name: "%[3]s", + %[4]s contents: ["%[2]s"], apex_available: ["%[1]s"], hidden_api: { @@ -100,7 +108,7 @@ func prepareApexBootJarModule(apexName string, moduleName string) android.Fixtur compile_dex: true, apex_available: ["%[1]s"], } - `, apexName, moduleName)), + `, apexName, moduleName, fragmentName, imageNameProp)), android.FixtureMergeMockFs(android.MockFS{ fmt.Sprintf("%s/apex_manifest.json", moduleSourceDir): nil, fmt.Sprintf("%s/%s.avbpubkey", moduleSourceDir, apexName): nil, @@ -192,7 +200,7 @@ func CheckArtBootImageConfig(t *testing.T, result *android.TestResult) { // getArtImageConfig gets the ART bootImageConfig that was created during the test. func getArtImageConfig(result *android.TestResult) *bootImageConfig { pathCtx := &android.TestPathContext{TestResult: result} - imageConfig := artBootImageConfig(pathCtx) + imageConfig := genBootImageConfigs(pathCtx)["art"] return imageConfig } @@ -1136,7 +1144,6 @@ func nestedCheckBootImageConfig(t *testing.T, imageConfig *bootImageConfig, expe android.AssertPathRelativeToTopEquals(t, "dir", expected.dir, imageConfig.dir) android.AssertPathRelativeToTopEquals(t, "symbolsDir", expected.symbolsDir, imageConfig.symbolsDir) android.AssertStringEquals(t, "installDir", expected.installDir, imageConfig.installDir) - android.AssertStringEquals(t, "profileInstallPathInApex", expected.profileInstallPathInApex, imageConfig.profileInstallPathInApex) android.AssertDeepEquals(t, "modules", expected.modules, imageConfig.modules) android.AssertPathsRelativeToTopEquals(t, "dexPaths", expected.dexPaths, imageConfig.dexPaths.Paths()) android.AssertPathsRelativeToTopEquals(t, "dexPathsDeps", expected.dexPathsDeps, imageConfig.dexPathsDeps.Paths()) diff --git a/sdk/bootclasspath_fragment_sdk_test.go b/sdk/bootclasspath_fragment_sdk_test.go index 894109a79..60c297b27 100644 --- a/sdk/bootclasspath_fragment_sdk_test.go +++ b/sdk/bootclasspath_fragment_sdk_test.go @@ -86,27 +86,27 @@ func TestSnapshotWithBootclasspathFragment_ImageName(t *testing.T) { // Add a platform_bootclasspath that depends on the fragment. fixtureAddPlatformBootclasspathForBootclasspathFragmentWithExtra( - "com.android.art", "mybootclasspathfragment", java.ApexBootJarFragmentsForPlatformBootclasspath), + "com.android.art", "art-bootclasspath-fragment", java.ApexBootJarFragmentsForPlatformBootclasspath), java.PrepareForBootImageConfigTest, java.PrepareApexBootJarConfigsAndModules, android.FixtureWithRootAndroidBp(` sdk { name: "mysdk", - bootclasspath_fragments: ["mybootclasspathfragment"], + bootclasspath_fragments: ["art-bootclasspath-fragment"], } apex { name: "com.android.art", key: "com.android.art.key", bootclasspath_fragments: [ - "mybootclasspathfragment", + "art-bootclasspath-fragment", ], updatable: false, } bootclasspath_fragment { - name: "mybootclasspathfragment", + name: "art-bootclasspath-fragment", image_name: "art", contents: ["core1", "core2"], apex_available: ["com.android.art"], @@ -142,10 +142,10 @@ func TestSnapshotWithBootclasspathFragment_ImageName(t *testing.T) { ).RunTest(t) // A preparer to update the test fixture used when processing an unpackage snapshot. - preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("com.android.art", "mybootclasspathfragment") + preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("com.android.art", "art-bootclasspath-fragment") // Check that source on its own configures the bootImageConfig correctly. - java.CheckMutatedArtBootImageConfig(t, result, "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/meta_lic") + java.CheckMutatedArtBootImageConfig(t, result, "out/soong/.intermediates/art-bootclasspath-fragment/android_common_apex10000/meta_lic") java.CheckMutatedFrameworkBootImageConfig(t, result, "out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/meta_lic") CheckSnapshot(t, result, "mysdk", "", @@ -153,7 +153,7 @@ func TestSnapshotWithBootclasspathFragment_ImageName(t *testing.T) { // This is auto-generated. DO NOT EDIT. prebuilt_bootclasspath_fragment { - name: "mybootclasspathfragment", + name: "art-bootclasspath-fragment", prefer: false, visibility: ["//visibility:public"], apex_available: ["com.android.art"], @@ -189,12 +189,12 @@ java_import { } `), checkAllCopyRules(` -.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv -.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv -.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/index.csv -> hiddenapi/index.csv -.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/signature-patterns.csv -> hiddenapi/signature-patterns.csv -.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/filtered-stub-flags.csv -> hiddenapi/filtered-stub-flags.csv -.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/filtered-flags.csv -> hiddenapi/filtered-flags.csv +.intermediates/art-bootclasspath-fragment/android_common/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv +.intermediates/art-bootclasspath-fragment/android_common/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv +.intermediates/art-bootclasspath-fragment/android_common/modular-hiddenapi/index.csv -> hiddenapi/index.csv +.intermediates/art-bootclasspath-fragment/android_common/modular-hiddenapi/signature-patterns.csv -> hiddenapi/signature-patterns.csv +.intermediates/art-bootclasspath-fragment/android_common/modular-hiddenapi/filtered-stub-flags.csv -> hiddenapi/filtered-stub-flags.csv +.intermediates/art-bootclasspath-fragment/android_common/modular-hiddenapi/filtered-flags.csv -> hiddenapi/filtered-flags.csv .intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/core1.jar .intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/core2.jar `), @@ -213,7 +213,7 @@ java_import { java.ApexBootJarDexJarPaths..., )..., ) - java.CheckMutatedArtBootImageConfig(t, result, "out/soong/.intermediates/snapshot/mybootclasspathfragment/android_common_com.android.art/meta_lic") + java.CheckMutatedArtBootImageConfig(t, result, "out/soong/.intermediates/snapshot/art-bootclasspath-fragment/android_common_com.android.art/meta_lic") java.CheckMutatedFrameworkBootImageConfig(t, result, "out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/meta_lic") }), @@ -221,7 +221,7 @@ java_import { // Check the behavior of the snapshot when the source is preferred. snapshotTestChecker(checkSnapshotWithSourcePreferred, func(t *testing.T, result *android.TestResult) { - java.CheckMutatedArtBootImageConfig(t, result, "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/meta_lic") + java.CheckMutatedArtBootImageConfig(t, result, "out/soong/.intermediates/art-bootclasspath-fragment/android_common_apex10000/meta_lic") java.CheckMutatedFrameworkBootImageConfig(t, result, "out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/meta_lic") }), @@ -229,7 +229,7 @@ java_import { // Check the behavior of the snapshot when it is preferred. snapshotTestChecker(checkSnapshotPreferredWithSource, func(t *testing.T, result *android.TestResult) { - java.CheckMutatedArtBootImageConfig(t, result, "out/soong/.intermediates/snapshot/prebuilt_mybootclasspathfragment/android_common_com.android.art/meta_lic") + java.CheckMutatedArtBootImageConfig(t, result, "out/soong/.intermediates/snapshot/prebuilt_art-bootclasspath-fragment/android_common_com.android.art/meta_lic") java.CheckMutatedFrameworkBootImageConfig(t, result, "out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/meta_lic") }), ) From f7f782c4f1242f7f2c869b42a97f195c59317172 Mon Sep 17 00:00:00 2001 From: Jiakai Zhang Date: Tue, 11 Jul 2023 14:51:04 +0100 Subject: [PATCH 2/5] Remove Modules() from BootclasspathFragmentApexContentInfo. The Modules() method was for the ART boot image in the ART APEX. It's no longer needed because we don't install the ART boot image in the ART APEX anymore. Bug: 290583827 Test: m nothing Change-Id: I674a5fa1ed18908413a64129df5947c7d26e638e --- apex/bootclasspath_fragment_test.go | 82 ----------------------------- java/bootclasspath_fragment.go | 9 ---- 2 files changed, 91 deletions(-) diff --git a/apex/bootclasspath_fragment_test.go b/apex/bootclasspath_fragment_test.go index 53afbb577..7be8477df 100644 --- a/apex/bootclasspath_fragment_test.go +++ b/apex/bootclasspath_fragment_test.go @@ -46,78 +46,6 @@ var prepareForTestWithArtApex = android.GroupFixturePreparers( dexpreopt.FixtureSetBootImageProfiles("art/build/boot/boot-image-profile.txt"), ) -func TestBootclasspathFragments(t *testing.T) { - result := android.GroupFixturePreparers( - prepareForTestWithBootclasspathFragment, - // Configure some libraries in the art bootclasspath_fragment and platform_bootclasspath. - java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo", "platform:bar"), - prepareForTestWithArtApex, - - java.PrepareForTestWithJavaSdkLibraryFiles, - java.FixtureWithLastReleaseApis("foo"), - ).RunTestWithBp(t, ` - java_sdk_library { - name: "foo", - srcs: ["b.java"], - } - - java_library { - name: "bar", - srcs: ["b.java"], - installable: true, - } - - apex { - name: "com.android.art", - key: "com.android.art.key", - bootclasspath_fragments: ["art-bootclasspath-fragment"], - updatable: false, - } - - apex_key { - name: "com.android.art.key", - public_key: "com.android.art.avbpubkey", - private_key: "com.android.art.pem", - } - - java_library { - name: "baz", - apex_available: [ - "com.android.art", - ], - srcs: ["b.java"], - compile_dex: true, - } - - java_library { - name: "quuz", - apex_available: [ - "com.android.art", - ], - srcs: ["b.java"], - compile_dex: true, - } - - bootclasspath_fragment { - name: "art-bootclasspath-fragment", - image_name: "art", - // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. - contents: ["baz", "quuz"], - apex_available: [ - "com.android.art", - ], - hidden_api: { - split_packages: ["*"], - }, - } -`, - ) - - // Make sure that the art-bootclasspath-fragment is using the correct configuration. - checkBootclasspathFragment(t, result, "art-bootclasspath-fragment", "android_common_apex10000", - "com.android.art:baz,com.android.art:quuz") -} - func TestBootclasspathFragments_FragmentDependency(t *testing.T) { result := android.GroupFixturePreparers( prepareForTestWithBootclasspathFragment, @@ -248,16 +176,6 @@ func TestBootclasspathFragments_FragmentDependency(t *testing.T) { checkAPIScopeStubs("other", otherInfo, java.CorePlatformHiddenAPIScope) } -func checkBootclasspathFragment(t *testing.T, result *android.TestResult, moduleName, variantName string, expectedConfiguredModules string) { - t.Helper() - - bootclasspathFragment := result.ModuleForTests(moduleName, variantName).Module().(*java.BootclasspathFragmentModule) - - bootclasspathFragmentInfo := result.ModuleProvider(bootclasspathFragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo) - modules := bootclasspathFragmentInfo.Modules() - android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String()) -} - func TestBootclasspathFragmentInArtApex(t *testing.T) { commonPreparer := android.GroupFixturePreparers( prepareForTestWithBootclasspathFragment, diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index 50429b07a..ac45ce181 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -389,10 +389,6 @@ var BootclasspathFragmentApexContentInfoProvider = blueprint.NewProvider(Bootcla // BootclasspathFragmentApexContentInfo contains the bootclasspath_fragments contributions to the // apex contents. type BootclasspathFragmentApexContentInfo struct { - // The configured modules, will be empty if this is from a bootclasspath_fragment that does not - // set image_name: "art". - modules android.ConfiguredJarList - // Map from the base module name (without prebuilt_ prefix) of a fragment's contents module to the // hidden API encoded dex jar path. contentModuleDexJarPaths bootDexJarByModule @@ -405,10 +401,6 @@ type BootclasspathFragmentApexContentInfo struct { profileInstallPathInApex string } -func (i BootclasspathFragmentApexContentInfo) Modules() android.ConfiguredJarList { - return i.modules -} - // DexBootJarPathForContentModule returns the path to the dex boot jar for specified module. // // The dex boot jar is one which has had hidden API encoding performed on it. @@ -597,7 +589,6 @@ func (b *BootclasspathFragmentModule) provideApexContentInfo(ctx android.ModuleC } if imageConfig != nil { - info.modules = imageConfig.modules global := dexpreopt.GetGlobalConfig(ctx) if !global.DisableGenerateProfile { info.profilePathOnHost = bootImageFiles.profile From da47d3c6f3914fca33eddcc4d1ad4c8d3b4ec630 Mon Sep 17 00:00:00 2001 From: Jiakai Zhang Date: Tue, 11 Jul 2023 14:53:12 +0100 Subject: [PATCH 3/5] Fix dumpOatRules. This method generates a build rule that runs oatdump for debugging purposes. - Pass "--runtime-arg -Xgc:CMC" to oatdump if UFFD GC is enabled. - Build the phony name from the image name to avoid conflicts when using this method for multiple boot images. Bug: 290583827 Test: m dump-oat-boot Change-Id: I7adc97cb85b571486b78f173fb80ff7da2c4bfe4 --- java/dexpreopt_bootjars.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go index 35f60979f..9057a1cb0 100644 --- a/java/dexpreopt_bootjars.go +++ b/java/dexpreopt_bootjars.go @@ -972,6 +972,8 @@ func bootFrameworkProfileRule(ctx android.ModuleContext, image *bootImageConfig) func dumpOatRules(ctx android.ModuleContext, image *bootImageConfig) { var allPhonies android.Paths + name := image.name + global := dexpreopt.GetGlobalConfig(ctx) for _, image := range image.variants { arch := image.target.Arch.ArchType suffix := arch.String() @@ -980,36 +982,39 @@ func dumpOatRules(ctx android.ModuleContext, image *bootImageConfig) { suffix = "host-" + suffix } // Create a rule to call oatdump. - output := android.PathForOutput(ctx, "boot."+suffix+".oatdump.txt") + output := android.PathForOutput(ctx, name+"."+suffix+".oatdump.txt") rule := android.NewRuleBuilder(pctx, ctx) imageLocationsOnHost, _ := image.imageLocations() - rule.Command(). + cmd := rule.Command(). BuiltTool("oatdump"). FlagWithInputList("--runtime-arg -Xbootclasspath:", image.dexPathsDeps.Paths(), ":"). FlagWithList("--runtime-arg -Xbootclasspath-locations:", image.dexLocationsDeps, ":"). FlagWithArg("--image=", strings.Join(imageLocationsOnHost, ":")).Implicits(image.imagesDeps.Paths()). FlagWithOutput("--output=", output). FlagWithArg("--instruction-set=", arch.String()) - rule.Build("dump-oat-boot-"+suffix, "dump oat boot "+arch.String()) + if global.EnableUffdGc && image.target.Os == android.Android { + cmd.Flag("--runtime-arg").Flag("-Xgc:CMC") + } + rule.Build("dump-oat-"+name+"-"+suffix, "dump oat "+name+" "+arch.String()) // Create a phony rule that depends on the output file and prints the path. - phony := android.PathForPhony(ctx, "dump-oat-boot-"+suffix) + phony := android.PathForPhony(ctx, "dump-oat-"+name+"-"+suffix) rule = android.NewRuleBuilder(pctx, ctx) rule.Command(). Implicit(output). ImplicitOutput(phony). Text("echo").FlagWithArg("Output in ", output.String()) - rule.Build("phony-dump-oat-boot-"+suffix, "dump oat boot "+arch.String()) + rule.Build("phony-dump-oat-"+name+"-"+suffix, "dump oat "+name+" "+arch.String()) allPhonies = append(allPhonies, phony) } - phony := android.PathForPhony(ctx, "dump-oat-boot") + phony := android.PathForPhony(ctx, "dump-oat-"+name) ctx.Build(pctx, android.BuildParams{ Rule: android.Phony, Output: phony, Inputs: allPhonies, - Description: "dump-oat-boot", + Description: "dump-oat-"+name, }) } From b1639db53f1df445f08924c6414bba53d9cee512 Mon Sep 17 00:00:00 2001 From: Jiakai Zhang Date: Tue, 11 Jul 2023 15:03:13 +0100 Subject: [PATCH 4/5] Extract duplicate code to common helper functions. Also, fall back to using a default name for the dexpreopt directory if we are not building for Android. Bug: 290583827 Test: m nothing Change-Id: I3fc6ff9142a2dcdf995796f75891b242fe2848d0 --- android/configured_jars.go | 5 +++++ java/bootclasspath.go | 2 +- java/dexpreopt_bootjars.go | 3 +-- java/dexpreopt_config.go | 15 +++++++++------ java/hiddenapi_singleton.go | 2 +- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/android/configured_jars.go b/android/configured_jars.go index 53fef052a..1281bae87 100644 --- a/android/configured_jars.go +++ b/android/configured_jars.go @@ -311,4 +311,9 @@ func EmptyConfiguredJarList() ConfiguredJarList { return ConfiguredJarList{} } +// IsConfiguredJarForPlatform returns true if the given apex name is a special name for the platform. +func IsConfiguredJarForPlatform(apex string) bool { + return apex == "platform" || apex == "system_ext" +} + var earlyBootJarsKey = NewOnceKey("earlyBootJars") diff --git a/java/bootclasspath.go b/java/bootclasspath.go index f4cef7fa6..29eed795d 100644 --- a/java/bootclasspath.go +++ b/java/bootclasspath.go @@ -77,7 +77,7 @@ func addDependencyOntoApexVariants(ctx android.BottomUpMutatorContext, propertyN // Use gatherApexModulePairDepsWithTag to retrieve the dependencies. func addDependencyOntoApexModulePair(ctx android.BottomUpMutatorContext, apex string, name string, tag blueprint.DependencyTag) { var variations []blueprint.Variation - if apex != "platform" && apex != "system_ext" { + if !android.IsConfiguredJarForPlatform(apex) { // Pick the correct apex variant. variations = []blueprint.Variation{ {Mutator: "apex", Variation: apex}, diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go index 9057a1cb0..794bc4ae6 100644 --- a/java/dexpreopt_bootjars.go +++ b/java/dexpreopt_bootjars.go @@ -505,8 +505,7 @@ func (d *dexpreoptBootJars) GenerateSingletonBuildActions(ctx android.SingletonC // No module has enabled dexpreopting, so we assume there will be no boot image to make. return } - archType := ctx.Config().Targets[android.Android][0].Arch.ArchType - d.dexpreoptConfigForMake = android.PathForOutput(ctx, toDexpreoptDirName(archType), "dexpreopt.config") + d.dexpreoptConfigForMake = android.PathForOutput(ctx, getDexpreoptDirName(ctx), "dexpreopt.config") writeGlobalConfigForMake(ctx, d.dexpreoptConfigForMake) global := dexpreopt.GetGlobalConfig(ctx) diff --git a/java/dexpreopt_config.go b/java/dexpreopt_config.go index 9100e87c6..d9c474dc0 100644 --- a/java/dexpreopt_config.go +++ b/java/dexpreopt_config.go @@ -105,8 +105,7 @@ func genBootImageConfigRaw(ctx android.PathContext) map[string]*bootImageConfig func genBootImageConfigs(ctx android.PathContext) map[string]*bootImageConfig { return ctx.Config().Once(bootImageConfigKey, func() interface{} { targets := dexpreoptTargets(ctx) - archType := ctx.Config().Targets[android.Android][0].Arch.ArchType - deviceDir := android.PathForOutput(ctx, toDexpreoptDirName(archType)) + deviceDir := android.PathForOutput(ctx, getDexpreoptDirName(ctx)) configs := genBootImageConfigRaw(ctx) @@ -218,8 +217,7 @@ var updatableBootConfigKey = android.NewOnceKey("apexBootConfig") func GetApexBootConfig(ctx android.PathContext) apexBootConfig { return ctx.Config().Once(updatableBootConfigKey, func() interface{} { apexBootJars := dexpreopt.GetGlobalConfig(ctx).ApexBootJars - archType := ctx.Config().Targets[android.Android][0].Arch.ArchType - dir := android.PathForOutput(ctx, toDexpreoptDirName(archType), "apex_bootjars") + dir := android.PathForOutput(ctx, getDexpreoptDirName(ctx), "apex_bootjars") dexPaths := apexBootJars.BuildPaths(ctx, dir) dexPathsByModuleName := apexBootJars.BuildPathsByModule(ctx, dir) @@ -260,6 +258,11 @@ func dexpreoptConfigMakevars(ctx android.MakeVarsContext) { ctx.Strict("DEXPREOPT_BOOT_JARS_MODULES", strings.Join(defaultBootImageConfig(ctx).modules.CopyOfApexJarPairs(), ":")) } -func toDexpreoptDirName(arch android.ArchType) string { - return "dexpreopt_" + arch.String() +func getDexpreoptDirName(ctx android.PathContext) string { + prefix := "dexpreopt_" + targets := ctx.Config().Targets[android.Android] + if len(targets) > 0 { + return prefix+targets[0].Arch.ArchType.String() + } + return prefix+"unknown_target" } diff --git a/java/hiddenapi_singleton.go b/java/hiddenapi_singleton.go index d4ee4fc9f..714634f58 100644 --- a/java/hiddenapi_singleton.go +++ b/java/hiddenapi_singleton.go @@ -166,7 +166,7 @@ func isModuleInConfiguredList(ctx android.BaseModuleContext, module android.Modu // Now match the apex part of the boot image configuration. requiredApex := configuredBootJars.Apex(index) - if requiredApex == "platform" || requiredApex == "system_ext" { + if android.IsConfiguredJarForPlatform(requiredApex) { if len(apexInfo.InApexVariants) != 0 { // A platform variant is required but this is for an apex so ignore it. return false From 3444e561dc4b331fcb5381fa3dd9d31439692469 Mon Sep 17 00:00:00 2001 From: Jiakai Zhang Date: Tue, 11 Jul 2023 15:13:35 +0100 Subject: [PATCH 5/5] Change the profile path on host. This is to decouple profile generation from image configs. A boot image profile is either for a mainline module or for the platform, which is orthogonal to boot images. Bug: 290583827 Test: m nothing Change-Id: I0918f2fa945a2af1839f1a08ecede331c64d0317 --- apex/dexpreopt_bootjars_test.go | 6 +++--- java/dexpreopt_bootjars.go | 29 ++++++++++++++++++----------- java/dexpreopt_config_testing.go | 4 ++-- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/apex/dexpreopt_bootjars_test.go b/apex/dexpreopt_bootjars_test.go index a56d3a240..ff8f912b9 100644 --- a/apex/dexpreopt_bootjars_test.go +++ b/apex/dexpreopt_bootjars_test.go @@ -162,8 +162,8 @@ func TestDexpreoptBootJarsWithSourceArtApex(t *testing.T) { "out/soong/dexpreopt_arm64/dex_bootjars_input/foo.jar", "out/soong/dexpreopt_arm64/dex_bootjars_input/bar.jar", "out/soong/dexpreopt_arm64/dex_bootjars_input/baz.jar", - "out/soong/dexpreopt_arm64/dex_artjars/boot.prof", - "out/soong/dexpreopt_arm64/dex_bootjars/boot.prof", + "out/soong/.intermediates/art-bootclasspath-fragment/android_common_apex10000/art/boot.prof", + "out/soong/.intermediates/platform-bootclasspath/android_common/boot/boot.prof", } expectedOutputs := []string{ @@ -200,7 +200,7 @@ func TestDexpreoptBootJarsWithPrebuiltArtApex(t *testing.T) { "out/soong/dexpreopt_arm64/dex_bootjars_input/bar.jar", "out/soong/dexpreopt_arm64/dex_bootjars_input/baz.jar", "out/soong/.intermediates/com.android.art.deapexer/android_common/deapexer/etc/boot-image.prof", - "out/soong/dexpreopt_arm64/dex_bootjars/boot.prof", + "out/soong/.intermediates/platform-bootclasspath/android_common/boot/boot.prof", } expectedOutputs := []string{ diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go index 794bc4ae6..0ffe152a0 100644 --- a/java/dexpreopt_bootjars.go +++ b/java/dexpreopt_bootjars.go @@ -880,11 +880,7 @@ const failureMessage = `ERROR: Dex2oat failed to compile a boot image. It is likely that the boot classpath is inconsistent. Rebuild with ART_BOOT_IMAGE_EXTRA_ARGS="--runtime-arg -verbose:verifier" to see verification errors.` -func bootImageProfileRule(ctx android.ModuleContext, image *bootImageConfig) android.WritablePath { - if !image.isProfileGuided() { - return nil - } - +func bootImageProfileRuleCommon(ctx android.ModuleContext, name string, dexFiles android.Paths, dexLocations []string) android.WritablePath { globalSoong := dexpreopt.GetGlobalSoongConfig(ctx) global := dexpreopt.GetGlobalConfig(ctx) @@ -911,28 +907,39 @@ func bootImageProfileRule(ctx android.ModuleContext, image *bootImageConfig) and if path := android.ExistentPathForSource(ctx, extraProfile); path.Valid() { profiles = append(profiles, path.Path()) } - bootImageProfile := image.dir.Join(ctx, "boot-image-profile.txt") + bootImageProfile := android.PathForModuleOut(ctx, name, "boot-image-profile.txt") rule.Command().Text("cat").Inputs(profiles).Text(">").Output(bootImageProfile) - profile := image.dir.Join(ctx, "boot.prof") + profile := android.PathForModuleOut(ctx, name, "boot.prof") rule.Command(). Text(`ANDROID_LOG_TAGS="*:e"`). Tool(globalSoong.Profman). Flag("--output-profile-type=boot"). FlagWithInput("--create-profile-from=", bootImageProfile). - FlagForEachInput("--apk=", image.dexPathsDeps.Paths()). - FlagForEachArg("--dex-location=", image.getAnyAndroidVariant().dexLocationsDeps). + FlagForEachInput("--apk=", dexFiles). + FlagForEachArg("--dex-location=", dexLocations). FlagWithOutput("--reference-profile-file=", profile) + rule.Build("bootJarsProfile_"+name, "profile boot jars "+name) + + return profile +} + +func bootImageProfileRule(ctx android.ModuleContext, image *bootImageConfig) android.WritablePath { + if !image.isProfileGuided() { + return nil + } + + profile := bootImageProfileRuleCommon(ctx, image.name, image.dexPathsDeps.Paths(), image.getAnyAndroidVariant().dexLocationsDeps) + if image == defaultBootImageConfig(ctx) { + rule := android.NewRuleBuilder(pctx, ctx) rule.Install(profile, "/system/etc/boot-image.prof") image.profileInstalls = append(image.profileInstalls, rule.Installs()...) image.profileLicenseMetadataFile = android.OptionalPathForPath(ctx.LicenseMetadataFile()) } - rule.Build("bootJarsProfile", "profile boot jars") - return profile } diff --git a/java/dexpreopt_config_testing.go b/java/dexpreopt_config_testing.go index 2bef6434c..56f16e01f 100644 --- a/java/dexpreopt_config_testing.go +++ b/java/dexpreopt_config_testing.go @@ -814,7 +814,7 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut }, profileInstalls: []normalizedInstall{ {from: "out/soong/dexpreopt_arm64/dex_bootjars/boot.bprof", to: "/system/etc/boot-image.bprof"}, - {from: "out/soong/dexpreopt_arm64/dex_bootjars/boot.prof", to: "/system/etc/boot-image.prof"}, + {from: "out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/boot/boot.prof", to: "/system/etc/boot-image.prof"}, }, profileLicenseMetadataFile: expectedLicenseMetadataFile, } @@ -1245,7 +1245,7 @@ DEXPREOPT_IMAGE_LOCATIONS_ON_HOSTart=out/soong/dexpreopt_arm64/dex_artjars/andro DEXPREOPT_IMAGE_LOCATIONS_ON_HOSTboot=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/boot.art DEXPREOPT_IMAGE_LOCATIONS_ON_HOSTmainline=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/boot.art:out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/boot-framework-foo.art DEXPREOPT_IMAGE_NAMES=art boot mainline -DEXPREOPT_IMAGE_PROFILE_BUILT_INSTALLED=out/soong/dexpreopt_arm64/dex_bootjars/boot.bprof:/system/etc/boot-image.bprof out/soong/dexpreopt_arm64/dex_bootjars/boot.prof:/system/etc/boot-image.prof +DEXPREOPT_IMAGE_PROFILE_BUILT_INSTALLED=out/soong/dexpreopt_arm64/dex_bootjars/boot.bprof:/system/etc/boot-image.bprof out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/boot/boot.prof:/system/etc/boot-image.prof DEXPREOPT_IMAGE_PROFILE_LICENSE_METADATA=out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/meta_lic DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_art_arm=out/soong/dexpreopt_arm64/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm/boot.oat:/apex/art_boot_images/javalib/arm/boot.oat out/soong/dexpreopt_arm64/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm/boot-core2.oat:/apex/art_boot_images/javalib/arm/boot-core2.oat DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_art_arm64=out/soong/dexpreopt_arm64/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm64/boot.oat:/apex/art_boot_images/javalib/arm64/boot.oat out/soong/dexpreopt_arm64/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm64/boot-core2.oat:/apex/art_boot_images/javalib/arm64/boot-core2.oat