123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251 |
- // Copyright (C) 2021 The Android Open Source Project
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package apex
- import (
- "fmt"
- "path"
- "sort"
- "strings"
- "testing"
- "android/soong/android"
- "android/soong/dexpreopt"
- "android/soong/java"
- "github.com/google/blueprint/proptools"
- )
- // Contains tests for bootclasspath_fragment logic from java/bootclasspath_fragment.go as the ART
- // bootclasspath_fragment requires modules from the ART apex.
- var prepareForTestWithBootclasspathFragment = android.GroupFixturePreparers(
- java.PrepareForTestWithDexpreopt,
- PrepareForTestWithApexBuildComponents,
- )
- // Some additional files needed for the art apex.
- var prepareForTestWithArtApex = android.GroupFixturePreparers(
- android.FixtureMergeMockFs(android.MockFS{
- "com.android.art.avbpubkey": nil,
- "com.android.art.pem": nil,
- "system/sepolicy/apex/com.android.art-file_contexts": nil,
- }),
- 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,
- // Configure some libraries in the art bootclasspath_fragment and platform_bootclasspath.
- java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"),
- java.FixtureConfigureApexBootJars("someapex:foo", "someapex:bar"),
- prepareForTestWithArtApex,
- java.PrepareForTestWithJavaSdkLibraryFiles,
- java.FixtureWithLastReleaseApis("foo", "baz"),
- ).RunTestWithBp(t, `
- java_sdk_library {
- name: "foo",
- srcs: ["b.java"],
- shared_library: false,
- public: {
- enabled: true,
- },
- system: {
- enabled: true,
- },
- }
- 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_sdk_library {
- name: "baz",
- apex_available: [
- "com.android.art",
- ],
- srcs: ["b.java"],
- shared_library: false,
- public: {
- enabled: true,
- },
- system: {
- enabled: true,
- },
- test: {
- enabled: 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: ["*"],
- },
- }
- bootclasspath_fragment {
- name: "other-bootclasspath-fragment",
- contents: ["foo", "bar"],
- fragments: [
- {
- apex: "com.android.art",
- module: "art-bootclasspath-fragment",
- },
- ],
- hidden_api: {
- split_packages: ["*"],
- },
- }
- `,
- )
- checkAPIScopeStubs := func(message string, info java.HiddenAPIInfo, apiScope *java.HiddenAPIScope, expectedPaths ...string) {
- t.Helper()
- paths := info.TransitiveStubDexJarsByScope.StubDexJarsForScope(apiScope)
- android.AssertPathsRelativeToTopEquals(t, fmt.Sprintf("%s %s", message, apiScope), expectedPaths, paths)
- }
- // Check stub dex paths exported by art.
- artFragment := result.Module("art-bootclasspath-fragment", "android_common")
- artInfo := result.ModuleProvider(artFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo)
- bazPublicStubs := "out/soong/.intermediates/baz.stubs/android_common/dex/baz.stubs.jar"
- bazSystemStubs := "out/soong/.intermediates/baz.stubs.system/android_common/dex/baz.stubs.system.jar"
- bazTestStubs := "out/soong/.intermediates/baz.stubs.test/android_common/dex/baz.stubs.test.jar"
- checkAPIScopeStubs("art", artInfo, java.PublicHiddenAPIScope, bazPublicStubs)
- checkAPIScopeStubs("art", artInfo, java.SystemHiddenAPIScope, bazSystemStubs)
- checkAPIScopeStubs("art", artInfo, java.TestHiddenAPIScope, bazTestStubs)
- checkAPIScopeStubs("art", artInfo, java.CorePlatformHiddenAPIScope)
- // Check stub dex paths exported by other.
- otherFragment := result.Module("other-bootclasspath-fragment", "android_common")
- otherInfo := result.ModuleProvider(otherFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo)
- fooPublicStubs := "out/soong/.intermediates/foo.stubs/android_common/dex/foo.stubs.jar"
- fooSystemStubs := "out/soong/.intermediates/foo.stubs.system/android_common/dex/foo.stubs.system.jar"
- checkAPIScopeStubs("other", otherInfo, java.PublicHiddenAPIScope, bazPublicStubs, fooPublicStubs)
- checkAPIScopeStubs("other", otherInfo, java.SystemHiddenAPIScope, bazSystemStubs, fooSystemStubs)
- checkAPIScopeStubs("other", otherInfo, java.TestHiddenAPIScope, bazTestStubs, fooSystemStubs)
- 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,
- prepareForTestWithArtApex,
- android.FixtureWithRootAndroidBp(`
- apex {
- name: "com.android.art",
- key: "com.android.art.key",
- bootclasspath_fragments: [
- "mybootclasspathfragment",
- ],
- // bar (like foo) should be transitively included in this apex because it is part of the
- // mybootclasspathfragment bootclasspath_fragment.
- updatable: false,
- }
- apex_key {
- name: "com.android.art.key",
- 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,
- }
- `),
- )
- contentsInsert := func(contents []string) string {
- insert := ""
- if contents != nil {
- insert = fmt.Sprintf(`contents: ["%s"],`, strings.Join(contents, `", "`))
- }
- return insert
- }
- addSource := func(contents ...string) android.FixturePreparer {
- text := fmt.Sprintf(`
- bootclasspath_fragment {
- name: "mybootclasspathfragment",
- image_name: "art",
- %s
- apex_available: [
- "com.android.art",
- ],
- hidden_api: {
- split_packages: ["*"],
- },
- }
- `, contentsInsert(contents))
- return android.FixtureAddTextFile("art/build/boot/Android.bp", text)
- }
- addPrebuilt := func(prefer bool, contents ...string) android.FixturePreparer {
- text := fmt.Sprintf(`
- prebuilt_apex {
- name: "com.android.art",
- arch: {
- arm64: {
- src: "com.android.art-arm64.apex",
- },
- arm: {
- src: "com.android.art-arm.apex",
- },
- },
- exported_bootclasspath_fragments: ["mybootclasspathfragment"],
- }
- prebuilt_bootclasspath_fragment {
- name: "mybootclasspathfragment",
- image_name: "art",
- %s
- prefer: %t,
- apex_available: [
- "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",
- },
- }
- `, contentsInsert(contents), prefer)
- return android.FixtureAddTextFile("prebuilts/module_sdk/art/Android.bp", text)
- }
- t.Run("boot image files from source", func(t *testing.T) {
- result := android.GroupFixturePreparers(
- commonPreparer,
- // Configure some libraries in the art bootclasspath_fragment that match the source
- // bootclasspath_fragment's contents property.
- java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
- addSource("foo", "bar"),
- java.FixtureSetBootImageInstallDirOnDevice("art", "apex/com.android.art/javalib"),
- ).RunTest(t)
- ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
- "etc/boot-image.prof",
- "etc/classpaths/bootclasspath.pb",
- "javalib/bar.jar",
- "javalib/foo.jar",
- })
- java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
- `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")
- checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo")
- })
- t.Run("generate boot image profile even if dexpreopt is disabled", func(t *testing.T) {
- result := android.GroupFixturePreparers(
- commonPreparer,
- // Configure some libraries in the art bootclasspath_fragment that match the source
- // bootclasspath_fragment's contents property.
- java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
- addSource("foo", "bar"),
- java.FixtureSetBootImageInstallDirOnDevice("art", "system/framework"),
- dexpreopt.FixtureDisableDexpreoptBootImages(true),
- ).RunTest(t)
- ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
- "etc/boot-image.prof",
- "etc/classpaths/bootclasspath.pb",
- "javalib/bar.jar",
- "javalib/foo.jar",
- })
- })
- t.Run("boot image disable generate profile", func(t *testing.T) {
- result := android.GroupFixturePreparers(
- commonPreparer,
- // Configure some libraries in the art bootclasspath_fragment that match the source
- // bootclasspath_fragment's contents property.
- java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
- addSource("foo", "bar"),
- dexpreopt.FixtureDisableGenerateProfile(true),
- ).RunTest(t)
- files := getFiles(t, result.TestContext, "com.android.art", "android_common_com.android.art_image")
- for _, file := range files {
- matched, _ := path.Match("etc/boot-image.prof", file.path)
- android.AssertBoolEquals(t, "\"etc/boot-image.prof\" should not be in the APEX", matched, false)
- }
- })
- t.Run("boot image files with preferred prebuilt", func(t *testing.T) {
- result := android.GroupFixturePreparers(
- commonPreparer,
- // Configure some libraries in the art bootclasspath_fragment that match the source
- // bootclasspath_fragment's contents property.
- java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
- addSource("foo", "bar"),
- // Make sure that a preferred prebuilt with consistent contents doesn't affect the apex.
- addPrebuilt(true, "foo", "bar"),
- java.FixtureSetBootImageInstallDirOnDevice("art", "apex/com.android.art/javalib"),
- ).RunTest(t)
- ensureExactDeapexedContents(t, result.TestContext, "com.android.art", "android_common", []string{
- "etc/boot-image.prof",
- "javalib/bar.jar",
- "javalib/foo.jar",
- })
- java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
- `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")
- checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo")
- })
- t.Run("source with inconsistency between config and contents", func(t *testing.T) {
- android.GroupFixturePreparers(
- commonPreparer,
- // Create an inconsistency between the ArtApexJars configuration and the art source
- // bootclasspath_fragment module's contents property.
- java.FixtureConfigureBootJars("com.android.art:foo"),
- addSource("foo", "bar"),
- ).
- ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
- RunTest(t)
- })
- t.Run("prebuilt with inconsistency between config and contents", func(t *testing.T) {
- android.GroupFixturePreparers(
- commonPreparer,
- // Create an inconsistency between the ArtApexJars configuration and the art
- // prebuilt_bootclasspath_fragment module's contents property.
- java.FixtureConfigureBootJars("com.android.art:foo"),
- addPrebuilt(false, "foo", "bar"),
- ).
- ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
- RunTest(t)
- })
- t.Run("preferred prebuilt with inconsistency between config and contents", func(t *testing.T) {
- android.GroupFixturePreparers(
- commonPreparer,
- // Create an inconsistency between the ArtApexJars configuration and the art
- // prebuilt_bootclasspath_fragment module's contents property.
- java.FixtureConfigureBootJars("com.android.art:foo"),
- addPrebuilt(true, "foo", "bar"),
- // Source contents property is consistent with the config.
- addSource("foo"),
- ).
- ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
- RunTest(t)
- })
- t.Run("source preferred and prebuilt with inconsistency between config and contents", func(t *testing.T) {
- android.GroupFixturePreparers(
- commonPreparer,
- // Create an inconsistency between the ArtApexJars configuration and the art
- // prebuilt_bootclasspath_fragment module's contents property.
- java.FixtureConfigureBootJars("com.android.art:foo"),
- addPrebuilt(false, "foo", "bar"),
- // Source contents property is consistent with the config.
- addSource("foo"),
- // This should pass because while the prebuilt is inconsistent with the configuration it is
- // not actually used.
- ).RunTest(t)
- })
- }
- func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) {
- preparers := android.GroupFixturePreparers(
- prepareForTestWithBootclasspathFragment,
- prepareForTestWithArtApex,
- android.FixtureMergeMockFs(android.MockFS{
- "com.android.art-arm64.apex": nil,
- "com.android.art-arm.apex": nil,
- }),
- // Configure some libraries in the art bootclasspath_fragment.
- java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
- java.FixtureSetBootImageInstallDirOnDevice("art", "apex/com.android.art/javalib"),
- )
- bp := `
- prebuilt_apex {
- name: "com.android.art",
- arch: {
- arm64: {
- src: "com.android.art-arm64.apex",
- },
- arm: {
- src: "com.android.art-arm.apex",
- },
- },
- exported_bootclasspath_fragments: ["mybootclasspathfragment"],
- }
- java_import {
- name: "foo",
- jars: ["foo.jar"],
- apex_available: [
- "com.android.art",
- ],
- }
- java_import {
- name: "bar",
- jars: ["bar.jar"],
- apex_available: [
- "com.android.art",
- ],
- }
- prebuilt_bootclasspath_fragment {
- name: "mybootclasspathfragment",
- image_name: "art",
- // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
- contents: ["foo", "bar"],
- apex_available: [
- "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",
- },
- }
- // A prebuilt apex with the same apex_name that shouldn't interfere when it isn't enabled.
- prebuilt_apex {
- name: "com.mycompany.android.art",
- apex_name: "com.android.art",
- %s
- src: "com.mycompany.android.art.apex",
- exported_bootclasspath_fragments: ["mybootclasspathfragment"],
- }
- `
- t.Run("disabled alternative APEX", func(t *testing.T) {
- result := preparers.RunTestWithBp(t, fmt.Sprintf(bp, "enabled: false,"))
- java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art", []string{
- `com.android.art.apex.selector`,
- `prebuilt_mybootclasspathfragment`,
- })
- java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_com.android.art", []string{
- `com.android.art.deapexer`,
- `dex2oatd`,
- `prebuilt_bar`,
- `prebuilt_foo`,
- })
- module := result.ModuleForTests("mybootclasspathfragment", "android_common_com.android.art")
- checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo")
- })
- t.Run("enabled alternative APEX", func(t *testing.T) {
- preparers.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
- "Multiple installable prebuilt APEXes provide ambiguous deapexers: com.android.art and com.mycompany.android.art")).
- RunTestWithBp(t, fmt.Sprintf(bp, ""))
- })
- }
- // checkCopiesToPredefinedLocationForArt checks that the supplied modules are copied to the
- // predefined locations of boot dex jars used as inputs for the ART boot image.
- func checkCopiesToPredefinedLocationForArt(t *testing.T, config android.Config, module android.TestingModule, modules ...string) {
- t.Helper()
- bootJarLocations := []string{}
- for _, output := range module.AllOutputs() {
- output = android.StringRelativeToTop(config, output)
- if strings.HasPrefix(output, "out/soong/dexpreopt_arm64/dex_artjars_input/") {
- bootJarLocations = append(bootJarLocations, output)
- }
- }
- sort.Strings(bootJarLocations)
- expected := []string{}
- for _, m := range modules {
- expected = append(expected, fmt.Sprintf("out/soong/dexpreopt_arm64/dex_artjars_input/%s.jar", m))
- }
- sort.Strings(expected)
- android.AssertArrayString(t, "copies to predefined locations for art", expected, bootJarLocations)
- }
- func TestBootclasspathFragmentContentsNoName(t *testing.T) {
- result := android.GroupFixturePreparers(
- prepareForTestWithBootclasspathFragment,
- prepareForTestWithMyapex,
- // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
- java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
- // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
- // is disabled.
- android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
- java.PrepareForTestWithJavaSdkLibraryFiles,
- java.FixtureWithLastReleaseApis("foo"),
- ).RunTestWithBp(t, `
- apex {
- name: "myapex",
- key: "myapex.key",
- bootclasspath_fragments: [
- "mybootclasspathfragment",
- ],
- updatable: false,
- }
- apex_key {
- name: "myapex.key",
- public_key: "testkey.avbpubkey",
- private_key: "testkey.pem",
- }
- java_sdk_library {
- name: "foo",
- srcs: ["b.java"],
- shared_library: false,
- public: {enabled: true},
- apex_available: [
- "myapex",
- ],
- }
- java_library {
- name: "bar",
- srcs: ["b.java"],
- installable: true,
- apex_available: [
- "myapex",
- ],
- }
- bootclasspath_fragment {
- name: "mybootclasspathfragment",
- contents: [
- "foo",
- "bar",
- ],
- apex_available: [
- "myapex",
- ],
- hidden_api: {
- split_packages: ["*"],
- },
- }
- `)
- ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
- // This does not include art, oat or vdex files as they are only included for the art boot
- // image.
- "etc/classpaths/bootclasspath.pb",
- "javalib/bar.jar",
- "javalib/foo.jar",
- })
- java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
- `myapex.key`,
- `mybootclasspathfragment`,
- })
- apex := result.ModuleForTests("myapex", "android_common_myapex_image")
- apexRule := apex.Rule("apexRule")
- copyCommands := apexRule.Args["copy_commands"]
- // Make sure that the fragment provides the hidden API encoded dex jars to the APEX.
- fragment := result.Module("mybootclasspathfragment", "android_common_apex10000")
- info := result.ModuleProvider(fragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
- checkFragmentExportedDexJar := func(name string, expectedDexJar string) {
- module := result.Module(name, "android_common_apex10000")
- dexJar, err := info.DexBootJarPathForContentModule(module)
- if err != nil {
- t.Error(err)
- }
- android.AssertPathRelativeToTopEquals(t, name+" dex", expectedDexJar, dexJar)
- expectedCopyCommand := fmt.Sprintf("&& cp -f %s out/soong/.intermediates/myapex/android_common_myapex_image/image.apex/javalib/%s.jar", expectedDexJar, name)
- android.AssertStringDoesContain(t, name+" apex copy command", copyCommands, expectedCopyCommand)
- }
- checkFragmentExportedDexJar("foo", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/foo.jar")
- checkFragmentExportedDexJar("bar", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/bar.jar")
- }
- func getDexJarPath(result *android.TestResult, name string) string {
- module := result.Module(name, "android_common")
- return module.(java.UsesLibraryDependency).DexJarBuildPath().Path().RelativeToTop().String()
- }
- // TestBootclasspathFragment_HiddenAPIList checks to make sure that the correct parameters are
- // passed to the hiddenapi list tool.
- func TestBootclasspathFragment_HiddenAPIList(t *testing.T) {
- result := android.GroupFixturePreparers(
- prepareForTestWithBootclasspathFragment,
- prepareForTestWithArtApex,
- prepareForTestWithMyapex,
- // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
- java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"),
- java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
- // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
- // is disabled.
- android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
- java.PrepareForTestWithJavaSdkLibraryFiles,
- java.FixtureWithLastReleaseApis("foo", "quuz"),
- ).RunTestWithBp(t, `
- 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_sdk_library {
- name: "quuz",
- apex_available: [
- "com.android.art",
- ],
- srcs: ["b.java"],
- compile_dex: true,
- public: {enabled: true},
- system: {enabled: true},
- test: {enabled: true},
- module_lib: {enabled: 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: ["*"],
- },
- }
- apex {
- name: "myapex",
- key: "myapex.key",
- bootclasspath_fragments: [
- "mybootclasspathfragment",
- ],
- updatable: false,
- }
- apex_key {
- name: "myapex.key",
- public_key: "testkey.avbpubkey",
- private_key: "testkey.pem",
- }
- java_sdk_library {
- name: "foo",
- srcs: ["b.java"],
- shared_library: false,
- public: {enabled: true},
- apex_available: [
- "myapex",
- ],
- }
- java_library {
- name: "bar",
- srcs: ["b.java"],
- installable: true,
- apex_available: [
- "myapex",
- ],
- }
- bootclasspath_fragment {
- name: "mybootclasspathfragment",
- contents: [
- "foo",
- "bar",
- ],
- apex_available: [
- "myapex",
- ],
- fragments: [
- {
- apex: "com.android.art",
- module: "art-bootclasspath-fragment",
- },
- ],
- hidden_api: {
- split_packages: ["*"],
- },
- }
- `)
- java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{
- "art-bootclasspath-fragment",
- "bar",
- "dex2oatd",
- "foo",
- })
- fooStubs := getDexJarPath(result, "foo.stubs")
- quuzPublicStubs := getDexJarPath(result, "quuz.stubs")
- quuzSystemStubs := getDexJarPath(result, "quuz.stubs.system")
- quuzTestStubs := getDexJarPath(result, "quuz.stubs.test")
- quuzModuleLibStubs := getDexJarPath(result, "quuz.stubs.module_lib")
- // Make sure that the fragment uses the quuz stub dex jars when generating the hidden API flags.
- fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
- rule := fragment.Rule("modularHiddenAPIStubFlagsFile")
- command := rule.RuleParams.Command
- android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list")
- // Make sure that the quuz stubs are available for resolving references from the implementation
- // boot dex jars provided by this module.
- android.AssertStringDoesContain(t, "quuz widest", command, "--dependency-stub-dex="+quuzModuleLibStubs)
- // Make sure that the quuz stubs are available for resolving references from the different API
- // stubs provided by this module.
- android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+quuzPublicStubs+":"+fooStubs)
- android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+quuzSystemStubs+":"+fooStubs)
- android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+quuzTestStubs+":"+fooStubs)
- }
- // TestBootclasspathFragment_AndroidNonUpdatable checks to make sure that setting
- // additional_stubs: ["android-non-updatable"] causes the source android-non-updatable modules to be
- // added to the hiddenapi list tool.
- func TestBootclasspathFragment_AndroidNonUpdatable(t *testing.T) {
- result := android.GroupFixturePreparers(
- prepareForTestWithBootclasspathFragment,
- prepareForTestWithArtApex,
- prepareForTestWithMyapex,
- // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
- java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"),
- java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
- // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
- // is disabled.
- android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
- java.PrepareForTestWithJavaSdkLibraryFiles,
- java.FixtureWithLastReleaseApis("foo", "android-non-updatable"),
- ).RunTestWithBp(t, `
- java_sdk_library {
- name: "android-non-updatable",
- srcs: ["b.java"],
- compile_dex: true,
- public: {
- enabled: true,
- },
- system: {
- enabled: true,
- },
- test: {
- enabled: true,
- },
- module_lib: {
- enabled: 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: ["*"],
- },
- }
- apex {
- name: "myapex",
- key: "myapex.key",
- bootclasspath_fragments: [
- "mybootclasspathfragment",
- ],
- updatable: false,
- }
- apex_key {
- name: "myapex.key",
- public_key: "testkey.avbpubkey",
- private_key: "testkey.pem",
- }
- java_sdk_library {
- name: "foo",
- srcs: ["b.java"],
- shared_library: false,
- public: {enabled: true},
- apex_available: [
- "myapex",
- ],
- }
- java_library {
- name: "bar",
- srcs: ["b.java"],
- installable: true,
- apex_available: [
- "myapex",
- ],
- }
- bootclasspath_fragment {
- name: "mybootclasspathfragment",
- contents: [
- "foo",
- "bar",
- ],
- apex_available: [
- "myapex",
- ],
- additional_stubs: ["android-non-updatable"],
- fragments: [
- {
- apex: "com.android.art",
- module: "art-bootclasspath-fragment",
- },
- ],
- hidden_api: {
- split_packages: ["*"],
- },
- }
- `)
- java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{
- "android-non-updatable.stubs",
- "android-non-updatable.stubs.module_lib",
- "android-non-updatable.stubs.system",
- "android-non-updatable.stubs.test",
- "art-bootclasspath-fragment",
- "bar",
- "dex2oatd",
- "foo",
- })
- nonUpdatablePublicStubs := getDexJarPath(result, "android-non-updatable.stubs")
- nonUpdatableSystemStubs := getDexJarPath(result, "android-non-updatable.stubs.system")
- nonUpdatableTestStubs := getDexJarPath(result, "android-non-updatable.stubs.test")
- nonUpdatableModuleLibStubs := getDexJarPath(result, "android-non-updatable.stubs.module_lib")
- // Make sure that the fragment uses the android-non-updatable modules when generating the hidden
- // API flags.
- fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
- rule := fragment.Rule("modularHiddenAPIStubFlagsFile")
- command := rule.RuleParams.Command
- android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list")
- // Make sure that the module_lib non-updatable stubs are available for resolving references from
- // the implementation boot dex jars provided by this module.
- android.AssertStringDoesContain(t, "android-non-updatable widest", command, "--dependency-stub-dex="+nonUpdatableModuleLibStubs)
- // Make sure that the appropriate non-updatable stubs are available for resolving references from
- // the different API stubs provided by this module.
- android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+nonUpdatablePublicStubs)
- android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+nonUpdatableSystemStubs)
- android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+nonUpdatableTestStubs)
- }
- // TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks checks to make sure that
- // setting additional_stubs: ["android-non-updatable"] causes the prebuilt android-non-updatable
- // modules to be added to the hiddenapi list tool.
- func TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks(t *testing.T) {
- result := android.GroupFixturePreparers(
- prepareForTestWithBootclasspathFragment,
- java.PrepareForTestWithDexpreopt,
- prepareForTestWithArtApex,
- prepareForTestWithMyapex,
- // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
- java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"),
- java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
- // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
- // is disabled.
- android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
- android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
- variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
- }),
- java.PrepareForTestWithJavaSdkLibraryFiles,
- java.FixtureWithPrebuiltApis(map[string][]string{
- "current": {"android-non-updatable"},
- "30": {"foo"},
- }),
- ).RunTestWithBp(t, `
- 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: ["*"],
- },
- }
- apex {
- name: "myapex",
- key: "myapex.key",
- bootclasspath_fragments: [
- "mybootclasspathfragment",
- ],
- updatable: false,
- }
- apex_key {
- name: "myapex.key",
- public_key: "testkey.avbpubkey",
- private_key: "testkey.pem",
- }
- java_sdk_library {
- name: "foo",
- srcs: ["b.java"],
- shared_library: false,
- public: {enabled: true},
- apex_available: [
- "myapex",
- ],
- }
- java_library {
- name: "bar",
- srcs: ["b.java"],
- installable: true,
- apex_available: [
- "myapex",
- ],
- }
- bootclasspath_fragment {
- name: "mybootclasspathfragment",
- contents: [
- "foo",
- "bar",
- ],
- apex_available: [
- "myapex",
- ],
- additional_stubs: ["android-non-updatable"],
- fragments: [
- {
- apex: "com.android.art",
- module: "art-bootclasspath-fragment",
- },
- ],
- hidden_api: {
- split_packages: ["*"],
- },
- }
- `)
- java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{
- "art-bootclasspath-fragment",
- "bar",
- "dex2oatd",
- "foo",
- "prebuilt_sdk_module-lib_current_android-non-updatable",
- "prebuilt_sdk_public_current_android-non-updatable",
- "prebuilt_sdk_system_current_android-non-updatable",
- "prebuilt_sdk_test_current_android-non-updatable",
- })
- nonUpdatablePublicStubs := getDexJarPath(result, "sdk_public_current_android-non-updatable")
- nonUpdatableSystemStubs := getDexJarPath(result, "sdk_system_current_android-non-updatable")
- nonUpdatableTestStubs := getDexJarPath(result, "sdk_test_current_android-non-updatable")
- nonUpdatableModuleLibStubs := getDexJarPath(result, "sdk_module-lib_current_android-non-updatable")
- // Make sure that the fragment uses the android-non-updatable modules when generating the hidden
- // API flags.
- fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
- rule := fragment.Rule("modularHiddenAPIStubFlagsFile")
- command := rule.RuleParams.Command
- android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list")
- // Make sure that the module_lib non-updatable stubs are available for resolving references from
- // the implementation boot dex jars provided by this module.
- android.AssertStringDoesContain(t, "android-non-updatable widest", command, "--dependency-stub-dex="+nonUpdatableModuleLibStubs)
- // Make sure that the appropriate non-updatable stubs are available for resolving references from
- // the different API stubs provided by this module.
- android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+nonUpdatablePublicStubs)
- android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+nonUpdatableSystemStubs)
- android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+nonUpdatableTestStubs)
- }
- // TODO(b/177892522) - add test for host apex.
|