From 21d7add8cdf117de762d415ce16a8bd263e34b99 Mon Sep 17 00:00:00 2001 From: Alan Viverette Date: Wed, 16 Feb 2022 12:58:55 -0500 Subject: [PATCH 001/172] Remove duplicate optional libs Fixes: 219958699 Test: ./update_prebuilts.py -x ######## Change-Id: I2ff0aff78379da84db5711e5d5a47b1253936bce --- cmd/pom2bp/pom2bp.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/cmd/pom2bp/pom2bp.go b/cmd/pom2bp/pom2bp.go index 1c88bcae6..f8844fc94 100644 --- a/cmd/pom2bp/pom2bp.go +++ b/cmd/pom2bp/pom2bp.go @@ -627,13 +627,6 @@ var bpDepsTemplate = template.Must(template.New("bp").Parse(` {{- end}} ], {{- end}} - {{- if .BpOptionalUsesLibs}} - optional_uses_libs: [ - {{- range .BpOptionalUsesLibs}} - "{{.}}", - {{- end}} - ], - {{- end}} java_version: "1.7", } `)) From 386ee59a235dfb98560a70f9f7928b7a335cb212 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 10 Feb 2022 11:41:18 -0800 Subject: [PATCH 002/172] Use single module for clang runtime libraries The clang prebuilts now provide a single module with per-architecture variants instead of a module per architecture. Bug: 220019988 Test: m checkbuild Change-Id: I39e2cf8ae14edf8510276dab38011afaef85822c --- apex/apex.go | 2 +- apex/apex_test.go | 10 +++-- cc/cc.go | 2 +- cc/cc_test.go | 4 +- cc/config/toolchain.go | 9 +---- cc/sanitize_test.go | 6 +-- cc/testing.go | 78 ++++-------------------------------- cc/vndk.go | 2 +- rust/config/toolchain.go | 9 +---- rust/testing.go | 4 +- rust/vendor_snapshot_test.go | 25 ++++-------- 11 files changed, 32 insertions(+), 119 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index b2e4fe96a..496c9f6e5 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -1405,7 +1405,7 @@ func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext for _, target := range ctx.MultiTargets() { if target.Arch.ArchType.Multilib == "lib64" { addDependenciesForNativeModules(ctx, ApexNativeDependencies{ - Native_shared_libs: []string{"libclang_rt.hwasan-aarch64-android"}, + Native_shared_libs: []string{"libclang_rt.hwasan"}, Tests: nil, Jni_libs: nil, Binaries: nil, diff --git a/apex/apex_test.go b/apex/apex_test.go index 6d77b0623..aa0e8584d 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -1412,13 +1412,14 @@ func TestRuntimeApexShouldInstallHwasanIfLibcDependsOnIt(t *testing.T) { } cc_prebuilt_library_shared { - name: "libclang_rt.hwasan-aarch64-android", + name: "libclang_rt.hwasan", no_libcrt: true, nocrt: true, stl: "none", system_shared_libs: [], srcs: [""], stubs: { versions: ["1"] }, + stem: "libclang_rt.hwasan-aarch64-android", sanitize: { never: true, @@ -1431,7 +1432,7 @@ func TestRuntimeApexShouldInstallHwasanIfLibcDependsOnIt(t *testing.T) { "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", }) - hwasan := ctx.ModuleForTests("libclang_rt.hwasan-aarch64-android", "android_arm64_armv8-a_shared") + hwasan := ctx.ModuleForTests("libclang_rt.hwasan", "android_arm64_armv8-a_shared") installed := hwasan.Description("install libclang_rt.hwasan") ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") @@ -1459,13 +1460,14 @@ func TestRuntimeApexShouldInstallHwasanIfHwaddressSanitized(t *testing.T) { } cc_prebuilt_library_shared { - name: "libclang_rt.hwasan-aarch64-android", + name: "libclang_rt.hwasan", no_libcrt: true, nocrt: true, stl: "none", system_shared_libs: [], srcs: [""], stubs: { versions: ["1"] }, + stem: "libclang_rt.hwasan-aarch64-android", sanitize: { never: true, @@ -1479,7 +1481,7 @@ func TestRuntimeApexShouldInstallHwasanIfHwaddressSanitized(t *testing.T) { "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", }) - hwasan := ctx.ModuleForTests("libclang_rt.hwasan-aarch64-android", "android_arm64_armv8-a_shared") + hwasan := ctx.ModuleForTests("libclang_rt.hwasan", "android_arm64_armv8-a_shared") installed := hwasan.Description("install libclang_rt.hwasan") ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") diff --git a/cc/cc.go b/cc/cc.go index a8adb0c4c..58ab28c7c 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -1383,7 +1383,7 @@ func isBionic(name string) bool { } func InstallToBootstrap(name string, config android.Config) bool { - if name == "libclang_rt.hwasan-aarch64-android" { + if name == "libclang_rt.hwasan" { return true } return isBionic(name) diff --git a/cc/cc_test.go b/cc/cc_test.go index 51a6a271f..278efa174 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -2944,13 +2944,13 @@ func TestStaticLibDepExport(t *testing.T) { // Check the shared version of lib2. variant := "android_arm64_armv8-a_shared" module := ctx.ModuleForTests("lib2", variant).Module().(*Module) - checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android"}, module) + checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins"}, module) // Check the static version of lib2. variant = "android_arm64_armv8-a_static" module = ctx.ModuleForTests("lib2", variant).Module().(*Module) // libc++_static is linked additionally. - checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android"}, module) + checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins"}, module) } var compilerFlagsTestCases = []struct { diff --git a/cc/config/toolchain.go b/cc/config/toolchain.go index 6cede11a0..7175fdc1a 100644 --- a/cc/config/toolchain.go +++ b/cc/config/toolchain.go @@ -227,14 +227,7 @@ func addPrefix(list []string, prefix string) []string { } func LibclangRuntimeLibrary(t Toolchain, library string) string { - arch := t.LibclangRuntimeLibraryArch() - if arch == "" { - return "" - } - if !t.Bionic() { - return "libclang_rt." + library + "-" + arch - } - return "libclang_rt." + library + "-" + arch + "-android" + return "libclang_rt." + library } func BuiltinsRuntimeLibrary(t Toolchain) string { diff --git a/cc/sanitize_test.go b/cc/sanitize_test.go index 0070e4026..c1ca03408 100644 --- a/cc/sanitize_test.go +++ b/cc/sanitize_test.go @@ -24,11 +24,7 @@ import ( var prepareForAsanTest = android.FixtureAddFile("asan/Android.bp", []byte(` cc_library_shared { - name: "libclang_rt.asan-aarch64-android", - } - - cc_library_shared { - name: "libclang_rt.asan-arm-android", + name: "libclang_rt.asan", } `)) diff --git a/cc/testing.go b/cc/testing.go index a03d147a0..32f7c6080 100644 --- a/cc/testing.go +++ b/cc/testing.go @@ -86,53 +86,19 @@ func commonDefaultModules() string { } cc_prebuilt_library_static { - name: "libclang_rt.builtins-arm-android", - defaults: ["toolchain_libs_defaults"], - native_bridge_supported: true, - vendor_ramdisk_available: true, - } - - cc_prebuilt_library_static { - name: "libclang_rt.builtins-aarch64-android", - defaults: ["toolchain_libs_defaults"], - native_bridge_supported: true, - vendor_ramdisk_available: true, - } - - cc_prebuilt_library_static { - name: "libclang_rt.builtins-x86_64", - defaults: ["toolchain_libs_defaults"], - host_supported: true, - } - - cc_prebuilt_library_static { - name: "libclang_rt.builtins-i386", + name: "libclang_rt.builtins", defaults: ["toolchain_libs_defaults"], host_supported: true, + vendor_available: true, + vendor_ramdisk_available: true, + native_bridge_supported: true, } cc_prebuilt_library_shared { - name: "libclang_rt.hwasan-aarch64-android", + name: "libclang_rt.hwasan", defaults: ["toolchain_libs_defaults"], } - cc_prebuilt_library_static { - name: "libclang_rt.builtins-i686-android", - defaults: ["toolchain_libs_defaults"], - vendor_ramdisk_available: true, - native_bridge_supported: true, - } - - cc_prebuilt_library_static { - name: "libclang_rt.builtins-x86_64-android", - defaults: [ - "linux_bionic_supported", - "toolchain_libs_defaults", - ], - native_bridge_supported: true, - vendor_ramdisk_available: true, - } - cc_prebuilt_library_static { name: "libunwind", defaults: [ @@ -144,30 +110,7 @@ func commonDefaultModules() string { } cc_prebuilt_library_static { - name: "libclang_rt.fuzzer-arm-android", - defaults: ["toolchain_libs_defaults"], - } - - cc_prebuilt_library_static { - name: "libclang_rt.fuzzer-aarch64-android", - defaults: ["toolchain_libs_defaults"], - } - - cc_prebuilt_library_static { - name: "libclang_rt.fuzzer-i686-android", - defaults: ["toolchain_libs_defaults"], - } - - cc_prebuilt_library_static { - name: "libclang_rt.fuzzer-x86_64-android", - defaults: [ - "linux_bionic_supported", - "toolchain_libs_defaults", - ], - } - - cc_prebuilt_library_static { - name: "libclang_rt.fuzzer-x86_64", + name: "libclang_rt.fuzzer", defaults: [ "linux_bionic_supported", "toolchain_libs_defaults", @@ -176,17 +119,12 @@ func commonDefaultModules() string { // Needed for sanitizer cc_prebuilt_library_shared { - name: "libclang_rt.ubsan_standalone-aarch64-android", + name: "libclang_rt.ubsan_standalone", defaults: ["toolchain_libs_defaults"], } cc_prebuilt_library_static { - name: "libclang_rt.ubsan_minimal-aarch64-android", - defaults: ["toolchain_libs_defaults"], - } - - cc_prebuilt_library_static { - name: "libclang_rt.ubsan_minimal-arm-android", + name: "libclang_rt.ubsan_minimal", defaults: ["toolchain_libs_defaults"], } diff --git a/cc/vndk.go b/cc/vndk.go index c9c9f2c08..bf6148b1c 100644 --- a/cc/vndk.go +++ b/cc/vndk.go @@ -450,7 +450,7 @@ var _ android.OutputFileProducer = &vndkLibrariesTxt{} // Therefore, by removing the library here, we cause it to only be installed if libc // depends on it. func llndkLibrariesTxtFactory() android.SingletonModule { - return newVndkLibrariesWithMakeVarFilter(llndkLibraries, "LLNDK_LIBRARIES", "libclang_rt.hwasan-") + return newVndkLibrariesWithMakeVarFilter(llndkLibraries, "LLNDK_LIBRARIES", "libclang_rt.hwasan") } // vndksp_libraries_txt is a singleton module whose content is a list of VNDKSP libraries diff --git a/rust/config/toolchain.go b/rust/config/toolchain.go index a769f121c..9c9d5724a 100644 --- a/rust/config/toolchain.go +++ b/rust/config/toolchain.go @@ -121,14 +121,7 @@ func LibFuzzerRuntimeLibrary(t Toolchain) string { } func LibclangRuntimeLibrary(t Toolchain, library string) string { - arch := t.LibclangRuntimeLibraryArch() - if arch == "" { - return "" - } - if !t.Bionic() { - return "libclang_rt." + library + "-" + arch - } - return "libclang_rt." + library + "-" + arch + "-android" + return "libclang_rt." + library } func LibRustRuntimeLibrary(t Toolchain, library string) string { diff --git a/rust/testing.go b/rust/testing.go index 1b34dfe8e..cb98bed65 100644 --- a/rust/testing.go +++ b/rust/testing.go @@ -88,13 +88,13 @@ func GatherRequiredDepsForTest() string { export_include_dirs: ["libprotobuf-cpp-full-includes"], } cc_library { - name: "libclang_rt.asan-aarch64-android", + name: "libclang_rt.asan", no_libcrt: true, nocrt: true, system_shared_libs: [], } cc_library { - name: "libclang_rt.hwasan_static-aarch64-android", + name: "libclang_rt.hwasan_static", no_libcrt: true, nocrt: true, system_shared_libs: [], diff --git a/rust/vendor_snapshot_test.go b/rust/vendor_snapshot_test.go index 03bd867a3..7be00425e 100644 --- a/rust/vendor_snapshot_test.go +++ b/rust/vendor_snapshot_test.go @@ -561,7 +561,7 @@ func TestVendorSnapshotUse(t *testing.T) { static_libs: [ "libvendor", "libvndk", - "libclang_rt.builtins-aarch64-android", + "libclang_rt.builtins", "note_memtag_heap_sync", ], shared_libs: [ @@ -589,7 +589,7 @@ func TestVendorSnapshotUse(t *testing.T) { static_libs: [ "libvendor", "libvndk", - "libclang_rt.builtins-arm-android", + "libclang_rt.builtins", ], shared_libs: [ "libvendor_available", @@ -731,19 +731,7 @@ func TestVendorSnapshotUse(t *testing.T) { } vendor_snapshot_static { - name: "libclang_rt.builtins-aarch64-android", - version: "30", - target_arch: "arm64", - vendor: true, - arch: { - arm64: { - src: "libclang_rt.builtins-aarch64-android.a", - }, - }, - } - - vendor_snapshot_static { - name: "libclang_rt.builtins-arm-android", + name: "libclang_rt.builtins", version: "30", target_arch: "arm64", vendor: true, @@ -751,6 +739,9 @@ func TestVendorSnapshotUse(t *testing.T) { arm: { src: "libclang_rt.builtins-arm-android.a", }, + arm64: { + src: "libclang_rt.builtins-aarch64-android.a", + }, }, } @@ -967,7 +958,7 @@ func TestVendorSnapshotUse(t *testing.T) { } libclientAndroidMkStaticLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkStaticLibs - if g, w := libclientAndroidMkStaticLibs, []string{"libvendor", "libvendor_without_snapshot", "libclang_rt.builtins-aarch64-android.vendor"}; !reflect.DeepEqual(g, w) { + if g, w := libclientAndroidMkStaticLibs, []string{"libvendor", "libvendor_without_snapshot", "libclang_rt.builtins.vendor"}; !reflect.DeepEqual(g, w) { t.Errorf("wanted libclient AndroidMkStaticLibs %q, got %q", w, g) } @@ -1024,7 +1015,7 @@ func TestVendorSnapshotUse(t *testing.T) { } memtagStaticLibs := ctx.ModuleForTests("memtag_binary", "android_vendor.30_arm64_armv8-a").Module().(*Module).Properties.AndroidMkStaticLibs - if g, w := memtagStaticLibs, []string{"libclang_rt.builtins-aarch64-android.vendor", "note_memtag_heap_sync.vendor"}; !reflect.DeepEqual(g, w) { + if g, w := memtagStaticLibs, []string{"libclang_rt.builtins.vendor", "note_memtag_heap_sync.vendor"}; !reflect.DeepEqual(g, w) { t.Errorf("wanted memtag_binary AndroidMkStaticLibs %q, got %q", w, g) } } From 6ca1fe0e7e7d43abefa46a62514199b8413dfcd3 Mon Sep 17 00:00:00 2001 From: Jingwen Chen Date: Fri, 25 Mar 2022 02:57:49 +0000 Subject: [PATCH 003/172] Suffix the build ID to the dirname of APK-in-APEX files. This fixes an issue with package manager's cache invalidation. Test: CI Bug: 226559955 Bug: 224589412 Change-Id: I8af49d51ff99cf8184d0e4d1136fff1cdb29c23e --- apex/apex.go | 31 +++++++++++++++++++++++--- apex/apex_test.go | 57 ++++++++++++++++++++++++++++++++++++----------- 2 files changed, 72 insertions(+), 16 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index fef275747..418858ccd 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -19,6 +19,7 @@ package apex import ( "fmt" "path/filepath" + "regexp" "sort" "strings" @@ -1658,13 +1659,33 @@ type androidApp interface { var _ androidApp = (*java.AndroidApp)(nil) var _ androidApp = (*java.AndroidAppImport)(nil) +func sanitizedBuildIdForPath(ctx android.BaseModuleContext) string { + buildId := ctx.Config().BuildId() + + // The build ID is used as a suffix for a filename, so ensure that + // the set of characters being used are sanitized. + // - any word character: [a-zA-Z0-9_] + // - dots: . + // - dashes: - + validRegex := regexp.MustCompile(`^[\w\.\-\_]+$`) + if !validRegex.MatchString(buildId) { + ctx.ModuleErrorf("Unable to use build id %s as filename suffix, valid characters are [a-z A-Z 0-9 _ . -].", buildId) + } + return buildId +} + func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile { appDir := "app" if aapp.Privileged() { appDir = "priv-app" } - dirInApex := filepath.Join(appDir, aapp.InstallApkName()) + + // TODO(b/224589412, b/226559955): Ensure that the subdirname is suffixed + // so that PackageManager correctly invalidates the existing installed apk + // in favour of the new APK-in-APEX. See bugs for more information. + dirInApex := filepath.Join(appDir, aapp.InstallApkName()+"@"+sanitizedBuildIdForPath(ctx)) fileToCopy := aapp.OutputFile() + af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp) af.jacocoReportClassesFile = aapp.JacocoReportClassesFile() af.lintDepSets = aapp.LintDepSets() @@ -1897,8 +1918,12 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { if ap.Privileged() { appDir = "priv-app" } - af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(), - filepath.Join(appDir, ap.BaseModuleName()), appSet, ap) + // TODO(b/224589412, b/226559955): Ensure that the dirname is + // suffixed so that PackageManager correctly invalidates the + // existing installed apk in favour of the new APK-in-APEX. + // See bugs for more information. + appDirName := filepath.Join(appDir, ap.BaseModuleName()+"@"+sanitizedBuildIdForPath(ctx)) + af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(), appDirName, appSet, ap) af.certificate = java.PresignedCertificate filesInfo = append(filesInfo, af) } else { diff --git a/apex/apex_test.go b/apex/apex_test.go index 85bd59526..ac20f0613 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -219,6 +219,7 @@ var prepareForApexTest = android.GroupFixturePreparers( // not because of these tests specifically (it's not used by the tests) variables.Platform_version_active_codenames = []string{"Q", "Tiramisu"} variables.Platform_vndk_version = proptools.StringPtr("29") + variables.BuildId = proptools.StringPtr("TEST.BUILD_ID") }), ) @@ -687,7 +688,7 @@ func TestDefaults(t *testing.T) { "etc/myetc", "javalib/myjar.jar", "lib64/mylib.so", - "app/AppFoo/AppFoo.apk", + "app/AppFoo@TEST.BUILD_ID/AppFoo.apk", "overlay/blue/rro.apk", "etc/bpf/bpf.o", "etc/bpf/bpf2.o", @@ -5667,8 +5668,8 @@ func TestApexWithApps(t *testing.T) { apexRule := module.Rule("apexRule") copyCmds := apexRule.Args["copy_commands"] - ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk") - ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk") + ensureContains(t, copyCmds, "image.apex/app/AppFoo@TEST.BUILD_ID/AppFoo.apk") + ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv@TEST.BUILD_ID/AppFooPriv.apk") appZipRule := ctx.ModuleForTests("AppFoo", "android_common_apex10000").Description("zip jni libs") // JNI libraries are uncompressed @@ -5685,6 +5686,36 @@ func TestApexWithApps(t *testing.T) { } } +func TestApexWithAppImportBuildId(t *testing.T) { + invalidBuildIds := []string{"../", "a b", "a/b", "a/b/../c", "/a"} + for _, id := range invalidBuildIds { + message := fmt.Sprintf("Unable to use build id %s as filename suffix", id) + fixture := android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + variables.BuildId = proptools.StringPtr(id) + }) + testApexError(t, message, `apex { + name: "myapex", + key: "myapex.key", + apps: ["AppFooPrebuilt"], + updatable: false, + } + + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + + android_app_import { + name: "AppFooPrebuilt", + apk: "PrebuiltAppFoo.apk", + presigned: true, + apex_available: ["myapex"], + } + `, fixture) + } +} + func TestApexWithAppImports(t *testing.T) { ctx := testApex(t, ` apex { @@ -5730,8 +5761,8 @@ func TestApexWithAppImports(t *testing.T) { apexRule := module.Rule("apexRule") copyCmds := apexRule.Args["copy_commands"] - ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk") - ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AwesomePrebuiltAppFooPriv.apk") + ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt@TEST.BUILD_ID/AppFooPrebuilt.apk") + ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt@TEST.BUILD_ID/AwesomePrebuiltAppFooPriv.apk") } func TestApexWithAppImportsPrefer(t *testing.T) { @@ -5772,7 +5803,7 @@ func TestApexWithAppImportsPrefer(t *testing.T) { })) ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ - "app/AppFoo/AppFooPrebuilt.apk", + "app/AppFoo@TEST.BUILD_ID/AppFooPrebuilt.apk", }) } @@ -5805,7 +5836,7 @@ func TestApexWithTestHelperApp(t *testing.T) { apexRule := module.Rule("apexRule") copyCmds := apexRule.Args["copy_commands"] - ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk") + ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo@TEST.BUILD_ID/TesterHelpAppFoo.apk") } func TestApexPropertiesShouldBeDefaultable(t *testing.T) { @@ -6248,8 +6279,8 @@ func TestOverrideApex(t *testing.T) { apexRule := module.Rule("apexRule") copyCmds := apexRule.Args["copy_commands"] - ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk") - ensureContains(t, copyCmds, "image.apex/app/override_app/override_app.apk") + ensureNotContains(t, copyCmds, "image.apex/app/app@TEST.BUILD_ID/app.apk") + ensureContains(t, copyCmds, "image.apex/app/override_app@TEST.BUILD_ID/override_app.apk") ensureNotContains(t, copyCmds, "image.apex/etc/bpf/bpf.o") ensureContains(t, copyCmds, "image.apex/etc/bpf/override_bpf.o") @@ -7035,7 +7066,7 @@ func TestAppBundle(t *testing.T) { content := bundleConfigRule.Args["content"] ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) - ensureContains(t, content, `"apex_config":{"apex_embedded_apk_config":[{"package_name":"com.android.foo","path":"app/AppFoo/AppFoo.apk"}]}`) + ensureContains(t, content, `"apex_config":{"apex_embedded_apk_config":[{"package_name":"com.android.foo","path":"app/AppFoo@TEST.BUILD_ID/AppFoo.apk"}]}`) } func TestAppSetBundle(t *testing.T) { @@ -7066,9 +7097,9 @@ func TestAppSetBundle(t *testing.T) { if len(copyCmds) != 3 { t.Fatalf("Expected 3 commands, got %d in:\n%s", len(copyCmds), s) } - ensureMatches(t, copyCmds[0], "^rm -rf .*/app/AppSet$") - ensureMatches(t, copyCmds[1], "^mkdir -p .*/app/AppSet$") - ensureMatches(t, copyCmds[2], "^unzip .*-d .*/app/AppSet .*/AppSet.zip$") + ensureMatches(t, copyCmds[0], "^rm -rf .*/app/AppSet@TEST.BUILD_ID$") + ensureMatches(t, copyCmds[1], "^mkdir -p .*/app/AppSet@TEST.BUILD_ID$") + ensureMatches(t, copyCmds[2], "^unzip .*-d .*/app/AppSet@TEST.BUILD_ID .*/AppSet.zip$") } func TestAppSetBundlePrebuilt(t *testing.T) { From 56d75785bd52c8a8f684935eed67fceb2c0e6850 Mon Sep 17 00:00:00 2001 From: Matt Banda Date: Fri, 1 Apr 2022 17:48:31 +0000 Subject: [PATCH 004/172] Surface Java APIs Used By APK-only Modules. Previously we were only generating used-by API-coverage for APEX modules. This change adds support for APK-only modules such as NetworkStack and DocumentsUI. Bug: b/216313756 Forrest Run: https://android-build.googleplex.com/builds/abtd/run/L10800000953846781 Test: TARGET_BUILD_VARIANT=userdebug PRODUCT=mainline_modules_x86 ./vendor/google/build/build_unbundled_coverage_mainline_module.sh -j16 Change-Id: Id17e4a55c2a52e9903632a654e778f8d54982dfc --- apex/testing.go | 1 - java/androidmk.go | 10 +++++++++- java/app.go | 3 +++ java/app_builder.go | 12 ++++++++++++ java/testing.go | 2 ++ 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/apex/testing.go b/apex/testing.go index 337c86210..69bd73e5d 100644 --- a/apex/testing.go +++ b/apex/testing.go @@ -24,7 +24,6 @@ var PrepareForTestWithApexBuildComponents = android.GroupFixturePreparers( android.MockFS{ // Needed by apex. "system/core/rootdir/etc/public.libraries.android.txt": nil, - "build/soong/scripts/gen_java_usedby_apex.sh": nil, "build/soong/scripts/gen_ndk_backedby_apex.sh": nil, // Needed by prebuilt_apex. "build/soong/scripts/unpack-prebuilt-apex.sh": nil, diff --git a/java/androidmk.go b/java/androidmk.go index e3e85a996..f51e072bd 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -409,7 +409,15 @@ func (app *AndroidApp) AndroidMkEntries() []android.AndroidMkEntries { entries.SetOptionalPaths("LOCAL_SOONG_LINT_REPORTS", app.linter.reports) }, }, - }} + ExtraFooters: []android.AndroidMkExtraFootersFunc{ + func(w io.Writer, name, prefix, moduleDir string) { + if app.javaApiUsedByOutputFile.String() != "" { + fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s/$(notdir %s))\n", + app.installApkName, app.javaApiUsedByOutputFile.String(), "java_apis_used_by_apex", app.javaApiUsedByOutputFile.String()) + } + }, + }}, + } } func (a *AndroidApp) getOverriddenPackages() []string { diff --git a/java/app.go b/java/app.go index 5f67482eb..784ac6e7c 100755 --- a/java/app.go +++ b/java/app.go @@ -169,6 +169,8 @@ type AndroidApp struct { overriddenManifestPackageName string android.ApexBundleDepsInfo + + javaApiUsedByOutputFile android.ModuleOutPath } func (a *AndroidApp) IsInstallable() bool { @@ -277,6 +279,7 @@ func (a *AndroidTestHelperApp) GenerateAndroidBuildActions(ctx android.ModuleCon func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) { a.checkAppSdkVersions(ctx) a.generateAndroidBuildActions(ctx) + a.generateJavaUsedByApex(ctx) } func (a *AndroidApp) checkAppSdkVersions(ctx android.ModuleContext) { diff --git a/java/app_builder.go b/java/app_builder.go index 74cd85c08..31023cb9c 100644 --- a/java/app_builder.go +++ b/java/app_builder.go @@ -258,6 +258,18 @@ func TransformJniLibsToJar(ctx android.ModuleContext, outputFile android.Writabl }) } +func (a *AndroidApp) generateJavaUsedByApex(ctx android.ModuleContext) { + javaApiUsedByOutputFile := android.PathForModuleOut(ctx, a.installApkName+"_using.xml") + javaUsedByRule := android.NewRuleBuilder(pctx, ctx) + javaUsedByRule.Command(). + Tool(android.PathForSource(ctx, "build/soong/scripts/gen_java_usedby_apex.sh")). + BuiltTool("dexdeps"). + Output(javaApiUsedByOutputFile). + Input(a.Library.Module.outputFile) + javaUsedByRule.Build("java_usedby_list", "Generate Java APIs used by Apex") + a.javaApiUsedByOutputFile = javaApiUsedByOutputFile +} + func targetToJniDir(target android.Target) string { return filepath.Join("lib", target.Arch.Abi[0]) } diff --git a/java/testing.go b/java/testing.go index 82aa29b61..9178b1653 100644 --- a/java/testing.go +++ b/java/testing.go @@ -54,6 +54,8 @@ var PrepareForTestWithJavaBuildComponents = android.GroupFixturePreparers( "build/soong/java/lint_defaults.txt": nil, // Needed for apps that do not provide their own. "build/make/target/product/security": nil, + // Required to generate Java used-by API coverage + "build/soong/scripts/gen_java_usedby_apex.sh": nil, }.AddToFixture(), ) From ccc679e4be454ef09a5b9bbdd29c0fbeb0dc51a3 Mon Sep 17 00:00:00 2001 From: Matt Banda Date: Fri, 1 Apr 2022 17:48:31 +0000 Subject: [PATCH 005/172] Surface Java APIs Used By APK-only Modules. Previously we were only generating used-by API-coverage for APEX modules. This change adds support for APK-only modules such as NetworkStack and DocumentsUI. Bug: b/216313756 Forrest Run: https://android-build.googleplex.com/builds/abtd/run/L10800000953846781 Test: TARGET_BUILD_VARIANT=userdebug PRODUCT=mainline_modules_x86 ./vendor/google/build/build_unbundled_coverage_mainline_module.sh -j16 Change-Id: Id17e4a55c2a52e9903632a654e778f8d54982dfc Merged-In: Id17e4a55c2a52e9903632a654e778f8d54982dfc (cherry picked from commit 56d75785bd52c8a8f684935eed67fceb2c0e6850) --- apex/testing.go | 1 - java/androidmk.go | 10 +++++++++- java/app.go | 3 +++ java/app_builder.go | 12 ++++++++++++ java/testing.go | 2 ++ 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/apex/testing.go b/apex/testing.go index 337c86210..69bd73e5d 100644 --- a/apex/testing.go +++ b/apex/testing.go @@ -24,7 +24,6 @@ var PrepareForTestWithApexBuildComponents = android.GroupFixturePreparers( android.MockFS{ // Needed by apex. "system/core/rootdir/etc/public.libraries.android.txt": nil, - "build/soong/scripts/gen_java_usedby_apex.sh": nil, "build/soong/scripts/gen_ndk_backedby_apex.sh": nil, // Needed by prebuilt_apex. "build/soong/scripts/unpack-prebuilt-apex.sh": nil, diff --git a/java/androidmk.go b/java/androidmk.go index e3e85a996..f51e072bd 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -409,7 +409,15 @@ func (app *AndroidApp) AndroidMkEntries() []android.AndroidMkEntries { entries.SetOptionalPaths("LOCAL_SOONG_LINT_REPORTS", app.linter.reports) }, }, - }} + ExtraFooters: []android.AndroidMkExtraFootersFunc{ + func(w io.Writer, name, prefix, moduleDir string) { + if app.javaApiUsedByOutputFile.String() != "" { + fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s/$(notdir %s))\n", + app.installApkName, app.javaApiUsedByOutputFile.String(), "java_apis_used_by_apex", app.javaApiUsedByOutputFile.String()) + } + }, + }}, + } } func (a *AndroidApp) getOverriddenPackages() []string { diff --git a/java/app.go b/java/app.go index a1a854e50..1b65f33ca 100755 --- a/java/app.go +++ b/java/app.go @@ -169,6 +169,8 @@ type AndroidApp struct { overriddenManifestPackageName string android.ApexBundleDepsInfo + + javaApiUsedByOutputFile android.ModuleOutPath } func (a *AndroidApp) IsInstallable() bool { @@ -277,6 +279,7 @@ func (a *AndroidTestHelperApp) GenerateAndroidBuildActions(ctx android.ModuleCon func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) { a.checkAppSdkVersions(ctx) a.generateAndroidBuildActions(ctx) + a.generateJavaUsedByApex(ctx) } func (a *AndroidApp) checkAppSdkVersions(ctx android.ModuleContext) { diff --git a/java/app_builder.go b/java/app_builder.go index 74cd85c08..31023cb9c 100644 --- a/java/app_builder.go +++ b/java/app_builder.go @@ -258,6 +258,18 @@ func TransformJniLibsToJar(ctx android.ModuleContext, outputFile android.Writabl }) } +func (a *AndroidApp) generateJavaUsedByApex(ctx android.ModuleContext) { + javaApiUsedByOutputFile := android.PathForModuleOut(ctx, a.installApkName+"_using.xml") + javaUsedByRule := android.NewRuleBuilder(pctx, ctx) + javaUsedByRule.Command(). + Tool(android.PathForSource(ctx, "build/soong/scripts/gen_java_usedby_apex.sh")). + BuiltTool("dexdeps"). + Output(javaApiUsedByOutputFile). + Input(a.Library.Module.outputFile) + javaUsedByRule.Build("java_usedby_list", "Generate Java APIs used by Apex") + a.javaApiUsedByOutputFile = javaApiUsedByOutputFile +} + func targetToJniDir(target android.Target) string { return filepath.Join("lib", target.Arch.Abi[0]) } diff --git a/java/testing.go b/java/testing.go index 82aa29b61..9178b1653 100644 --- a/java/testing.go +++ b/java/testing.go @@ -54,6 +54,8 @@ var PrepareForTestWithJavaBuildComponents = android.GroupFixturePreparers( "build/soong/java/lint_defaults.txt": nil, // Needed for apps that do not provide their own. "build/make/target/product/security": nil, + // Required to generate Java used-by API coverage + "build/soong/scripts/gen_java_usedby_apex.sh": nil, }.AddToFixture(), ) From fbc5effdfd7b16c0cbc04ed94687d99228f95e94 Mon Sep 17 00:00:00 2001 From: Tianyu Jiang Date: Mon, 2 May 2022 22:57:18 +0000 Subject: [PATCH 006/172] Revert "Update to clang-r450784e" Revert submission 2080443-update-clang-8508608 Reason for revert: b/230930120 Reverted Changes: I678829f02:Update to clang-r450784e Change-Id: I89e336ec1deffddbbbf872a3ee4a1082a65fb137 --- cc/config/global.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cc/config/global.go b/cc/config/global.go index dc6310c81..3caf32792 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -286,8 +286,8 @@ var ( // prebuilts/clang default settings. ClangDefaultBase = "prebuilts/clang/host" - ClangDefaultVersion = "clang-r450784e" - ClangDefaultShortVersion = "14.0.7" + ClangDefaultVersion = "clang-r450784d" + ClangDefaultShortVersion = "14.0.6" // Directories with warnings from Android.bp files. WarningAllowedProjects = []string{ From a2054105d35bf805fa0ef1528a08df0e339438c2 Mon Sep 17 00:00:00 2001 From: Stephen Hines Date: Mon, 2 May 2022 23:44:24 -0700 Subject: [PATCH 007/172] Reland "Update to clang-r450784e" This reverts commit fbc5effdfd7b16c0cbc04ed94687d99228f95e94. Bug: http://b/197965342 Bug: http://b/230930120 Test: m and also test internal targets Change-Id: I49b2d80ef4191ebb08bb6e80507042ee628c7f09 --- cc/config/global.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cc/config/global.go b/cc/config/global.go index 3caf32792..dc6310c81 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -286,8 +286,8 @@ var ( // prebuilts/clang default settings. ClangDefaultBase = "prebuilts/clang/host" - ClangDefaultVersion = "clang-r450784d" - ClangDefaultShortVersion = "14.0.6" + ClangDefaultVersion = "clang-r450784e" + ClangDefaultShortVersion = "14.0.7" // Directories with warnings from Android.bp files. WarningAllowedProjects = []string{ From 88e6445b689edceeacf5e998e5daab47542e80bd Mon Sep 17 00:00:00 2001 From: Artur Satayev Date: Wed, 4 May 2022 12:28:59 +0000 Subject: [PATCH 008/172] Add support to max-target-s to generate_hiddenapi_lists Test: make Bug: 169748350 Change-Id: I2662a643a190ed531d85755d01e1be9c49c02e25 --- scripts/hiddenapi/generate_hiddenapi_lists.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/hiddenapi/generate_hiddenapi_lists.py b/scripts/hiddenapi/generate_hiddenapi_lists.py index 35e0948f0..6546c7f80 100755 --- a/scripts/hiddenapi/generate_hiddenapi_lists.py +++ b/scripts/hiddenapi/generate_hiddenapi_lists.py @@ -27,6 +27,7 @@ FLAG_MAX_TARGET_O = 'max-target-o' FLAG_MAX_TARGET_P = 'max-target-p' FLAG_MAX_TARGET_Q = 'max-target-q' FLAG_MAX_TARGET_R = 'max-target-r' +FLAG_MAX_TARGET_S = 'max-target-s' FLAG_CORE_PLATFORM_API = 'core-platform-api' FLAG_PUBLIC_API = 'public-api' FLAG_SYSTEM_API = 'system-api' @@ -41,6 +42,7 @@ FLAGS_API_LIST = [ FLAG_MAX_TARGET_P, FLAG_MAX_TARGET_Q, FLAG_MAX_TARGET_R, + FLAG_MAX_TARGET_S, ] ALL_FLAGS = FLAGS_API_LIST + [ FLAG_CORE_PLATFORM_API, From 1a44a993b5131f28e5d4c58e5772b9c632134229 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 6 May 2022 09:38:02 +0000 Subject: [PATCH 009/172] For each sdk built generate a JSON file describing its contents Some build scripts need to know information about the contents of an sdk, such as what APIs it provides (via java_sdk_library). Rather than duplicate that information in the scripts or attempt to access that information (where available) by looking at the contents of the snapshot this change generates a JSON file that sits alongside the snapshot itself. The info file can be generated without generating the snapshot zip file but whenever a snapshot zip file is generated the info is generated too. The info file sits alongside the zip file in out/mainline-sdks. Bug: 204763318 Test: m art-module-sdk m dist Merged-In: I289530bb21693dc6443826c24c17c9b5d85d2d8b Change-Id: I289530bb21693dc6443826c24c17c9b5d85d2d8b (cherry picked from commit c6ba182f3c6dc8ba58675dc05262d2c8273c47a4) --- sdk/java_sdk_test.go | 38 +++++++++++ sdk/sdk.go | 17 +++-- sdk/sdk_test.go | 5 +- sdk/testing.go | 15 +++++ sdk/update.go | 150 +++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 212 insertions(+), 13 deletions(-) diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go index f0d3b35d7..e3e9a0763 100644 --- a/sdk/java_sdk_test.go +++ b/sdk/java_sdk_test.go @@ -879,6 +879,44 @@ sdk_snapshot { .intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar .intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt .intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt +`), + checkInfoContents(` +[ + { + "@type": "sdk", + "@name": "mysdk", + "java_header_libs": [ + "exported-system-module", + "system-module" + ], + "java_sdk_libs": [ + "myjavalib" + ], + "java_system_modules": [ + "my-system-modules" + ] + }, + { + "@type": "java_library", + "@name": "exported-system-module" + }, + { + "@type": "java_system_modules", + "@name": "my-system-modules", + "@deps": [ + "exported-system-module", + "system-module" + ] + }, + { + "@type": "java_sdk_library", + "@name": "myjavalib" + }, + { + "@type": "java_library", + "@name": "system-module" + } +] `), ) } diff --git a/sdk/sdk.go b/sdk/sdk.go index 84c9a96e4..26f517de3 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -76,6 +76,8 @@ type sdk struct { snapshotFile android.OptionalPath + infoFile android.OptionalPath + // The builder, preserved for testing. builderForTests *snapshotBuilder } @@ -192,27 +194,32 @@ func (s *sdk) GenerateAndroidBuildActions(ctx android.ModuleContext) { } // Generate the snapshot from the member info. - p := s.buildSnapshot(ctx, sdkVariants) - zip := ctx.InstallFile(android.PathForMainlineSdksInstall(ctx), p.Base(), p) - s.snapshotFile = android.OptionalPathForPath(zip) + s.buildSnapshot(ctx, sdkVariants) } } func (s *sdk) AndroidMkEntries() []android.AndroidMkEntries { - if !s.snapshotFile.Valid() { + if !s.snapshotFile.Valid() != !s.infoFile.Valid() { + panic("Snapshot (%q) and info file (%q) should both be set or neither should be set.") + } else if !s.snapshotFile.Valid() { return []android.AndroidMkEntries{} } return []android.AndroidMkEntries{android.AndroidMkEntries{ Class: "FAKE", OutputFile: s.snapshotFile, - DistFiles: android.MakeDefaultDistFiles(s.snapshotFile.Path()), + DistFiles: android.MakeDefaultDistFiles(s.snapshotFile.Path(), s.infoFile.Path()), Include: "$(BUILD_PHONY_PACKAGE)", ExtraFooters: []android.AndroidMkExtraFootersFunc{ func(w io.Writer, name, prefix, moduleDir string) { // Allow the sdk to be built by simply passing its name on the command line. fmt.Fprintln(w, ".PHONY:", s.Name()) fmt.Fprintln(w, s.Name()+":", s.snapshotFile.String()) + + // Allow the sdk info to be built by simply passing its name on the command line. + infoTarget := s.Name() + ".info" + fmt.Fprintln(w, ".PHONY:", infoTarget) + fmt.Fprintln(w, infoTarget+":", s.infoFile.String()) }, }, }} diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go index 83294f6ab..7af5d80de 100644 --- a/sdk/sdk_test.go +++ b/sdk/sdk_test.go @@ -321,7 +321,10 @@ func TestSdkInstall(t *testing.T) { result := testSdkWithFs(t, sdk, nil) CheckSnapshot(t, result, "mysdk", "", - checkAllOtherCopyRules(`.intermediates/mysdk/common_os/mysdk-current.zip -> mysdk-current.zip`)) + checkAllOtherCopyRules(` +.intermediates/mysdk/common_os/mysdk-current.info -> mysdk-current.info +.intermediates/mysdk/common_os/mysdk-current.zip -> mysdk-current.zip +`)) } type EmbeddedPropertiesStruct struct { diff --git a/sdk/testing.go b/sdk/testing.go index 062f2000e..b0f5fdc62 100644 --- a/sdk/testing.go +++ b/sdk/testing.go @@ -142,6 +142,7 @@ func getSdkSnapshotBuildInfo(t *testing.T, result *android.TestResult, sdk *sdk) androidBpContents: sdk.GetAndroidBpContentsForTests(), androidUnversionedBpContents: sdk.GetUnversionedAndroidBpContentsForTests(), androidVersionedBpContents: sdk.GetVersionedAndroidBpContentsForTests(), + infoContents: sdk.GetInfoContentsForTests(), snapshotTestCustomizations: map[snapshotTest]*snapshotTestCustomization{}, targetBuildRelease: sdk.builderForTests.targetBuildRelease, } @@ -402,6 +403,17 @@ func checkMergeZips(expected ...string) snapshotBuildInfoChecker { } } +// Check that the snapshot's info contents are ciorrect. +// +// Both the expected and actual string are both trimmed before comparing. +func checkInfoContents(expected string) snapshotBuildInfoChecker { + return func(info *snapshotBuildInfo) { + info.t.Helper() + android.AssertTrimmedStringEquals(info.t, "info contents do not match", + expected, info.infoContents) + } +} + type resultChecker func(t *testing.T, result *android.TestResult) // snapshotTestPreparer registers a preparer that will be used to customize the specified @@ -479,6 +491,9 @@ type snapshotBuildInfo struct { // The contents of the versioned Android.bp file androidVersionedBpContents string + // The contents of the info file. + infoContents string + // The paths, relative to the snapshot root, of all files and directories copied into the // snapshot. snapshotContents []string diff --git a/sdk/update.go b/sdk/update.go index 5db604b7c..71bd042a6 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -15,6 +15,8 @@ package sdk import ( + "bytes" + "encoding/json" "fmt" "reflect" "sort" @@ -219,9 +221,19 @@ func (s *sdk) collectMembers(ctx android.ModuleContext) { exportedComponentsInfo = ctx.OtherModuleProvider(child, android.ExportedComponentsInfoProvider).(android.ExportedComponentsInfo) } + var container android.SdkAware + if parent != ctx.Module() { + container = parent.(android.SdkAware) + } + export := memberTag.ExportMember() s.memberVariantDeps = append(s.memberVariantDeps, sdkMemberVariantDep{ - s, memberType, child.(android.SdkAware), export, exportedComponentsInfo, + sdkVariant: s, + memberType: memberType, + variant: child.(android.SdkAware), + container: container, + export: export, + exportedComponentsInfo: exportedComponentsInfo, }) // Recurse down into the member's dependencies as it may have dependencies that need to be @@ -311,7 +323,7 @@ func versionedSdkMemberName(ctx android.ModuleContext, memberName string, versio // buildSnapshot is the main function in this source file. It creates rules to copy // the contents (header files, stub libraries, etc) into the zip file. -func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) android.OutputPath { +func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) { // Aggregate all the sdkMemberVariantDep instances from all the sdk variants. hasLicenses := false @@ -370,9 +382,9 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) andro // Unversioned modules are not required in that case because the numbered version will be a // finalized version of the snapshot that is intended to be kept separate from the generateUnversioned := version == soongSdkSnapshotVersionUnversioned || version == soongSdkSnapshotVersionCurrent - snapshotZipFileSuffix := "" + snapshotFileSuffix := "" if generateVersioned { - snapshotZipFileSuffix = "-" + version + snapshotFileSuffix = "-" + version } currentBuildRelease := latestBuildRelease() @@ -489,7 +501,7 @@ be unnecessary as every module in the sdk already has its own licenses property. filesToZip := builder.filesToZip // zip them all - zipPath := fmt.Sprintf("%s%s.zip", ctx.ModuleName(), snapshotZipFileSuffix) + zipPath := fmt.Sprintf("%s%s.zip", ctx.ModuleName(), snapshotFileSuffix) outputZipFile := android.PathForModuleOut(ctx, zipPath).OutputPath outputDesc := "Building snapshot for " + ctx.ModuleName() @@ -502,7 +514,7 @@ be unnecessary as every module in the sdk already has its own licenses property. zipFile = outputZipFile desc = outputDesc } else { - intermediatePath := fmt.Sprintf("%s%s.unmerged.zip", ctx.ModuleName(), snapshotZipFileSuffix) + intermediatePath := fmt.Sprintf("%s%s.unmerged.zip", ctx.ModuleName(), snapshotFileSuffix) zipFile = android.PathForModuleOut(ctx, intermediatePath).OutputPath desc = "Building intermediate snapshot for " + ctx.ModuleName() } @@ -527,7 +539,120 @@ be unnecessary as every module in the sdk already has its own licenses property. }) } - return outputZipFile + modules := s.generateInfoData(ctx, memberVariantDeps) + + // Output the modules information as pretty printed JSON. + info := newGeneratedFile(ctx, fmt.Sprintf("%s%s.info", ctx.ModuleName(), snapshotFileSuffix)) + output, err := json.MarshalIndent(modules, "", " ") + if err != nil { + ctx.ModuleErrorf("error generating %q: %s", info, err) + } + builder.infoContents = string(output) + info.generatedContents.UnindentedPrintf("%s", output) + info.build(pctx, ctx, nil) + infoPath := info.path + installedInfo := ctx.InstallFile(android.PathForMainlineSdksInstall(ctx), infoPath.Base(), infoPath) + s.infoFile = android.OptionalPathForPath(installedInfo) + + // Install the zip, making sure that the info file has been installed as well. + installedZip := ctx.InstallFile(android.PathForMainlineSdksInstall(ctx), outputZipFile.Base(), outputZipFile, installedInfo) + s.snapshotFile = android.OptionalPathForPath(installedZip) +} + +type moduleInfo struct { + // The type of the module, e.g. java_sdk_library + moduleType string + // The name of the module. + name string + // A list of additional dependencies of the module. + deps []string + // Additional dynamic properties. + dynamic map[string]interface{} +} + +func (m *moduleInfo) MarshalJSON() ([]byte, error) { + buffer := bytes.Buffer{} + + separator := "" + writeObjectPair := func(key string, value interface{}) { + buffer.WriteString(fmt.Sprintf("%s%q: ", separator, key)) + b, err := json.Marshal(value) + if err != nil { + panic(err) + } + buffer.Write(b) + separator = "," + } + + buffer.WriteString("{") + writeObjectPair("@type", m.moduleType) + writeObjectPair("@name", m.name) + if m.deps != nil { + writeObjectPair("@deps", m.deps) + } + for _, k := range android.SortedStringKeys(m.dynamic) { + v := m.dynamic[k] + writeObjectPair(k, v) + } + buffer.WriteString("}") + return buffer.Bytes(), nil +} + +var _ json.Marshaler = (*moduleInfo)(nil) + +// generateInfoData creates a list of moduleInfo structures that will be marshalled into JSON. +func (s *sdk) generateInfoData(ctx android.ModuleContext, memberVariantDeps []sdkMemberVariantDep) interface{} { + modules := []*moduleInfo{} + sdkInfo := moduleInfo{ + moduleType: "sdk", + name: ctx.ModuleName(), + dynamic: map[string]interface{}{}, + } + modules = append(modules, &sdkInfo) + + name2Info := map[string]*moduleInfo{} + getModuleInfo := func(module android.Module) *moduleInfo { + name := module.Name() + info := name2Info[name] + if info == nil { + moduleType := ctx.OtherModuleType(module) + // Remove any suffix added when creating modules dynamically. + moduleType = strings.Split(moduleType, "__")[0] + info = &moduleInfo{ + moduleType: moduleType, + name: name, + } + name2Info[name] = info + } + return info + } + + for _, memberVariantDep := range memberVariantDeps { + propertyName := memberVariantDep.memberType.SdkPropertyName() + var list []string + if v, ok := sdkInfo.dynamic[propertyName]; ok { + list = v.([]string) + } + + memberName := memberVariantDep.variant.Name() + list = append(list, memberName) + sdkInfo.dynamic[propertyName] = android.SortedUniqueStrings(list) + + if memberVariantDep.container != nil { + containerInfo := getModuleInfo(memberVariantDep.container) + containerInfo.deps = android.SortedUniqueStrings(append(containerInfo.deps, memberName)) + } + + // Make sure that the module info is created for each module. + getModuleInfo(memberVariantDep.variant) + } + + for _, memberName := range android.SortedStringKeys(name2Info) { + info := name2Info[memberName] + modules = append(modules, info) + } + + return modules } // filterOutComponents removes any item from the deps list that is a component of another item in @@ -1033,6 +1158,10 @@ func (s *sdk) GetAndroidBpContentsForTests() string { return contents.content.String() } +func (s *sdk) GetInfoContentsForTests() string { + return s.builderForTests.infoContents +} + func (s *sdk) GetUnversionedAndroidBpContentsForTests() string { contents := &generatedContents{} generateFilteredBpContents(contents, s.builderForTests.bpFile, func(module *bpModule) bool { @@ -1087,6 +1216,8 @@ type snapshotBuilder struct { // The target build release for which the snapshot is to be generated. targetBuildRelease *buildRelease + + infoContents string } func (s *snapshotBuilder) CopyToSnapshot(src android.Path, dest string) { @@ -1322,6 +1453,11 @@ type sdkMemberVariantDep struct { // The variant that is added to the sdk. variant android.SdkAware + // The optional container of this member, i.e. the module that is depended upon by the sdk + // (possibly transitively) and whose dependency on this module is why it was added to the sdk. + // Is nil if this a direct dependency of the sdk. + container android.SdkAware + // True if the member should be exported, i.e. accessible, from outside the sdk. export bool From dec8138db1ddb8e7e768135b3f4682154b23163d Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Mon, 16 May 2022 13:10:47 +0000 Subject: [PATCH 010/172] Add custom java_sdk_library info to the SDK info file (cherry picked from commit 958806b8c846a5c37830721d82e2d2adb9e7dc16) Previously the SDK info file only contained basic common information about each member. This change adds support for each member to provide custom information to add to the info file. It uses that mechanism to add the following: * "dist_stem" * "scopes" object containing: * for each scope a: "" object containing: * "current_api" - the path within the snapshot for the API's .txt file. * "removed_api" - the path within the snapshot for the removed API's .txt file. * "latest_api" - the path within the build to the latest finalized API .txt file. * "latest_removed_api" - the path within the build to the latest finalized removed API .txt file. In order to access the latest API files it was necessary to add and resolve dependencies on the module that makes them available. In order to do that safely the code for creating the names of the modules was refactored to avoid duplicating the name creation logic. Bug: 204763318 Test: m nothing Merged-In: Ica68abbd2b2c7c2b2b7877b502f96cc89f06fd68 Change-Id: Ica68abbd2b2c7c2b2b7877b502f96cc89f06fd68 --- android/sdk.go | 7 ++ java/prebuilt_apis.go | 15 +++-- java/sdk_library.go | 136 ++++++++++++++++++++++++++++++++++++--- java/sdk_library_test.go | 10 +++ sdk/java_sdk_test.go | 27 +++++++- sdk/testing.go | 4 +- sdk/update.go | 24 ++++--- 7 files changed, 192 insertions(+), 31 deletions(-) diff --git a/android/sdk.go b/android/sdk.go index 3a5624030..9317910ee 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -961,3 +961,10 @@ type ExportedComponentsInfo struct { } var ExportedComponentsInfoProvider = blueprint.NewProvider(ExportedComponentsInfo{}) + +// AdditionalSdkInfo contains additional properties to add to the generated SDK info file. +type AdditionalSdkInfo struct { + Properties map[string]interface{} +} + +var AdditionalSdkInfoProvider = blueprint.NewProvider(AdditionalSdkInfo{}) diff --git a/java/prebuilt_apis.go b/java/prebuilt_apis.go index 44650a6d0..944970783 100644 --- a/java/prebuilt_apis.go +++ b/java/prebuilt_apis.go @@ -212,6 +212,10 @@ func createSystemModules(mctx android.LoadHookContext, version, scope string) { mctx.CreateModule(systemModulesImportFactory, &props) } +func PrebuiltApiModuleName(module, scope, version string) string { + return module + ".api." + scope + "." + version +} + func prebuiltApiFiles(mctx android.LoadHookContext, p *prebuiltApis) { // //api/.txt apiLevelFiles := globApiDirs(mctx, p, "api/*.txt") @@ -220,12 +224,9 @@ func prebuiltApiFiles(mctx android.LoadHookContext, p *prebuiltApis) { } // Create modules for all (, ) triplets, - apiModuleName := func(module, scope, version string) string { - return module + ".api." + scope + "." + version - } for _, f := range apiLevelFiles { module, version, scope := parseFinalizedPrebuiltPath(mctx, f) - createApiModule(mctx, apiModuleName(module, scope, strconv.Itoa(version)), f) + createApiModule(mctx, PrebuiltApiModuleName(module, scope, strconv.Itoa(version)), f) } // Figure out the latest version of each module/scope @@ -266,7 +267,7 @@ func prebuiltApiFiles(mctx android.LoadHookContext, p *prebuiltApis) { // Sort the keys in order to make build.ninja stable for _, k := range android.SortedStringKeys(latest) { info := latest[k] - name := apiModuleName(info.module, info.scope, "latest") + name := PrebuiltApiModuleName(info.module, info.scope, "latest") createApiModule(mctx, name, info.path) } @@ -278,7 +279,7 @@ func prebuiltApiFiles(mctx android.LoadHookContext, p *prebuiltApis) { filename, _, scope := parsePrebuiltPath(mctx, f) referencedModule := strings.TrimSuffix(filename, "-incompatibilities") - createApiModule(mctx, apiModuleName(referencedModule+"-incompatibilities", scope, "latest"), f) + createApiModule(mctx, PrebuiltApiModuleName(referencedModule+"-incompatibilities", scope, "latest"), f) incompatibilities[referencedModule+"."+scope] = true } @@ -286,7 +287,7 @@ func prebuiltApiFiles(mctx android.LoadHookContext, p *prebuiltApis) { // Create empty incompatibilities files for remaining modules for _, k := range android.SortedStringKeys(latest) { if _, ok := incompatibilities[k]; !ok { - createEmptyFile(mctx, apiModuleName(latest[k].module+"-incompatibilities", latest[k].scope, "latest")) + createEmptyFile(mctx, PrebuiltApiModuleName(latest[k].module+"-incompatibilities", latest[k].scope, "latest")) } } } diff --git a/java/sdk_library.go b/java/sdk_library.go index cd8e8755e..8778937d5 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -97,6 +97,13 @@ type apiScope struct { // The tag to use to depend on the stubs source and API module. stubsSourceAndApiTag scopeDependencyTag + // The tag to use to depend on the module that provides the latest version of the API .txt file. + latestApiModuleTag scopeDependencyTag + + // The tag to use to depend on the module that provides the latest version of the API removed.txt + // file. + latestRemovedApiModuleTag scopeDependencyTag + // The scope specific prefix to add to the api file base of "current.txt" or "removed.txt". apiFilePrefix string @@ -158,6 +165,16 @@ func initApiScope(scope *apiScope) *apiScope { apiScope: scope, depInfoExtractor: (*scopePaths).extractStubsSourceAndApiInfoFromApiStubsProvider, } + scope.latestApiModuleTag = scopeDependencyTag{ + name: name + "-latest-api", + apiScope: scope, + depInfoExtractor: (*scopePaths).extractLatestApiPath, + } + scope.latestRemovedApiModuleTag = scopeDependencyTag{ + name: name + "-latest-removed-api", + apiScope: scope, + depInfoExtractor: (*scopePaths).extractLatestRemovedApiPath, + } // To get the args needed to generate the stubs source append all the args from // this scope and all the scopes it extends as each set of args adds additional @@ -203,6 +220,24 @@ func (scope *apiScope) String() string { return scope.name } +// snapshotRelativeDir returns the snapshot directory into which the files related to scopes will +// be stored. +func (scope *apiScope) snapshotRelativeDir() string { + return filepath.Join("sdk_library", scope.name) +} + +// snapshotRelativeCurrentApiTxtPath returns the snapshot path to the API .txt file for the named +// library. +func (scope *apiScope) snapshotRelativeCurrentApiTxtPath(name string) string { + return filepath.Join(scope.snapshotRelativeDir(), name+".txt") +} + +// snapshotRelativeRemovedApiTxtPath returns the snapshot path to the removed API .txt file for the +// named library. +func (scope *apiScope) snapshotRelativeRemovedApiTxtPath(name string) string { + return filepath.Join(scope.snapshotRelativeDir(), name+"-removed.txt") +} + type apiScopes []*apiScope func (scopes apiScopes) Strings(accessor func(*apiScope) string) []string { @@ -539,6 +574,12 @@ type scopePaths struct { // Extracted annotations. annotationsZip android.OptionalPath + + // The path to the latest API file. + latestApiPath android.OptionalPath + + // The path to the latest removed API file. + latestRemovedApiPath android.OptionalPath } func (paths *scopePaths) extractStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error { @@ -602,6 +643,31 @@ func (paths *scopePaths) extractStubsSourceAndApiInfoFromApiStubsProvider(ctx an }) } +func extractSingleOptionalOutputPath(dep android.Module) (android.OptionalPath, error) { + var paths android.Paths + if sourceFileProducer, ok := dep.(android.SourceFileProducer); ok { + paths = sourceFileProducer.Srcs() + } else { + return android.OptionalPath{}, fmt.Errorf("module %q does not produce source files", dep) + } + if len(paths) != 1 { + return android.OptionalPath{}, fmt.Errorf("expected one path from %q, got %q", dep, paths) + } + return android.OptionalPathForPath(paths[0]), nil +} + +func (paths *scopePaths) extractLatestApiPath(ctx android.ModuleContext, dep android.Module) error { + outputPath, err := extractSingleOptionalOutputPath(dep) + paths.latestApiPath = outputPath + return err +} + +func (paths *scopePaths) extractLatestRemovedApiPath(ctx android.ModuleContext, dep android.Module) error { + outputPath, err := extractSingleOptionalOutputPath(dep) + paths.latestRemovedApiPath = outputPath + return err +} + type commonToSdkLibraryAndImportProperties struct { // The naming scheme to use for the components that this module creates. // @@ -1174,6 +1240,16 @@ func (module *SdkLibrary) ComponentDepsMutator(ctx android.BottomUpMutatorContex // Add a dependency on the stubs source in order to access both stubs source and api information. ctx.AddVariationDependencies(nil, apiScope.stubsSourceAndApiTag, module.stubsSourceModuleName(apiScope)) + + if module.compareAgainstLatestApi(apiScope) { + // Add dependencies on the latest finalized version of the API .txt file. + latestApiModuleName := module.latestApiModuleName(apiScope) + ctx.AddDependency(module, apiScope.latestApiModuleTag, latestApiModuleName) + + // Add dependencies on the latest finalized version of the remove API .txt file. + latestRemovedApiModuleName := module.latestRemovedApiModuleName(apiScope) + ctx.AddDependency(module, apiScope.latestRemovedApiModuleTag, latestRemovedApiModuleName) + } } if module.requiresRuntimeImplementationLibrary() { @@ -1194,13 +1270,13 @@ func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { if apiScope.unstable { continue } - if m := android.SrcIsModule(module.latestApiFilegroupName(apiScope)); !ctx.OtherModuleExists(m) { + if m := module.latestApiModuleName(apiScope); !ctx.OtherModuleExists(m) { missingApiModules = append(missingApiModules, m) } - if m := android.SrcIsModule(module.latestRemovedApiFilegroupName(apiScope)); !ctx.OtherModuleExists(m) { + if m := module.latestRemovedApiModuleName(apiScope); !ctx.OtherModuleExists(m) { missingApiModules = append(missingApiModules, m) } - if m := android.SrcIsModule(module.latestIncompatibilitiesFilegroupName(apiScope)); !ctx.OtherModuleExists(m) { + if m := module.latestIncompatibilitiesModuleName(apiScope); !ctx.OtherModuleExists(m) { missingApiModules = append(missingApiModules, m) } } @@ -1274,6 +1350,26 @@ func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) // Make the set of components exported by this module available for use elsewhere. exportedComponentInfo := android.ExportedComponentsInfo{Components: android.SortedStringKeys(exportedComponents)} ctx.SetProvider(android.ExportedComponentsInfoProvider, exportedComponentInfo) + + // Provide additional information for inclusion in an sdk's generated .info file. + additionalSdkInfo := map[string]interface{}{} + additionalSdkInfo["dist_stem"] = module.distStem() + baseModuleName := module.BaseModuleName() + scopes := map[string]interface{}{} + additionalSdkInfo["scopes"] = scopes + for scope, scopePaths := range module.scopePaths { + scopeInfo := map[string]interface{}{} + scopes[scope.name] = scopeInfo + scopeInfo["current_api"] = scope.snapshotRelativeCurrentApiTxtPath(baseModuleName) + scopeInfo["removed_api"] = scope.snapshotRelativeRemovedApiTxtPath(baseModuleName) + if p := scopePaths.latestApiPath; p.Valid() { + scopeInfo["latest_api"] = p.Path().String() + } + if p := scopePaths.latestRemovedApiPath; p.Valid() { + scopeInfo["latest_removed_api"] = p.Path().String() + } + } + ctx.SetProvider(android.AdditionalSdkInfoProvider, android.AdditionalSdkInfo{additionalSdkInfo}) } func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries { @@ -1319,16 +1415,32 @@ func (module *SdkLibrary) distGroup() string { return proptools.StringDefault(module.sdkLibraryProperties.Dist_group, "unknown") } +func latestPrebuiltApiModuleName(name string, apiScope *apiScope) string { + return PrebuiltApiModuleName(name, apiScope.name, "latest") +} + func (module *SdkLibrary) latestApiFilegroupName(apiScope *apiScope) string { - return ":" + module.distStem() + ".api." + apiScope.name + ".latest" + return ":" + module.latestApiModuleName(apiScope) +} + +func (module *SdkLibrary) latestApiModuleName(apiScope *apiScope) string { + return latestPrebuiltApiModuleName(module.distStem(), apiScope) } func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope *apiScope) string { - return ":" + module.distStem() + "-removed.api." + apiScope.name + ".latest" + return ":" + module.latestRemovedApiModuleName(apiScope) +} + +func (module *SdkLibrary) latestRemovedApiModuleName(apiScope *apiScope) string { + return latestPrebuiltApiModuleName(module.distStem()+"-removed", apiScope) } func (module *SdkLibrary) latestIncompatibilitiesFilegroupName(apiScope *apiScope) string { - return ":" + module.distStem() + "-incompatibilities.api." + apiScope.name + ".latest" + return ":" + module.latestIncompatibilitiesModuleName(apiScope) +} + +func (module *SdkLibrary) latestIncompatibilitiesModuleName(apiScope *apiScope) string { + return latestPrebuiltApiModuleName(module.distStem()+"-incompatibilities", apiScope) } func childModuleVisibility(childVisibility []string) []string { @@ -1557,7 +1669,7 @@ func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookC props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName) props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName) - if !(apiScope.unstable || module.sdkLibraryProperties.Unsafe_ignore_missing_latest_api) { + if module.compareAgainstLatestApi(apiScope) { // check against the latest released API latestApiFilegroupName := proptools.StringPtr(module.latestApiFilegroupName(apiScope)) props.Previous_api = latestApiFilegroupName @@ -1609,6 +1721,10 @@ func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookC mctx.CreateModule(DroidstubsFactory, &props) } +func (module *SdkLibrary) compareAgainstLatestApi(apiScope *apiScope) bool { + return !(apiScope.unstable || module.sdkLibraryProperties.Unsafe_ignore_missing_latest_api) +} + // Implements android.ApexModule func (module *SdkLibrary) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool { depTag := mctx.OtherModuleDependencyTag(dep) @@ -2903,7 +3019,7 @@ func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberCo if properties, ok := s.Scopes[apiScope]; ok { scopeSet := propertySet.AddPropertySet(apiScope.propertyName) - scopeDir := filepath.Join("sdk_library", s.OsPrefix(), apiScope.name) + scopeDir := apiScope.snapshotRelativeDir() var jars []string for _, p := range properties.Jars { @@ -2927,13 +3043,13 @@ func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberCo } if properties.CurrentApiFile != nil { - currentApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+".txt") + currentApiSnapshotPath := apiScope.snapshotRelativeCurrentApiTxtPath(ctx.Name()) ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, currentApiSnapshotPath) scopeSet.AddProperty("current_api", currentApiSnapshotPath) } if properties.RemovedApiFile != nil { - removedApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+"-removed.txt") + removedApiSnapshotPath := apiScope.snapshotRelativeRemovedApiTxtPath(ctx.Name()) ctx.SnapshotBuilder().CopyToSnapshot(properties.RemovedApiFile, removedApiSnapshotPath) scopeSet.AddProperty("removed_api", removedApiSnapshotPath) } diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go index 3500c84d2..805bc226f 100644 --- a/java/sdk_library_test.go +++ b/java/sdk_library_test.go @@ -126,6 +126,10 @@ func TestJavaSdkLibrary(t *testing.T) { exportedComponentsInfo := result.ModuleProvider(foo.Module(), android.ExportedComponentsInfoProvider).(android.ExportedComponentsInfo) expectedFooExportedComponents := []string{ + "foo-removed.api.public.latest", + "foo-removed.api.system.latest", + "foo.api.public.latest", + "foo.api.system.latest", "foo.stubs", "foo.stubs.source", "foo.stubs.source.system", @@ -529,6 +533,8 @@ func TestJavaSdkLibrary_Deps(t *testing.T) { CheckModuleDependencies(t, result.TestContext, "sdklib", "android_common", []string{ `dex2oatd`, + `sdklib-removed.api.public.latest`, + `sdklib.api.public.latest`, `sdklib.impl`, `sdklib.stubs`, `sdklib.stubs.source`, @@ -851,6 +857,8 @@ func TestJavaSdkLibraryImport_WithSource(t *testing.T) { CheckModuleDependencies(t, result.TestContext, "sdklib", "android_common", []string{ `dex2oatd`, `prebuilt_sdklib`, + `sdklib-removed.api.public.latest`, + `sdklib.api.public.latest`, `sdklib.impl`, `sdklib.stubs`, `sdklib.stubs.source`, @@ -894,6 +902,8 @@ func TestJavaSdkLibraryImport_Preferred(t *testing.T) { CheckModuleDependencies(t, result.TestContext, "sdklib", "android_common", []string{ `prebuilt_sdklib`, + `sdklib-removed.api.public.latest`, + `sdklib.api.public.latest`, `sdklib.impl`, `sdklib.stubs`, `sdklib.stubs.source`, diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go index 9d0c3deb9..f33aa268e 100644 --- a/sdk/java_sdk_test.go +++ b/sdk/java_sdk_test.go @@ -651,7 +651,19 @@ module_exports_snapshot { } func TestSnapshotWithJavaSystemModules(t *testing.T) { - result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, ` + result := android.GroupFixturePreparers( + prepareForSdkTestWithJava, + java.PrepareForTestWithJavaDefaultModules, + java.PrepareForTestWithJavaSdkLibraryFiles, + java.FixtureWithPrebuiltApisAndExtensions(map[string][]string{ + "31": {"myjavalib"}, + "32": {"myjavalib"}, + "current": {"myjavalib"}, + }, map[string][]string{ + "1": {"myjavalib"}, + "2": {"myjavalib"}, + }), + ).RunTestWithBp(t, ` sdk { name: "mysdk", java_header_libs: ["exported-system-module"], @@ -796,7 +808,7 @@ sdk_snapshot { .intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt .intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt `), - checkInfoContents(` + checkInfoContents(result.Config, ` [ { "@type": "sdk", @@ -826,7 +838,16 @@ sdk_snapshot { }, { "@type": "java_sdk_library", - "@name": "myjavalib" + "@name": "myjavalib", + "dist_stem": "myjavalib", + "scopes": { + "public": { + "current_api": "sdk_library/public/myjavalib.txt", + "latest_api": "out/soong/.intermediates/prebuilts/sdk/myjavalib.api.public.latest/gen/myjavalib.api.public.latest", + "latest_removed_api": "out/soong/.intermediates/prebuilts/sdk/myjavalib-removed.api.public.latest/gen/myjavalib-removed.api.public.latest", + "removed_api": "sdk_library/public/myjavalib-removed.txt" + } + } }, { "@type": "java_library", diff --git a/sdk/testing.go b/sdk/testing.go index b0f5fdc62..72344de25 100644 --- a/sdk/testing.go +++ b/sdk/testing.go @@ -406,11 +406,11 @@ func checkMergeZips(expected ...string) snapshotBuildInfoChecker { // Check that the snapshot's info contents are ciorrect. // // Both the expected and actual string are both trimmed before comparing. -func checkInfoContents(expected string) snapshotBuildInfoChecker { +func checkInfoContents(config android.Config, expected string) snapshotBuildInfoChecker { return func(info *snapshotBuildInfo) { info.t.Helper() android.AssertTrimmedStringEquals(info.t, "info contents do not match", - expected, info.infoContents) + expected, android.StringRelativeToTop(config, info.infoContents)) } } diff --git a/sdk/update.go b/sdk/update.go index 71bd042a6..e61ae0d0a 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -566,8 +566,9 @@ type moduleInfo struct { name string // A list of additional dependencies of the module. deps []string - // Additional dynamic properties. - dynamic map[string]interface{} + // Additional member specific properties. + // These will be added into the generated JSON alongside the above properties. + memberSpecific map[string]interface{} } func (m *moduleInfo) MarshalJSON() ([]byte, error) { @@ -590,8 +591,8 @@ func (m *moduleInfo) MarshalJSON() ([]byte, error) { if m.deps != nil { writeObjectPair("@deps", m.deps) } - for _, k := range android.SortedStringKeys(m.dynamic) { - v := m.dynamic[k] + for _, k := range android.SortedStringKeys(m.memberSpecific) { + v := m.memberSpecific[k] writeObjectPair(k, v) } buffer.WriteString("}") @@ -604,9 +605,9 @@ var _ json.Marshaler = (*moduleInfo)(nil) func (s *sdk) generateInfoData(ctx android.ModuleContext, memberVariantDeps []sdkMemberVariantDep) interface{} { modules := []*moduleInfo{} sdkInfo := moduleInfo{ - moduleType: "sdk", - name: ctx.ModuleName(), - dynamic: map[string]interface{}{}, + moduleType: "sdk", + name: ctx.ModuleName(), + memberSpecific: map[string]interface{}{}, } modules = append(modules, &sdkInfo) @@ -622,6 +623,10 @@ func (s *sdk) generateInfoData(ctx android.ModuleContext, memberVariantDeps []sd moduleType: moduleType, name: name, } + + additionalSdkInfo := ctx.OtherModuleProvider(module, android.AdditionalSdkInfoProvider).(android.AdditionalSdkInfo) + info.memberSpecific = additionalSdkInfo.Properties + name2Info[name] = info } return info @@ -630,13 +635,13 @@ func (s *sdk) generateInfoData(ctx android.ModuleContext, memberVariantDeps []sd for _, memberVariantDep := range memberVariantDeps { propertyName := memberVariantDep.memberType.SdkPropertyName() var list []string - if v, ok := sdkInfo.dynamic[propertyName]; ok { + if v, ok := sdkInfo.memberSpecific[propertyName]; ok { list = v.([]string) } memberName := memberVariantDep.variant.Name() list = append(list, memberName) - sdkInfo.dynamic[propertyName] = android.SortedUniqueStrings(list) + sdkInfo.memberSpecific[propertyName] = android.SortedUniqueStrings(list) if memberVariantDep.container != nil { containerInfo := getModuleInfo(memberVariantDep.container) @@ -1217,6 +1222,7 @@ type snapshotBuilder struct { // The target build release for which the snapshot is to be generated. targetBuildRelease *buildRelease + // The contents of the .info file that describes the sdk contents. infoContents string } From 870462bb6a999f46adfe0f17a97823b911e5072d Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 27 May 2022 12:23:08 +0000 Subject: [PATCH 011/172] Check that API is up-to-date when building java_sdk_library Previously, the checked in version of an API was only checked to make sure it was up-to-date when running the checkapi target. This change adds a validation dependency to the ninja rule that generates the API from source so that up-to-date check is always performed every time the API is generated. However, because it is a validation dependency it does not lengthen the build's critical path. Bug: 234113632 Test: echo > packages/modules/SdkExtensions/java/android/os/ext/api/current.txt m framework-sdkextension # Passes without this change even though the checked in API is # not up-to-date. # With this change the build fails reporting correctly that the # checked in API is not up-to-date. Change-Id: I8e65cf716d94aecd61bd943f1485468664ad4a22 (cherry picked from commit c166b6858947161d6e958090f11fe33001427c05) Merged-In: I8e65cf716d94aecd61bd943f1485468664ad4a22 --- java/droidstubs.go | 161 +++++++++++++++++++++++---------------------- 1 file changed, 84 insertions(+), 77 deletions(-) diff --git a/java/droidstubs.go b/java/droidstubs.go index 3b1f7c041..20ea5ff96 100644 --- a/java/droidstubs.go +++ b/java/droidstubs.go @@ -675,87 +675,16 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) { zipSyncCleanupCmd(rule, srcJarDir) - rule.Build("metalava", "metalava merged") - if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") { + d.generateCheckCurrentCheckedInApiIsUpToDateBuildRules(ctx) - if len(d.Javadoc.properties.Out) > 0 { - ctx.PropertyErrorf("out", "out property may not be combined with check_api") - } - - apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file)) - removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file)) - baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Current.Baseline_file) - - if baselineFile.Valid() { - ctx.PropertyErrorf("baseline_file", "current API check can't have a baseline file. (module %s)", ctx.ModuleName()) - } - - d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "metalava", "check_current_api.timestamp") - - rule := android.NewRuleBuilder(pctx, ctx) - - // Diff command line. - // -F matches the closest "opening" line, such as "package android {" - // and " public class Intent {". - diff := `diff -u -F '{ *$'` - - rule.Command().Text("( true") - rule.Command(). - Text(diff). - Input(apiFile).Input(d.apiFile) - - rule.Command(). - Text(diff). - Input(removedApiFile).Input(d.removedApiFile) - - msg := fmt.Sprintf(`\n******************************\n`+ - `You have tried to change the API from what has been previously approved.\n\n`+ - `To make these errors go away, you have two choices:\n`+ - ` 1. You can add '@hide' javadoc comments (and remove @SystemApi/@TestApi/etc)\n`+ - ` to the new methods, etc. shown in the above diff.\n\n`+ - ` 2. You can update current.txt and/or removed.txt by executing the following command:\n`+ - ` m %s-update-current-api\n\n`+ - ` To submit the revised current.txt to the main Android repository,\n`+ - ` you will need approval.\n`+ - `******************************\n`, ctx.ModuleName()) - - rule.Command(). - Text("touch").Output(d.checkCurrentApiTimestamp). - Text(") || ("). - Text("echo").Flag("-e").Flag(`"` + msg + `"`). - Text("; exit 38"). - Text(")") - - rule.Build("metalavaCurrentApiCheck", "check current API") - - d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "metalava", "update_current_api.timestamp") - - // update API rule - rule = android.NewRuleBuilder(pctx, ctx) - - rule.Command().Text("( true") - - rule.Command(). - Text("cp").Flag("-f"). - Input(d.apiFile).Flag(apiFile.String()) - - rule.Command(). - Text("cp").Flag("-f"). - Input(d.removedApiFile).Flag(removedApiFile.String()) - - msg = "failed to update public API" - - rule.Command(). - Text("touch").Output(d.updateCurrentApiTimestamp). - Text(") || ("). - Text("echo").Flag("-e").Flag(`"` + msg + `"`). - Text("; exit 38"). - Text(")") - - rule.Build("metalavaCurrentApiUpdate", "update current API") + // Make sure that whenever the API stubs are generated that the current checked in API files are + // checked to make sure that they are up-to-date. + cmd.Validation(d.checkCurrentApiTimestamp) } + rule.Build("metalava", "metalava merged") + if String(d.properties.Check_nullability_warnings) != "" { if d.nullabilityWarningsFile == nil { ctx.PropertyErrorf("check_nullability_warnings", @@ -792,6 +721,84 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) { } } +func (d *Droidstubs) generateCheckCurrentCheckedInApiIsUpToDateBuildRules(ctx android.ModuleContext) { + if len(d.Javadoc.properties.Out) > 0 { + ctx.PropertyErrorf("out", "out property may not be combined with check_api") + } + + apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file)) + removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file)) + baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Current.Baseline_file) + + if baselineFile.Valid() { + ctx.PropertyErrorf("baseline_file", "current API check can't have a baseline file. (module %s)", ctx.ModuleName()) + } + + d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "metalava", "check_current_api.timestamp") + + rule := android.NewRuleBuilder(pctx, ctx) + + // Diff command line. + // -F matches the closest "opening" line, such as "package android {" + // and " public class Intent {". + diff := `diff -u -F '{ *$'` + + rule.Command().Text("( true") + rule.Command(). + Text(diff). + Input(apiFile).Input(d.apiFile) + + rule.Command(). + Text(diff). + Input(removedApiFile).Input(d.removedApiFile) + + msg := fmt.Sprintf(`\n******************************\n`+ + `You have tried to change the API from what has been previously approved.\n\n`+ + `To make these errors go away, you have two choices:\n`+ + ` 1. You can add '@hide' javadoc comments (and remove @SystemApi/@TestApi/etc)\n`+ + ` to the new methods, etc. shown in the above diff.\n\n`+ + ` 2. You can update current.txt and/or removed.txt by executing the following command:\n`+ + ` m %s-update-current-api\n\n`+ + ` To submit the revised current.txt to the main Android repository,\n`+ + ` you will need approval.\n`+ + `******************************\n`, ctx.ModuleName()) + + rule.Command(). + Text("touch").Output(d.checkCurrentApiTimestamp). + Text(") || ("). + Text("echo").Flag("-e").Flag(`"` + msg + `"`). + Text("; exit 38"). + Text(")") + + rule.Build("metalavaCurrentApiCheck", "check current API") + + d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "metalava", "update_current_api.timestamp") + + // update API rule + rule = android.NewRuleBuilder(pctx, ctx) + + rule.Command().Text("( true") + + rule.Command(). + Text("cp").Flag("-f"). + Input(d.apiFile).Flag(apiFile.String()) + + rule.Command(). + Text("cp").Flag("-f"). + Input(d.removedApiFile).Flag(removedApiFile.String()) + + msg = "failed to update public API" + + rule.Command(). + Text("touch").Output(d.updateCurrentApiTimestamp). + Text(") || ("). + Text("echo").Flag("-e").Flag(`"` + msg + `"`). + Text("; exit 38"). + Text(")") + + rule.Build("metalavaCurrentApiUpdate", "update current API") +} + func StubsDefaultsFactory() android.Module { module := &DocDefaults{} From b8d3df82ac1d3e5ccb4a58bb3b31457d7450e353 Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Wed, 25 May 2022 09:01:35 +0900 Subject: [PATCH 012/172] Remove AIDL modules from VndkMustUseVendorVariantList Vendor variants of AIDL-gen CC modules are by default different from core variants. So instead of adding them manually to the list, AIDL builder can mark them as MustUseVendorVariant. Bug: 233616647 Test: m Change-Id: Ifca0eb64d60ecb49d72cd0347336b69fb332c58c --- cc/config/vndk.go | 102 +--------------------------------------------- 1 file changed, 1 insertion(+), 101 deletions(-) diff --git a/cc/config/vndk.go b/cc/config/vndk.go index db69ce785..dd612ce63 100644 --- a/cc/config/vndk.go +++ b/cc/config/vndk.go @@ -17,109 +17,9 @@ package config // List of VNDK libraries that have different core variant and vendor variant. // For these libraries, the vendor variants must be installed even if the device // has VndkUseCoreVariant set. -// TODO(b/150578172): clean up unstable and non-versioned aidl module +// Note that AIDL-generated modules must use vendor variants by default. var VndkMustUseVendorVariantList = []string{ - "android.hardware.authsecret-V1-ndk", - "android.hardware.authsecret-V1-ndk_platform", - "android.hardware.authsecret-ndk_platform", - "android.hardware.authsecret-unstable-ndk_platform", - "android.hardware.automotive.occupant_awareness-V1-ndk", - "android.hardware.automotive.occupant_awareness-V1-ndk_platform", - "android.hardware.automotive.occupant_awareness-ndk_platform", - "android.hardware.drm-V1-ndk", - "android.hardware.dumpstate-V1-ndk", - "android.hardware.gnss-V1-ndk", - "android.hardware.gnss-V1-ndk_platform", - "android.hardware.gnss-V2-ndk", - "android.hardware.gnss-ndk_platform", - "android.hardware.gnss-unstable-ndk_platform", - "android.hardware.health-V1-ndk", - "android.hardware.health-ndk", - "android.hardware.health.storage-V1-ndk", - "android.hardware.health.storage-V1-ndk_platform", - "android.hardware.health.storage-ndk_platform", - "android.hardware.health.storage-unstable-ndk_platform", - "android.hardware.identity-V2-ndk_platform", - "android.hardware.identity-V3-ndk", - "android.hardware.identity-V3-ndk_platform", - "android.hardware.identity-ndk_platform", - "android.hardware.light-V1-ndk", - "android.hardware.light-V1-ndk_platform", - "android.hardware.light-ndk_platform", - "android.hardware.memtrack-V1-ndk", - "android.hardware.memtrack-V1-ndk_platform", - "android.hardware.memtrack-ndk_platform", - "android.hardware.memtrack-unstable-ndk_platform", "android.hardware.nfc@1.2", - "android.hardware.oemlock-V1-ndk", - "android.hardware.oemlock-V1-ndk_platform", - "android.hardware.oemlock-ndk_platform", - "android.hardware.oemlock-unstable-ndk_platform", - "android.hardware.power-V1-ndk_platform", - "android.hardware.power-V2-ndk", - "android.hardware.power-V2-ndk_platform", - "android.hardware.power-ndk_platform", - "android.hardware.power.stats-V1-ndk", - "android.hardware.power.stats-V1-ndk_platform", - "android.hardware.power.stats-ndk_platform", - "android.hardware.power.stats-unstable-ndk_platform", - "android.hardware.rebootescrow-V1-ndk", - "android.hardware.rebootescrow-V1-ndk_platform", - "android.hardware.rebootescrow-ndk_platform", - "android.hardware.radio-V1-ndk", - "android.hardware.radio-V1-ndk_platform", - "android.hardware.radio.config-V1-ndk", - "android.hardware.radio.config-V1-ndk_platform", - "android.hardware.radio.data-V1-ndk", - "android.hardware.radio.data-V1-ndk_platform", - "android.hardware.radio.messaging-V1-ndk", - "android.hardware.radio.messaging-V1-ndk_platform", - "android.hardware.radio.modem-V1-ndk", - "android.hardware.radio.modem-V1-ndk_platform", - "android.hardware.radio.network-V1-ndk", - "android.hardware.radio.network-V1-ndk_platform", - "android.hardware.radio.sim-V1-ndk", - "android.hardware.radio.sim-V1-ndk_platform", - "android.hardware.radio.voice-V1-ndk", - "android.hardware.radio.voice-V1-ndk_platform", - "android.hardware.security.keymint-V1-ndk", - "android.hardware.security.keymint-V1-ndk_platform", - "android.hardware.security.keymint-ndk_platform", - "android.hardware.security.keymint-unstable-ndk_platform", - "android.hardware.security.secureclock-V1-ndk", - "android.hardware.security.secureclock-V1-ndk_platform", - "android.hardware.security.secureclock-ndk_platform", - "android.hardware.security.secureclock-unstable-ndk_platform", - "android.hardware.security.sharedsecret-V1-ndk", - "android.hardware.security.sharedsecret-V1-ndk_platform", - "android.hardware.security.sharedsecret-ndk_platform", - "android.hardware.security.sharedsecret-unstable-ndk_platform", - "android.hardware.sensors-V1-ndk", - "android.hardware.soundtrigger3-V1-ndk", - "android.hardware.soundtrigger3-V1-ndk_platform", - "android.hardware.uwb-V1-ndk", - "android.hardware.uwb-V1-ndk_platform", - "android.hardware.vibrator-V1-ndk_platform", - "android.hardware.vibrator-V2-ndk", - "android.hardware.vibrator-V2-ndk_platform", - "android.hardware.vibrator-ndk_platform", - "android.hardware.weaver-V1-ndk", - "android.hardware.weaver-V1-ndk_platform", - "android.hardware.weaver-ndk_platform", - "android.hardware.weaver-unstable-ndk_platform", - "android.system.suspend-V1-ndk", - "android.system.keystore2-V1-ndk", - "android.se.omapi-V1-ndk_platform", - "android.se.omapi-ndk_platform", - "android.se.omapi-unstable-ndk_platform", - "android.hardware.wifi.hostapd-V1-ndk", - "android.hardware.wifi.hostapd-V1-ndk_platform", - "android.hardware.wifi.supplicant-V1-ndk", - "android.system.keystore2-V1-ndk_platform", - "android.system.keystore2-ndk_platform", - "android.system.keystore2-unstable-ndk_platform", - "android.system.suspend-V1-ndk", - "android.system.suspend-V1-ndk_platform", "libbinder", "libcrypto", "libexpat", From 55680485f45151e37feac8b2a2f18abc468f45bb Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 9 Jun 2022 11:07:01 -0700 Subject: [PATCH 013/172] Use -fdebug-default-version=4 for assembly files -fdebug-default-version=5 is causing $TMPDIR to end up in the dwarf debug data, which causes the buildbot results to be nondeterministic. Pass -fdebug-default-version=4 for assembly files as a workaround. Bug: 235105792 Test: lunch aosp_arm-userdebug && m libbase && llvm-dwarfdump --debug-line out/target/product/generic/symbols/system/lib/libbase.so Change-Id: Ife04e3c898bbb1291f71b8365fbca854cd2d2b66 Merged-In: Ife04e3c898bbb1291f71b8365fbca854cd2d2b66 (cherry picked from commit cdcb680dbdd5eca4974eab623a782a0bc3c074e6) --- cc/cc_test.go | 2 +- cc/compiler.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cc/cc_test.go b/cc/cc_test.go index 09cc352a2..893c52e1d 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -4076,7 +4076,7 @@ func TestIncludeDirectoryOrdering(t *testing.T) { { name: "assemble", src: "foo.s", - expected: combineSlices(baseExpectedFlags, []string{"-D__ASSEMBLY__"}, expectedIncludes, lastIncludes), + expected: combineSlices(baseExpectedFlags, []string{"-D__ASSEMBLY__", "-fdebug-default-version=4"}, expectedIncludes, lastIncludes), }, } diff --git a/cc/compiler.go b/cc/compiler.go index eb5458fc6..383eed025 100644 --- a/cc/compiler.go +++ b/cc/compiler.go @@ -491,6 +491,10 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps flags.Global.AsFlags = append(flags.Global.AsFlags, "-D__ASSEMBLY__") + // TODO(b/235105792): override global -fdebug-default-version=5, it is causing $TMPDIR to + // end up in the dwarf data for crtend_so.S. + flags.Global.AsFlags = append(flags.Global.AsFlags, "-fdebug-default-version=4") + flags.Global.CppFlags = append(flags.Global.CppFlags, tc.Cppflags()) flags.Global.YasmFlags = append(flags.Global.YasmFlags, tc.YasmFlags()) From a3defe199a599bd688948c5f65d6a3879dcbac9e Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Wed, 20 Apr 2022 23:11:43 -0700 Subject: [PATCH 014/172] LOG_DIR changes should not trigger soong_build to re-run On the build servers, LOG_DIR is a subset of DIST_DIR, which encodes the build number. This means that LOG_DIR is guaranteed to be different for every build, and we'll never re-use previous soong runs on CI builds. The current use case (writing out soong metrics) shouldn't care if the value changes, so pipe the environment variable through, bypassing the env dep checks. It's not clear if this is the only issue triggering soong_build re-runs on the build servers, but it's a start. Test: Change DIST_DIR, soong_build does not re-run. Change-Id: I59bf117f3fbc0e7f10f0506d3d1ac7564c6a00dc (cherry picked from commit ccf36aa928669fac1116878270a271ed8edd5eaa) Merged-In: I59bf117f3fbc0e7f10f0506d3d1ac7564c6a00dc --- cmd/soong_build/main.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go index 4b3161b33..3f8105c88 100644 --- a/cmd/soong_build/main.go +++ b/cmd/soong_build/main.go @@ -183,8 +183,7 @@ func runQueryView(queryviewDir, queryviewMarker string, configuration android.Co touch(shared.JoinPath(topDir, queryviewMarker)) } -func writeMetrics(configuration android.Config, eventHandler metrics.EventHandler) { - metricsDir := configuration.Getenv("LOG_DIR") +func writeMetrics(configuration android.Config, eventHandler metrics.EventHandler, metricsDir string) { if len(metricsDir) < 1 { fmt.Fprintf(os.Stderr, "\nMissing required env var for generating soong metrics: LOG_DIR\n") os.Exit(1) @@ -238,7 +237,7 @@ func writeDepFile(outputFile string, eventHandler metrics.EventHandler, ninjaDep // doChosenActivity runs Soong for a specific activity, like bp2build, queryview // or the actual Soong build for the build.ninja file. Returns the top level // output file of the specific activity. -func doChosenActivity(configuration android.Config, extraNinjaDeps []string) string { +func doChosenActivity(configuration android.Config, extraNinjaDeps []string, logDir string) string { mixedModeBuild := configuration.BazelContext.BazelEnabled() generateBazelWorkspace := bp2buildMarker != "" generateQueryView := bazelQueryViewDir != "" @@ -302,7 +301,7 @@ func doChosenActivity(configuration android.Config, extraNinjaDeps []string) str } } - writeMetrics(configuration, *ctx.EventHandler) + writeMetrics(configuration, *ctx.EventHandler, logDir) return cmdlineArgs.OutFile } @@ -358,7 +357,11 @@ func main() { extraNinjaDeps = append(extraNinjaDeps, filepath.Join(configuration.SoongOutDir(), "always_rerun_for_delve")) } - finalOutputFile := doChosenActivity(configuration, extraNinjaDeps) + // Bypass configuration.Getenv, as LOG_DIR does not need to be dependency tracked. By definition, it will + // change between every CI build, so tracking it would require re-running Soong for every build. + logDir := availableEnv["LOG_DIR"] + + finalOutputFile := doChosenActivity(configuration, extraNinjaDeps, logDir) writeUsedEnvironmentFile(configuration, finalOutputFile) } From 4890e20f48ffd9b1623649754762faa7d59c9fc3 Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Fri, 24 Jun 2022 14:56:43 +0900 Subject: [PATCH 015/172] Remove min_sdk_version allowlist This hard-coded list causes inconsistent behavior regarding -target triple and _ANDROID_APEX_MIN_SDK_VERSION_ macro for native modules. Bug: 158059172 Test: m Change-Id: Iae3ecb3bfaefc2ee73ed38a9268c68b6673f30c5 --- android/apex.go | 50 +++++++------------------------------------------ 1 file changed, 7 insertions(+), 43 deletions(-) diff --git a/android/apex.go b/android/apex.go index ac2f838e0..934cf723e 100644 --- a/android/apex.go +++ b/android/apex.go @@ -837,40 +837,6 @@ func (d *ApexBundleDepsInfo) BuildDepsInfoLists(ctx ModuleContext, minSdkVersion ctx.Phony(fmt.Sprintf("%s-depsinfo", ctx.ModuleName()), d.fullListPath, d.flatListPath) } -// TODO(b/158059172): remove minSdkVersion allowlist -var minSdkVersionAllowlist = func(apiMap map[string]int) map[string]ApiLevel { - list := make(map[string]ApiLevel, len(apiMap)) - for name, finalApiInt := range apiMap { - list[name] = uncheckedFinalApiLevel(finalApiInt) - } - return list -}(map[string]int{ - "androidx-constraintlayout_constraintlayout-solver-nodeps": 29, - "apache-commons-compress": 29, - "bouncycastle_ike_digests": 30, - "brotli-java": 29, - "flatbuffer_headers": 30, - "gemmlowp_headers": 30, - "ike-internals": 30, - "libbrotli": 30, - "libcrypto_static": 30, - "libeigen": 30, - "liblz4": 30, - "libmdnssd": 30, - "libprocpartition": 30, - "libprotobuf-java-lite": 30, - "libprotoutil": 30, - "libtextclassifier_hash_headers": 30, - "libtextclassifier_hash_static": 30, - "libtflite_kernel_utils": 30, - "libzstd": 30, - "net-utils-framework-common": 29, - "philox_random_headers": 30, - "philox_random": 30, - "tensorflow_headers": 30, - "xz-java": 29, -}) - // Function called while walking an APEX's payload dependencies. // // Return true if the `to` module should be visited, false otherwise. @@ -922,15 +888,13 @@ func CheckMinSdkVersion(ctx ModuleContext, minSdkVersion ApiLevel, walk WalkPayl } if err := to.ShouldSupportSdkVersion(ctx, minSdkVersion); err != nil { toName := ctx.OtherModuleName(to) - if ver, ok := minSdkVersionAllowlist[toName]; !ok || ver.GreaterThan(minSdkVersion) { - ctx.OtherModuleErrorf(to, "should support min_sdk_version(%v) for %q: %v."+ - "\n\nDependency path: %s\n\n"+ - "Consider adding 'min_sdk_version: %q' to %q", - minSdkVersion, ctx.ModuleName(), err.Error(), - ctx.GetPathString(false), - minSdkVersion, toName) - return false - } + ctx.OtherModuleErrorf(to, "should support min_sdk_version(%v) for %q: %v."+ + "\n\nDependency path: %s\n\n"+ + "Consider adding 'min_sdk_version: %q' to %q", + minSdkVersion, ctx.ModuleName(), err.Error(), + ctx.GetPathString(false), + minSdkVersion, toName) + return false } return true }) From 251f5bbab26797e5ea6a9b2a3d2bd86f4e0ba01c Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 4 May 2022 11:39:52 +0000 Subject: [PATCH 016/172] Add protected_properties support in defaults modules Previously, there was no way to prevent a module from overriding a value provided by a defaults. That made it difficult to ensure consistency across modules, e.g. for modules that use framework-module-defaults. This change adds the protected_properties property to defaults modules which allows a default module to list those properties that should not be changed by a module applying those defaults. Properties can either be listed explicitly by name, or it can just be a single "*" in which case all properties that are set on the defaults will be protected. Bug: 230841626 Test: m nothing Change-Id: Ibb0e482c2856a572437e7818466f41c5493baf33 (cherry picked from commit 799962789a81bc0ac3d4d4afe868e93da94b9cd7) Merged-In: Ibb0e482c2856a572437e7818466f41c5493baf33 --- android/defaults.go | 321 +++++++++++++++++++++++++++++++++++---- android/defaults_test.go | 173 ++++++++++++++++++++- 2 files changed, 463 insertions(+), 31 deletions(-) diff --git a/android/defaults.go b/android/defaults.go index 8b121f6d9..54f44bcec 100644 --- a/android/defaults.go +++ b/android/defaults.go @@ -15,6 +15,8 @@ package android import ( + "bytes" + "fmt" "reflect" "github.com/google/blueprint" @@ -67,9 +69,11 @@ type Defaultable interface { // Set the property structures into which defaults will be added. setProperties(props []interface{}, variableProperties interface{}) - // Apply defaults from the supplied Defaults to the property structures supplied to + // Apply defaults from the supplied DefaultsModule to the property structures supplied to // setProperties(...). - applyDefaults(TopDownMutatorContext, []Defaults) + applyDefaults(TopDownMutatorContext, []DefaultsModule) + + applySingleDefaultsWithTracker(EarlyModuleContext, DefaultsModule, defaultsTrackerFunc) // Set the hook to be called after any defaults have been applied. // @@ -115,9 +119,23 @@ type DefaultsVisibilityProperties struct { Defaults_visibility []string } +// AdditionalDefaultsProperties contains properties of defaults modules which +// can have other defaults applied. +type AdditionalDefaultsProperties struct { + + // The list of properties set by the default whose values must not be changed by any module that + // applies these defaults. It is an error if a property is not supported by the defaults module or + // has not been set to a non-zero value. If this contains "*" then that must be the only entry in + // which case all properties that are set on this defaults will be protected (except the + // protected_properties and visibility. + Protected_properties []string +} + type DefaultsModuleBase struct { DefaultableModuleBase + defaultsProperties AdditionalDefaultsProperties + // Included to support setting bazel_module.label for multiple Soong modules to the same Bazel // target. This is primarily useful for modules that were architecture specific and instead are // handled in Bazel as a select(). @@ -151,6 +169,18 @@ type Defaults interface { // DefaultsModuleBase will type-assert to the Defaults interface. isDefaults() bool + // additionalDefaultableProperties returns additional properties provided by the defaults which + // can themselves have defaults applied. + additionalDefaultableProperties() []interface{} + + // protectedProperties returns the names of the properties whose values cannot be changed by a + // module that applies these defaults. + protectedProperties() []string + + // setProtectedProperties sets the names of the properties whose values cannot be changed by a + // module that applies these defaults. + setProtectedProperties(protectedProperties []string) + // Get the structures containing the properties for which defaults can be provided. properties() []interface{} @@ -167,6 +197,18 @@ type DefaultsModule interface { Bazelable } +func (d *DefaultsModuleBase) additionalDefaultableProperties() []interface{} { + return []interface{}{&d.defaultsProperties} +} + +func (d *DefaultsModuleBase) protectedProperties() []string { + return d.defaultsProperties.Protected_properties +} + +func (d *DefaultsModuleBase) setProtectedProperties(protectedProperties []string) { + d.defaultsProperties.Protected_properties = protectedProperties +} + func (d *DefaultsModuleBase) properties() []interface{} { return d.defaultableProperties } @@ -190,6 +232,10 @@ func InitDefaultsModule(module DefaultsModule) { &ApexProperties{}, &distProperties{}) + // Additional properties of defaults modules that can themselves have + // defaults applied. + module.AddProperties(module.additionalDefaultableProperties()...) + // Bazel module must be initialized _before_ Defaults to be included in cc_defaults module. InitBazelModule(module) initAndroidModuleBase(module) @@ -218,6 +264,57 @@ func InitDefaultsModule(module DefaultsModule) { // The applicable licenses property for defaults is 'licenses'. setPrimaryLicensesProperty(module, "licenses", &commonProperties.Licenses) + AddLoadHook(module, func(ctx LoadHookContext) { + + protectedProperties := module.protectedProperties() + if len(protectedProperties) == 0 { + return + } + + propertiesAvailable := map[string]struct{}{} + propertiesSet := map[string]struct{}{} + + // A defaults tracker which will keep track of which properties have been set on this module. + collector := func(defaults DefaultsModule, property string, dstValue interface{}, srcValue interface{}) bool { + value := reflect.ValueOf(dstValue) + propertiesAvailable[property] = struct{}{} + if !value.IsZero() { + propertiesSet[property] = struct{}{} + } + // Skip all the properties so that there are no changes to the defaults. + return false + } + + // Try and apply this module's defaults to itself, so that the properties can be collected but + // skip all the properties so it doesn't actually do anything. + module.applySingleDefaultsWithTracker(ctx, module, collector) + + if InList("*", protectedProperties) { + if len(protectedProperties) != 1 { + ctx.PropertyErrorf("protected_properties", `if specified then "*" must be the only property listed`) + return + } + + // Do not automatically protect the protected_properties property. + delete(propertiesSet, "protected_properties") + + // Or the visibility property. + delete(propertiesSet, "visibility") + + // Replace the "*" with the names of all the properties that have been set. + protectedProperties = SortedStringKeys(propertiesSet) + module.setProtectedProperties(protectedProperties) + } else { + for _, property := range protectedProperties { + if _, ok := propertiesAvailable[property]; !ok { + ctx.PropertyErrorf(property, "property is not supported by this module type %q", + ctx.ModuleType()) + } else if _, ok := propertiesSet[property]; !ok { + ctx.PropertyErrorf(property, "is not set; protected properties must be explicitly set") + } + } + } + }) } var _ Defaults = (*DefaultsModuleBase)(nil) @@ -269,35 +366,204 @@ func applyNamespacedVariableDefaults(defaultDep Defaults, ctx TopDownMutatorCont b.setNamespacedVariableProps(dst) } +// defaultValueInfo contains information about each default value that applies to a protected +// property. +type defaultValueInfo struct { + // The DefaultsModule providing the value, which may be defined on that module or applied as a + // default from other modules. + module Module + + // The default value, as returned by getComparableValue + defaultValue reflect.Value +} + +// protectedPropertyInfo contains information about each property that has to be protected when +// applying defaults. +type protectedPropertyInfo struct { + // True if the property was set on the module to which defaults are applied, this is an error. + propertySet bool + + // The original value of the property on the module, as returned by getComparableValue. + originalValue reflect.Value + + // A list of defaults for the property that are being applied. + defaultValues []defaultValueInfo +} + +// getComparableValue takes a reflect.Value that may be a pointer to another value and returns a +// reflect.Value to the underlying data or the original if was not a pointer or was nil. The +// returned values can then be compared for equality. +func getComparableValue(value reflect.Value) reflect.Value { + if value.IsZero() { + return value + } + for value.Kind() == reflect.Ptr { + value = value.Elem() + } + return value +} + func (defaultable *DefaultableModuleBase) applyDefaults(ctx TopDownMutatorContext, - defaultsList []Defaults) { + defaultsList []DefaultsModule) { + + // Collate information on all the properties protected by each of the default modules applied + // to this module. + allProtectedProperties := map[string]*protectedPropertyInfo{} + for _, defaults := range defaultsList { + for _, property := range defaults.protectedProperties() { + info := allProtectedProperties[property] + if info == nil { + info = &protectedPropertyInfo{} + allProtectedProperties[property] = info + } + } + } + + // If there are any protected properties then collate information about attempts to change them. + var protectedPropertyInfoCollector defaultsTrackerFunc + if len(allProtectedProperties) > 0 { + protectedPropertyInfoCollector = func(defaults DefaultsModule, property string, + dstValue interface{}, srcValue interface{}) bool { + + // If the property is not protected then return immediately. + info := allProtectedProperties[property] + if info == nil { + return true + } + + currentValue := reflect.ValueOf(dstValue) + if info.defaultValues == nil { + info.propertySet = !currentValue.IsZero() + info.originalValue = getComparableValue(currentValue) + } + + defaultValue := reflect.ValueOf(srcValue) + if !defaultValue.IsZero() { + info.defaultValues = append(info.defaultValues, + defaultValueInfo{defaults, getComparableValue(defaultValue)}) + } + + return true + } + } for _, defaults := range defaultsList { if ctx.Config().runningAsBp2Build { applyNamespacedVariableDefaults(defaults, ctx) } - for _, prop := range defaultable.defaultableProperties { - if prop == defaultable.defaultableVariableProperties { - defaultable.applyDefaultVariableProperties(ctx, defaults, prop) - } else { - defaultable.applyDefaultProperties(ctx, defaults, prop) + + defaultable.applySingleDefaultsWithTracker(ctx, defaults, protectedPropertyInfoCollector) + } + + // Check the status of any protected properties. + for property, info := range allProtectedProperties { + if len(info.defaultValues) == 0 { + // No defaults were applied to the protected properties. Possibly because this module type + // does not support any of them. + continue + } + + // Check to make sure that there are no conflicts between the defaults. + conflictingDefaults := false + previousDefaultValue := reflect.ValueOf(false) + for _, defaultInfo := range info.defaultValues { + defaultValue := defaultInfo.defaultValue + if previousDefaultValue.IsZero() { + previousDefaultValue = defaultValue + } else if !reflect.DeepEqual(previousDefaultValue.Interface(), defaultValue.Interface()) { + conflictingDefaults = true + break } } + + if conflictingDefaults { + var buf bytes.Buffer + for _, defaultInfo := range info.defaultValues { + buf.WriteString(fmt.Sprintf("\n defaults module %q provides value %#v", + ctx.OtherModuleName(defaultInfo.module), defaultInfo.defaultValue)) + } + result := buf.String() + ctx.ModuleErrorf("has conflicting default values for protected property %q:%s", property, result) + continue + } + + // Now check to see whether there the current module tried to override/append to the defaults. + if info.propertySet { + originalValue := info.originalValue + // Just compare against the first defaults. + defaultValue := info.defaultValues[0].defaultValue + defaults := info.defaultValues[0].module + + if originalValue.Kind() == reflect.Slice { + ctx.ModuleErrorf("attempts to append %q to protected property %q's value of %q defined in module %q", + originalValue, + property, + defaultValue, + ctx.OtherModuleName(defaults)) + } else { + same := reflect.DeepEqual(originalValue.Interface(), defaultValue.Interface()) + message := "" + if same { + message = fmt.Sprintf(" with a matching value (%#v) so this property can simply be removed.", originalValue) + } else { + message = fmt.Sprintf(" with a different value (override %#v with %#v) so removing the property may necessitate other changes.", defaultValue, originalValue) + } + ctx.ModuleErrorf("attempts to override protected property %q defined in module %q%s", + property, + ctx.OtherModuleName(defaults), message) + } + } + } +} + +func (defaultable *DefaultableModuleBase) applySingleDefaultsWithTracker(ctx EarlyModuleContext, defaults DefaultsModule, tracker defaultsTrackerFunc) { + for _, prop := range defaultable.defaultableProperties { + var err error + if prop == defaultable.defaultableVariableProperties { + err = defaultable.applyDefaultVariableProperties(defaults, prop, tracker) + } else { + err = defaultable.applyDefaultProperties(defaults, prop, tracker) + } + if err != nil { + if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { + ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) + } else { + panic(err) + } + } + } +} + +// defaultsTrackerFunc is the type of a function that can be used to track how defaults are applied. +type defaultsTrackerFunc func(defaults DefaultsModule, property string, + dstValue interface{}, srcValue interface{}) bool + +// filterForTracker wraps a defaultsTrackerFunc in a proptools.ExtendPropertyFilterFunc +func filterForTracker(defaults DefaultsModule, tracker defaultsTrackerFunc) proptools.ExtendPropertyFilterFunc { + if tracker == nil { + return nil + } + return func(property string, + dstField, srcField reflect.StructField, + dstValue, srcValue interface{}) (bool, error) { + + apply := tracker(defaults, property, dstValue, srcValue) + return apply, nil } } // Product variable properties need special handling, the type of the filtered product variable // property struct may not be identical between the defaults module and the defaultable module. // Use PrependMatchingProperties to apply whichever properties match. -func (defaultable *DefaultableModuleBase) applyDefaultVariableProperties(ctx TopDownMutatorContext, - defaults Defaults, defaultableProp interface{}) { +func (defaultable *DefaultableModuleBase) applyDefaultVariableProperties(defaults DefaultsModule, + defaultableProp interface{}, tracker defaultsTrackerFunc) error { if defaultableProp == nil { - return + return nil } defaultsProp := defaults.productVariableProperties() if defaultsProp == nil { - return + return nil } dst := []interface{}{ @@ -307,31 +573,26 @@ func (defaultable *DefaultableModuleBase) applyDefaultVariableProperties(ctx Top proptools.CloneEmptyProperties(reflect.ValueOf(defaultsProp)).Interface(), } - err := proptools.PrependMatchingProperties(dst, defaultsProp, nil) - if err != nil { - if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { - ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) - } else { - panic(err) - } - } + filter := filterForTracker(defaults, tracker) + + return proptools.PrependMatchingProperties(dst, defaultsProp, filter) } -func (defaultable *DefaultableModuleBase) applyDefaultProperties(ctx TopDownMutatorContext, - defaults Defaults, defaultableProp interface{}) { +func (defaultable *DefaultableModuleBase) applyDefaultProperties(defaults DefaultsModule, + defaultableProp interface{}, checker defaultsTrackerFunc) error { + + filter := filterForTracker(defaults, checker) for _, def := range defaults.properties() { if proptools.TypeEqual(defaultableProp, def) { - err := proptools.PrependProperties(defaultableProp, def, nil) + err := proptools.PrependProperties(defaultableProp, def, filter) if err != nil { - if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { - ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) - } else { - panic(err) - } + return err } } } + + return nil } func RegisterDefaultsPreArchMutators(ctx RegisterMutatorsContext) { @@ -348,12 +609,12 @@ func defaultsDepsMutator(ctx BottomUpMutatorContext) { func defaultsMutator(ctx TopDownMutatorContext) { if defaultable, ok := ctx.Module().(Defaultable); ok { if len(defaultable.defaults().Defaults) > 0 { - var defaultsList []Defaults + var defaultsList []DefaultsModule seen := make(map[Defaults]bool) ctx.WalkDeps(func(module, parent Module) bool { if ctx.OtherModuleDependencyTag(module) == DefaultsDepTag { - if defaults, ok := module.(Defaults); ok { + if defaults, ok := module.(DefaultsModule); ok { if !seen[defaults] { seen[defaults] = true defaultsList = append(defaultsList, defaults) diff --git a/android/defaults_test.go b/android/defaults_test.go index a7542abb3..d80f40cc6 100644 --- a/android/defaults_test.go +++ b/android/defaults_test.go @@ -19,7 +19,14 @@ import ( ) type defaultsTestProperties struct { - Foo []string + Foo []string + Bar []string + Nested struct { + Fizz *bool + } + Other struct { + Buzz *string + } } type defaultsTestModule struct { @@ -130,3 +137,167 @@ func TestDefaultsAllowMissingDependencies(t *testing.T) { // TODO: missing transitive defaults is currently not handled _ = missingTransitiveDefaults } + +func TestProtectedProperties_ProtectedPropertyNotSet(t *testing.T) { + bp := ` + defaults { + name: "transitive", + protected_properties: ["foo"], + } + ` + + GroupFixturePreparers( + prepareForDefaultsTest, + FixtureWithRootAndroidBp(bp), + ).ExtendWithErrorHandler(FixtureExpectsAtLeastOneErrorMatchingPattern( + "module \"transitive\": foo: is not set; protected properties must be explicitly set")). + RunTest(t) +} + +func TestProtectedProperties_ProtectedPropertyNotLeaf(t *testing.T) { + bp := ` + defaults { + name: "transitive", + protected_properties: ["nested"], + nested: { + fizz: true, + }, + } + ` + + GroupFixturePreparers( + prepareForDefaultsTest, + FixtureWithRootAndroidBp(bp), + ).ExtendWithErrorHandler(FixtureExpectsAtLeastOneErrorMatchingPattern( + `\Qmodule "transitive": nested: property is not supported by this module type "defaults"\E`)). + RunTest(t) +} + +// TestProtectedProperties_ApplyDefaults makes sure that the protected_properties property has +// defaults applied. +func TestProtectedProperties_HasDefaultsApplied(t *testing.T) { + + bp := ` + defaults { + name: "transitive", + protected_properties: ["foo"], + foo: ["transitive"], + } + + defaults { + name: "defaults", + defaults: ["transitive"], + protected_properties: ["bar"], + bar: ["defaults"], + } + ` + + result := GroupFixturePreparers( + prepareForDefaultsTest, + FixtureWithRootAndroidBp(bp), + ).RunTest(t) + + defaults := result.Module("defaults", "").(DefaultsModule) + AssertDeepEquals(t, "defaults protected properties", []string{"foo", "bar"}, defaults.protectedProperties()) +} + +// TestProtectedProperties_ProtectAllProperties makes sure that protected_properties: ["*"] protects +// all properties. +func TestProtectedProperties_ProtectAllProperties(t *testing.T) { + + bp := ` + defaults { + name: "transitive", + protected_properties: ["other.buzz"], + other: { + buzz: "transitive", + }, + } + + defaults { + name: "defaults", + defaults: ["transitive"], + visibility: ["//visibility:private"], + protected_properties: ["*"], + foo: ["other"], + bar: ["defaults"], + nested: { + fizz: true, + } + } + ` + + result := GroupFixturePreparers( + prepareForDefaultsTest, + FixtureWithRootAndroidBp(bp), + ).RunTest(t) + + defaults := result.Module("defaults", "").(DefaultsModule) + AssertDeepEquals(t, "defaults protected properties", []string{"other.buzz", "bar", "foo", "nested.fizz"}, + defaults.protectedProperties()) +} + +func TestProtectedProperties_DetectedOverride(t *testing.T) { + bp := ` + defaults { + name: "defaults", + protected_properties: ["foo", "nested.fizz"], + foo: ["defaults"], + nested: { + fizz: true, + }, + } + + test { + name: "foo", + defaults: ["defaults"], + foo: ["module"], + nested: { + fizz: false, + }, + } + ` + + GroupFixturePreparers( + prepareForDefaultsTest, + FixtureWithRootAndroidBp(bp), + ).ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern( + []string{ + `\Qmodule "foo": attempts to append ["module"] to protected property "foo"'s value of ["defaults"] defined in module "defaults"\E`, + `\Qmodule "foo": attempts to override protected property "nested.fizz" defined in module "defaults" with a different value (override true with false) so removing the property may necessitate other changes.\E`, + })).RunTest(t) +} + +func TestProtectedProperties_DefaultsConflict(t *testing.T) { + bp := ` + defaults { + name: "defaults1", + protected_properties: ["other.buzz"], + other: { + buzz: "value", + }, + } + + defaults { + name: "defaults2", + protected_properties: ["other.buzz"], + other: { + buzz: "another", + }, + } + + test { + name: "foo", + defaults: ["defaults1", "defaults2"], + } + ` + + GroupFixturePreparers( + prepareForDefaultsTest, + FixtureWithRootAndroidBp(bp), + ).ExtendWithErrorHandler(FixtureExpectsAtLeastOneErrorMatchingPattern( + `\Qmodule "foo": has conflicting default values for protected property "other.buzz": + defaults module "defaults1" provides value "value" + defaults module "defaults2" provides value "another"\E`, + )).RunTest(t) +} From 81c23549a5ce89c767a39807024b3e83d71de419 Mon Sep 17 00:00:00 2001 From: Alexei Nicoara Date: Tue, 24 May 2022 16:16:22 +0100 Subject: [PATCH 017/172] Passing the default apex version to the apexer Test: presubmit Bug: 231691643 Change-Id: I900a6acde9f212bf785b0be35f422416c8b62792 (cherry picked from commit 3f8cbcb82cc9297488e0b95678550cbd960b1de4) Merged-In: I900a6acde9f212bf785b0be35f422416c8b62792 --- apex/Android.bp | 1 + apex/builder.go | 2 ++ apex/constants.go | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 apex/constants.go diff --git a/apex/Android.bp b/apex/Android.bp index 41224ecd5..c4e64560e 100644 --- a/apex/Android.bp +++ b/apex/Android.bp @@ -24,6 +24,7 @@ bootstrap_go_package { "apex.go", "apex_singleton.go", "builder.go", + "constants.go", "deapexer.go", "key.go", "prebuilt.go", diff --git a/apex/builder.go b/apex/builder.go index a21fcb899..fc9bb3bec 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -655,6 +655,8 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { optFlags = append(optFlags, "--manifest_json "+a.manifestJsonOut.String()) } + optFlags = append(optFlags, "--apex_version "+defaultManifestVersion) + optFlags = append(optFlags, "--payload_fs_type "+a.payloadFsType.string()) ctx.Build(pctx, android.BuildParams{ diff --git a/apex/constants.go b/apex/constants.go new file mode 100644 index 000000000..c68edb724 --- /dev/null +++ b/apex/constants.go @@ -0,0 +1,36 @@ +// Copyright (C) 2022 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 + +// This file contains branch specific constants. They are stored in a separate +// file to minimise the potential of merge conflicts between branches when +// the code from the package is changed. + +// The default manifest version for all the modules on this branch. +// This version code will be used only if there is no version field in the +// module's apex_manifest.json. Release branches have their version injected +// into apex_manifest.json by the tooling and will not use the version set +// here. Developers can also set the version field locally in the +// apex_manifest.json to build a module with a specific version. +// +// The value follows the schema from go/mainline-version-codes, and is chosen +// based on the branch such that the builds from testing and development +// branches will have a version higher than the prebuilts. +// Versions per branch: +// * x-dev - xx0090000 (where xx is the branch SDK level) +// * AOSP - xx9990000 +// * x-mainline-prod - xx9990000 +// * master - 990090000 +const defaultManifestVersion = "339990000" From 029d72027de941b92315efe6219d8770f7c274e4 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 29 Jun 2022 10:15:52 +0000 Subject: [PATCH 018/172] Avoid modifying Compile_dex property Previously, the code would modify the Compile_dex property to set it to true if the module was part of an APEX as the APEX needs the dex file. That lost information about whether the Compile_dex property was specified in the .bp file and also meant that the APEX variant had different properties to other variants which could result in unexpected differences in behavior between them. One of those differences can occur in the sdk snapshot generation code which uses the Compile_dex property to determined whether to write a compile_dex property in the generated snapshot. If it uses an APEX variant then it will always add compile_dex: true but if it used a non APEX variant then it would depend on the setting of compile_dex in the source. That leads to the generated snapshot being affected not just by the set of modules that are included but also how they were specified. This change stops modifying the properties and just uses a local variable to store the updated value. All the other (4) uses of the Compile_dex property were checked and 1 accesses the property before it is updated, 2 access the property from a module type (Import) that does not update the property and the other is in the sdk snapshot generation code which accesses it after it has been modified but needs to access the unmodified value. This is needed for the follow up change that allows an sdk module to reference an apex to automatically add exportable parts of the apex contents to the sdk snapshot avoiding duplication which can lead to errors. Bug: 232401814 Test: m nothing Change-Id: Ibc80d93473a266dc9f9900ec1cb175b51460b5e9 (cherry picked from commit e7b1f5b0a55bba8e6f0e959464300d873da51eb9) Merged-In: Ibc80d93473a266dc9f9900ec1cb175b51460b5e9 --- java/base.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/java/base.go b/java/base.go index 7aa281495..717c7273f 100644 --- a/java/base.go +++ b/java/base.go @@ -1419,17 +1419,18 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { j.implementationAndResourcesJar = implementationAndResourcesJar // Enable dex compilation for the APEX variants, unless it is disabled explicitly + compileDex := j.dexProperties.Compile_dex apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) if j.DirectlyInAnyApex() && !apexInfo.IsForPlatform() { - if j.dexProperties.Compile_dex == nil { - j.dexProperties.Compile_dex = proptools.BoolPtr(true) + if compileDex == nil { + compileDex = proptools.BoolPtr(true) } if j.deviceProperties.Hostdex == nil { j.deviceProperties.Hostdex = proptools.BoolPtr(true) } } - if ctx.Device() && (Bool(j.properties.Installable) || Bool(j.dexProperties.Compile_dex)) { + if ctx.Device() && (Bool(j.properties.Installable) || Bool(compileDex)) { if j.hasCode(ctx) { if j.shouldInstrumentStatic(ctx) { j.dexer.extraProguardFlagFiles = append(j.dexer.extraProguardFlagFiles, From 606eee9ca259d84c9136038ef4901009918e2bd5 Mon Sep 17 00:00:00 2001 From: Alexei Nicoara Date: Thu, 30 Jun 2022 16:34:28 +0100 Subject: [PATCH 019/172] Removing comment lines from apex_manifest.json Allowing comments in apex_manifest.json by stripping all the lines which start with // Test: presubmit Bug: 237532860 Change-Id: Iec8c9987edf19b763b2b87df7d125c006ffb217a (cherry picked from commit ee4b633627fb291f6e39088307e38628d24a2070) Merged-In: Iec8c9987edf19b763b2b87df7d125c006ffb217a --- apex/builder.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/apex/builder.go b/apex/builder.go index fc9bb3bec..7e2b924c7 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -82,6 +82,11 @@ var ( Description: "prepare ${out}", }, "provideNativeLibs", "requireNativeLibs", "opt") + stripCommentsApexManifestRule = pctx.StaticRule("stripCommentsApexManifestRule", blueprint.RuleParams{ + Command: `sed '/^\s*\/\//d' $in > $out`, + Description: "strip lines starting with // ${in}=>${out}", + }) + stripApexManifestRule = pctx.StaticRule("stripApexManifestRule", blueprint.RuleParams{ Command: `rm -f $out && ${conv_apex_manifest} strip $in -o $out`, CommandDeps: []string{"${conv_apex_manifest}"}, @@ -205,10 +210,17 @@ func (a *apexBundle) buildManifest(ctx android.ModuleContext, provideNativeLibs, optCommands = append(optCommands, "-a jniLibs "+strings.Join(jniLibs, " ")) } + manifestJsonCommentsStripped := android.PathForModuleOut(ctx, "apex_manifest_comments_stripped.json") + ctx.Build(pctx, android.BuildParams{ + Rule: stripCommentsApexManifestRule, + Input: src, + Output: manifestJsonCommentsStripped, + }) + manifestJsonFullOut := android.PathForModuleOut(ctx, "apex_manifest_full.json") ctx.Build(pctx, android.BuildParams{ Rule: apexManifestRule, - Input: src, + Input: manifestJsonCommentsStripped, Output: manifestJsonFullOut, Args: map[string]string{ "provideNativeLibs": strings.Join(provideNativeLibs, " "), From 28b06d782bcffdf824f21f34ea7792ebc88d50be Mon Sep 17 00:00:00 2001 From: Alexei Nicoara Date: Fri, 1 Jul 2022 15:49:38 +0100 Subject: [PATCH 020/172] Updating master default version Test: presubmit Bug: 231691643 Change-Id: I17837dd4799ab8eedff76deec20083281a19d964 --- apex/constants.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apex/constants.go b/apex/constants.go index c68edb724..82eebffde 100644 --- a/apex/constants.go +++ b/apex/constants.go @@ -33,4 +33,4 @@ package apex // * AOSP - xx9990000 // * x-mainline-prod - xx9990000 // * master - 990090000 -const defaultManifestVersion = "339990000" +const defaultManifestVersion = "990090000" From 71b2daf9da6f5ec7d46a533072f087807f8b45b8 Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Wed, 20 Apr 2022 21:21:55 -0700 Subject: [PATCH 021/172] Fix some problems with soong metrics loading If we didn't need to run soong_build during the current run, we still try to load the soong metrics. But in the case of `dist`, that's in a directory that is not guaranteed to persist between runs. Make loading the soong metrics optional if the file does not exist. Also fixes a variable shadowing issue that meant we never passed it into ctx.Metrics. Test: treehugger Change-Id: Ic836282f4d13e91daa0e7241ad7c488de3293d8b (cherry picked from commit de3604453f61e4740afa5a85a1b09f0b8e793792) Merged-In: Ic836282f4d13e91daa0e7241ad7c488de3293d8b --- ui/build/soong.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/ui/build/soong.go b/ui/build/soong.go index c7f22f946..8992b4f07 100644 --- a/ui/build/soong.go +++ b/ui/build/soong.go @@ -15,7 +15,9 @@ package build import ( + "errors" "fmt" + "io/fs" "io/ioutil" "os" "path/filepath" @@ -491,10 +493,14 @@ func runSoong(ctx Context, config Config) { ninja("bootstrap", "bootstrap.ninja", targets...) - var soongBuildMetrics *soong_metrics_proto.SoongBuildMetrics if shouldCollectBuildSoongMetrics(config) { soongBuildMetrics := loadSoongBuildMetrics(ctx, config) - logSoongBuildMetrics(ctx, soongBuildMetrics) + if soongBuildMetrics != nil { + logSoongBuildMetrics(ctx, soongBuildMetrics) + if ctx.Metrics != nil { + ctx.Metrics.SetSoongBuildMetrics(soongBuildMetrics) + } + } } distGzipFile(ctx, config, config.SoongNinjaFile(), "soong") @@ -504,9 +510,6 @@ func runSoong(ctx Context, config Config) { distGzipFile(ctx, config, config.SoongMakeVarsMk(), "soong") } - if shouldCollectBuildSoongMetrics(config) && ctx.Metrics != nil { - ctx.Metrics.SetSoongBuildMetrics(soongBuildMetrics) - } if config.JsonModuleGraph() { distGzipFile(ctx, config, config.ModuleGraphFile(), "soong") } @@ -538,8 +541,12 @@ func shouldCollectBuildSoongMetrics(config Config) bool { func loadSoongBuildMetrics(ctx Context, config Config) *soong_metrics_proto.SoongBuildMetrics { soongBuildMetricsFile := filepath.Join(config.LogsDir(), "soong_build_metrics.pb") - buf, err := ioutil.ReadFile(soongBuildMetricsFile) - if err != nil { + buf, err := os.ReadFile(soongBuildMetricsFile) + if errors.Is(err, fs.ErrNotExist) { + // Soong may not have run during this invocation + ctx.Verbosef("Failed to read metrics file, %s: %s", soongBuildMetricsFile, err) + return nil + } else if err != nil { ctx.Fatalf("Failed to load %s: %s", soongBuildMetricsFile, err) } soongBuildMetrics := &soong_metrics_proto.SoongBuildMetrics{} From d4ba42e01c22b3c37845b4600f50cf47e884d15a Mon Sep 17 00:00:00 2001 From: Alexei Nicoara Date: Wed, 6 Jul 2022 12:03:11 +0100 Subject: [PATCH 022/172] Passing default version to zipApex as well Test: presubmit Bug: 231691643 Change-Id: Ic751d7ea2d23180855897702a03bf1b589d7ef80 (cherry picked from commit c939b0181d097c1a560e9de905fdfa59e4f7ea75) Merged-In: Ic751d7ea2d23180855897702a03bf1b589d7ef80 --- apex/builder.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apex/builder.go b/apex/builder.go index 7e2b924c7..e3c447632 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -112,6 +112,7 @@ var ( `--canned_fs_config ${canned_fs_config} ` + `--include_build_info ` + `--payload_type image ` + + `--apex_version ${apex_version} ` + `--key ${key} ${opt_flags} ${image_dir} ${out} `, CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}", "${mke2fs}", "${resize2fs}", "${sefcontext_compile}", "${make_f2fs}", "${sload_f2fs}", "${make_erofs}", @@ -119,7 +120,7 @@ var ( Rspfile: "${out}.copy_commands", RspfileContent: "${copy_commands}", Description: "APEX ${image_dir} => ${out}", - }, "tool_path", "image_dir", "copy_commands", "file_contexts", "canned_fs_config", "key", "opt_flags", "manifest", "payload_fs_type") + }, "tool_path", "image_dir", "copy_commands", "file_contexts", "canned_fs_config", "key", "opt_flags", "manifest", "payload_fs_type", "apex_version") zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{ Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` + @@ -127,12 +128,13 @@ var ( `APEXER_TOOL_PATH=${tool_path} ` + `${apexer} --force --manifest ${manifest} ` + `--payload_type zip ` + + `--apex_version ${apex_version} ` + `${image_dir} ${out} `, CommandDeps: []string{"${apexer}", "${merge_zips}", "${soong_zip}", "${zipalign}", "${aapt2}"}, Rspfile: "${out}.copy_commands", RspfileContent: "${copy_commands}", Description: "ZipAPEX ${image_dir} => ${out}", - }, "tool_path", "image_dir", "copy_commands", "manifest") + }, "tool_path", "image_dir", "copy_commands", "manifest", "apex_version") apexProtoConvertRule = pctx.AndroidStaticRule("apexProtoConvertRule", blueprint.RuleParams{ @@ -667,8 +669,6 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { optFlags = append(optFlags, "--manifest_json "+a.manifestJsonOut.String()) } - optFlags = append(optFlags, "--apex_version "+defaultManifestVersion) - optFlags = append(optFlags, "--payload_fs_type "+a.payloadFsType.string()) ctx.Build(pctx, android.BuildParams{ @@ -684,6 +684,7 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { "file_contexts": fileContexts.String(), "canned_fs_config": cannedFsConfig.String(), "key": a.privateKeyFile.String(), + "apex_version": defaultManifestVersion, "opt_flags": strings.Join(optFlags, " "), }, }) @@ -780,6 +781,7 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { "image_dir": imageDir.String(), "copy_commands": strings.Join(copyCommands, " && "), "manifest": a.manifestPbOut.String(), + "apex_version": defaultManifestVersion, }, }) } From 537b550ee324ed8b5dcdfa23213881bbcd3db79d Mon Sep 17 00:00:00 2001 From: "Lukacs T. Berki" Date: Fri, 20 May 2022 15:23:06 +0200 Subject: [PATCH 023/172] Remove memberInterVersionMutator. paulduffin@ says it's not necessary anymore. Test: Presubmits. Bug: 232546567 Change-Id: I6ac69fbdc7a202ac54f250ea6cde0ea99d75864c (cherry picked from commit ab392edc47cc89f5cd160aa92292caf284b174f0) Merged-In: I6ac69fbdc7a202ac54f250ea6cde0ea99d75864c --- sdk/sdk.go | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/sdk/sdk.go b/sdk/sdk.go index b37eaad69..468ed99ab 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -281,7 +281,6 @@ var _ android.SdkDependencyContext = (*dependencyContext)(nil) func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) { ctx.BottomUp("SdkMember", memberMutator).Parallel() ctx.TopDown("SdkMember_deps", memberDepsMutator).Parallel() - ctx.BottomUp("SdkMemberInterVersion", memberInterVersionMutator).Parallel() } type dependencyTag struct { @@ -383,22 +382,6 @@ func memberDepsMutator(mctx android.TopDownMutatorContext) { } } -// Step 3: create dependencies from the unversioned SDK member to snapshot versions -// of the same member. By having these dependencies, they are mutated for multiple Mainline modules -// (apex and apk), each of which might want different sdks to be built with. For example, if both -// apex A and B are referencing libfoo which is a member of sdk 'mysdk', the two APEXes can be -// built with libfoo.mysdk.11 and libfoo.mysdk.12, respectively depending on which sdk they are -// using. -func memberInterVersionMutator(mctx android.BottomUpMutatorContext) { - if m, ok := mctx.Module().(android.SdkAware); ok && m.IsInAnySdk() && m.IsVersioned() { - if !m.ContainingSdk().Unversioned() { - memberName := m.MemberName() - tag := sdkMemberVersionedDepTag{member: memberName, version: m.ContainingSdk().Version} - mctx.AddReverseDependency(mctx.Module(), tag, memberName) - } - } -} - // An interface that encapsulates all the functionality needed to manage the sdk dependencies. // // It is a mixture of apex and sdk module functionality. From 7b71083e356fb9a622841a13796698d5e9442bb1 Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Thu, 12 May 2022 20:40:00 -0400 Subject: [PATCH 024/172] Handle multiple linkages in sdk snapshots Currently, if the same library is specified for multiple of native_libs, native_shared_libs, and native_static_libs for different arch/oses, there can be a few errors: 1. specifying a .so file as `srcs` within a cc_prebuilt_library rather than being specified only for shared 2. the final type of prebuilt library is dependent on the arch/os This change introduces: * an ability for a member type to override the type for specified properties * checks for a library being used with incompatible member types * basing linkage nesting on the member type in addition to variants This will ensure that the correct library type is used, regardless of the order of iteration over oses/arches, and support nesting linkages where necessary but only one linkage variant exists. Test: soong tests Test: CI Change-Id: I81dee013b09b99c34ca6c18f9cfcc12ee56d33d1 (cherry picked from commit 96320dfff8fd5859a5e5f2a5c74bf8d79dd6499d) Merged-In: I81dee013b09b99c34ca6c18f9cfcc12ee56d33d1 --- android/sdk.go | 21 ++++ cc/library_sdk_member.go | 32 +++--- cc/object.go | 1 - sdk/cc_sdk_test.go | 223 +++++++++++++++++++++++++++++++++++++++ sdk/update.go | 30 +++++- 5 files changed, 285 insertions(+), 22 deletions(-) diff --git a/android/sdk.go b/android/sdk.go index 20ed794c7..533f2f4ec 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -674,6 +674,9 @@ type SdkMemberType interface { // host OS variant explicitly and disable all other host OS'es. IsHostOsDependent() bool + // SupportedLinkages returns the names of the linkage variants supported by this module. + SupportedLinkages() []string + // AddDependencies adds dependencies from the SDK module to all the module variants the member // type contributes to the SDK. `names` is the list of module names given in the member type // property (as returned by SdkPropertyName()) in the SDK module. The exact set of variants @@ -737,6 +740,9 @@ type SdkMemberType interface { // SupportedTraits returns the set of traits supported by this member type. SupportedTraits() SdkMemberTraitSet + + // Overrides returns whether type overrides other SdkMemberType + Overrides(SdkMemberType) bool } var _ sdkRegisterable = (SdkMemberType)(nil) @@ -760,6 +766,13 @@ type SdkDependencyContext interface { type SdkMemberTypeBase struct { PropertyName string + // Property names that this SdkMemberTypeBase can override, this is useful when a module type is a + // superset of another module type. + OverridesPropertyNames map[string]bool + + // The names of linkage variants supported by this module. + SupportedLinkageNames []string + // When set to true BpPropertyNotRequired indicates that the member type does not require the // property to be specifiable in an Android.bp file. BpPropertyNotRequired bool @@ -809,6 +822,14 @@ func (b *SdkMemberTypeBase) SupportedTraits() SdkMemberTraitSet { return NewSdkMemberTraitSet(b.Traits) } +func (b *SdkMemberTypeBase) Overrides(other SdkMemberType) bool { + return b.OverridesPropertyNames[other.SdkPropertyName()] +} + +func (b *SdkMemberTypeBase) SupportedLinkages() []string { + return b.SupportedLinkageNames +} + // registeredModuleExportsMemberTypes is the set of registered SdkMemberTypes for module_exports // modules. var registeredModuleExportsMemberTypes = &sdkRegistry{} diff --git a/cc/library_sdk_member.go b/cc/library_sdk_member.go index 8988de2e5..1bcbdc55d 100644 --- a/cc/library_sdk_member.go +++ b/cc/library_sdk_member.go @@ -27,32 +27,33 @@ import ( var sharedLibrarySdkMemberType = &librarySdkMemberType{ SdkMemberTypeBase: android.SdkMemberTypeBase{ - PropertyName: "native_shared_libs", - SupportsSdk: true, - HostOsDependent: true, + PropertyName: "native_shared_libs", + SupportsSdk: true, + HostOsDependent: true, + SupportedLinkageNames: []string{"shared"}, }, prebuiltModuleType: "cc_prebuilt_library_shared", - linkTypes: []string{"shared"}, } var staticLibrarySdkMemberType = &librarySdkMemberType{ SdkMemberTypeBase: android.SdkMemberTypeBase{ - PropertyName: "native_static_libs", - SupportsSdk: true, - HostOsDependent: true, + PropertyName: "native_static_libs", + SupportsSdk: true, + HostOsDependent: true, + SupportedLinkageNames: []string{"static"}, }, prebuiltModuleType: "cc_prebuilt_library_static", - linkTypes: []string{"static"}, } var staticAndSharedLibrarySdkMemberType = &librarySdkMemberType{ SdkMemberTypeBase: android.SdkMemberTypeBase{ - PropertyName: "native_libs", - SupportsSdk: true, - HostOsDependent: true, + PropertyName: "native_libs", + OverridesPropertyNames: map[string]bool{"native_shared_libs": true, "native_static_libs": true}, + SupportsSdk: true, + HostOsDependent: true, + SupportedLinkageNames: []string{"static", "shared"}, }, prebuiltModuleType: "cc_prebuilt_library", - linkTypes: []string{"static", "shared"}, } func init() { @@ -69,9 +70,6 @@ type librarySdkMemberType struct { noOutputFiles bool // True if there are no srcs files. - // The set of link types supported. A set of "static", "shared", or nil to - // skip link type variations. - linkTypes []string } func (mt *librarySdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) { @@ -165,12 +163,12 @@ func (mt *librarySdkMemberType) AddDependencies(ctx android.SdkDependencyContext // Add any additional dependencies needed. variations = append(variations, dependency.imageVariations...) - if mt.linkTypes == nil { + if mt.SupportedLinkageNames == nil { // No link types are supported so add a dependency directly. ctx.AddFarVariationDependencies(variations, dependencyTag, name) } else { // Otherwise, add a dependency on each supported link type in turn. - for _, linkType := range mt.linkTypes { + for _, linkType := range mt.SupportedLinkageNames { libVariations := append(variations, blueprint.Variation{Mutator: "link", Variation: linkType}) // If this is for the device and a shared link type then add a dependency onto the diff --git a/cc/object.go b/cc/object.go index bd5bd4517..3558efba1 100644 --- a/cc/object.go +++ b/cc/object.go @@ -37,7 +37,6 @@ var ccObjectSdkMemberType = &librarySdkMemberType{ SupportsSdk: true, }, prebuiltModuleType: "cc_prebuilt_object", - linkTypes: nil, } type objectLinker struct { diff --git a/sdk/cc_sdk_test.go b/sdk/cc_sdk_test.go index 571d21420..a4c7a8559 100644 --- a/sdk/cc_sdk_test.go +++ b/sdk/cc_sdk_test.go @@ -1740,6 +1740,229 @@ myinclude/Test.h -> include/myinclude/Test.h ) } +func TestSnapshotSameLibraryWithNativeLibsAndNativeSharedLib(t *testing.T) { + result := testSdkWithCc(t, ` + module_exports { + host_supported: true, + name: "myexports", + target: { + android: { + native_shared_libs: [ + "mynativelib", + ], + }, + not_windows: { + native_libs: [ + "mynativelib", + ], + }, + }, + } + + cc_library { + name: "mynativelib", + host_supported: true, + srcs: [ + "Test.cpp", + ], + stl: "none", + recovery_available: true, + vendor_available: true, + } + `) + + CheckSnapshot(t, result, "myexports", "", + checkUnversionedAndroidBpContents(` +// This is auto-generated. DO NOT EDIT. + +cc_prebuilt_library { + name: "mynativelib", + prefer: false, + visibility: ["//visibility:public"], + apex_available: ["//apex_available:platform"], + host_supported: true, + vendor_available: true, + stl: "none", + compile_multilib: "both", + target: { + host: { + enabled: false, + }, + android_arm64: { + shared: { + srcs: ["android/arm64/lib/mynativelib.so"], + }, + static: { + enabled: false, + }, + }, + android_arm: { + shared: { + srcs: ["android/arm/lib/mynativelib.so"], + }, + static: { + enabled: false, + }, + }, + linux_glibc_x86_64: { + enabled: true, + static: { + srcs: ["linux_glibc/x86_64/lib/mynativelib.a"], + }, + shared: { + srcs: ["linux_glibc/x86_64/lib/mynativelib.so"], + }, + }, + linux_glibc_x86: { + enabled: true, + static: { + srcs: ["linux_glibc/x86/lib/mynativelib.a"], + }, + shared: { + srcs: ["linux_glibc/x86/lib/mynativelib.so"], + }, + }, + }, +} +`), + checkAllCopyRules(` +.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> android/arm64/lib/mynativelib.so +.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> android/arm/lib/mynativelib.so +.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> linux_glibc/x86_64/lib/mynativelib.a +.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> linux_glibc/x86_64/lib/mynativelib.so +.intermediates/mynativelib/linux_glibc_x86_static/mynativelib.a -> linux_glibc/x86/lib/mynativelib.a +.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> linux_glibc/x86/lib/mynativelib.so +`), + ) +} + +func TestSnapshotSameLibraryWithAndroidNativeLibsAndHostNativeSharedLib(t *testing.T) { + result := testSdkWithCc(t, ` + module_exports { + host_supported: true, + name: "myexports", + target: { + android: { + native_libs: [ + "mynativelib", + ], + }, + not_windows: { + native_shared_libs: [ + "mynativelib", + ], + }, + }, + } + + cc_library { + name: "mynativelib", + host_supported: true, + srcs: [ + "Test.cpp", + ], + stl: "none", + recovery_available: true, + vendor_available: true, + } + `) + + CheckSnapshot(t, result, "myexports", "", + checkUnversionedAndroidBpContents(` +// This is auto-generated. DO NOT EDIT. + +cc_prebuilt_library { + name: "mynativelib", + prefer: false, + visibility: ["//visibility:public"], + apex_available: ["//apex_available:platform"], + host_supported: true, + vendor_available: true, + stl: "none", + compile_multilib: "both", + target: { + host: { + enabled: false, + }, + android_arm64: { + static: { + srcs: ["android/arm64/lib/mynativelib.a"], + }, + shared: { + srcs: ["android/arm64/lib/mynativelib.so"], + }, + }, + android_arm: { + static: { + srcs: ["android/arm/lib/mynativelib.a"], + }, + shared: { + srcs: ["android/arm/lib/mynativelib.so"], + }, + }, + linux_glibc_x86_64: { + enabled: true, + shared: { + srcs: ["linux_glibc/x86_64/lib/mynativelib.so"], + }, + static: { + enabled: false, + }, + }, + linux_glibc_x86: { + enabled: true, + shared: { + srcs: ["linux_glibc/x86/lib/mynativelib.so"], + }, + static: { + enabled: false, + }, + }, + }, +} +`), + checkAllCopyRules(` +.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> android/arm64/lib/mynativelib.a +.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> android/arm64/lib/mynativelib.so +.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> android/arm/lib/mynativelib.a +.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> android/arm/lib/mynativelib.so +.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> linux_glibc/x86_64/lib/mynativelib.so +.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> linux_glibc/x86/lib/mynativelib.so +`), + ) +} + +func TestSnapshotSameLibraryWithNativeStaticLibsAndNativeSharedLib(t *testing.T) { + testSdkError(t, "Incompatible member types", ` + module_exports { + host_supported: true, + name: "myexports", + target: { + android: { + native_shared_libs: [ + "mynativelib", + ], + }, + not_windows: { + native_static_libs: [ + "mynativelib", + ], + }, + }, + } + + cc_library { + name: "mynativelib", + host_supported: true, + srcs: [ + ], + stl: "none", + recovery_available: true, + vendor_available: true, + } + `) +} + func TestHostSnapshotWithMultiLib64(t *testing.T) { result := testSdkWithCc(t, ` module_exports { diff --git a/sdk/update.go b/sdk/update.go index af2b247b4..063597fad 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -268,13 +268,19 @@ func (s *sdk) groupMemberVariantsByMemberThenType(ctx android.ModuleContext, tar member = &sdkMember{memberType: memberType, name: name} byName[name] = member byType[memberType] = append(byType[memberType], member) + } else if member.memberType != memberType { + // validate whether this is the same member type or and overriding member type + if memberType.Overrides(member.memberType) { + member.memberType = memberType + } else if !member.memberType.Overrides(memberType) { + ctx.ModuleErrorf("Incompatible member types %q %q", member.memberType, memberType) + } } // Only append new variants to the list. This is needed because a member can be both // exported by the sdk and also be a transitive sdk member. member.variants = appendUniqueVariants(member.variants, variant) } - var members []*sdkMember for _, memberListProperty := range s.memberTypeListProperties() { memberType := memberListProperty.memberType @@ -1812,7 +1818,9 @@ func newArchSpecificInfo(ctx android.SdkMemberContext, archId archId, osType and // added. archInfo.Properties = variantPropertiesFactory() - if len(archVariants) == 1 { + // if there are multiple supported link variants, we want to nest based on linkage even if there + // is only one variant, otherwise, if there is only one variant we can populate based on the arch + if len(archVariants) == 1 && len(ctx.MemberType().SupportedLinkages()) <= 1 { archInfo.Properties.PopulateFromVariant(ctx, archVariants[0]) } else { // Group the variants by image type. @@ -1939,11 +1947,13 @@ func newImageVariantSpecificInfo(ctx android.SdkMemberContext, imageVariant stri // Create the properties into which the image variant specific properties will be added. imageInfo.Properties = variantPropertiesFactory() - if len(imageVariants) == 1 { + // if there are multiple supported link variants, we want to nest even if there is only one + // variant, otherwise, if there is only one variant we can populate based on the image + if len(imageVariants) == 1 && len(ctx.MemberType().SupportedLinkages()) <= 1 { imageInfo.Properties.PopulateFromVariant(ctx, imageVariants[0]) } else { // There is more than one variant for this image variant which must be differentiated by link - // type. + // type. Or there are multiple supported linkages and we need to nest based on link type. for _, linkVariant := range imageVariants { linkType := getLinkType(linkVariant) if linkType == "" { @@ -1987,10 +1997,22 @@ func (imageInfo *imageVariantSpecificInfo) addToPropertySet(ctx *memberContext, addSdkMemberPropertiesToSet(ctx, imageInfo.Properties, propertySet) + usedLinkages := make(map[string]bool, len(imageInfo.linkInfos)) for _, linkInfo := range imageInfo.linkInfos { + usedLinkages[linkInfo.linkType] = true linkInfo.addToPropertySet(ctx, propertySet) } + // If not all supported linkages had existing variants, we need to disable the unsupported variant + if len(imageInfo.linkInfos) < len(ctx.MemberType().SupportedLinkages()) { + for _, l := range ctx.MemberType().SupportedLinkages() { + if _, ok := usedLinkages[l]; !ok { + otherLinkagePropertySet := propertySet.AddPropertySet(l) + otherLinkagePropertySet.AddProperty("enabled", false) + } + } + } + // If this is for a non-core image variant then make sure that the property set does not contain // any properties as providing non-core image variant specific properties for prebuilts is not // currently supported. From e4713a88cbec18f1448ab7f180433d03827b8b30 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 13 May 2022 13:01:59 +0000 Subject: [PATCH 025/172] Pass pointer to dependencyTag instead of copying struct A follow up change will add some more fields to the tag which will make passing the struct around by value will get more expensive. Switching to pointers will make this slightly more efficient. Changing the type of the tags from dependencyTag to *dependencyTag broke a test. Rather than simply patch the test and then maybe have to patch it again in the next change this adds a a String() method that will insulate the test from being affected by changes in the dependencyTag contents. Bug: 232401814 Test: m nothing Change-Id: I23da742ebffb74ef3b9b68f772519ceb38332f5f (cherry picked from commit 520917af9d71b11bcc2179f1dfdb6c701dffe044) Merged-In: I23da742ebffb74ef3b9b68f772519ceb38332f5f --- apex/apex.go | 42 +++++++++++++++++++++++------------------- apex/apex_test.go | 2 +- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index 951157f17..d613861fb 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -606,30 +606,34 @@ type dependencyTag struct { sourceOnly bool } -func (d dependencyTag) ReplaceSourceWithPrebuilt() bool { +func (d *dependencyTag) String() string { + return fmt.Sprintf("apex.dependencyTag{%q}", d.name) +} + +func (d *dependencyTag) ReplaceSourceWithPrebuilt() bool { return !d.sourceOnly } var _ android.ReplaceSourceWithPrebuilt = &dependencyTag{} var ( - androidAppTag = dependencyTag{name: "androidApp", payload: true} - bpfTag = dependencyTag{name: "bpf", payload: true} - certificateTag = dependencyTag{name: "certificate"} - executableTag = dependencyTag{name: "executable", payload: true} - fsTag = dependencyTag{name: "filesystem", payload: true} - bcpfTag = dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true} - sscpfTag = dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true} - compatConfigTag = dependencyTag{name: "compatConfig", payload: true, sourceOnly: true} - javaLibTag = dependencyTag{name: "javaLib", payload: true} - jniLibTag = dependencyTag{name: "jniLib", payload: true} - keyTag = dependencyTag{name: "key"} - prebuiltTag = dependencyTag{name: "prebuilt", payload: true} - rroTag = dependencyTag{name: "rro", payload: true} - sharedLibTag = dependencyTag{name: "sharedLib", payload: true} - testForTag = dependencyTag{name: "test for"} - testTag = dependencyTag{name: "test", payload: true} - shBinaryTag = dependencyTag{name: "shBinary", payload: true} + androidAppTag = &dependencyTag{name: "androidApp", payload: true} + bpfTag = &dependencyTag{name: "bpf", payload: true} + certificateTag = &dependencyTag{name: "certificate"} + executableTag = &dependencyTag{name: "executable", payload: true} + fsTag = &dependencyTag{name: "filesystem", payload: true} + bcpfTag = &dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true} + sscpfTag = &dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true} + compatConfigTag = &dependencyTag{name: "compatConfig", payload: true, sourceOnly: true} + javaLibTag = &dependencyTag{name: "javaLib", payload: true} + jniLibTag = &dependencyTag{name: "jniLib", payload: true} + keyTag = &dependencyTag{name: "key"} + prebuiltTag = &dependencyTag{name: "prebuilt", payload: true} + rroTag = &dependencyTag{name: "rro", payload: true} + sharedLibTag = &dependencyTag{name: "sharedLib", payload: true} + testForTag = &dependencyTag{name: "test for"} + testTag = &dependencyTag{name: "test", payload: true} + shBinaryTag = &dependencyTag{name: "shBinary", payload: true} ) // TODO(jiyong): shorten this function signature @@ -1735,7 +1739,7 @@ func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.Paylo if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok { return false } - if dt, ok := depTag.(dependencyTag); ok && !dt.payload { + if dt, ok := depTag.(*dependencyTag); ok && !dt.payload { return false } diff --git a/apex/apex_test.go b/apex/apex_test.go index b3036b1fa..49b2b2d4d 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -5931,7 +5931,7 @@ func TestApexAvailable_DirectDep(t *testing.T) { func TestApexAvailable_IndirectDep(t *testing.T) { // libbbaz is an indirect dep testApexError(t, `requires "libbaz" that doesn't list the APEX under 'apex_available'.\n\nDependency path: -.*via tag apex\.dependencyTag.*name:sharedLib.* +.*via tag apex\.dependencyTag\{"sharedLib"\} .*-> libfoo.*link:shared.* .*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.* .*-> libbar.*link:shared.* From 42cdd62d91509b4212b278efcc992231ad67c41c Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 24 May 2022 20:10:05 +0000 Subject: [PATCH 026/172] Remove support for generating versioned snapshots (cherry picked from commit b01ac4b6ba89e13cbb47e9d22619bf015270ee26) Previously, the code for selecting specific versions of sdk snapshots was removed (along with the uses_sdks property). That makes versioned snapshots useless so this change removes all the code and tests that generated those versioned snapshots. Bug: 232546567 Test: m nothing packages/modules/common/build/mainline_modules_sdks.sh Change-Id: Ib6d1b72bc8399fbb39075494ae37da92f4b28d03 Merged-In: Ib6d1b72bc8399fbb39075494ae37da92f4b28d03 --- sdk/bootclasspath_fragment_sdk_test.go | 140 +-- sdk/bp.go | 12 +- sdk/cc_sdk_test.go | 838 +----------------- sdk/compat_config_sdk_test.go | 18 +- sdk/exports.go | 2 +- sdk/exports_test.go | 19 +- sdk/java_sdk_test.go | 606 +------------ sdk/license_sdk_test.go | 40 +- sdk/member_trait_test.go | 21 +- sdk/sdk.go | 34 +- sdk/sdk_test.go | 198 +---- ...systemserverclasspath_fragment_sdk_test.go | 73 +- sdk/testing.go | 66 +- sdk/update.go | 322 +------ 14 files changed, 120 insertions(+), 2269 deletions(-) diff --git a/sdk/bootclasspath_fragment_sdk_test.go b/sdk/bootclasspath_fragment_sdk_test.go index 2dacdb55c..a60039ac6 100644 --- a/sdk/bootclasspath_fragment_sdk_test.go +++ b/sdk/bootclasspath_fragment_sdk_test.go @@ -124,7 +124,7 @@ func TestSnapshotWithBootclasspathFragment_ImageName(t *testing.T) { preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("com.android.art", "mybootclasspathfragment") CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. prebuilt_bootclasspath_fragment { @@ -151,41 +151,6 @@ java_import { apex_available: ["com.android.art"], jars: ["java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar"], } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -prebuilt_bootclasspath_fragment { - name: "mysdk_mybootclasspathfragment@current", - sdk_member_name: "mybootclasspathfragment", - visibility: ["//visibility:public"], - apex_available: ["com.android.art"], - image_name: "art", - contents: ["mysdk_mybootlib@current"], - hidden_api: { - annotation_flags: "hiddenapi/annotation-flags.csv", - metadata: "hiddenapi/metadata.csv", - index: "hiddenapi/index.csv", - signature_patterns: "hiddenapi/signature-patterns.csv", - filtered_stub_flags: "hiddenapi/filtered-stub-flags.csv", - filtered_flags: "hiddenapi/filtered-flags.csv", - }, -} - -java_import { - name: "mysdk_mybootlib@current", - sdk_member_name: "mybootlib", - visibility: ["//visibility:public"], - apex_available: ["com.android.art"], - jars: ["java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar"], -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - bootclasspath_fragments: ["mysdk_mybootclasspathfragment@current"], - java_boot_libs: ["mysdk_mybootlib@current"], -} `), checkAllCopyRules(` .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv @@ -317,7 +282,7 @@ func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) { preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("myapex", "mybootclasspathfragment") CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. prebuilt_bootclasspath_fragment { @@ -400,103 +365,6 @@ java_sdk_library_import { removed_api: "sdk_library/public/mycoreplatform-removed.txt", sdk_version: "current", }, -} - `), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -prebuilt_bootclasspath_fragment { - name: "mysdk_mybootclasspathfragment@current", - sdk_member_name: "mybootclasspathfragment", - visibility: ["//visibility:public"], - apex_available: ["myapex"], - contents: [ - "mysdk_mybootlib@current", - "mysdk_myothersdklibrary@current", - ], - api: { - stub_libs: ["mysdk_mysdklibrary@current"], - }, - core_platform_api: { - stub_libs: ["mysdk_mycoreplatform@current"], - }, - hidden_api: { - annotation_flags: "hiddenapi/annotation-flags.csv", - metadata: "hiddenapi/metadata.csv", - index: "hiddenapi/index.csv", - signature_patterns: "hiddenapi/signature-patterns.csv", - filtered_stub_flags: "hiddenapi/filtered-stub-flags.csv", - filtered_flags: "hiddenapi/filtered-flags.csv", - }, -} - -java_import { - name: "mysdk_mybootlib@current", - sdk_member_name: "mybootlib", - visibility: ["//visibility:public"], - apex_available: ["myapex"], - jars: ["java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar"], - permitted_packages: ["mybootlib"], -} - -java_sdk_library_import { - name: "mysdk_myothersdklibrary@current", - sdk_member_name: "myothersdklibrary", - visibility: ["//visibility:public"], - apex_available: ["myapex"], - shared_library: true, - compile_dex: true, - permitted_packages: ["myothersdklibrary"], - public: { - jars: ["sdk_library/public/myothersdklibrary-stubs.jar"], - stub_srcs: ["sdk_library/public/myothersdklibrary_stub_sources"], - current_api: "sdk_library/public/myothersdklibrary.txt", - removed_api: "sdk_library/public/myothersdklibrary-removed.txt", - sdk_version: "current", - }, -} - -java_sdk_library_import { - name: "mysdk_mysdklibrary@current", - sdk_member_name: "mysdklibrary", - visibility: ["//visibility:public"], - apex_available: ["myapex"], - shared_library: false, - public: { - jars: ["sdk_library/public/mysdklibrary-stubs.jar"], - stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], - current_api: "sdk_library/public/mysdklibrary.txt", - removed_api: "sdk_library/public/mysdklibrary-removed.txt", - sdk_version: "current", - }, -} - -java_sdk_library_import { - name: "mysdk_mycoreplatform@current", - sdk_member_name: "mycoreplatform", - visibility: ["//visibility:public"], - apex_available: ["myapex"], - shared_library: true, - compile_dex: true, - public: { - jars: ["sdk_library/public/mycoreplatform-stubs.jar"], - stub_srcs: ["sdk_library/public/mycoreplatform_stub_sources"], - current_api: "sdk_library/public/mycoreplatform.txt", - removed_api: "sdk_library/public/mycoreplatform-removed.txt", - sdk_version: "current", - }, -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - bootclasspath_fragments: ["mysdk_mybootclasspathfragment@current"], - java_boot_libs: ["mysdk_mybootlib@current"], - java_sdk_libs: [ - "mysdk_myothersdklibrary@current", - "mysdk_mysdklibrary@current", - "mysdk_mycoreplatform@current", - ], } `), checkAllCopyRules(` @@ -630,7 +498,7 @@ func TestSnapshotWithBootClasspathFragment_Fragments(t *testing.T) { preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("myapex", "mybootclasspathfragment") CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. prebuilt_bootclasspath_fragment { @@ -828,7 +696,7 @@ func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) { preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("myapex", "mybootclasspathfragment") CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. prebuilt_bootclasspath_fragment { diff --git a/sdk/bp.go b/sdk/bp.go index e2dace8f9..7ff85a121 100644 --- a/sdk/bp.go +++ b/sdk/bp.go @@ -298,15 +298,15 @@ func (t identityTransformation) transformModule(module *bpModule) *bpModule { return module } -func (t identityTransformation) transformPropertySetBeforeContents(name string, propertySet *bpPropertySet, tag android.BpPropertyTag) (*bpPropertySet, android.BpPropertyTag) { +func (t identityTransformation) transformPropertySetBeforeContents(_ string, propertySet *bpPropertySet, tag android.BpPropertyTag) (*bpPropertySet, android.BpPropertyTag) { return propertySet, tag } -func (t identityTransformation) transformPropertySetAfterContents(name string, propertySet *bpPropertySet, tag android.BpPropertyTag) (*bpPropertySet, android.BpPropertyTag) { +func (t identityTransformation) transformPropertySetAfterContents(_ string, propertySet *bpPropertySet, tag android.BpPropertyTag) (*bpPropertySet, android.BpPropertyTag) { return propertySet, tag } -func (t identityTransformation) transformProperty(name string, value interface{}, tag android.BpPropertyTag) (interface{}, android.BpPropertyTag) { +func (t identityTransformation) transformProperty(_ string, value interface{}, tag android.BpPropertyTag) (interface{}, android.BpPropertyTag) { return value, tag } @@ -332,7 +332,7 @@ func (t deepCopyTransformation) transformModule(module *bpModule) *bpModule { return &moduleCopy } -func (t deepCopyTransformation) transformPropertySetBeforeContents(name string, propertySet *bpPropertySet, tag android.BpPropertyTag) (*bpPropertySet, android.BpPropertyTag) { +func (t deepCopyTransformation) transformPropertySetBeforeContents(_ string, propertySet *bpPropertySet, tag android.BpPropertyTag) (*bpPropertySet, android.BpPropertyTag) { // Create a shallow copy of the properties map. Any mutable property values will be copied by the // transformer. propertiesCopy := make(map[string]interface{}) @@ -354,7 +354,7 @@ func (t deepCopyTransformation) transformPropertySetBeforeContents(name string, }, tag } -func (t deepCopyTransformation) transformProperty(name string, value interface{}, tag android.BpPropertyTag) (interface{}, android.BpPropertyTag) { +func (t deepCopyTransformation) transformProperty(_ string, value interface{}, tag android.BpPropertyTag) (interface{}, android.BpPropertyTag) { // Copy string slice, otherwise return value. if values, ok := value.([]string); ok { valuesCopy := make([]string, len(values)) @@ -372,7 +372,7 @@ type bpFile struct { order []*bpModule } -// Add a module. +// AddModule adds a module to this. // // The module must have had its "name" property set to a string value that // is unique within this file. diff --git a/sdk/cc_sdk_test.go b/sdk/cc_sdk_test.go index a4c7a8559..265579aa1 100644 --- a/sdk/cc_sdk_test.go +++ b/sdk/cc_sdk_test.go @@ -120,7 +120,7 @@ func TestSdkCompileMultilibOverride(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library_shared { @@ -144,48 +144,6 @@ cc_prebuilt_library_shared { }, }, } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -cc_prebuilt_library_shared { - name: "mysdk_sdkmember@current", - sdk_member_name: "sdkmember", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - host_supported: true, - installable: false, - stl: "none", - compile_multilib: "64", - target: { - host: { - enabled: false, - }, - android_arm64: { - srcs: ["android/arm64/lib/sdkmember.so"], - }, - linux_glibc_x86_64: { - enabled: true, - srcs: ["linux_glibc/x86_64/lib/sdkmember.so"], - }, - }, -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - host_supported: true, - compile_multilib: "64", - native_shared_libs: ["mysdk_sdkmember@current"], - target: { - host: { - enabled: false, - }, - linux_glibc_x86_64: { - enabled: true, - }, - }, -} `), checkAllCopyRules(` .intermediates/sdkmember/android_arm64_armv8-a_shared/sdkmember.so -> android/arm64/lib/sdkmember.so @@ -265,7 +223,7 @@ func TestSnapshotWithObject(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_object { @@ -288,37 +246,6 @@ cc_prebuilt_object { }, }, } -`), - // Make sure that the generated sdk_snapshot uses the native_objects property. - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -cc_prebuilt_object { - name: "mysdk_crtobj@current", - sdk_member_name: "crtobj", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - stl: "none", - compile_multilib: "both", - system_shared_libs: [], - sanitize: { - never: true, - }, - arch: { - arm64: { - srcs: ["arm64/lib/crtobj.o"], - }, - arm: { - srcs: ["arm/lib/crtobj.o"], - }, - }, -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - native_objects: ["mysdk_crtobj@current"], -} `), checkAllCopyRules(` .intermediates/crtobj/android_arm64_armv8-a/crtobj.o -> arm64/lib/crtobj.o @@ -403,7 +330,7 @@ func TestSnapshotWithCcExportGeneratedHeaders(t *testing.T) { errorHandler := android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module source path "snapshot/include_gen/generated_foo/gen/protos" does not exist`) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library_shared { @@ -476,7 +403,7 @@ func TestSnapshotWithCcSharedLibraryCommonProperties(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library_shared { @@ -535,7 +462,7 @@ func TestSnapshotWithCcBinary(t *testing.T) { `) CheckSnapshot(t, result, "mymodule_exports", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_binary { @@ -553,33 +480,6 @@ cc_prebuilt_binary { }, }, } -`), - // Make sure that the generated sdk_snapshot uses the native_binaries property. - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -cc_prebuilt_binary { - name: "mymodule_exports_mynativebinary@current", - sdk_member_name: "mynativebinary", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - installable: false, - compile_multilib: "both", - arch: { - arm64: { - srcs: ["arm64/bin/mynativebinary"], - }, - arm: { - srcs: ["arm/bin/mynativebinary"], - }, - }, -} - -module_exports_snapshot { - name: "mymodule_exports@current", - visibility: ["//visibility:public"], - native_binaries: ["mymodule_exports_mynativebinary@current"], -} `), checkAllCopyRules(` .intermediates/mynativebinary/android_arm64_armv8-a/mynativebinary -> arm64/bin/mynativebinary @@ -620,7 +520,7 @@ func TestMultipleHostOsTypesSnapshotWithCcBinary(t *testing.T) { `) CheckSnapshot(t, result, "myexports", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_binary { @@ -655,68 +555,6 @@ cc_prebuilt_binary { }, }, } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -cc_prebuilt_binary { - name: "myexports_mynativebinary@current", - sdk_member_name: "mynativebinary", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - device_supported: false, - host_supported: true, - installable: false, - stl: "none", - target: { - host: { - enabled: false, - }, - linux_glibc: { - compile_multilib: "both", - }, - linux_glibc_x86_64: { - enabled: true, - srcs: ["linux_glibc/x86_64/bin/mynativebinary"], - }, - linux_glibc_x86: { - enabled: true, - srcs: ["linux_glibc/x86/bin/mynativebinary"], - }, - windows: { - compile_multilib: "64", - }, - windows_x86_64: { - enabled: true, - srcs: ["windows/x86_64/bin/mynativebinary.exe"], - }, - }, -} - -module_exports_snapshot { - name: "myexports@current", - visibility: ["//visibility:public"], - device_supported: false, - host_supported: true, - native_binaries: ["myexports_mynativebinary@current"], - target: { - windows: { - compile_multilib: "64", - }, - host: { - enabled: false, - }, - linux_glibc_x86_64: { - enabled: true, - }, - linux_glibc_x86: { - enabled: true, - }, - windows_x86_64: { - enabled: true, - }, - }, -} `), checkAllCopyRules(` .intermediates/mynativebinary/linux_glibc_x86_64/mynativebinary -> linux_glibc/x86_64/bin/mynativebinary @@ -780,7 +618,7 @@ func TestSnapshotWithSingleHostOsType(t *testing.T) { `) CheckSnapshot(t, result, "myexports", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_binary { @@ -822,69 +660,6 @@ cc_prebuilt_library_shared { }, }, } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -cc_prebuilt_binary { - name: "myexports_mynativebinary@current", - sdk_member_name: "mynativebinary", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - device_supported: false, - host_supported: true, - installable: false, - stl: "none", - compile_multilib: "64", - target: { - host: { - enabled: false, - }, - linux_bionic_x86_64: { - enabled: true, - srcs: ["x86_64/bin/mynativebinary"], - }, - }, -} - -cc_prebuilt_library_shared { - name: "myexports_mynativelib@current", - sdk_member_name: "mynativelib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - device_supported: false, - host_supported: true, - installable: false, - stl: "none", - compile_multilib: "64", - target: { - host: { - enabled: false, - }, - linux_bionic_x86_64: { - enabled: true, - srcs: ["x86_64/lib/mynativelib.so"], - }, - }, -} - -module_exports_snapshot { - name: "myexports@current", - visibility: ["//visibility:public"], - device_supported: false, - host_supported: true, - compile_multilib: "64", - native_binaries: ["myexports_mynativebinary@current"], - native_shared_libs: ["myexports_mynativelib@current"], - target: { - host: { - enabled: false, - }, - linux_bionic_x86_64: { - enabled: true, - }, - }, -} `), checkAllCopyRules(` .intermediates/mynativebinary/linux_bionic_x86_64/mynativebinary -> x86_64/bin/mynativebinary @@ -918,7 +693,7 @@ func TestSnapshotWithCcStaticNocrtBinary(t *testing.T) { `) CheckSnapshot(t, result, "mymodule_exports", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_binary { @@ -946,55 +721,6 @@ cc_prebuilt_binary { }, }, } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -cc_prebuilt_binary { - name: "mymodule_exports_linker@current", - sdk_member_name: "linker", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - device_supported: false, - host_supported: true, - installable: false, - stl: "none", - compile_multilib: "both", - static_executable: true, - nocrt: true, - target: { - host: { - enabled: false, - }, - linux_glibc_x86_64: { - enabled: true, - srcs: ["x86_64/bin/linker"], - }, - linux_glibc_x86: { - enabled: true, - srcs: ["x86/bin/linker"], - }, - }, -} - -module_exports_snapshot { - name: "mymodule_exports@current", - visibility: ["//visibility:public"], - device_supported: false, - host_supported: true, - native_binaries: ["mymodule_exports_linker@current"], - target: { - host: { - enabled: false, - }, - linux_glibc_x86_64: { - enabled: true, - }, - linux_glibc_x86: { - enabled: true, - }, - }, -} `), checkAllCopyRules(` .intermediates/linker/linux_glibc_x86_64/linker -> x86_64/bin/linker @@ -1026,7 +752,7 @@ func TestSnapshotWithCcSharedLibrary(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library_shared { @@ -1127,7 +853,7 @@ func TestSnapshotWithCcSharedLibrarySharedLibs(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library_shared { @@ -1224,7 +950,7 @@ func TestHostSnapshotWithCcSharedLibrary(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library_shared { @@ -1254,57 +980,6 @@ cc_prebuilt_library_shared { }, }, } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -cc_prebuilt_library_shared { - name: "mysdk_mynativelib@current", - sdk_member_name: "mynativelib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - device_supported: false, - host_supported: true, - installable: false, - sdk_version: "minimum", - stl: "none", - compile_multilib: "both", - export_include_dirs: ["include/myinclude"], - target: { - host: { - enabled: false, - }, - linux_glibc_x86_64: { - enabled: true, - srcs: ["x86_64/lib/mynativelib.so"], - export_include_dirs: ["x86_64/include_gen/mynativelib/linux_glibc_x86_64_shared/gen/aidl"], - }, - linux_glibc_x86: { - enabled: true, - srcs: ["x86/lib/mynativelib.so"], - export_include_dirs: ["x86/include_gen/mynativelib/linux_glibc_x86_shared/gen/aidl"], - }, - }, -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - device_supported: false, - host_supported: true, - native_shared_libs: ["mysdk_mynativelib@current"], - target: { - host: { - enabled: false, - }, - linux_glibc_x86_64: { - enabled: true, - }, - linux_glibc_x86: { - enabled: true, - }, - }, -} `), checkAllCopyRules(` myinclude/Test.h -> include/myinclude/Test.h @@ -1351,7 +1026,7 @@ func TestMultipleHostOsTypesSnapshotWithCcSharedLibrary(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library_shared { @@ -1386,68 +1061,6 @@ cc_prebuilt_library_shared { }, }, } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -cc_prebuilt_library_shared { - name: "mysdk_mynativelib@current", - sdk_member_name: "mynativelib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - device_supported: false, - host_supported: true, - installable: false, - stl: "none", - target: { - host: { - enabled: false, - }, - linux_glibc: { - compile_multilib: "both", - }, - linux_glibc_x86_64: { - enabled: true, - srcs: ["linux_glibc/x86_64/lib/mynativelib.so"], - }, - linux_glibc_x86: { - enabled: true, - srcs: ["linux_glibc/x86/lib/mynativelib.so"], - }, - windows: { - compile_multilib: "64", - }, - windows_x86_64: { - enabled: true, - srcs: ["windows/x86_64/lib/mynativelib.dll"], - }, - }, -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - device_supported: false, - host_supported: true, - native_shared_libs: ["mysdk_mynativelib@current"], - target: { - windows: { - compile_multilib: "64", - }, - host: { - enabled: false, - }, - linux_glibc_x86_64: { - enabled: true, - }, - linux_glibc_x86: { - enabled: true, - }, - windows_x86_64: { - enabled: true, - }, - }, -} `), checkAllCopyRules(` .intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> linux_glibc/x86_64/lib/mynativelib.so @@ -1479,7 +1092,7 @@ func TestSnapshotWithCcStaticLibrary(t *testing.T) { `) CheckSnapshot(t, result, "myexports", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library_static { @@ -1542,7 +1155,7 @@ func TestHostSnapshotWithCcStaticLibrary(t *testing.T) { `) CheckSnapshot(t, result, "myexports", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library_static { @@ -1571,56 +1184,6 @@ cc_prebuilt_library_static { }, }, } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -cc_prebuilt_library_static { - name: "myexports_mynativelib@current", - sdk_member_name: "mynativelib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - device_supported: false, - host_supported: true, - installable: false, - stl: "none", - compile_multilib: "both", - export_include_dirs: ["include/myinclude"], - target: { - host: { - enabled: false, - }, - linux_glibc_x86_64: { - enabled: true, - srcs: ["x86_64/lib/mynativelib.a"], - export_include_dirs: ["x86_64/include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl"], - }, - linux_glibc_x86: { - enabled: true, - srcs: ["x86/lib/mynativelib.a"], - export_include_dirs: ["x86/include_gen/mynativelib/linux_glibc_x86_static/gen/aidl"], - }, - }, -} - -module_exports_snapshot { - name: "myexports@current", - visibility: ["//visibility:public"], - device_supported: false, - host_supported: true, - native_static_libs: ["myexports_mynativelib@current"], - target: { - host: { - enabled: false, - }, - linux_glibc_x86_64: { - enabled: true, - }, - linux_glibc_x86: { - enabled: true, - }, - }, -} `), checkAllCopyRules(` myinclude/Test.h -> include/myinclude/Test.h @@ -1656,7 +1219,7 @@ func TestSnapshotWithCcLibrary(t *testing.T) { `) CheckSnapshot(t, result, "myexports", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library { @@ -1687,46 +1250,6 @@ cc_prebuilt_library { }, }, } -`), - // Make sure that the generated sdk_snapshot uses the native_libs property. - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -cc_prebuilt_library { - name: "myexports_mynativelib@current", - sdk_member_name: "mynativelib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - installable: false, - vendor_available: true, - stl: "none", - compile_multilib: "both", - export_include_dirs: ["include/myinclude"], - arch: { - arm64: { - static: { - srcs: ["arm64/lib/mynativelib.a"], - }, - shared: { - srcs: ["arm64/lib/mynativelib.so"], - }, - }, - arm: { - static: { - srcs: ["arm/lib/mynativelib.a"], - }, - shared: { - srcs: ["arm/lib/mynativelib.so"], - }, - }, - }, -} - -module_exports_snapshot { - name: "myexports@current", - visibility: ["//visibility:public"], - native_libs: ["myexports_mynativelib@current"], -} `), checkAllCopyRules(` myinclude/Test.h -> include/myinclude/Test.h @@ -1772,7 +1295,7 @@ func TestSnapshotSameLibraryWithNativeLibsAndNativeSharedLib(t *testing.T) { `) CheckSnapshot(t, result, "myexports", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library { @@ -1868,7 +1391,7 @@ func TestSnapshotSameLibraryWithAndroidNativeLibsAndHostNativeSharedLib(t *testi `) CheckSnapshot(t, result, "myexports", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library { @@ -1994,7 +1517,7 @@ func TestHostSnapshotWithMultiLib64(t *testing.T) { `) CheckSnapshot(t, result, "myexports", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library_static { @@ -2020,51 +1543,6 @@ cc_prebuilt_library_static { }, }, } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -cc_prebuilt_library_static { - name: "myexports_mynativelib@current", - sdk_member_name: "mynativelib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - device_supported: false, - host_supported: true, - installable: false, - stl: "none", - compile_multilib: "64", - export_include_dirs: [ - "include/myinclude", - "include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl", - ], - target: { - host: { - enabled: false, - }, - linux_glibc_x86_64: { - enabled: true, - srcs: ["x86_64/lib/mynativelib.a"], - }, - }, -} - -module_exports_snapshot { - name: "myexports@current", - visibility: ["//visibility:public"], - device_supported: false, - host_supported: true, - compile_multilib: "64", - native_static_libs: ["myexports_mynativelib@current"], - target: { - host: { - enabled: false, - }, - linux_glibc_x86_64: { - enabled: true, - }, - }, -} `), checkAllCopyRules(` myinclude/Test.h -> include/myinclude/Test.h @@ -2091,7 +1569,7 @@ func TestSnapshotWithCcHeadersLibrary(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library_headers { @@ -2135,7 +1613,7 @@ func TestSnapshotWithCcHeadersLibraryAndNativeBridgeSupport(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library_headers { @@ -2220,7 +1698,7 @@ func TestSnapshotWithCcHeadersLibraryAndImageVariants(t *testing.T) { `, trait, property)) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(fmt.Sprintf(` + checkAndroidBpContents(fmt.Sprintf(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library_headers { @@ -2269,7 +1747,7 @@ func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library_headers { @@ -2294,51 +1772,6 @@ cc_prebuilt_library_headers { }, }, } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -cc_prebuilt_library_headers { - name: "mysdk_mynativeheaders@current", - sdk_member_name: "mynativeheaders", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - device_supported: false, - host_supported: true, - stl: "none", - compile_multilib: "both", - export_include_dirs: ["include/myinclude"], - target: { - host: { - enabled: false, - }, - linux_glibc_x86_64: { - enabled: true, - }, - linux_glibc_x86: { - enabled: true, - }, - }, -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - device_supported: false, - host_supported: true, - native_header_libs: ["mysdk_mynativeheaders@current"], - target: { - host: { - enabled: false, - }, - linux_glibc_x86_64: { - enabled: true, - }, - linux_glibc_x86: { - enabled: true, - }, - }, -} `), checkAllCopyRules(` myinclude/Test.h -> include/myinclude/Test.h @@ -2371,7 +1804,7 @@ func TestDeviceAndHostSnapshotWithCcHeadersLibrary(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library_headers { @@ -2401,55 +1834,6 @@ cc_prebuilt_library_headers { }, }, } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -cc_prebuilt_library_headers { - name: "mysdk_mynativeheaders@current", - sdk_member_name: "mynativeheaders", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - host_supported: true, - stl: "none", - compile_multilib: "both", - export_system_include_dirs: ["common_os/include/myinclude"], - target: { - host: { - enabled: false, - }, - android: { - export_include_dirs: ["android/include/myinclude-android"], - }, - linux_glibc: { - export_include_dirs: ["linux_glibc/include/myinclude-host"], - }, - linux_glibc_x86_64: { - enabled: true, - }, - linux_glibc_x86: { - enabled: true, - }, - }, -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - host_supported: true, - native_header_libs: ["mysdk_mynativeheaders@current"], - target: { - host: { - enabled: false, - }, - linux_glibc_x86_64: { - enabled: true, - }, - linux_glibc_x86: { - enabled: true, - }, - }, -} `), checkAllCopyRules(` myinclude/Test.h -> common_os/include/myinclude/Test.h @@ -2483,7 +1867,7 @@ func TestSystemSharedLibPropagation(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library_shared { @@ -2556,7 +1940,7 @@ cc_prebuilt_library_shared { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library_shared { @@ -2590,59 +1974,7 @@ cc_prebuilt_library_shared { }, } `), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -cc_prebuilt_library_shared { - name: "mysdk_sslvariants@current", - sdk_member_name: "sslvariants", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - host_supported: true, - installable: false, - compile_multilib: "both", - target: { - host: { - enabled: false, - }, - android: { - system_shared_libs: [], - }, - android_arm64: { - srcs: ["android/arm64/lib/sslvariants.so"], - }, - android_arm: { - srcs: ["android/arm/lib/sslvariants.so"], - }, - linux_glibc_x86_64: { - enabled: true, - srcs: ["linux_glibc/x86_64/lib/sslvariants.so"], - }, - linux_glibc_x86: { - enabled: true, - srcs: ["linux_glibc/x86/lib/sslvariants.so"], - }, - }, -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - host_supported: true, - native_shared_libs: ["mysdk_sslvariants@current"], - target: { - host: { - enabled: false, - }, - linux_glibc_x86_64: { - enabled: true, - }, - linux_glibc_x86: { - enabled: true, - }, - }, -} -`)) + ) } func TestStubsLibrary(t *testing.T) { @@ -2667,7 +1999,7 @@ func TestStubsLibrary(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library_shared { @@ -2721,7 +2053,7 @@ func TestDeviceAndHostSnapshotWithStubsLibrary(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library_shared { @@ -2760,64 +2092,7 @@ cc_prebuilt_library_shared { }, } `), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -cc_prebuilt_library_shared { - name: "mysdk_stubslib@current", - sdk_member_name: "stubslib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - host_supported: true, - installable: false, - compile_multilib: "both", - stubs: { - versions: [ - "1", - "2", - "3", - "current", - ], - }, - target: { - host: { - enabled: false, - }, - android_arm64: { - srcs: ["android/arm64/lib/stubslib.so"], - }, - android_arm: { - srcs: ["android/arm/lib/stubslib.so"], - }, - linux_glibc_x86_64: { - enabled: true, - srcs: ["linux_glibc/x86_64/lib/stubslib.so"], - }, - linux_glibc_x86: { - enabled: true, - srcs: ["linux_glibc/x86/lib/stubslib.so"], - }, - }, -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - host_supported: true, - native_shared_libs: ["mysdk_stubslib@current"], - target: { - host: { - enabled: false, - }, - linux_glibc_x86_64: { - enabled: true, - }, - linux_glibc_x86: { - enabled: true, - }, - }, -} -`)) + ) } func TestUniqueHostSoname(t *testing.T) { @@ -2836,7 +2111,7 @@ func TestUniqueHostSoname(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library_shared { @@ -2867,57 +2142,6 @@ cc_prebuilt_library_shared { }, }, } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -cc_prebuilt_library_shared { - name: "mysdk_mylib@current", - sdk_member_name: "mylib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - host_supported: true, - installable: false, - unique_host_soname: true, - compile_multilib: "both", - target: { - host: { - enabled: false, - }, - android_arm64: { - srcs: ["android/arm64/lib/mylib.so"], - }, - android_arm: { - srcs: ["android/arm/lib/mylib.so"], - }, - linux_glibc_x86_64: { - enabled: true, - srcs: ["linux_glibc/x86_64/lib/mylib-host.so"], - }, - linux_glibc_x86: { - enabled: true, - srcs: ["linux_glibc/x86/lib/mylib-host.so"], - }, - }, -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - host_supported: true, - native_shared_libs: ["mysdk_mylib@current"], - target: { - host: { - enabled: false, - }, - linux_glibc_x86_64: { - enabled: true, - }, - linux_glibc_x86: { - enabled: true, - }, - }, -} `), checkAllCopyRules(` .intermediates/mylib/android_arm64_armv8-a_shared/mylib.so -> android/arm64/lib/mylib.so @@ -2951,7 +2175,7 @@ func TestNoSanitizerMembers(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. cc_prebuilt_library_shared { diff --git a/sdk/compat_config_sdk_test.go b/sdk/compat_config_sdk_test.go index 00073c29d..d166add00 100644 --- a/sdk/compat_config_sdk_test.go +++ b/sdk/compat_config_sdk_test.go @@ -37,23 +37,7 @@ func TestSnapshotWithCompatConfig(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -prebuilt_platform_compat_config { - name: "mysdk_myconfig@current", - sdk_member_name: "myconfig", - visibility: ["//visibility:public"], - metadata: "compat_configs/myconfig/myconfig_meta.xml", -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - compat_configs: ["mysdk_myconfig@current"], -} -`), - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. prebuilt_platform_compat_config { diff --git a/sdk/exports.go b/sdk/exports.go index 9a0ba4e32..7645d3fa1 100644 --- a/sdk/exports.go +++ b/sdk/exports.go @@ -31,7 +31,7 @@ func ModuleExportsFactory() android.Module { return newSdkModule(true) } -// module_exports_snapshot is a versioned snapshot of prebuilt versions of all the exports +// module_exports_snapshot is a snapshot of prebuilt versions of all the exports // of a mainline module. func ModuleExportsSnapshotsFactory() android.Module { s := newSdkModule(true) diff --git a/sdk/exports_test.go b/sdk/exports_test.go index 17ddf1772..2605fd141 100644 --- a/sdk/exports_test.go +++ b/sdk/exports_test.go @@ -43,7 +43,7 @@ func TestModuleExportsSnapshot(t *testing.T) { }) CheckSnapshot(t, result, "myexports", "package", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_import { @@ -53,23 +53,6 @@ java_import { apex_available: ["//apex_available:platform"], jars: ["java/myjavalib.jar"], } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_import { - name: "myexports_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - jars: ["java/myjavalib.jar"], -} - -module_exports_snapshot { - name: "myexports@current", - visibility: ["//visibility:public"], - java_libs: ["myexports_myjavalib@current"], -} `), ) } diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go index f33aa268e..d25138f5b 100644 --- a/sdk/java_sdk_test.go +++ b/sdk/java_sdk_test.go @@ -96,7 +96,7 @@ func TestSnapshotWithJavaHeaderLibrary(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_import { @@ -107,24 +107,6 @@ java_import { jars: ["java/myjavalib.jar"], permitted_packages: ["pkg.myjavalib"], } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_import { - name: "mysdk_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - jars: ["java/myjavalib.jar"], - permitted_packages: ["pkg.myjavalib"], -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - java_header_libs: ["mysdk_myjavalib@current"], -} `), checkAllCopyRules(` .intermediates/myjavalib/android_common/turbine-combined/myjavalib.jar -> java/myjavalib.jar @@ -160,7 +142,7 @@ func TestHostSnapshotWithJavaHeaderLibrary(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_import { @@ -172,27 +154,6 @@ java_import { host_supported: true, jars: ["java/myjavalib.jar"], } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_import { - name: "mysdk_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - device_supported: false, - host_supported: true, - jars: ["java/myjavalib.jar"], -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - device_supported: false, - host_supported: true, - java_header_libs: ["mysdk_myjavalib@current"], -} `), checkAllCopyRules(` .intermediates/myjavalib/linux_glibc_common/javac/myjavalib.jar -> java/myjavalib.jar @@ -220,7 +181,7 @@ func TestDeviceAndHostSnapshotWithJavaHeaderLibrary(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_import { @@ -238,32 +199,6 @@ java_import { }, }, } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_import { - name: "mysdk_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - host_supported: true, - target: { - android: { - jars: ["java/android/myjavalib.jar"], - }, - linux_glibc: { - jars: ["java/linux_glibc/myjavalib.jar"], - }, - }, -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - host_supported: true, - java_header_libs: ["mysdk_myjavalib@current"], -} `), checkAllCopyRules(` .intermediates/myjavalib/android_common/turbine-combined/myjavalib.jar -> java/android/myjavalib.jar @@ -298,7 +233,7 @@ func TestSnapshotWithJavaImplLibrary(t *testing.T) { `) CheckSnapshot(t, result, "myexports", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_import { @@ -308,23 +243,6 @@ java_import { apex_available: ["//apex_available:platform"], jars: ["java/myjavalib.jar"], } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_import { - name: "myexports_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - jars: ["java/myjavalib.jar"], -} - -module_exports_snapshot { - name: "myexports@current", - visibility: ["//visibility:public"], - java_libs: ["myexports_myjavalib@current"], -} `), checkAllCopyRules(` .intermediates/myjavalib/android_common/withres/myjavalib.jar -> java/myjavalib.jar @@ -361,7 +279,7 @@ func TestSnapshotWithJavaBootLibrary(t *testing.T) { `) CheckSnapshot(t, result, "myexports", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_import { @@ -372,25 +290,6 @@ java_import { jars: ["java_boot_libs/snapshot/jars/are/invalid/myjavalib.jar"], permitted_packages: ["pkg.myjavalib"], } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_import { - name: "myexports_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - jars: ["java_boot_libs/snapshot/jars/are/invalid/myjavalib.jar"], - permitted_packages: ["pkg.myjavalib"], -} - -module_exports_snapshot { - name: "myexports@current", - visibility: ["//visibility:public"], - java_boot_libs: ["myexports_myjavalib@current"], -} - `), checkAllCopyRules(` .intermediates/myexports/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/myjavalib.jar @@ -427,7 +326,7 @@ func TestSnapshotWithJavaSystemserverLibrary(t *testing.T) { `) CheckSnapshot(t, result, "myexports", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_import { @@ -438,24 +337,6 @@ java_import { jars: ["java_systemserver_libs/snapshot/jars/are/invalid/myjavalib.jar"], permitted_packages: ["pkg.myjavalib"], } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_import { - name: "myexports_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - jars: ["java_systemserver_libs/snapshot/jars/are/invalid/myjavalib.jar"], - permitted_packages: ["pkg.myjavalib"], -} - -module_exports_snapshot { - name: "myexports@current", - visibility: ["//visibility:public"], - java_systemserver_libs: ["myexports_myjavalib@current"], -} `), checkAllCopyRules(` .intermediates/myexports/common_os/empty -> java_systemserver_libs/snapshot/jars/are/invalid/myjavalib.jar @@ -490,7 +371,7 @@ func TestHostSnapshotWithJavaImplLibrary(t *testing.T) { `) CheckSnapshot(t, result, "myexports", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_import { @@ -502,27 +383,6 @@ java_import { host_supported: true, jars: ["java/myjavalib.jar"], } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_import { - name: "myexports_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - device_supported: false, - host_supported: true, - jars: ["java/myjavalib.jar"], -} - -module_exports_snapshot { - name: "myexports@current", - visibility: ["//visibility:public"], - device_supported: false, - host_supported: true, - java_libs: ["myexports_myjavalib@current"], -} `), checkAllCopyRules(` .intermediates/myjavalib/linux_glibc_common/javac/myjavalib.jar -> java/myjavalib.jar @@ -549,7 +409,7 @@ func TestSnapshotWithJavaTest(t *testing.T) { `) CheckSnapshot(t, result, "myexports", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_test_import { @@ -560,24 +420,6 @@ java_test_import { jars: ["java/myjavatests.jar"], test_config: "java/myjavatests-AndroidTest.xml", } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_test_import { - name: "myexports_myjavatests@current", - sdk_member_name: "myjavatests", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - jars: ["java/myjavatests.jar"], - test_config: "java/myjavatests-AndroidTest.xml", -} - -module_exports_snapshot { - name: "myexports@current", - visibility: ["//visibility:public"], - java_tests: ["myexports_myjavatests@current"], -} `), checkAllCopyRules(` .intermediates/myjavatests/android_common/javac/myjavatests.jar -> java/myjavatests.jar @@ -607,7 +449,7 @@ func TestHostSnapshotWithJavaTest(t *testing.T) { `) CheckSnapshot(t, result, "myexports", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_test_import { @@ -620,28 +462,6 @@ java_test_import { jars: ["java/myjavatests.jar"], test_config: "java/myjavatests-AndroidTest.xml", } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_test_import { - name: "myexports_myjavatests@current", - sdk_member_name: "myjavatests", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - device_supported: false, - host_supported: true, - jars: ["java/myjavatests.jar"], - test_config: "java/myjavatests-AndroidTest.xml", -} - -module_exports_snapshot { - name: "myexports@current", - visibility: ["//visibility:public"], - device_supported: false, - host_supported: true, - java_tests: ["myexports_myjavatests@current"], -} `), checkAllCopyRules(` .intermediates/myjavatests/linux_glibc_common/javac/myjavatests.jar -> java/myjavatests.jar @@ -703,7 +523,7 @@ func TestSnapshotWithJavaSystemModules(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_import { @@ -747,59 +567,6 @@ java_system_modules_import { "myjavalib.stubs", ], } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_import { - name: "mysdk_exported-system-module@current", - sdk_member_name: "exported-system-module", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - jars: ["java/exported-system-module.jar"], -} - -java_import { - name: "mysdk_system-module@current", - sdk_member_name: "system-module", - visibility: ["//visibility:private"], - apex_available: ["//apex_available:platform"], - jars: ["java/system-module.jar"], -} - -java_sdk_library_import { - name: "mysdk_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:anyapex"], - shared_library: false, - public: { - jars: ["sdk_library/public/myjavalib-stubs.jar"], - stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], - current_api: "sdk_library/public/myjavalib.txt", - removed_api: "sdk_library/public/myjavalib-removed.txt", - sdk_version: "current", - }, -} - -java_system_modules_import { - name: "mysdk_my-system-modules@current", - sdk_member_name: "my-system-modules", - visibility: ["//visibility:public"], - libs: [ - "mysdk_system-module@current", - "mysdk_exported-system-module@current", - "mysdk_myjavalib.stubs@current", - ], -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - java_header_libs: ["mysdk_exported-system-module@current"], - java_sdk_libs: ["mysdk_myjavalib@current"], - java_system_modules: ["mysdk_my-system-modules@current"], -} `), checkAllCopyRules(` .intermediates/exported-system-module/android_common/turbine-combined/exported-system-module.jar -> java/exported-system-module.jar @@ -885,7 +652,7 @@ func TestHostSnapshotWithJavaSystemModules(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_import { @@ -906,36 +673,6 @@ java_system_modules_import { host_supported: true, libs: ["mysdk_system-module"], } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_import { - name: "mysdk_system-module@current", - sdk_member_name: "system-module", - visibility: ["//visibility:private"], - apex_available: ["//apex_available:platform"], - device_supported: false, - host_supported: true, - jars: ["java/system-module.jar"], -} - -java_system_modules_import { - name: "mysdk_my-system-modules@current", - sdk_member_name: "my-system-modules", - visibility: ["//visibility:public"], - device_supported: false, - host_supported: true, - libs: ["mysdk_system-module@current"], -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - device_supported: false, - host_supported: true, - java_system_modules: ["mysdk_my-system-modules@current"], -} `), checkAllCopyRules(".intermediates/system-module/linux_glibc_common/javac/system-module.jar -> java/system-module.jar"), ) @@ -979,7 +716,7 @@ func TestDeviceAndHostSnapshotWithOsSpecificMembers(t *testing.T) { `) CheckSnapshot(t, result, "myexports", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_import { @@ -1015,58 +752,6 @@ java_import { }, }, } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_import { - name: "myexports_hostjavalib@current", - sdk_member_name: "hostjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - device_supported: false, - host_supported: true, - jars: ["java/hostjavalib.jar"], -} - -java_import { - name: "myexports_androidjavalib@current", - sdk_member_name: "androidjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - jars: ["java/androidjavalib.jar"], -} - -java_import { - name: "myexports_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - host_supported: true, - target: { - android: { - jars: ["java/android/myjavalib.jar"], - }, - linux_glibc: { - jars: ["java/linux_glibc/myjavalib.jar"], - }, - }, -} - -module_exports_snapshot { - name: "myexports@current", - visibility: ["//visibility:public"], - host_supported: true, - java_libs: ["myexports_myjavalib@current"], - target: { - android: { - java_header_libs: ["myexports_androidjavalib@current"], - }, - linux_glibc: { - java_header_libs: ["myexports_hostjavalib@current"], - }, - }, -} `), checkAllCopyRules(` .intermediates/hostjavalib/linux_glibc_common/javac/hostjavalib.jar -> java/hostjavalib.jar @@ -1097,7 +782,7 @@ func TestSnapshotWithJavaSdkLibrary(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_sdk_library_import { @@ -1129,45 +814,6 @@ java_sdk_library_import { sdk_version: "test_current", }, } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_sdk_library_import { - name: "mysdk_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:anyapex"], - shared_library: false, - permitted_packages: ["pkg.myjavalib"], - public: { - jars: ["sdk_library/public/myjavalib-stubs.jar"], - stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], - current_api: "sdk_library/public/myjavalib.txt", - removed_api: "sdk_library/public/myjavalib-removed.txt", - sdk_version: "current", - }, - system: { - jars: ["sdk_library/system/myjavalib-stubs.jar"], - stub_srcs: ["sdk_library/system/myjavalib_stub_sources"], - current_api: "sdk_library/system/myjavalib.txt", - removed_api: "sdk_library/system/myjavalib-removed.txt", - sdk_version: "system_current", - }, - test: { - jars: ["sdk_library/test/myjavalib-stubs.jar"], - stub_srcs: ["sdk_library/test/myjavalib_stub_sources"], - current_api: "sdk_library/test/myjavalib.txt", - removed_api: "sdk_library/test/myjavalib-removed.txt", - sdk_version: "test_current", - }, -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - java_sdk_libs: ["mysdk_myjavalib@current"], -} `), checkAllCopyRules(` .intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar @@ -1185,12 +831,6 @@ sdk_snapshot { ".intermediates/mysdk/common_os/tmp/sdk_library/system/myjavalib_stub_sources.zip", ".intermediates/mysdk/common_os/tmp/sdk_library/test/myjavalib_stub_sources.zip", ), - snapshotTestChecker(checkSnapshotWithoutSource, func(t *testing.T, result *android.TestResult) { - // Make sure that the name of the child modules created by a versioned java_sdk_library_import - // module is correct, i.e. the suffix is added before the version and not after. - result.Module("mysdk_myjavalib.stubs@current", "android_common") - result.Module("mysdk_myjavalib.stubs.source@current", "android_common") - }), ) } @@ -1218,7 +858,7 @@ func TestSnapshotWithJavaSdkLibrary_UseSrcJar(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_sdk_library_import { @@ -1265,7 +905,7 @@ func TestSnapshotWithJavaSdkLibrary_AnnotationsZip(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_sdk_library_import { @@ -1319,7 +959,7 @@ func TestSnapshotWithJavaSdkLibrary_AnnotationsZip_PreT(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_sdk_library_import { @@ -1369,7 +1009,7 @@ func TestSnapshotWithJavaSdkLibrary_CompileDex(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_sdk_library_import { @@ -1436,7 +1076,7 @@ func TestSnapshotWithJavaSdkLibrary_SdkVersion_None(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_sdk_library_import { @@ -1453,30 +1093,6 @@ java_sdk_library_import { sdk_version: "none", }, } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_sdk_library_import { - name: "mysdk_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - shared_library: true, - public: { - jars: ["sdk_library/public/myjavalib-stubs.jar"], - stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], - current_api: "sdk_library/public/myjavalib.txt", - removed_api: "sdk_library/public/myjavalib-removed.txt", - sdk_version: "none", - }, -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - java_sdk_libs: ["mysdk_myjavalib@current"], -} `), checkAllCopyRules(` .intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar @@ -1508,7 +1124,7 @@ func TestSnapshotWithJavaSdkLibrary_SdkVersion_ForScope(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_sdk_library_import { @@ -1525,30 +1141,6 @@ java_sdk_library_import { sdk_version: "module_current", }, } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_sdk_library_import { - name: "mysdk_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - shared_library: true, - public: { - jars: ["sdk_library/public/myjavalib-stubs.jar"], - stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], - current_api: "sdk_library/public/myjavalib.txt", - removed_api: "sdk_library/public/myjavalib-removed.txt", - sdk_version: "module_current", - }, -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - java_sdk_libs: ["mysdk_myjavalib@current"], -} `), checkAllCopyRules(` .intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar @@ -1583,7 +1175,7 @@ func TestSnapshotWithJavaSdkLibrary_ApiScopes(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_sdk_library_import { @@ -1607,37 +1199,6 @@ java_sdk_library_import { sdk_version: "system_current", }, } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_sdk_library_import { - name: "mysdk_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:anyapex"], - shared_library: true, - public: { - jars: ["sdk_library/public/myjavalib-stubs.jar"], - stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], - current_api: "sdk_library/public/myjavalib.txt", - removed_api: "sdk_library/public/myjavalib-removed.txt", - sdk_version: "current", - }, - system: { - jars: ["sdk_library/system/myjavalib-stubs.jar"], - stub_srcs: ["sdk_library/system/myjavalib_stub_sources"], - current_api: "sdk_library/system/myjavalib.txt", - removed_api: "sdk_library/system/myjavalib-removed.txt", - sdk_version: "system_current", - }, -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - java_sdk_libs: ["mysdk_myjavalib@current"], -} `), checkAllCopyRules(` .intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar @@ -1679,7 +1240,7 @@ func TestSnapshotWithJavaSdkLibrary_ModuleLib(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_sdk_library_import { @@ -1710,44 +1271,6 @@ java_sdk_library_import { sdk_version: "module_current", }, } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_sdk_library_import { - name: "mysdk_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:anyapex"], - shared_library: true, - public: { - jars: ["sdk_library/public/myjavalib-stubs.jar"], - stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], - current_api: "sdk_library/public/myjavalib.txt", - removed_api: "sdk_library/public/myjavalib-removed.txt", - sdk_version: "current", - }, - system: { - jars: ["sdk_library/system/myjavalib-stubs.jar"], - stub_srcs: ["sdk_library/system/myjavalib_stub_sources"], - current_api: "sdk_library/system/myjavalib.txt", - removed_api: "sdk_library/system/myjavalib-removed.txt", - sdk_version: "system_current", - }, - module_lib: { - jars: ["sdk_library/module-lib/myjavalib-stubs.jar"], - stub_srcs: ["sdk_library/module-lib/myjavalib_stub_sources"], - current_api: "sdk_library/module-lib/myjavalib.txt", - removed_api: "sdk_library/module-lib/myjavalib-removed.txt", - sdk_version: "module_current", - }, -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - java_sdk_libs: ["mysdk_myjavalib@current"], -} `), checkAllCopyRules(` .intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar @@ -1790,7 +1313,7 @@ func TestSnapshotWithJavaSdkLibrary_SystemServer(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_sdk_library_import { @@ -1814,37 +1337,6 @@ java_sdk_library_import { sdk_version: "system_server_current", }, } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_sdk_library_import { - name: "mysdk_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:anyapex"], - shared_library: true, - public: { - jars: ["sdk_library/public/myjavalib-stubs.jar"], - stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], - current_api: "sdk_library/public/myjavalib.txt", - removed_api: "sdk_library/public/myjavalib-removed.txt", - sdk_version: "current", - }, - system_server: { - jars: ["sdk_library/system-server/myjavalib-stubs.jar"], - stub_srcs: ["sdk_library/system-server/myjavalib_stub_sources"], - current_api: "sdk_library/system-server/myjavalib.txt", - removed_api: "sdk_library/system-server/myjavalib-removed.txt", - sdk_version: "system_server_current", - }, -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - java_sdk_libs: ["mysdk_myjavalib@current"], -} `), checkAllCopyRules(` .intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar @@ -1881,7 +1373,7 @@ func TestSnapshotWithJavaSdkLibrary_NamingScheme(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_sdk_library_import { @@ -1899,31 +1391,6 @@ java_sdk_library_import { sdk_version: "current", }, } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_sdk_library_import { - name: "mysdk_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:anyapex"], - naming_scheme: "default", - shared_library: true, - public: { - jars: ["sdk_library/public/myjavalib-stubs.jar"], - stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], - current_api: "sdk_library/public/myjavalib.txt", - removed_api: "sdk_library/public/myjavalib-removed.txt", - sdk_version: "current", - }, -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - java_sdk_libs: ["mysdk_myjavalib@current"], -} `), checkAllCopyRules(` .intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar @@ -1963,7 +1430,7 @@ func TestSnapshotWithJavaSdkLibrary_DoctagFiles(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_sdk_library_import { @@ -1981,31 +1448,6 @@ java_sdk_library_import { sdk_version: "current", }, } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_sdk_library_import { - name: "mysdk_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - shared_library: true, - doctag_files: ["doctags/docs/known_doctags"], - public: { - jars: ["sdk_library/public/myjavalib-stubs.jar"], - stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], - current_api: "sdk_library/public/myjavalib.txt", - removed_api: "sdk_library/public/myjavalib-removed.txt", - sdk_version: "current", - }, -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - java_sdk_libs: ["mysdk_myjavalib@current"], -} `), checkAllCopyRules(` .intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar diff --git a/sdk/license_sdk_test.go b/sdk/license_sdk_test.go index 1ef6fe684..829edf117 100644 --- a/sdk/license_sdk_test.go +++ b/sdk/license_sdk_test.go @@ -60,7 +60,7 @@ func TestSnapshotWithPackageDefaultLicense(t *testing.T) { `) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. package { @@ -89,44 +89,6 @@ license { "licenses/NOTICE1", "licenses/NOTICE2", ], -} - `), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -package { - // A default list here prevents the license LSC from adding its own list which would - // be unnecessary as every module in the sdk already has its own licenses property. - default_applicable_licenses: ["Android-Apache-2.0"], -} - -java_import { - name: "mysdk_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - licenses: ["mysdk_mylicense@current"], - jars: ["java/myjavalib.jar"], -} - -license { - name: "mysdk_mylicense@current", - sdk_member_name: "mylicense", - visibility: ["//visibility:private"], - license_kinds: [ - "SPDX-license-identifier-Apache-2.0", - "legacy_unencumbered", - ], - license_text: [ - "licenses/NOTICE1", - "licenses/NOTICE2", - ], -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - java_header_libs: ["mysdk_myjavalib@current"], } `), checkAllCopyRules(` diff --git a/sdk/member_trait_test.go b/sdk/member_trait_test.go index a3db189b2..99caf13e3 100644 --- a/sdk/member_trait_test.go +++ b/sdk/member_trait_test.go @@ -134,7 +134,7 @@ func TestBasicTrait_WithoutTrait(t *testing.T) { ).RunTest(t) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_import { @@ -144,23 +144,6 @@ java_import { apex_available: ["//apex_available:platform"], jars: ["javalibs/myjavalib.jar"], } -`), - checkVersionedAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_import { - name: "mysdk_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - jars: ["javalibs/myjavalib.jar"], -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - fake_members: ["mysdk_myjavalib@current"], -} `), ) } @@ -216,7 +199,7 @@ func TestBasicTrait_MultipleTraits(t *testing.T) { ).RunTest(t) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_test_import { diff --git a/sdk/sdk.go b/sdk/sdk.go index 468ed99ab..aeeedb428 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -146,7 +146,7 @@ func newSdkModule(moduleExports bool) *sdk { return s } -// sdk_snapshot is a versioned snapshot of an SDK. This is an auto-generated module. +// sdk_snapshot is a snapshot of an SDK. This is an auto-generated module. func SnapshotModuleFactory() android.Module { s := newSdkModule(false) s.properties.Snapshot = true @@ -292,38 +292,6 @@ func (t dependencyTag) ExcludeFromApexContents() {} var _ android.ExcludeFromApexContentsTag = dependencyTag{} -// For dependencies from an in-development version of an SDK member to frozen versions of the same member -// e.g. libfoo -> libfoo.mysdk.11 and libfoo.mysdk.12 -// -// The dependency represented by this tag requires that for every APEX variant created for the -// `from` module that an equivalent APEX variant is created for the 'to' module. This is because an -// APEX that requires a specific version of an sdk (via the `uses_sdks` property will replace -// dependencies on the unversioned sdk member with a dependency on the appropriate versioned sdk -// member. In order for that to work the versioned sdk member needs to have a variant for that APEX. -// As it is not known at the time that the APEX variants are created which specific APEX variants of -// a versioned sdk members will be required it is necessary for the versioned sdk members to have -// variants for any APEX that it could be used within. -// -// If the APEX selects a versioned sdk member then it will not have a dependency on the `from` -// module at all so any dependencies of that module will not affect the APEX. However, if the APEX -// selects the unversioned sdk member then it must exclude all the versioned sdk members. In no -// situation would this dependency cause the `to` module to be added to the APEX hence why this tag -// also excludes the `to` module from being added to the APEX contents. -type sdkMemberVersionedDepTag struct { - dependencyTag - member string - version string -} - -func (t sdkMemberVersionedDepTag) AlwaysRequireApexVariant() bool { - return true -} - -// Mark this tag so dependencies that use it are excluded from visibility enforcement. -func (t sdkMemberVersionedDepTag) ExcludeFromVisibilityEnforcement() {} - -var _ android.AlwaysRequireApexVariantTag = sdkMemberVersionedDepTag{} - // Step 1: create dependencies from an SDK module to its members. func memberMutator(mctx android.BottomUpMutatorContext) { if s, ok := mctx.Module().(*sdk); ok { diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go index ccbeb8d9a..e230d5c0b 100644 --- a/sdk/sdk_test.go +++ b/sdk/sdk_test.go @@ -118,18 +118,6 @@ func TestSnapshotVisibility(t *testing.T) { checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. -java_import { - name: "mysdk_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: [ - "//other/foo", - "//package", - "//prebuilts/mysdk", - ], - apex_available: ["//apex_available:platform"], - jars: ["java/myjavalib.jar"], -} - java_import { name: "myjavalib", prefer: false, @@ -142,14 +130,6 @@ java_import { jars: ["java/myjavalib.jar"], } -java_import { - name: "mysdk_mypublicjavalib@current", - sdk_member_name: "mypublicjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - jars: ["java/mypublicjavalib.jar"], -} - java_import { name: "mypublicjavalib", prefer: false, @@ -158,18 +138,6 @@ java_import { jars: ["java/mypublicjavalib.jar"], } -java_import { - name: "mysdk_mydefaultedjavalib@current", - sdk_member_name: "mydefaultedjavalib", - visibility: [ - "//other/bar", - "//package", - "//prebuilts/mysdk", - ], - apex_available: ["//apex_available:platform"], - jars: ["java/mydefaultedjavalib.jar"], -} - java_import { name: "mydefaultedjavalib", prefer: false, @@ -182,17 +150,6 @@ java_import { jars: ["java/mydefaultedjavalib.jar"], } -java_import { - name: "mysdk_myprivatejavalib@current", - sdk_member_name: "myprivatejavalib", - visibility: [ - "//package", - "//prebuilts/mysdk", - ], - apex_available: ["//apex_available:platform"], - jars: ["java/myprivatejavalib.jar"], -} - java_import { name: "myprivatejavalib", prefer: false, @@ -203,20 +160,6 @@ java_import { apex_available: ["//apex_available:platform"], jars: ["java/myprivatejavalib.jar"], } - -sdk_snapshot { - name: "mysdk@current", - visibility: [ - "//other/foo", - "//package:__subpackages__", - ], - java_header_libs: [ - "mysdk_myjavalib@current", - "mysdk_mypublicjavalib@current", - "mysdk_mydefaultedjavalib@current", - "mysdk_myprivatejavalib@current", - ], -} `)) } @@ -449,14 +392,6 @@ func TestSnapshot_EnvConfiguration(t *testing.T) { checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. -java_import { - name: "mysdk_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - jars: ["java/myjavalib.jar"], -} - java_import { name: "myjavalib", prefer: false, @@ -464,12 +399,6 @@ java_import { apex_available: ["//apex_available:platform"], jars: ["java/myjavalib.jar"], } - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - java_header_libs: ["mysdk_myjavalib@current"], -} `), ) }) @@ -488,14 +417,6 @@ sdk_snapshot { checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. -java_import { - name: "mysdk_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - jars: ["java/myjavalib.jar"], -} - java_import { name: "myjavalib", prefer: true, @@ -503,12 +424,6 @@ java_import { apex_available: ["//apex_available:platform"], jars: ["java/myjavalib.jar"], } - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - java_header_libs: ["mysdk_myjavalib@current"], -} `), ) }) @@ -527,14 +442,6 @@ sdk_snapshot { checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. -java_import { - name: "mysdk_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - jars: ["java/myjavalib.jar"], -} - java_import { name: "myjavalib", prefer: false, @@ -546,113 +453,10 @@ java_import { apex_available: ["//apex_available:platform"], jars: ["java/myjavalib.jar"], } - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - java_header_libs: ["mysdk_myjavalib@current"], -} `), ) }) - t.Run("SOONG_SDK_SNAPSHOT_VERSION=unversioned", func(t *testing.T) { - result := android.GroupFixturePreparers( - preparer, - android.FixtureMergeEnv(map[string]string{ - "SOONG_SDK_SNAPSHOT_VERSION": "unversioned", - }), - ).RunTest(t) - - checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk.zip") - - CheckSnapshot(t, result, "mysdk", "", - checkAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_import { - name: "myjavalib", - prefer: false, - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - jars: ["java/myjavalib.jar"], -} - `), - ) - }) - - t.Run("SOONG_SDK_SNAPSHOT_VERSION=current", func(t *testing.T) { - result := android.GroupFixturePreparers( - preparer, - android.FixtureMergeEnv(map[string]string{ - "SOONG_SDK_SNAPSHOT_VERSION": "current", - }), - ).RunTest(t) - - checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-current.zip") - - CheckSnapshot(t, result, "mysdk", "", - checkAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_import { - name: "mysdk_myjavalib@current", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - jars: ["java/myjavalib.jar"], -} - -java_import { - name: "myjavalib", - prefer: false, - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - jars: ["java/myjavalib.jar"], -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - java_header_libs: ["mysdk_myjavalib@current"], -} - `), - ) - }) - - t.Run("SOONG_SDK_SNAPSHOT_VERSION=2", func(t *testing.T) { - result := android.GroupFixturePreparers( - preparer, - android.FixtureMergeEnv(map[string]string{ - "SOONG_SDK_SNAPSHOT_VERSION": "2", - }), - ).RunTest(t) - - checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-2.zip") - - CheckSnapshot(t, result, "mysdk", "", - checkAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_import { - name: "mysdk_myjavalib@2", - sdk_member_name: "myjavalib", - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - jars: ["java/myjavalib.jar"], -} - -sdk_snapshot { - name: "mysdk@2", - visibility: ["//visibility:public"], - java_header_libs: ["mysdk_myjavalib@2"], -} - `), - // A versioned snapshot cannot be used on its own so add the source back in. - snapshotTestPreparer(checkSnapshotWithoutSource, android.FixtureWithRootAndroidBp(bp)), - ) - }) - t.Run("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE=S", func(t *testing.T) { result := android.GroupFixturePreparers( prepareForSdkTestWithJava, @@ -685,7 +489,7 @@ sdk_snapshot { ).RunTest(t) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. prebuilt_bootclasspath_fragment { diff --git a/sdk/systemserverclasspath_fragment_sdk_test.go b/sdk/systemserverclasspath_fragment_sdk_test.go index 819083d23..1c84a7bba 100644 --- a/sdk/systemserverclasspath_fragment_sdk_test.go +++ b/sdk/systemserverclasspath_fragment_sdk_test.go @@ -22,7 +22,7 @@ import ( "android/soong/java" ) -func testSnapshotWithSystemServerClasspathFragment(t *testing.T, targetBuildRelease string, expectedUnversionedSdkSnapshot string, expectedVersionedSdkSnapshot string) { +func testSnapshotWithSystemServerClasspathFragment(t *testing.T, targetBuildRelease string, expectedSdkSnapshot string) { result := android.GroupFixturePreparers( prepareForSdkTestWithJava, java.PrepareForTestWithJavaDefaultModules, @@ -86,8 +86,7 @@ func testSnapshotWithSystemServerClasspathFragment(t *testing.T, targetBuildRele ).RunTest(t) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(expectedUnversionedSdkSnapshot), - checkVersionedAndroidBpContents(expectedVersionedSdkSnapshot), + checkAndroidBpContents(expectedSdkSnapshot), ) } @@ -110,29 +109,6 @@ java_sdk_library_import { sdk_version: "current", }, } -`, ` -// This is auto-generated. DO NOT EDIT. - -java_sdk_library_import { - name: "mysdk_mysdklibrary@current", - sdk_member_name: "mysdklibrary", - visibility: ["//visibility:public"], - apex_available: ["myapex"], - shared_library: false, - public: { - jars: ["sdk_library/public/mysdklibrary-stubs.jar"], - stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], - current_api: "sdk_library/public/mysdklibrary.txt", - removed_api: "sdk_library/public/mysdklibrary-removed.txt", - sdk_version: "current", - }, -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - java_sdk_libs: ["mysdk_mysdklibrary@current"], -} `) }) @@ -174,51 +150,6 @@ prebuilt_systemserverclasspath_fragment { "mysdklibrary", ], } -`, ` -// This is auto-generated. DO NOT EDIT. - -java_sdk_library_import { - name: "mysdk_mysdklibrary@current", - sdk_member_name: "mysdklibrary", - visibility: ["//visibility:public"], - apex_available: ["myapex"], - shared_library: false, - public: { - jars: ["sdk_library/public/mysdklibrary-stubs.jar"], - stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], - current_api: "sdk_library/public/mysdklibrary.txt", - removed_api: "sdk_library/public/mysdklibrary-removed.txt", - sdk_version: "current", - }, -} - -java_import { - name: "mysdk_mylib@current", - sdk_member_name: "mylib", - visibility: ["//visibility:public"], - apex_available: ["myapex"], - jars: ["java_systemserver_libs/snapshot/jars/are/invalid/mylib.jar"], - permitted_packages: ["mylib"], -} - -prebuilt_systemserverclasspath_fragment { - name: "mysdk_mysystemserverclasspathfragment@current", - sdk_member_name: "mysystemserverclasspathfragment", - visibility: ["//visibility:public"], - apex_available: ["myapex"], - contents: [ - "mysdk_mylib@current", - "mysdk_mysdklibrary@current", - ], -} - -sdk_snapshot { - name: "mysdk@current", - visibility: ["//visibility:public"], - java_sdk_libs: ["mysdk_mysdklibrary@current"], - java_systemserver_libs: ["mysdk_mylib@current"], - systemserverclasspath_fragments: ["mysdk_mysystemserverclasspathfragment@current"], -} `) }) } diff --git a/sdk/testing.go b/sdk/testing.go index 72344de25..bed11b27d 100644 --- a/sdk/testing.go +++ b/sdk/testing.go @@ -122,29 +122,18 @@ func ensureListContains(t *testing.T, result []string, expected string) { } } -func pathsToStrings(paths android.Paths) []string { - var ret []string - for _, p := range paths { - ret = append(ret, p.String()) - } - return ret -} - // Analyse the sdk build rules to extract information about what it is doing. // // e.g. find the src/dest pairs from each cp command, the various zip files // generated, etc. func getSdkSnapshotBuildInfo(t *testing.T, result *android.TestResult, sdk *sdk) *snapshotBuildInfo { info := &snapshotBuildInfo{ - t: t, - r: result, - version: sdk.builderForTests.version, - androidBpContents: sdk.GetAndroidBpContentsForTests(), - androidUnversionedBpContents: sdk.GetUnversionedAndroidBpContentsForTests(), - androidVersionedBpContents: sdk.GetVersionedAndroidBpContentsForTests(), - infoContents: sdk.GetInfoContentsForTests(), - snapshotTestCustomizations: map[snapshotTest]*snapshotTestCustomization{}, - targetBuildRelease: sdk.builderForTests.targetBuildRelease, + t: t, + r: result, + androidBpContents: sdk.GetAndroidBpContentsForTests(), + infoContents: sdk.GetInfoContentsForTests(), + snapshotTestCustomizations: map[snapshotTest]*snapshotTestCustomization{}, + targetBuildRelease: sdk.builderForTests.targetBuildRelease, } buildParams := sdk.BuildParamsForTests() @@ -258,10 +247,7 @@ func CheckSnapshot(t *testing.T, result *android.TestResult, name string, dir st if dir != "" { dir = filepath.Clean(dir) + "/" } - suffix := "" - if snapshotBuildInfo.version != soongSdkSnapshotVersionUnversioned { - suffix = "-" + snapshotBuildInfo.version - } + suffix := "-" + soongSdkSnapshotVersionCurrent expectedZipPath := fmt.Sprintf(".intermediates/%s%s/%s/%s%s.zip", dir, name, variant, name, suffix) android.AssertStringEquals(t, "Snapshot zip file in wrong place", expectedZipPath, actual) @@ -345,33 +331,6 @@ func checkAndroidBpContents(expected string) snapshotBuildInfoChecker { } } -// Check that the snapshot's unversioned generated Android.bp is correct. -// -// This func should be used to check the general snapshot generation code. -// -// Both the expected and actual string are both trimmed before comparing. -func checkUnversionedAndroidBpContents(expected string) snapshotBuildInfoChecker { - return func(info *snapshotBuildInfo) { - info.t.Helper() - android.AssertTrimmedStringEquals(info.t, "unversioned Android.bp contents do not match", expected, info.androidUnversionedBpContents) - } -} - -// Check that the snapshot's versioned generated Android.bp is correct. -// -// This func should only be used to check the version specific snapshot generation code, -// i.e. the encoding of version into module names and the generation of the _snapshot module. The -// general snapshot generation code should be checked using the checkUnversionedAndroidBpContents() -// func. -// -// Both the expected and actual string are both trimmed before comparing. -func checkVersionedAndroidBpContents(expected string) snapshotBuildInfoChecker { - return func(info *snapshotBuildInfo) { - info.t.Helper() - android.AssertTrimmedStringEquals(info.t, "versioned Android.bp contents do not match", expected, info.androidVersionedBpContents) - } -} - // Check that the snapshot's copy rules are correct. // // The copy rules are formatted as -> , one per line and then compared @@ -477,20 +436,9 @@ type snapshotBuildInfo struct { // The result from RunTest() r *android.TestResult - // The version of the generated snapshot. - // - // See snapshotBuilder.version for more information about this field. - version string - // The contents of the generated Android.bp file androidBpContents string - // The contents of the unversioned Android.bp file - androidUnversionedBpContents string - - // The contents of the versioned Android.bp file - androidVersionedBpContents string - // The contents of the info file. infoContents string diff --git a/sdk/update.go b/sdk/update.go index 063597fad..8e4f9d4e2 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -35,7 +35,7 @@ import ( // ======================================================== // // SOONG_SDK_SNAPSHOT_PREFER -// By default every unversioned module in the generated snapshot has prefer: false. Building it +// By default every module in the generated snapshot has prefer: false. Building it // with SOONG_SDK_SNAPSHOT_PREFER=true will force them to use prefer: true. // // SOONG_SDK_SNAPSHOT_USE_SOURCE_CONFIG_VAR @@ -69,20 +69,6 @@ import ( // maintainable solution has been implemented. // TODO(b/174997203): Remove when no longer necessary. // -// SOONG_SDK_SNAPSHOT_VERSION -// This provides control over the version of the generated snapshot. -// -// SOONG_SDK_SNAPSHOT_VERSION=current will generate unversioned and versioned prebuilts and a -// versioned snapshot module. This is the default behavior. The zip file containing the -// generated snapshot will be -current.zip. -// -// SOONG_SDK_SNAPSHOT_VERSION=unversioned will generate unversioned prebuilts only and the zip -// file containing the generated snapshot will be .zip. -// -// SOONG_SDK_SNAPSHOT_VERSION= will generate versioned prebuilts and a versioned -// snapshot module only. The zip file containing the generated snapshot will be -// -.zip. -// // SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE // This allows the target build release (i.e. the release version of the build within which // the snapshot will be used) of the snapshot to be specified. If unspecified then it defaults @@ -130,8 +116,7 @@ var ( ) const ( - soongSdkSnapshotVersionUnversioned = "unversioned" - soongSdkSnapshotVersionCurrent = "current" + soongSdkSnapshotVersionCurrent = "current" ) type generatedContents struct { @@ -163,13 +148,13 @@ func (gc *generatedContents) Dedent() { // IndentedPrintf will add spaces to indent the line to the appropriate level before printing the // arguments. func (gc *generatedContents) IndentedPrintf(format string, args ...interface{}) { - fmt.Fprintf(&(gc.content), strings.Repeat(" ", gc.indentLevel)+format, args...) + _, _ = fmt.Fprintf(&(gc.content), strings.Repeat(" ", gc.indentLevel)+format, args...) } // UnindentedPrintf does not add spaces to indent the line to the appropriate level before printing // the arguments. func (gc *generatedContents) UnindentedPrintf(format string, args ...interface{}) { - fmt.Fprintf(&(gc.content), format, args...) + _, _ = fmt.Fprintf(&(gc.content), format, args...) } func (gf *generatedFile) build(pctx android.PackageContext, ctx android.BuilderContext, implicits android.Paths) { @@ -347,12 +332,6 @@ const BUILD_NUMBER_FILE = "snapshot-creation-build-number.txt" // /lib/ // libFoo.so : a stub library -// A name that uniquely identifies a prebuilt SDK member for a version of SDK snapshot -// This isn't visible to users, so could be changed in future. -func versionedSdkMemberName(ctx android.ModuleContext, memberName string, version string) string { - return ctx.ModuleName() + "_" + memberName + string(android.SdkVersionSeparator) + version -} - // buildSnapshot is the main function in this source file. It creates rules to copy // the contents (header files, stub libraries, etc) into the zip file. func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) { @@ -404,20 +383,9 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) { } config := ctx.Config() - version := config.GetenvWithDefault("SOONG_SDK_SNAPSHOT_VERSION", "current") - // Generate versioned modules in the snapshot unless an unversioned snapshot has been requested. - generateVersioned := version != soongSdkSnapshotVersionUnversioned - - // Generate unversioned modules in the snapshot unless a numbered snapshot has been requested. - // - // Unversioned modules are not required in that case because the numbered version will be a - // finalized version of the snapshot that is intended to be kept separate from the - generateUnversioned := version == soongSdkSnapshotVersionUnversioned || version == soongSdkSnapshotVersionCurrent - snapshotFileSuffix := "" - if generateVersioned { - snapshotFileSuffix = "-" + version - } + // Always add -current to the end + snapshotFileSuffix := "-current" currentBuildRelease := latestBuildRelease() targetBuildReleaseEnv := config.GetenvWithDefault("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE", currentBuildRelease.name) @@ -430,7 +398,6 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) { builder := &snapshotBuilder{ ctx: ctx, sdk: s, - version: version, snapshotDir: snapshotDir.OutputPath, copies: make(map[string]string), filesToZip: []android.Path{bp.path}, @@ -480,38 +447,19 @@ be unnecessary as every module in the sdk already has its own licenses property. s.createMemberSnapshot(memberCtx, member, prebuiltModule.(*bpModule)) } - // Create a transformer that will transform an unversioned module into a versioned module. - unversionedToVersionedTransformer := unversionedToVersionedTransformation{builder: builder} - - // Create a transformer that will transform an unversioned module by replacing any references + // Create a transformer that will transform a module by replacing any references // to internal members with a unique module name and setting prefer: false. - unversionedTransformer := unversionedTransformation{ + snapshotTransformer := snapshotTransformation{ builder: builder, } - for _, unversioned := range builder.prebuiltOrder { + for _, module := range builder.prebuiltOrder { // Prune any empty property sets. - unversioned = unversioned.transform(pruneEmptySetTransformer{}) + module = module.transform(pruneEmptySetTransformer{}) - if generateVersioned { - // Copy the unversioned module so it can be modified to make it versioned. - versioned := unversioned.deepCopy() - - // Transform the unversioned module into a versioned one. - versioned.transform(unversionedToVersionedTransformer) - bpFile.AddModule(versioned) - } - - if generateUnversioned { - // Transform the unversioned module to make it suitable for use in the snapshot. - unversioned.transform(unversionedTransformer) - bpFile.AddModule(unversioned) - } - } - - if generateVersioned { - // Add the sdk/module_exports_snapshot module to the bp file. - s.addSnapshotModule(ctx, builder, sdkVariants, memberVariantDeps) + // Transform the module module to make it suitable for use in the snapshot. + module.transform(snapshotTransformer) + bpFile.AddModule(module) } // generate Android.bp @@ -698,7 +646,7 @@ func (s *sdk) generateInfoData(ctx android.ModuleContext, memberVariantDeps []sd func filterOutComponents(ctx android.ModuleContext, deps []sdkMemberVariantDep) []sdkMemberVariantDep { // Collate the set of components that all the modules added to the sdk provide. components := map[string]*sdkMemberVariantDep{} - for i, _ := range deps { + for i := range deps { dep := &deps[i] for _, c := range dep.exportedComponentsInfo.Components { components[c] = dep @@ -733,81 +681,6 @@ func filterOutComponents(ctx android.ModuleContext, deps []sdkMemberVariantDep) return filtered } -// addSnapshotModule adds the sdk_snapshot/module_exports_snapshot module to the builder. -func (s *sdk) addSnapshotModule(ctx android.ModuleContext, builder *snapshotBuilder, sdkVariants []*sdk, memberVariantDeps []sdkMemberVariantDep) { - bpFile := builder.bpFile - - snapshotName := ctx.ModuleName() + string(android.SdkVersionSeparator) + builder.version - var snapshotModuleType string - if s.properties.Module_exports { - snapshotModuleType = "module_exports_snapshot" - } else { - snapshotModuleType = "sdk_snapshot" - } - snapshotModule := bpFile.newModule(snapshotModuleType) - snapshotModule.AddProperty("name", snapshotName) - - // Make sure that the snapshot has the same visibility as the sdk. - visibility := android.EffectiveVisibilityRules(ctx, s).Strings() - if len(visibility) != 0 { - snapshotModule.AddProperty("visibility", visibility) - } - - addHostDeviceSupportedProperties(s.ModuleBase.DeviceSupported(), s.ModuleBase.HostSupported(), snapshotModule) - - combinedPropertiesList := s.collateSnapshotModuleInfo(ctx, sdkVariants, memberVariantDeps) - commonCombinedProperties := s.optimizeSnapshotModuleProperties(ctx, combinedPropertiesList) - - s.addSnapshotPropertiesToPropertySet(builder, snapshotModule, commonCombinedProperties) - - targetPropertySet := snapshotModule.AddPropertySet("target") - - // Create a mapping from osType to combined properties. - osTypeToCombinedProperties := map[android.OsType]*combinedSnapshotModuleProperties{} - for _, combined := range combinedPropertiesList { - osTypeToCombinedProperties[combined.sdkVariant.Os()] = combined - } - - // Iterate over the os types in a fixed order. - for _, osType := range s.getPossibleOsTypes() { - if combined, ok := osTypeToCombinedProperties[osType]; ok { - osPropertySet := targetPropertySet.AddPropertySet(osType.Name) - - s.addSnapshotPropertiesToPropertySet(builder, osPropertySet, combined) - } - } - - // If host is supported and any member is host OS dependent then disable host - // by default, so that we can enable each host OS variant explicitly. This - // avoids problems with implicitly enabled OS variants when the snapshot is - // used, which might be different from this run (e.g. different build OS). - if s.HostSupported() { - var supportedHostTargets []string - for _, memberVariantDep := range memberVariantDeps { - if memberVariantDep.memberType.IsHostOsDependent() && memberVariantDep.variant.Target().Os.Class == android.Host { - targetString := memberVariantDep.variant.Target().Os.String() + "_" + memberVariantDep.variant.Target().Arch.ArchType.String() - if !android.InList(targetString, supportedHostTargets) { - supportedHostTargets = append(supportedHostTargets, targetString) - } - } - } - if len(supportedHostTargets) > 0 { - hostPropertySet := targetPropertySet.AddPropertySet("host") - hostPropertySet.AddProperty("enabled", false) - } - // Enable the _ variant explicitly when we've disabled it by default on host. - for _, hostTarget := range supportedHostTargets { - propertySet := targetPropertySet.AddPropertySet(hostTarget) - propertySet.AddProperty("enabled", true) - } - } - - // Prune any empty property sets. - snapshotModule.transform(pruneEmptySetTransformer{}) - - bpFile.AddModule(snapshotModule) -} - // Check the syntax of the generated Android.bp file contents and if they are // invalid then log an error with the contents (tagged with line numbers) and the // errors that were found so that it is easy to see where the problem lies. @@ -944,95 +817,34 @@ func (s *sdk) optimizeSnapshotModuleProperties(ctx android.ModuleContext, list [ } } -func (s *sdk) addSnapshotPropertiesToPropertySet(builder *snapshotBuilder, propertySet android.BpPropertySet, combined *combinedSnapshotModuleProperties) { - staticProperties := combined.staticProperties - multilib := staticProperties.Compile_multilib - if multilib != "" && multilib != "both" { - // Compile_multilib defaults to both so only needs to be set when it's specified and not both. - propertySet.AddProperty("compile_multilib", multilib) - } - - dynamicMemberTypeListProperties := combined.dynamicProperties - for _, memberListProperty := range s.memberTypeListProperties() { - if memberListProperty.getter == nil { - continue - } - if !isMemberTypeSupportedByTargetBuildRelease(memberListProperty.memberType, builder.targetBuildRelease) { - continue - } - names := memberListProperty.getter(dynamicMemberTypeListProperties) - if len(names) > 0 { - propertySet.AddProperty(memberListProperty.propertyName(), builder.versionedSdkMemberNames(names, false)) - } - } -} - type propertyTag struct { name string } var _ android.BpPropertyTag = propertyTag{} -// A BpPropertyTag to add to a property that contains references to other sdk members. +// BpPropertyTag instances to add to a property that contains references to other sdk members. // -// This will cause the references to be rewritten to a versioned reference in the version -// specific instance of a snapshot module. +// These will ensure that the referenced modules are available, if required. var requiredSdkMemberReferencePropertyTag = propertyTag{"requiredSdkMemberReferencePropertyTag"} var optionalSdkMemberReferencePropertyTag = propertyTag{"optionalSdkMemberReferencePropertyTag"} -// A BpPropertyTag that indicates the property should only be present in the versioned -// module. -// -// This will cause the property to be removed from the unversioned instance of a -// snapshot module. -var sdkVersionedOnlyPropertyTag = propertyTag{"sdkVersionedOnlyPropertyTag"} - -type unversionedToVersionedTransformation struct { +type snapshotTransformation struct { identityTransformation builder *snapshotBuilder } -func (t unversionedToVersionedTransformation) transformModule(module *bpModule) *bpModule { - // Use a versioned name for the module but remember the original name for the - // snapshot. - name := module.Name() - module.setProperty("name", t.builder.versionedSdkMemberName(name, true)) - module.insertAfter("name", "sdk_member_name", name) - // Remove the prefer property if present as versioned modules never need marking with prefer. - module.removeProperty("prefer") - // Ditto for use_source_config_var - module.removeProperty("use_source_config_var") - return module -} - -func (t unversionedToVersionedTransformation) transformProperty(name string, value interface{}, tag android.BpPropertyTag) (interface{}, android.BpPropertyTag) { - if tag == requiredSdkMemberReferencePropertyTag || tag == optionalSdkMemberReferencePropertyTag { - required := tag == requiredSdkMemberReferencePropertyTag - return t.builder.versionedSdkMemberNames(value.([]string), required), tag - } else { - return value, tag - } -} - -type unversionedTransformation struct { - identityTransformation - builder *snapshotBuilder -} - -func (t unversionedTransformation) transformModule(module *bpModule) *bpModule { +func (t snapshotTransformation) transformModule(module *bpModule) *bpModule { // If the module is an internal member then use a unique name for it. name := module.Name() - module.setProperty("name", t.builder.unversionedSdkMemberName(name, true)) + module.setProperty("name", t.builder.snapshotSdkMemberName(name, true)) return module } -func (t unversionedTransformation) transformProperty(name string, value interface{}, tag android.BpPropertyTag) (interface{}, android.BpPropertyTag) { +func (t snapshotTransformation) transformProperty(_ string, value interface{}, tag android.BpPropertyTag) (interface{}, android.BpPropertyTag) { if tag == requiredSdkMemberReferencePropertyTag || tag == optionalSdkMemberReferencePropertyTag { required := tag == requiredSdkMemberReferencePropertyTag - return t.builder.unversionedSdkMemberNames(value.([]string), required), tag - } else if tag == sdkVersionedOnlyPropertyTag { - // The property is not allowed in the unversioned module so remove it. - return nil, nil + return t.builder.snapshotSdkMemberNames(value.([]string), required), tag } else { return value, tag } @@ -1044,7 +856,7 @@ type pruneEmptySetTransformer struct { var _ bpTransformer = (*pruneEmptySetTransformer)(nil) -func (t pruneEmptySetTransformer) transformPropertySetAfterContents(name string, propertySet *bpPropertySet, tag android.BpPropertyTag) (*bpPropertySet, android.BpPropertyTag) { +func (t pruneEmptySetTransformer) transformPropertySetAfterContents(_ string, propertySet *bpPropertySet, tag android.BpPropertyTag) (*bpPropertySet, android.BpPropertyTag) { if len(propertySet.properties) == 0 { return nil, nil } else { @@ -1053,20 +865,12 @@ func (t pruneEmptySetTransformer) transformPropertySetAfterContents(name string, } func generateBpContents(contents *generatedContents, bpFile *bpFile) { - generateFilteredBpContents(contents, bpFile, func(*bpModule) bool { - return true - }) -} - -func generateFilteredBpContents(contents *generatedContents, bpFile *bpFile, moduleFilter func(module *bpModule) bool) { contents.IndentedPrintf("// This is auto-generated. DO NOT EDIT.\n") for _, bpModule := range bpFile.order { - if moduleFilter(bpModule) { - contents.IndentedPrintf("\n") - contents.IndentedPrintf("%s {\n", bpModule.moduleType) - outputPropertySet(contents, bpModule.bpPropertySet) - contents.IndentedPrintf("}\n") - } + contents.IndentedPrintf("\n") + contents.IndentedPrintf("%s {\n", bpModule.moduleType) + outputPropertySet(contents, bpModule.bpPropertySet) + contents.IndentedPrintf("}\n") } } @@ -1202,36 +1006,10 @@ func (s *sdk) GetInfoContentsForTests() string { return s.builderForTests.infoContents } -func (s *sdk) GetUnversionedAndroidBpContentsForTests() string { - contents := &generatedContents{} - generateFilteredBpContents(contents, s.builderForTests.bpFile, func(module *bpModule) bool { - name := module.Name() - // Include modules that are either unversioned or have no name. - return !strings.Contains(name, "@") - }) - return contents.content.String() -} - -func (s *sdk) GetVersionedAndroidBpContentsForTests() string { - contents := &generatedContents{} - generateFilteredBpContents(contents, s.builderForTests.bpFile, func(module *bpModule) bool { - name := module.Name() - // Include modules that are either versioned or have no name. - return name == "" || strings.Contains(name, "@") - }) - return contents.content.String() -} - type snapshotBuilder struct { ctx android.ModuleContext sdk *sdk - // The version of the generated snapshot. - // - // See the documentation of SOONG_SDK_SNAPSHOT_VERSION above for details of the valid values of - // this field. - version string - snapshotDir android.OutputPath bpFile *bpFile @@ -1385,13 +1163,6 @@ func (s *snapshotBuilder) AddPrebuiltModule(member android.SdkMember, moduleType addHostDeviceSupportedProperties(deviceSupported, hostSupported, m) - // Disable installation in the versioned module of those modules that are ever installable. - if installable, ok := variant.(interface{ EverInstallable() bool }); ok { - if installable.EverInstallable() { - m.AddPropertyWithTag("installable", false, sdkVersionedOnlyPropertyTag) - } - } - s.prebuiltModules[name] = m s.prebuiltOrder = append(s.prebuiltOrder, m) return m @@ -1424,45 +1195,28 @@ func (s *snapshotBuilder) OptionalSdkMemberReferencePropertyTag() android.BpProp return optionalSdkMemberReferencePropertyTag } -// Get a versioned name appropriate for the SDK snapshot version being taken. -func (s *snapshotBuilder) versionedSdkMemberName(unversionedName string, required bool) string { - if _, ok := s.allMembersByName[unversionedName]; !ok { +// Get a name for sdk snapshot member. If the member is private then generate a snapshot specific +// name. As part of the processing this checks to make sure that any required members are part of +// the snapshot. +func (s *snapshotBuilder) snapshotSdkMemberName(name string, required bool) string { + if _, ok := s.allMembersByName[name]; !ok { if required { - s.ctx.ModuleErrorf("Required member reference %s is not a member of the sdk", unversionedName) + s.ctx.ModuleErrorf("Required member reference %s is not a member of the sdk", name) } - return unversionedName - } - return versionedSdkMemberName(s.ctx, unversionedName, s.version) -} - -func (s *snapshotBuilder) versionedSdkMemberNames(members []string, required bool) []string { - var references []string = nil - for _, m := range members { - references = append(references, s.versionedSdkMemberName(m, required)) - } - return references -} - -// Get an internal name unique to the sdk. -func (s *snapshotBuilder) unversionedSdkMemberName(unversionedName string, required bool) string { - if _, ok := s.allMembersByName[unversionedName]; !ok { - if required { - s.ctx.ModuleErrorf("Required member reference %s is not a member of the sdk", unversionedName) - } - return unversionedName + return name } - if s.isInternalMember(unversionedName) { - return s.ctx.ModuleName() + "_" + unversionedName + if s.isInternalMember(name) { + return s.ctx.ModuleName() + "_" + name } else { - return unversionedName + return name } } -func (s *snapshotBuilder) unversionedSdkMemberNames(members []string, required bool) []string { +func (s *snapshotBuilder) snapshotSdkMemberNames(members []string, required bool) []string { var references []string = nil for _, m := range members { - references = append(references, s.unversionedSdkMemberName(m, required)) + references = append(references, s.snapshotSdkMemberName(m, required)) } return references } From 2bf4389d33aa63fc0b73571f962037ad101d5db6 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 13 May 2022 13:12:19 +0000 Subject: [PATCH 027/172] Add apexes property to sdk Specifying an apex in the apexes propety will cause all the *classpath_fragments that are contents of the APEX to be automatically added as members of the sdk and appear in the snapshot. The purpose of this change is to dedup the APEX and sdk definitions and try and avoid some of the issues that we have been finding while attempting to build against the prebuilts. Two tests, one each for bootclasspath_fragment and systemserverclasspath_fragment, have been refactored to compare the output when adding the *fragment to the sdk directly of via the APEX. That ensures switching to use the APEX will not change the sdk snapshot unless it was previously missing a *fragment. There was also a slight difference in where the hidden API flags were copied from. That should have no impact on the output as the flags are identical. The sdk snapshot generation needed some tweaks to avoid generating a prebuilt for the APEX. Bug: 232401814 Test: m nothing Merged-In: I7aaf16a3a0ab4bebf97765d1484215cc008dc4b8 Change-Id: I7aaf16a3a0ab4bebf97765d1484215cc008dc4b8 (cherry picked from commit 4e7d1c43e27cc484cf598a7d683b0a41363d6f97) --- android/sdk.go | 20 ++- apex/Android.bp | 1 + apex/apex.go | 17 ++- apex/apex_sdk_member.go | 58 ++++++++ java/bootclasspath_fragment.go | 16 ++- java/systemserver_classpath_fragment.go | 21 +-- sdk/bootclasspath_fragment_sdk_test.go | 118 +++++++++++----- ...systemserverclasspath_fragment_sdk_test.go | 91 +++++++++--- sdk/update.go | 133 +++++++++++++++++- 9 files changed, 404 insertions(+), 71 deletions(-) create mode 100644 apex/apex_sdk_member.go diff --git a/android/sdk.go b/android/sdk.go index 533f2f4ec..07b94b246 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -677,6 +677,10 @@ type SdkMemberType interface { // SupportedLinkages returns the names of the linkage variants supported by this module. SupportedLinkages() []string + // ArePrebuiltsRequired returns true if prebuilts are required in the sdk snapshot, false + // otherwise. + ArePrebuiltsRequired() bool + // AddDependencies adds dependencies from the SDK module to all the module variants the member // type contributes to the SDK. `names` is the list of module names given in the member type // property (as returned by SdkPropertyName()) in the SDK module. The exact set of variants @@ -782,7 +786,12 @@ type SdkMemberTypeBase struct { // If not specified then it is assumed to be available on all targeted build releases. SupportedBuildReleaseSpecification string - SupportsSdk bool + // Set to true if this must be usable with the sdk/sdk_snapshot module types. Otherwise, it will + // only be usable with module_exports/module_exports_snapshots module types. + SupportsSdk bool + + // Set to true if prebuilt host artifacts of this member may be specific to the host OS. Only + // applicable to modules where HostSupported() is true. HostOsDependent bool // When set to true UseSourceModuleTypeInSnapshot indicates that the member type creates a source @@ -790,6 +799,11 @@ type SdkMemberTypeBase struct { // code from automatically adding a prefer: true flag. UseSourceModuleTypeInSnapshot bool + // Set to proptools.BoolPtr(false) if this member does not generate prebuilts but is only provided + // to allow the sdk to gather members from this member's dependencies. If not specified then + // defaults to true. + PrebuiltsRequired *bool + // The list of supported traits. Traits []SdkMemberTrait } @@ -814,6 +828,10 @@ func (b *SdkMemberTypeBase) IsHostOsDependent() bool { return b.HostOsDependent } +func (b *SdkMemberTypeBase) ArePrebuiltsRequired() bool { + return proptools.BoolDefault(b.PrebuiltsRequired, true) +} + func (b *SdkMemberTypeBase) UsesSourceModuleTypeInSnapshot() bool { return b.UseSourceModuleTypeInSnapshot } diff --git a/apex/Android.bp b/apex/Android.bp index c4e64560e..312aadb2a 100644 --- a/apex/Android.bp +++ b/apex/Android.bp @@ -22,6 +22,7 @@ bootstrap_go_package { srcs: [ "androidmk.go", "apex.go", + "apex_sdk_member.go", "apex_singleton.go", "builder.go", "constants.go", diff --git a/apex/apex.go b/apex/apex.go index d613861fb..744a9a602 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -604,6 +604,18 @@ type dependencyTag struct { // replacement. This is needed because some prebuilt modules do not provide all the information // needed by the apex. sourceOnly bool + + // If not-nil and an APEX is a member of an SDK then dependencies of that APEX with this tag will + // also be added as exported members of that SDK. + memberType android.SdkMemberType +} + +func (d *dependencyTag) SdkMemberType(_ android.Module) android.SdkMemberType { + return d.memberType +} + +func (d *dependencyTag) ExportMember() bool { + return true } func (d *dependencyTag) String() string { @@ -615,6 +627,7 @@ func (d *dependencyTag) ReplaceSourceWithPrebuilt() bool { } var _ android.ReplaceSourceWithPrebuilt = &dependencyTag{} +var _ android.SdkMemberDependencyTag = &dependencyTag{} var ( androidAppTag = &dependencyTag{name: "androidApp", payload: true} @@ -622,8 +635,8 @@ var ( certificateTag = &dependencyTag{name: "certificate"} executableTag = &dependencyTag{name: "executable", payload: true} fsTag = &dependencyTag{name: "filesystem", payload: true} - bcpfTag = &dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true} - sscpfTag = &dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true} + bcpfTag = &dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true, memberType: java.BootclasspathFragmentSdkMemberType} + sscpfTag = &dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true, memberType: java.SystemServerClasspathFragmentSdkMemberType} compatConfigTag = &dependencyTag{name: "compatConfig", payload: true, sourceOnly: true} javaLibTag = &dependencyTag{name: "javaLib", payload: true} jniLibTag = &dependencyTag{name: "jniLib", payload: true} diff --git a/apex/apex_sdk_member.go b/apex/apex_sdk_member.go new file mode 100644 index 000000000..284158f07 --- /dev/null +++ b/apex/apex_sdk_member.go @@ -0,0 +1,58 @@ +// Copyright (C) 2022 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 ( + "android/soong/android" + "github.com/google/blueprint" + "github.com/google/blueprint/proptools" +) + +// This file contains support for using apex modules within an sdk. + +func init() { + // Register sdk member types. + android.RegisterSdkMemberType(&apexSdkMemberType{ + SdkMemberTypeBase: android.SdkMemberTypeBase{ + PropertyName: "apexes", + SupportsSdk: true, + + // The apexes property does not need to be included in the snapshot as adding an apex to an + // sdk does not produce any prebuilts of the apex. + PrebuiltsRequired: proptools.BoolPtr(false), + }, + }) +} + +type apexSdkMemberType struct { + android.SdkMemberTypeBase +} + +func (mt *apexSdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) { + ctx.AddVariationDependencies(nil, dependencyTag, names...) +} + +func (mt *apexSdkMemberType) IsInstance(module android.Module) bool { + _, ok := module.(*apexBundle) + return ok +} + +func (mt *apexSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { + panic("Sdk does not create prebuilts of the apexes in its snapshot") +} + +func (mt *apexSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { + panic("Sdk does not create prebuilts of the apexes in its snapshot") +} diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index 96009351f..1c77fdb43 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -32,12 +32,7 @@ import ( func init() { registerBootclasspathFragmentBuildComponents(android.InitRegistrationContext) - android.RegisterSdkMemberType(&bootclasspathFragmentMemberType{ - SdkMemberTypeBase: android.SdkMemberTypeBase{ - PropertyName: "bootclasspath_fragments", - SupportsSdk: true, - }, - }) + android.RegisterSdkMemberType(BootclasspathFragmentSdkMemberType) } func registerBootclasspathFragmentBuildComponents(ctx android.RegistrationContext) { @@ -45,6 +40,15 @@ func registerBootclasspathFragmentBuildComponents(ctx android.RegistrationContex ctx.RegisterModuleType("prebuilt_bootclasspath_fragment", prebuiltBootclasspathFragmentFactory) } +// BootclasspathFragmentSdkMemberType is the member type used to add bootclasspath_fragments to +// the SDK snapshot. It is exported for use by apex. +var BootclasspathFragmentSdkMemberType = &bootclasspathFragmentMemberType{ + SdkMemberTypeBase: android.SdkMemberTypeBase{ + PropertyName: "bootclasspath_fragments", + SupportsSdk: true, + }, +} + type bootclasspathFragmentContentDependencyTag struct { blueprint.BaseDependencyTag } diff --git a/java/systemserver_classpath_fragment.go b/java/systemserver_classpath_fragment.go index 79d2ee9f7..a2cd2619a 100644 --- a/java/systemserver_classpath_fragment.go +++ b/java/systemserver_classpath_fragment.go @@ -24,15 +24,7 @@ import ( func init() { registerSystemserverClasspathBuildComponents(android.InitRegistrationContext) - android.RegisterSdkMemberType(&systemServerClasspathFragmentMemberType{ - SdkMemberTypeBase: android.SdkMemberTypeBase{ - PropertyName: "systemserverclasspath_fragments", - SupportsSdk: true, - - // This was only added in Tiramisu. - SupportedBuildReleaseSpecification: "Tiramisu+", - }, - }) + android.RegisterSdkMemberType(SystemServerClasspathFragmentSdkMemberType) } func registerSystemserverClasspathBuildComponents(ctx android.RegistrationContext) { @@ -41,6 +33,17 @@ func registerSystemserverClasspathBuildComponents(ctx android.RegistrationContex ctx.RegisterModuleType("prebuilt_systemserverclasspath_fragment", prebuiltSystemServerClasspathModuleFactory) } +var SystemServerClasspathFragmentSdkMemberType = &systemServerClasspathFragmentMemberType{ + SdkMemberTypeBase: android.SdkMemberTypeBase{ + PropertyName: "systemserverclasspath_fragments", + SupportsSdk: true, + + // Support for adding systemserverclasspath_fragments to the sdk snapshot was only added in + // Tiramisu. + SupportedBuildReleaseSpecification: "Tiramisu+", + }, +} + type platformSystemServerClasspathModule struct { android.ModuleBase diff --git a/sdk/bootclasspath_fragment_sdk_test.go b/sdk/bootclasspath_fragment_sdk_test.go index a60039ac6..7283cf050 100644 --- a/sdk/bootclasspath_fragment_sdk_test.go +++ b/sdk/bootclasspath_fragment_sdk_test.go @@ -187,7 +187,7 @@ func checkBootJarsPackageCheckRule(t *testing.T, result *android.TestResult, exp android.AssertStringDoesContain(t, "boot jars package check", command, expectedCommandArgs) } -func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) { +func testSnapshotWithBootClasspathFragment_Contents(t *testing.T, sdk string, copyRules string) { result := android.GroupFixturePreparers( prepareForSdkTestWithJava, java.PrepareForTestWithJavaDefaultModules, @@ -199,19 +199,7 @@ func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) { // Add a platform_bootclasspath that depends on the fragment. fixtureAddPlatformBootclasspathForBootclasspathFragment("myapex", "mybootclasspathfragment"), - android.FixtureWithRootAndroidBp(` - sdk { - name: "mysdk", - bootclasspath_fragments: ["mybootclasspathfragment"], - java_sdk_libs: [ - // This is not strictly needed as it should be automatically added to the sdk_snapshot as - // a java_sdk_libs module because it is used in the mybootclasspathfragment's - // api.stub_libs property. However, it is specified here to ensure that duplicates are - // correctly deduped. - "mysdklibrary", - ], - } - + android.FixtureWithRootAndroidBp(sdk+` apex { name: "myapex", key: "myapex.key", @@ -367,24 +355,7 @@ java_sdk_library_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/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar -.intermediates/myothersdklibrary.stubs/android_common/javac/myothersdklibrary.stubs.jar -> sdk_library/public/myothersdklibrary-stubs.jar -.intermediates/myothersdklibrary.stubs.source/android_common/metalava/myothersdklibrary.stubs.source_api.txt -> sdk_library/public/myothersdklibrary.txt -.intermediates/myothersdklibrary.stubs.source/android_common/metalava/myothersdklibrary.stubs.source_removed.txt -> sdk_library/public/myothersdklibrary-removed.txt -.intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar -.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt -.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt -.intermediates/mycoreplatform.stubs/android_common/javac/mycoreplatform.stubs.jar -> sdk_library/public/mycoreplatform-stubs.jar -.intermediates/mycoreplatform.stubs.source/android_common/metalava/mycoreplatform.stubs.source_api.txt -> sdk_library/public/mycoreplatform.txt -.intermediates/mycoreplatform.stubs.source/android_common/metalava/mycoreplatform.stubs.source_removed.txt -> sdk_library/public/mycoreplatform-removed.txt -`), + checkAllCopyRules(copyRules), snapshotTestPreparer(checkSnapshotWithoutSource, preparerForSnapshot), snapshotTestChecker(checkSnapshotWithoutSource, func(t *testing.T, result *android.TestResult) { module := result.ModuleForTests("platform-bootclasspath", "android_common") @@ -421,6 +392,89 @@ java_sdk_library_import { ) } +func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) { + t.Run("added-directly", func(t *testing.T) { + testSnapshotWithBootClasspathFragment_Contents(t, ` + sdk { + name: "mysdk", + bootclasspath_fragments: ["mybootclasspathfragment"], + java_sdk_libs: [ + // This is not strictly needed as it should be automatically added to the sdk_snapshot as + // a java_sdk_libs module because it is used in the mybootclasspathfragment's + // api.stub_libs property. However, it is specified here to ensure that duplicates are + // correctly deduped. + "mysdklibrary", + ], + } + `, ` +.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/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar +.intermediates/myothersdklibrary.stubs/android_common/javac/myothersdklibrary.stubs.jar -> sdk_library/public/myothersdklibrary-stubs.jar +.intermediates/myothersdklibrary.stubs.source/android_common/metalava/myothersdklibrary.stubs.source_api.txt -> sdk_library/public/myothersdklibrary.txt +.intermediates/myothersdklibrary.stubs.source/android_common/metalava/myothersdklibrary.stubs.source_removed.txt -> sdk_library/public/myothersdklibrary-removed.txt +.intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar +.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt +.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt +.intermediates/mycoreplatform.stubs/android_common/javac/mycoreplatform.stubs.jar -> sdk_library/public/mycoreplatform-stubs.jar +.intermediates/mycoreplatform.stubs.source/android_common/metalava/mycoreplatform.stubs.source_api.txt -> sdk_library/public/mycoreplatform.txt +.intermediates/mycoreplatform.stubs.source/android_common/metalava/mycoreplatform.stubs.source_removed.txt -> sdk_library/public/mycoreplatform-removed.txt +`) + }) + + copyBootclasspathFragmentFromApexVariantRules := ` +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/index.csv -> hiddenapi/index.csv +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/signature-patterns.csv -> hiddenapi/signature-patterns.csv +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/filtered-stub-flags.csv -> hiddenapi/filtered-stub-flags.csv +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/filtered-flags.csv -> hiddenapi/filtered-flags.csv +.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar +.intermediates/myothersdklibrary.stubs/android_common/javac/myothersdklibrary.stubs.jar -> sdk_library/public/myothersdklibrary-stubs.jar +.intermediates/myothersdklibrary.stubs.source/android_common/metalava/myothersdklibrary.stubs.source_api.txt -> sdk_library/public/myothersdklibrary.txt +.intermediates/myothersdklibrary.stubs.source/android_common/metalava/myothersdklibrary.stubs.source_removed.txt -> sdk_library/public/myothersdklibrary-removed.txt +.intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar +.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt +.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt +.intermediates/mycoreplatform.stubs/android_common/javac/mycoreplatform.stubs.jar -> sdk_library/public/mycoreplatform-stubs.jar +.intermediates/mycoreplatform.stubs.source/android_common/metalava/mycoreplatform.stubs.source_api.txt -> sdk_library/public/mycoreplatform.txt +.intermediates/mycoreplatform.stubs.source/android_common/metalava/mycoreplatform.stubs.source_removed.txt -> sdk_library/public/mycoreplatform-removed.txt +` + t.Run("added-via-apex", func(t *testing.T) { + testSnapshotWithBootClasspathFragment_Contents(t, ` + sdk { + name: "mysdk", + apexes: ["myapex"], + } + `, copyBootclasspathFragmentFromApexVariantRules) + }) + + t.Run("added-directly-and-indirectly", func(t *testing.T) { + testSnapshotWithBootClasspathFragment_Contents(t, ` + sdk { + name: "mysdk", + apexes: ["myapex"], + // This is not strictly needed as it should be automatically added to the sdk_snapshot as + // a bootclasspath_fragments module because it is used in the myapex's + // bootclasspath_fragments property. However, it is specified here to ensure that duplicates + // are correctly deduped. + bootclasspath_fragments: ["mybootclasspathfragment"], + java_sdk_libs: [ + // This is not strictly needed as it should be automatically added to the sdk_snapshot as + // a java_sdk_libs module because it is used in the mybootclasspathfragment's + // api.stub_libs property. However, it is specified here to ensure that duplicates are + // correctly deduped. + "mysdklibrary", + ], + } + `, copyBootclasspathFragmentFromApexVariantRules) + }) +} + // TestSnapshotWithBootClasspathFragment_Fragments makes sure that the fragments property of a // bootclasspath_fragment is correctly output to the sdk snapshot. func TestSnapshotWithBootClasspathFragment_Fragments(t *testing.T) { diff --git a/sdk/systemserverclasspath_fragment_sdk_test.go b/sdk/systemserverclasspath_fragment_sdk_test.go index 1c84a7bba..1ac405d7d 100644 --- a/sdk/systemserverclasspath_fragment_sdk_test.go +++ b/sdk/systemserverclasspath_fragment_sdk_test.go @@ -22,7 +22,7 @@ import ( "android/soong/java" ) -func testSnapshotWithSystemServerClasspathFragment(t *testing.T, targetBuildRelease string, expectedSdkSnapshot string) { +func testSnapshotWithSystemServerClasspathFragment(t *testing.T, sdk string, targetBuildRelease string, expectedSdkSnapshot string) { result := android.GroupFixturePreparers( prepareForSdkTestWithJava, java.PrepareForTestWithJavaDefaultModules, @@ -30,23 +30,13 @@ func testSnapshotWithSystemServerClasspathFragment(t *testing.T, targetBuildRele java.FixtureWithLastReleaseApis("mysdklibrary"), dexpreopt.FixtureSetApexSystemServerJars("myapex:mylib", "myapex:mysdklibrary"), android.FixtureModifyEnv(func(env map[string]string) { - env["SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE"] = targetBuildRelease + if targetBuildRelease != "latest" { + env["SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE"] = targetBuildRelease + } }), prepareForSdkTestWithApex, - android.FixtureWithRootAndroidBp(` - sdk { - name: "mysdk", - systemserverclasspath_fragments: ["mysystemserverclasspathfragment"], - java_sdk_libs: [ - // This is not strictly needed as it should be automatically added to the sdk_snapshot as - // a java_sdk_libs module because it is used in the mysystemserverclasspathfragment's - // contents property. However, it is specified here to ensure that duplicates are - // correctly deduped. - "mysdklibrary", - ], - } - + android.FixtureWithRootAndroidBp(sdk+` apex { name: "myapex", key: "myapex.key", @@ -91,8 +81,62 @@ func testSnapshotWithSystemServerClasspathFragment(t *testing.T, targetBuildRele } func TestSnapshotWithSystemServerClasspathFragment(t *testing.T) { + + commonSdk := ` +sdk { + name: "mysdk", + systemserverclasspath_fragments: ["mysystemserverclasspathfragment"], + java_sdk_libs: [ + // This is not strictly needed as it should be automatically added to the sdk_snapshot as + // a java_sdk_libs module because it is used in the mysystemserverclasspathfragment's + // contents property. However, it is specified here to ensure that duplicates are + // correctly deduped. + "mysdklibrary", + ], +} + ` + + expectedLatestSnapshot := ` +// This is auto-generated. DO NOT EDIT. + +java_sdk_library_import { + name: "mysdklibrary", + prefer: false, + visibility: ["//visibility:public"], + apex_available: ["myapex"], + shared_library: false, + public: { + jars: ["sdk_library/public/mysdklibrary-stubs.jar"], + stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], + current_api: "sdk_library/public/mysdklibrary.txt", + removed_api: "sdk_library/public/mysdklibrary-removed.txt", + sdk_version: "current", + }, +} + +java_import { + name: "mylib", + prefer: false, + visibility: ["//visibility:public"], + apex_available: ["myapex"], + jars: ["java_systemserver_libs/snapshot/jars/are/invalid/mylib.jar"], + permitted_packages: ["mylib"], +} + +prebuilt_systemserverclasspath_fragment { + name: "mysystemserverclasspathfragment", + prefer: false, + visibility: ["//visibility:public"], + apex_available: ["myapex"], + contents: [ + "mylib", + "mysdklibrary", + ], +} +` + t.Run("target-s", func(t *testing.T) { - testSnapshotWithSystemServerClasspathFragment(t, "S", ` + testSnapshotWithSystemServerClasspathFragment(t, commonSdk, "S", ` // This is auto-generated. DO NOT EDIT. java_sdk_library_import { @@ -113,7 +157,7 @@ java_sdk_library_import { }) t.Run("target-t", func(t *testing.T) { - testSnapshotWithSystemServerClasspathFragment(t, "Tiramisu", ` + testSnapshotWithSystemServerClasspathFragment(t, commonSdk, "Tiramisu", ` // This is auto-generated. DO NOT EDIT. java_sdk_library_import { @@ -152,4 +196,17 @@ prebuilt_systemserverclasspath_fragment { } `) }) + + t.Run("added-directly", func(t *testing.T) { + testSnapshotWithSystemServerClasspathFragment(t, commonSdk, `latest`, expectedLatestSnapshot) + }) + + t.Run("added-via-apex", func(t *testing.T) { + testSnapshotWithSystemServerClasspathFragment(t, ` + sdk { + name: "mysdk", + apexes: ["myapex"], + } + `, `latest`, expectedLatestSnapshot) + }) } diff --git a/sdk/update.go b/sdk/update.go index 8e4f9d4e2..b9ef3d0f4 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -433,6 +433,9 @@ be unnecessary as every module in the sdk already has its own licenses property. traits := s.gatherTraits() for _, member := range members { memberType := member.memberType + if !memberType.ArePrebuiltsRequired() { + continue + } name := member.name requiredTraits := traits[name] @@ -1319,6 +1322,119 @@ func (m multilibUsage) String() string { } } +// TODO(187910671): BEGIN - Remove once modules do not have an APEX and default variant. +// variantCoordinate contains the coordinates used to identify a variant of an SDK member. +type variantCoordinate struct { + // osType identifies the OS target of a variant. + osType android.OsType + // archId identifies the architecture and whether it is for the native bridge. + archId archId + // image is the image variant name. + image string + // linkType is the link type name. + linkType string +} + +func getVariantCoordinate(ctx *memberContext, variant android.Module) variantCoordinate { + linkType := "" + if len(ctx.MemberType().SupportedLinkages()) > 0 { + linkType = getLinkType(variant) + } + return variantCoordinate{ + osType: variant.Target().Os, + archId: archIdFromTarget(variant.Target()), + image: variant.ImageVariation().Variation, + linkType: linkType, + } +} + +// selectApexVariantsWhereAvailable filters the input list of variants by selecting the APEX +// specific variant for a specific variantCoordinate when there is both an APEX and default variant. +// +// There is a long-standing issue where a module that is added to an APEX has both an APEX and +// default/platform variant created even when the module does not require a platform variant. As a +// result an indirect dependency onto a module via the APEX will use the APEX variant, whereas a +// direct dependency onto the module will use the default/platform variant. That would result in a +// failure while attempting to optimize the properties for a member as it would have two variants +// when only one was expected. +// +// This function mitigates that problem by detecting when there are two variants that differ only +// by apex variant, where one is the default/platform variant and one is the APEX variant. In that +// case it picks the APEX variant. It picks the APEX variant because that is the behavior that would +// be expected +func selectApexVariantsWhereAvailable(ctx *memberContext, variants []android.SdkAware) []android.SdkAware { + moduleCtx := ctx.sdkMemberContext + + // Group the variants by coordinates. + variantsByCoord := make(map[variantCoordinate][]android.SdkAware) + for _, variant := range variants { + coord := getVariantCoordinate(ctx, variant) + variantsByCoord[coord] = append(variantsByCoord[coord], variant) + } + + toDiscard := make(map[android.SdkAware]struct{}) + for coord, list := range variantsByCoord { + count := len(list) + if count == 1 { + continue + } + + variantsByApex := make(map[string]android.SdkAware) + conflictDetected := false + for _, variant := range list { + apexInfo := moduleCtx.OtherModuleProvider(variant, android.ApexInfoProvider).(android.ApexInfo) + apexVariationName := apexInfo.ApexVariationName + // If there are two variants for a specific APEX variation then there is conflict. + if _, ok := variantsByApex[apexVariationName]; ok { + conflictDetected = true + break + } + variantsByApex[apexVariationName] = variant + } + + // If there are more than 2 apex variations or one of the apex variations is not the + // default/platform variation then there is a conflict. + if len(variantsByApex) != 2 { + conflictDetected = true + } else if _, ok := variantsByApex[""]; !ok { + conflictDetected = true + } + + // If there are no conflicts then add the default/platform variation to the list to remove. + if !conflictDetected { + toDiscard[variantsByApex[""]] = struct{}{} + continue + } + + // There are duplicate variants at this coordinate and they are not the default and APEX variant + // so fail. + variantDescriptions := []string{} + for _, m := range list { + variantDescriptions = append(variantDescriptions, fmt.Sprintf(" %s", m.String())) + } + + moduleCtx.ModuleErrorf("multiple conflicting variants detected for OsType{%s}, %s, Image{%s}, Link{%s}\n%s", + coord.osType, coord.archId.String(), coord.image, coord.linkType, + strings.Join(variantDescriptions, "\n")) + } + + // If there are any variants to discard then remove them from the list of variants, while + // preserving the order. + if len(toDiscard) > 0 { + filtered := []android.SdkAware{} + for _, variant := range variants { + if _, ok := toDiscard[variant]; !ok { + filtered = append(filtered, variant) + } + } + variants = filtered + } + + return variants +} + +// TODO(187910671): END - Remove once modules do not have an APEX and default variant. + type baseInfo struct { Properties android.SdkMemberProperties } @@ -1374,7 +1490,14 @@ func newOsTypeSpecificInfo(ctx android.SdkMemberContext, osType android.OsType, if commonVariants, ok := variantsByArchId[commonArchId]; ok { if len(osTypeVariants) != 1 { - panic(fmt.Errorf("Expected to only have 1 variant when arch type is common but found %d", len(osTypeVariants))) + variants := []string{} + for _, m := range osTypeVariants { + variants = append(variants, fmt.Sprintf(" %s", m.String())) + } + panic(fmt.Errorf("expected to only have 1 variant of %q when arch type is common but found %d\n%s", + ctx.Name(), + len(osTypeVariants), + strings.Join(variants, "\n"))) } // A common arch type only has one variant and its properties should be treated @@ -1854,7 +1977,8 @@ func (s *sdk) createMemberSnapshot(ctx *memberContext, member *sdkMember, bpModu memberType := member.memberType // Do not add the prefer property if the member snapshot module is a source module type. - config := ctx.sdkMemberContext.Config() + moduleCtx := ctx.sdkMemberContext + config := moduleCtx.Config() if !memberType.UsesSourceModuleTypeInSnapshot() { // Set the prefer based on the environment variable. This is a temporary work around to allow a // snapshot to be created that sets prefer: true. @@ -1879,9 +2003,10 @@ func (s *sdk) createMemberSnapshot(ctx *memberContext, member *sdkMember, bpModu } } + variants := selectApexVariantsWhereAvailable(ctx, member.variants) + // Group the variants by os type. variantsByOsType := make(map[android.OsType][]android.Module) - variants := member.Variants() for _, variant := range variants { osType := variant.Target().Os variantsByOsType[osType] = append(variantsByOsType[osType], variant) @@ -1927,7 +2052,7 @@ func (s *sdk) createMemberSnapshot(ctx *memberContext, member *sdkMember, bpModu } // Extract properties which are common across all architectures and os types. - extractCommonProperties(ctx.sdkMemberContext, commonValueExtractor, commonProperties, osSpecificPropertiesContainers) + extractCommonProperties(moduleCtx, commonValueExtractor, commonProperties, osSpecificPropertiesContainers) // Add the common properties to the module. addSdkMemberPropertiesToSet(ctx, commonProperties, bpModule) From 68a7a2b33305d36fa3a4960b0b739d0774f3ba00 Mon Sep 17 00:00:00 2001 From: Alexei Nicoara Date: Fri, 8 Jul 2022 15:24:41 +0100 Subject: [PATCH 028/172] Replace version 0 with the default version Having 0 as the default version causes problems in flattened apexes and is being parsed in protobuf as non-existing field. It will be hard to revert 100 of commits for all the modules. Changing the version in soong to mitigate time impact. Test: presubmit, checked .intermediary jsons Bug: 231691643 Change-Id: I451186d79fd9f8345fd4e28d9daadbfc59047445 (cherry picked from commit e922d2139dd4fec6fdae4a6e71ec62de264bd212) Merged-In: I451186d79fd9f8345fd4e28d9daadbfc59047445 --- apex/builder.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/apex/builder.go b/apex/builder.go index e3c447632..dda342f82 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -93,6 +93,11 @@ var ( Description: "strip ${in}=>${out}", }) + setVersionApexManifestRule = pctx.StaticRule("setVersionApexManifestRule", blueprint.RuleParams{ + Command: `sed 's/\"version\":\s*0\([^0-9]*\)$$/\"version\":\ ${default_version}\1/' $in > $out`, + Description: "Replace 'version: 0' with the correct version // ${in}=>${out}", + }, "default_version") + pbApexManifestRule = pctx.StaticRule("pbApexManifestRule", blueprint.RuleParams{ Command: `rm -f $out && ${conv_apex_manifest} proto $in -o $out`, CommandDeps: []string{"${conv_apex_manifest}"}, @@ -219,10 +224,20 @@ func (a *apexBundle) buildManifest(ctx android.ModuleContext, provideNativeLibs, Output: manifestJsonCommentsStripped, }) + manifestJsonVersionChanged := android.PathForModuleOut(ctx, "apex_manifest_version_changed.json") + ctx.Build(pctx, android.BuildParams{ + Rule: setVersionApexManifestRule, + Input: manifestJsonCommentsStripped, + Output: manifestJsonVersionChanged, + Args: map[string]string{ + "default_version": defaultManifestVersion, + }, + }) + manifestJsonFullOut := android.PathForModuleOut(ctx, "apex_manifest_full.json") ctx.Build(pctx, android.BuildParams{ Rule: apexManifestRule, - Input: manifestJsonCommentsStripped, + Input: manifestJsonVersionChanged, Output: manifestJsonFullOut, Args: map[string]string{ "provideNativeLibs": strings.Join(provideNativeLibs, " "), From ab9fbab7ef165c1312f540899ab00301fab0de81 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 31 Mar 2022 15:42:30 +0100 Subject: [PATCH 029/172] bootclasspath_fragment: Add test specific module type This is needed to allow the behavior of the bootclasspath_fragment to be tweaked for test fragments. Bug: 194063708 Test: m nothing Change-Id: Iee5c09d5b580d088ba081d95a788dbde883078ed (cherry picked from commit c15b9e99e5e208410a1f1c3766c97125e63c22b3) Merged-In: Iee5c09d5b580d088ba081d95a788dbde883078ed --- java/bootclasspath_fragment.go | 15 +++++++++++ java/bootclasspath_fragment_test.go | 39 +++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index 1c77fdb43..3dce64095 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -37,6 +37,7 @@ func init() { func registerBootclasspathFragmentBuildComponents(ctx android.RegistrationContext) { ctx.RegisterModuleType("bootclasspath_fragment", bootclasspathFragmentFactory) + ctx.RegisterModuleType("bootclasspath_fragment_test", testBootclasspathFragmentFactory) ctx.RegisterModuleType("prebuilt_bootclasspath_fragment", prebuiltBootclasspathFragmentFactory) } @@ -231,6 +232,9 @@ type BootclasspathFragmentModule struct { android.SdkBase ClasspathFragmentBase + // True if this fragment is for testing purposes. + testFragment bool + properties bootclasspathFragmentProperties sourceOnlyProperties SourceOnlyBootclasspathProperties @@ -302,6 +306,12 @@ func bootclasspathFragmentFactory() android.Module { return m } +func testBootclasspathFragmentFactory() android.Module { + m := bootclasspathFragmentFactory().(*BootclasspathFragmentModule) + m.testFragment = true + return m +} + // bootclasspathFragmentInitContentsFromImage will initialize the contents property from the image_name if // necessary. func bootclasspathFragmentInitContentsFromImage(ctx android.EarlyModuleContext, m *BootclasspathFragmentModule) { @@ -823,6 +833,11 @@ func (b *BootclasspathFragmentModule) createHiddenAPIFlagInput(ctx android.Modul return input } +// isTestFragment returns true if the current module is a test bootclasspath_fragment. +func (b *BootclasspathFragmentModule) isTestFragment() bool { + return b.testFragment +} + // produceHiddenAPIOutput produces the hidden API all-flags.csv file (and supporting files) // for the fragment as well as encoding the flags in the boot dex jars. func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput { diff --git a/java/bootclasspath_fragment_test.go b/java/bootclasspath_fragment_test.go index d3de675d8..2307ce02b 100644 --- a/java/bootclasspath_fragment_test.go +++ b/java/bootclasspath_fragment_test.go @@ -278,3 +278,42 @@ func TestBootclasspathFragment_StubLibs(t *testing.T) { android.AssertPathsRelativeToTopEquals(t, "widest dex stubs jar", expectedWidestPaths, info.TransitiveStubDexJarsByScope.StubDexJarsForWidestAPIScope()) } + +func TestBootclasspathFragment_Test(t *testing.T) { + result := android.GroupFixturePreparers( + prepareForTestWithBootclasspathFragment, + PrepareForTestWithJavaSdkLibraryFiles, + FixtureWithLastReleaseApis("mysdklibrary"), + ).RunTestWithBp(t, ` + bootclasspath_fragment { + name: "myfragment", + contents: ["mysdklibrary"], + hidden_api: { + split_packages: [], + }, + } + + bootclasspath_fragment_test { + name: "a_test_fragment", + contents: ["mysdklibrary"], + hidden_api: { + split_packages: [], + }, + } + + + java_sdk_library { + name: "mysdklibrary", + srcs: ["a.java"], + shared_library: false, + public: {enabled: true}, + system: {enabled: true}, + } + `) + + fragment := result.Module("myfragment", "android_common").(*BootclasspathFragmentModule) + android.AssertBoolEquals(t, "not a test fragment", false, fragment.isTestFragment()) + + fragment = result.Module("a_test_fragment", "android_common").(*BootclasspathFragmentModule) + android.AssertBoolEquals(t, "is a test fragment by type", true, fragment.isTestFragment()) +} From e2c7fd9b8cdde214c5d6d4addee1cd48dd5cab0a Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 12 Apr 2022 18:20:14 +0100 Subject: [PATCH 030/172] bootclasspath_fragment: Treat some specific modules as test Treats bootclasspath_fragment modules that have not yet been converted to test modules as if they were test modules. This is a temporary work around to ease the migration to bootclasspath_fragment_test modules and is expected to be reverted. Bug: 194063708 Test: m nothing Change-Id: I093fbec4e926719b644c64ebfc63f9e3070e28db (cherry picked from commit ff9b6faba2b9a949289c70657db87c0b1790cc07) Merged-In: I093fbec4e926719b644c64ebfc63f9e3070e28db --- java/bootclasspath_fragment.go | 17 ++++++++++++++++- java/bootclasspath_fragment_test.go | 22 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index 3dce64095..6e9492ad4 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -835,7 +835,22 @@ func (b *BootclasspathFragmentModule) createHiddenAPIFlagInput(ctx android.Modul // isTestFragment returns true if the current module is a test bootclasspath_fragment. func (b *BootclasspathFragmentModule) isTestFragment() bool { - return b.testFragment + if b.testFragment { + return true + } + + // TODO(b/194063708): Once test fragments all use bootclasspath_fragment_test + // Some temporary exceptions until all test fragments use the + // bootclasspath_fragment_test module type. + name := b.BaseModuleName() + if strings.HasPrefix(name, "test_") { + return true + } + if name == "apex.apexd_test_bootclasspath-fragment" { + return true + } + + return false } // produceHiddenAPIOutput produces the hidden API all-flags.csv file (and supporting files) diff --git a/java/bootclasspath_fragment_test.go b/java/bootclasspath_fragment_test.go index 2307ce02b..8ffe99a77 100644 --- a/java/bootclasspath_fragment_test.go +++ b/java/bootclasspath_fragment_test.go @@ -293,6 +293,22 @@ func TestBootclasspathFragment_Test(t *testing.T) { }, } + bootclasspath_fragment { + name: "test_fragment", + contents: ["mysdklibrary"], + hidden_api: { + split_packages: [], + }, + } + + bootclasspath_fragment { + name: "apex.apexd_test_bootclasspath-fragment", + contents: ["mysdklibrary"], + hidden_api: { + split_packages: [], + }, + } + bootclasspath_fragment_test { name: "a_test_fragment", contents: ["mysdklibrary"], @@ -314,6 +330,12 @@ func TestBootclasspathFragment_Test(t *testing.T) { fragment := result.Module("myfragment", "android_common").(*BootclasspathFragmentModule) android.AssertBoolEquals(t, "not a test fragment", false, fragment.isTestFragment()) + fragment = result.Module("test_fragment", "android_common").(*BootclasspathFragmentModule) + android.AssertBoolEquals(t, "is a test fragment by prefix", true, fragment.isTestFragment()) + fragment = result.Module("a_test_fragment", "android_common").(*BootclasspathFragmentModule) android.AssertBoolEquals(t, "is a test fragment by type", true, fragment.isTestFragment()) + + fragment = result.Module("apex.apexd_test_bootclasspath-fragment", "android_common").(*BootclasspathFragmentModule) + android.AssertBoolEquals(t, "is a test fragment by name", true, fragment.isTestFragment()) } From 3532c556ed4d24084e1eeeb97f2d865748dbd739 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 31 Mar 2022 15:42:30 +0100 Subject: [PATCH 031/172] bootclasspath_fragment: Require at least one hidden_api package property Previously, the split_packages, single_packages and package_prefixes properties were all optional and the split_packages defaulted to ["*"]. As that value conflicted with the other package properties that meant that split_packages always had to be specified even if it was to just set it to an empty array. This change requires at least one of them to be specified and defaults split_packages to an empty list which means it is not required, although it can be helpful to make that explicit. Bug: 194063708 Test: m nothing Change-Id: I5a4c2d68e72e39f5c4a2441326dfce8685fc8ff2 (cherry picked from commit 9fd564711ec5fd7361d0fc723256bb58569501f5) Merged-In: I5a4c2d68e72e39f5c4a2441326dfce8685fc8ff2 --- apex/apex_test.go | 24 +++++++++++++++++++ apex/bootclasspath_fragment_test.go | 33 ++++++++++++++++++++++++++ apex/classpath_element_test.go | 6 +++++ apex/platform_bootclasspath_test.go | 22 +++++++++++++++++ java/bootclasspath_fragment.go | 13 +++++++--- java/bootclasspath_fragment_test.go | 6 +++++ sdk/bootclasspath_fragment_sdk_test.go | 16 +++++++++++++ sdk/sdk_test.go | 3 +++ 8 files changed, 120 insertions(+), 3 deletions(-) diff --git a/apex/apex_test.go b/apex/apex_test.go index 49b2b2d4d..dbe918010 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -6227,6 +6227,9 @@ func TestOverrideApex(t *testing.T) { name: "mybootclasspath_fragment", contents: ["bcplib"], apex_available: ["myapex"], + hidden_api: { + split_packages: ["*"], + }, } java_library { @@ -6241,6 +6244,9 @@ func TestOverrideApex(t *testing.T) { name: "override_bootclasspath_fragment", contents: ["override_bcplib"], apex_available: ["myapex"], + hidden_api: { + split_packages: ["*"], + }, } java_library { @@ -7294,6 +7300,9 @@ func testNoUpdatableJarsInBootImage(t *testing.T, errmsg string, preparer androi apex_available: [ "some-non-updatable-apex", ], + hidden_api: { + split_packages: ["*"], + }, } java_library { @@ -7352,6 +7361,9 @@ func testNoUpdatableJarsInBootImage(t *testing.T, errmsg string, preparer androi apex_available: [ "com.android.art.debug", ], + hidden_api: { + split_packages: ["*"], + }, } apex_key { @@ -8796,6 +8808,9 @@ func TestApexJavaCoverage(t *testing.T) { name: "mybootclasspathfragment", contents: ["mybootclasspathlib"], apex_available: ["myapex"], + hidden_api: { + split_packages: ["*"], + }, } java_library { @@ -9116,6 +9131,9 @@ func TestSdkLibraryCanHaveHigherMinSdkVersion(t *testing.T) { name: "mybootclasspathfragment", contents: ["mybootclasspathlib"], apex_available: ["myapex"], + hidden_api: { + split_packages: ["*"], + }, } java_sdk_library { @@ -9216,6 +9234,9 @@ func TestSdkLibraryCanHaveHigherMinSdkVersion(t *testing.T) { name: "mybootclasspathfragment", contents: ["mybootclasspathlib"], apex_available: ["myapex"], + hidden_api: { + split_packages: ["*"], + }, } java_sdk_library { @@ -9435,6 +9456,9 @@ func TestApexStrictUpdtabilityLintBcpFragmentDeps(t *testing.T) { name: "mybootclasspathfragment", contents: ["myjavalib"], apex_available: ["myapex"], + hidden_api: { + split_packages: ["*"], + }, } java_library { name: "myjavalib", diff --git a/apex/bootclasspath_fragment_test.go b/apex/bootclasspath_fragment_test.go index ce6b7f730..b298dac5d 100644 --- a/apex/bootclasspath_fragment_test.go +++ b/apex/bootclasspath_fragment_test.go @@ -110,6 +110,9 @@ func TestBootclasspathFragments(t *testing.T) { apex_available: [ "com.android.art", ], + hidden_api: { + split_packages: ["*"], + }, } `, ) @@ -209,6 +212,9 @@ func TestBootclasspathFragments_FragmentDependency(t *testing.T) { apex_available: [ "com.android.art", ], + hidden_api: { + split_packages: ["*"], + }, } bootclasspath_fragment { @@ -220,6 +226,9 @@ func TestBootclasspathFragments_FragmentDependency(t *testing.T) { module: "art-bootclasspath-fragment", }, ], + hidden_api: { + split_packages: ["*"], + }, } `, ) @@ -361,6 +370,9 @@ func TestBootclasspathFragmentInArtApex(t *testing.T) { apex_available: [ "com.android.art", ], + hidden_api: { + split_packages: ["*"], + }, } `, contentsInsert(contents)) @@ -853,6 +865,9 @@ func TestBootclasspathFragmentContentsNoName(t *testing.T) { apex_available: [ "myapex", ], + hidden_api: { + split_packages: ["*"], + }, } `) @@ -959,6 +974,9 @@ func TestBootclasspathFragment_HiddenAPIList(t *testing.T) { apex_available: [ "com.android.art", ], + hidden_api: { + split_packages: ["*"], + }, } apex { @@ -1010,6 +1028,9 @@ func TestBootclasspathFragment_HiddenAPIList(t *testing.T) { module: "art-bootclasspath-fragment", }, ], + hidden_api: { + split_packages: ["*"], + }, } `) @@ -1123,6 +1144,9 @@ func TestBootclasspathFragment_AndroidNonUpdatable(t *testing.T) { apex_available: [ "com.android.art", ], + hidden_api: { + split_packages: ["*"], + }, } apex { @@ -1175,6 +1199,9 @@ func TestBootclasspathFragment_AndroidNonUpdatable(t *testing.T) { module: "art-bootclasspath-fragment", }, ], + hidden_api: { + split_packages: ["*"], + }, } `) @@ -1282,6 +1309,9 @@ func TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks(t *test apex_available: [ "com.android.art", ], + hidden_api: { + split_packages: ["*"], + }, } apex { @@ -1334,6 +1364,9 @@ func TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks(t *test module: "art-bootclasspath-fragment", }, ], + hidden_api: { + split_packages: ["*"], + }, } `) diff --git a/apex/classpath_element_test.go b/apex/classpath_element_test.go index 60f18bd57..9142eed99 100644 --- a/apex/classpath_element_test.go +++ b/apex/classpath_element_test.go @@ -88,6 +88,9 @@ func TestCreateClasspathElements(t *testing.T) { "baz", "quuz", ], + hidden_api: { + split_packages: ["*"], + }, } java_library { @@ -134,6 +137,9 @@ func TestCreateClasspathElements(t *testing.T) { contents: [ "bar", ], + hidden_api: { + split_packages: ["*"], + }, } java_library { diff --git a/apex/platform_bootclasspath_test.go b/apex/platform_bootclasspath_test.go index 06c39ee4b..4b48da8e2 100644 --- a/apex/platform_bootclasspath_test.go +++ b/apex/platform_bootclasspath_test.go @@ -125,6 +125,7 @@ func TestPlatformBootclasspath_Fragments(t *testing.T) { unsupported_packages: [ "bar-unsupported-packages.txt", ], + split_packages: ["*"], }, } @@ -274,6 +275,9 @@ func TestPlatformBootclasspathDependencies(t *testing.T) { "baz", "quuz", ], + hidden_api: { + split_packages: ["*"], + }, } java_library { @@ -317,6 +321,9 @@ func TestPlatformBootclasspathDependencies(t *testing.T) { name: "my-bootclasspath-fragment", contents: ["bar"], apex_available: ["myapex"], + hidden_api: { + split_packages: ["*"], + }, } apex_key { @@ -482,6 +489,9 @@ func TestPlatformBootclasspath_AlwaysUsePrebuiltSdks(t *testing.T) { contents: [ "foo", "bar", ], + hidden_api: { + split_packages: ["*"], + }, } prebuilt_bootclasspath_fragment { @@ -599,6 +609,9 @@ func TestPlatformBootclasspath_IncludesRemainingApexJars(t *testing.T) { generate_classpaths_proto: false, contents: ["foo"], apex_available: ["myapex"], + hidden_api: { + split_packages: ["*"], + }, } java_library { @@ -656,6 +669,9 @@ func TestBootJarNotInApex(t *testing.T) { contents: [ "foo", ], + hidden_api: { + split_packages: ["*"], + }, } platform_bootclasspath { @@ -696,6 +712,9 @@ func TestBootFragmentNotInApex(t *testing.T) { bootclasspath_fragment { name: "not-in-apex-fragment", contents: ["foo"], + hidden_api: { + split_packages: ["*"], + }, } platform_bootclasspath { @@ -746,6 +765,9 @@ func TestNonBootJarInFragment(t *testing.T) { name: "apex-fragment", contents: ["foo", "bar"], apex_available:[ "myapex" ], + hidden_api: { + split_packages: ["*"], + }, } platform_bootclasspath { diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index 6e9492ad4..b6b179cdf 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -866,11 +866,18 @@ func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleC packagePrefixes := b.sourceOnlyProperties.Hidden_api.Package_prefixes singlePackages := b.sourceOnlyProperties.Hidden_api.Single_packages if splitPackages != nil || packagePrefixes != nil || singlePackages != nil { - if splitPackages == nil { - splitPackages = []string{"*"} - } output.SignaturePatternsPath = buildRuleSignaturePatternsFile( ctx, output.AllFlagsPath, splitPackages, packagePrefixes, singlePackages) + } else if !b.isTestFragment() { + ctx.ModuleErrorf(`Must specify at least one of the split_packages, package_prefixes and single_packages properties + If this is a new bootclasspath_fragment or you are unsure what to do add the + the following to the bootclasspath_fragment: + hidden_api: {split_packages: ["*"]}, + and then run the following: + m analyze_bcpf && analyze_bcpf --bcpf %q + it will analyze the bootclasspath_fragment and provide hints as to what you + should specify here. If you are happy with its suggestions then you can add + the --fix option and it will fix them for you.`, b.BaseModuleName()) } return output diff --git a/java/bootclasspath_fragment_test.go b/java/bootclasspath_fragment_test.go index 8ffe99a77..83beb6d23 100644 --- a/java/bootclasspath_fragment_test.go +++ b/java/bootclasspath_fragment_test.go @@ -121,6 +121,9 @@ func TestBootclasspathFragment_Coverage(t *testing.T) { ], }, }, + hidden_api: { + split_packages: ["*"], + }, } java_library { @@ -201,6 +204,9 @@ func TestBootclasspathFragment_StubLibs(t *testing.T) { core_platform_api: { stub_libs: ["mycoreplatform.stubs"], }, + hidden_api: { + split_packages: ["*"], + }, } java_library { diff --git a/sdk/bootclasspath_fragment_sdk_test.go b/sdk/bootclasspath_fragment_sdk_test.go index 7283cf050..13ddbe768 100644 --- a/sdk/bootclasspath_fragment_sdk_test.go +++ b/sdk/bootclasspath_fragment_sdk_test.go @@ -101,6 +101,9 @@ func TestSnapshotWithBootclasspathFragment_ImageName(t *testing.T) { image_name: "art", contents: ["mybootlib"], apex_available: ["com.android.art"], + hidden_api: { + split_packages: ["*"], + }, } apex_key { @@ -223,6 +226,9 @@ func testSnapshotWithBootClasspathFragment_Contents(t *testing.T, sdk string, co // This should be automatically added to the sdk_snapshot as a java_sdk_libs module. stub_libs: ["mycoreplatform"], }, + hidden_api: { + split_packages: ["*"], + }, } java_library { @@ -507,6 +513,9 @@ func TestSnapshotWithBootClasspathFragment_Fragments(t *testing.T) { contents: [ "myotherlib", ], + hidden_api: { + split_packages: ["*"], + }, } java_library { @@ -536,6 +545,9 @@ func TestSnapshotWithBootClasspathFragment_Fragments(t *testing.T) { module: "myotherbootclasspathfragment" }, ], + hidden_api: { + split_packages: ["*"], + }, } java_sdk_library { @@ -615,6 +627,9 @@ func TestBasicSdkWithBootclasspathFragment(t *testing.T) { image_name: "art", contents: ["mybootlib"], apex_available: ["myapex"], + hidden_api: { + split_packages: ["*"], + }, } java_library { @@ -722,6 +737,7 @@ func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) { unsupported_packages: [ "my-unsupported-packages.txt", ], + split_packages: ["*"], }, } diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go index e230d5c0b..1ec12c346 100644 --- a/sdk/sdk_test.go +++ b/sdk/sdk_test.go @@ -473,6 +473,9 @@ java_import { name: "mybootclasspathfragment", apex_available: ["myapex"], contents: ["mysdklibrary"], + hidden_api: { + split_packages: ["*"], + }, } java_sdk_library { From 221f5734aa4bd7b74c73242323e37db5f544b8a5 Mon Sep 17 00:00:00 2001 From: Alexei Nicoara Date: Mon, 11 Jul 2022 12:38:50 +0100 Subject: [PATCH 032/172] Adding support to conditionally replace a value Bug: 231691643 Test: presubmit Change-Id: I786ab152a94126ebc8a9d7dea0bb68e07d789a0b (cherry picked from commit 7d69b1d8e664e15bb891149384a18a5c715cc0f3) Merged-In: I786ab152a94126ebc8a9d7dea0bb68e07d789a0b --- scripts/Android.bp | 10 +++++ scripts/jsonmodify.py | 12 ++++++ scripts/jsonmodify_test.py | 75 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 scripts/jsonmodify_test.py diff --git a/scripts/Android.bp b/scripts/Android.bp index 4773579e3..a37d2597b 100644 --- a/scripts/Android.bp +++ b/scripts/Android.bp @@ -84,6 +84,16 @@ python_binary_host { ], } +python_test_host { + name: "jsonmodify_test", + main: "jsonmodify_test.py", + srcs: [ + "jsonmodify_test.py", + "jsonmodify.py", + ], + test_suites: ["general-tests"], +} + python_binary_host { name: "test_config_fixer", main: "test_config_fixer.py", diff --git a/scripts/jsonmodify.py b/scripts/jsonmodify.py index ba1109e7a..96ff8cacd 100755 --- a/scripts/jsonmodify.py +++ b/scripts/jsonmodify.py @@ -59,6 +59,13 @@ class Replace(str): cur[key] = val +class ReplaceIfEqual(str): + def apply(self, obj, old_val, new_val): + cur, key = follow_path(obj, self) + if cur and cur[key] == int(old_val): + cur[key] = new_val + + class Remove(str): def apply(self, obj): cur, key = follow_path(obj, self) @@ -91,6 +98,11 @@ def main(): help='replace value of the key specified by path. If path doesn\'t exist, no op.', metavar=('path', 'value'), nargs=2, dest='patch', action='append') + parser.add_argument("-se", "--replace-if-equal", type=ReplaceIfEqual, + help='replace value of the key specified by path to new_value if it\'s equal to old_value.' + + 'If path doesn\'t exist or the value is not equal to old_value, no op.', + metavar=('path', 'old_value', 'new_value'), + nargs=3, dest='patch', action='append') parser.add_argument("-r", "--remove", type=Remove, help='remove the key specified by path. If path doesn\'t exist, no op.', metavar='path', diff --git a/scripts/jsonmodify_test.py b/scripts/jsonmodify_test.py new file mode 100644 index 000000000..6f0291dfb --- /dev/null +++ b/scripts/jsonmodify_test.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +# +# Copyright (C) 2022 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. +# +"""Tests for jsonmodify.""" + +import json +import jsonmodify +import unittest + + +class JsonmodifyTest(unittest.TestCase): + + def test_set_value(self): + obj = json.loads('{"field1": 111}') + field1 = jsonmodify.SetValue("field1") + field1.apply(obj, 222) + field2 = jsonmodify.SetValue("field2") + field2.apply(obj, 333) + expected = json.loads('{"field1": 222, "field2": 333}') + self.assertEqual(obj, expected) + + def test_replace(self): + obj = json.loads('{"field1": 111}') + field1 = jsonmodify.Replace("field1") + field1.apply(obj, 222) + field2 = jsonmodify.Replace("field2") + field2.apply(obj, 333) + expected = json.loads('{"field1": 222}') + self.assertEqual(obj, expected) + + def test_replace_if_equal(self): + obj = json.loads('{"field1": 111, "field2": 222}') + field1 = jsonmodify.ReplaceIfEqual("field1") + field1.apply(obj, 111, 333) + field2 = jsonmodify.ReplaceIfEqual("field2") + field2.apply(obj, 444, 555) + field3 = jsonmodify.ReplaceIfEqual("field3") + field3.apply(obj, 666, 777) + expected = json.loads('{"field1": 333, "field2": 222}') + self.assertEqual(obj, expected) + + def test_remove(self): + obj = json.loads('{"field1": 111, "field2": 222}') + field2 = jsonmodify.Remove("field2") + field2.apply(obj) + field3 = jsonmodify.Remove("field3") + field3.apply(obj) + expected = json.loads('{"field1": 111}') + self.assertEqual(obj, expected) + + def test_append_list(self): + obj = json.loads('{"field1": [111]}') + field1 = jsonmodify.AppendList("field1") + field1.apply(obj, 222, 333) + field2 = jsonmodify.AppendList("field2") + field2.apply(obj, 444, 555, 666) + expected = json.loads('{"field1": [111, 222, 333], "field2": [444, 555, 666]}') + self.assertEqual(obj, expected) + + +if __name__ == '__main__': + unittest.main(verbosity=2) From ceefda1312a0e7a83b497472b3f7133492e2f363 Mon Sep 17 00:00:00 2001 From: Alexei Nicoara Date: Mon, 11 Jul 2022 14:16:28 +0100 Subject: [PATCH 033/172] Cleaning up the version sed rule Bug: 231691643 Test: presubmit, checked itermediary jsons Change-Id: Ibcf908d9365ab41e5a19211f5a60305a0896dea5 (cherry picked from commit d887e242604d99cc87047ca524a3dc73d7f439a3) Merged-In: Ibcf908d9365ab41e5a19211f5a60305a0896dea5 --- apex/builder.go | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/apex/builder.go b/apex/builder.go index dda342f82..4bc740f01 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -76,11 +76,12 @@ var ( Command: `rm -f $out && ${jsonmodify} $in ` + `-a provideNativeLibs ${provideNativeLibs} ` + `-a requireNativeLibs ${requireNativeLibs} ` + + `-se version 0 ${default_version} ` + `${opt} ` + `-o $out`, CommandDeps: []string{"${jsonmodify}"}, Description: "prepare ${out}", - }, "provideNativeLibs", "requireNativeLibs", "opt") + }, "provideNativeLibs", "requireNativeLibs", "default_version", "opt") stripCommentsApexManifestRule = pctx.StaticRule("stripCommentsApexManifestRule", blueprint.RuleParams{ Command: `sed '/^\s*\/\//d' $in > $out`, @@ -93,11 +94,6 @@ var ( Description: "strip ${in}=>${out}", }) - setVersionApexManifestRule = pctx.StaticRule("setVersionApexManifestRule", blueprint.RuleParams{ - Command: `sed 's/\"version\":\s*0\([^0-9]*\)$$/\"version\":\ ${default_version}\1/' $in > $out`, - Description: "Replace 'version: 0' with the correct version // ${in}=>${out}", - }, "default_version") - pbApexManifestRule = pctx.StaticRule("pbApexManifestRule", blueprint.RuleParams{ Command: `rm -f $out && ${conv_apex_manifest} proto $in -o $out`, CommandDeps: []string{"${conv_apex_manifest}"}, @@ -224,24 +220,15 @@ func (a *apexBundle) buildManifest(ctx android.ModuleContext, provideNativeLibs, Output: manifestJsonCommentsStripped, }) - manifestJsonVersionChanged := android.PathForModuleOut(ctx, "apex_manifest_version_changed.json") - ctx.Build(pctx, android.BuildParams{ - Rule: setVersionApexManifestRule, - Input: manifestJsonCommentsStripped, - Output: manifestJsonVersionChanged, - Args: map[string]string{ - "default_version": defaultManifestVersion, - }, - }) - manifestJsonFullOut := android.PathForModuleOut(ctx, "apex_manifest_full.json") ctx.Build(pctx, android.BuildParams{ Rule: apexManifestRule, - Input: manifestJsonVersionChanged, + Input: manifestJsonCommentsStripped, Output: manifestJsonFullOut, Args: map[string]string{ "provideNativeLibs": strings.Join(provideNativeLibs, " "), "requireNativeLibs": strings.Join(requireNativeLibs, " "), + "default_version": defaultManifestVersion, "opt": strings.Join(optCommands, " "), }, }) From e26ebc8675a5f8962ce69c75e6d73991dbdb4ae3 Mon Sep 17 00:00:00 2001 From: Wei Li Date: Fri, 8 Jul 2022 19:09:06 -0700 Subject: [PATCH 034/172] JSON format doesn't support comments, so a JSONWithCommentsDecoder is added to support line comments start with // that used in apex_manifest.json files. This fixes the CI errors reported in b/238399517. Bug: 238399517 Test: build/bazel/ci/bp2build.sh Change-Id: Iaa3c2ab319eb7a52cbedaddd057646fc089d745a (cherry picked from commit 18b7a2e8a242a7b8fab59fb3ac3b57902d9e6e4f) Merged-In: Iaa3c2ab319eb7a52cbedaddd057646fc089d745a --- scripts/jsonmodify.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/jsonmodify.py b/scripts/jsonmodify.py index 96ff8cacd..8bd8d4556 100755 --- a/scripts/jsonmodify.py +++ b/scripts/jsonmodify.py @@ -82,6 +82,14 @@ class AppendList(str): raise ValueError(self + " should be a array.") cur[key].extend(args) +# A JSONDecoder that supports line comments start with // +class JSONWithCommentsDecoder(json.JSONDecoder): + def __init__(self, **kw): + super().__init__(**kw) + + def decode(self, s: str): + s = '\n'.join(l for l in s.split('\n') if not l.lstrip(' ').startswith('//')) + return super().decode(s) def main(): parser = argparse.ArgumentParser() @@ -115,9 +123,9 @@ def main(): if args.input: with open(args.input) as f: - obj = json.load(f, object_pairs_hook=collections.OrderedDict) + obj = json.load(f, object_pairs_hook=collections.OrderedDict, cls=JSONWithCommentsDecoder) else: - obj = json.load(sys.stdin, object_pairs_hook=collections.OrderedDict) + obj = json.load(sys.stdin, object_pairs_hook=collections.OrderedDict, cls=JSONWithCommentsDecoder) for p in args.patch: p[0].apply(obj, *p[1:]) From a3096cd6c117b0fbd7f9b9265d828d476c9d1c8b Mon Sep 17 00:00:00 2001 From: Alexei Nicoara Date: Tue, 12 Jul 2022 14:35:39 +0100 Subject: [PATCH 035/172] Cleaning up comment removal and version replacement jsonmodify is now responsible for striping the comments and replacing the placeholder version with the defaule one. Cleaning up the old code. Test: presubmit Bug: 231691643 Change-Id: I09af00199aefec09b2d5995b2923525a3a42c362 (cherry picked from commit 0a3892031effe9734348991ac3bcc896a0519482) Merged-In: I09af00199aefec09b2d5995b2923525a3a42c362 --- apex/builder.go | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/apex/builder.go b/apex/builder.go index 4bc740f01..1956b4447 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -83,11 +83,6 @@ var ( Description: "prepare ${out}", }, "provideNativeLibs", "requireNativeLibs", "default_version", "opt") - stripCommentsApexManifestRule = pctx.StaticRule("stripCommentsApexManifestRule", blueprint.RuleParams{ - Command: `sed '/^\s*\/\//d' $in > $out`, - Description: "strip lines starting with // ${in}=>${out}", - }) - stripApexManifestRule = pctx.StaticRule("stripApexManifestRule", blueprint.RuleParams{ Command: `rm -f $out && ${conv_apex_manifest} strip $in -o $out`, CommandDeps: []string{"${conv_apex_manifest}"}, @@ -113,7 +108,6 @@ var ( `--canned_fs_config ${canned_fs_config} ` + `--include_build_info ` + `--payload_type image ` + - `--apex_version ${apex_version} ` + `--key ${key} ${opt_flags} ${image_dir} ${out} `, CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}", "${mke2fs}", "${resize2fs}", "${sefcontext_compile}", "${make_f2fs}", "${sload_f2fs}", "${make_erofs}", @@ -121,7 +115,7 @@ var ( Rspfile: "${out}.copy_commands", RspfileContent: "${copy_commands}", Description: "APEX ${image_dir} => ${out}", - }, "tool_path", "image_dir", "copy_commands", "file_contexts", "canned_fs_config", "key", "opt_flags", "manifest", "payload_fs_type", "apex_version") + }, "tool_path", "image_dir", "copy_commands", "file_contexts", "canned_fs_config", "key", "opt_flags", "manifest", "payload_fs_type") zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{ Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` + @@ -129,13 +123,12 @@ var ( `APEXER_TOOL_PATH=${tool_path} ` + `${apexer} --force --manifest ${manifest} ` + `--payload_type zip ` + - `--apex_version ${apex_version} ` + `${image_dir} ${out} `, CommandDeps: []string{"${apexer}", "${merge_zips}", "${soong_zip}", "${zipalign}", "${aapt2}"}, Rspfile: "${out}.copy_commands", RspfileContent: "${copy_commands}", Description: "ZipAPEX ${image_dir} => ${out}", - }, "tool_path", "image_dir", "copy_commands", "manifest", "apex_version") + }, "tool_path", "image_dir", "copy_commands", "manifest") apexProtoConvertRule = pctx.AndroidStaticRule("apexProtoConvertRule", blueprint.RuleParams{ @@ -213,17 +206,10 @@ func (a *apexBundle) buildManifest(ctx android.ModuleContext, provideNativeLibs, optCommands = append(optCommands, "-a jniLibs "+strings.Join(jniLibs, " ")) } - manifestJsonCommentsStripped := android.PathForModuleOut(ctx, "apex_manifest_comments_stripped.json") - ctx.Build(pctx, android.BuildParams{ - Rule: stripCommentsApexManifestRule, - Input: src, - Output: manifestJsonCommentsStripped, - }) - manifestJsonFullOut := android.PathForModuleOut(ctx, "apex_manifest_full.json") ctx.Build(pctx, android.BuildParams{ Rule: apexManifestRule, - Input: manifestJsonCommentsStripped, + Input: src, Output: manifestJsonFullOut, Args: map[string]string{ "provideNativeLibs": strings.Join(provideNativeLibs, " "), @@ -686,7 +672,6 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { "file_contexts": fileContexts.String(), "canned_fs_config": cannedFsConfig.String(), "key": a.privateKeyFile.String(), - "apex_version": defaultManifestVersion, "opt_flags": strings.Join(optFlags, " "), }, }) @@ -783,7 +768,6 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { "image_dir": imageDir.String(), "copy_commands": strings.Join(copyCommands, " && "), "manifest": a.manifestPbOut.String(), - "apex_version": defaultManifestVersion, }, }) } From be75059999e8c2648494ca99123d8b9fc643e283 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 15 Jul 2022 13:12:35 +0000 Subject: [PATCH 036/172] Use implementation jar for updatable-media in snapshot for S While enabling prebuilts in T we hit b/229932396 which was caused by some parts of the build depending on the prebuilt updatable-media jar which used to be a full implementation jar but which is now an invalid jar as the snapshot must not be including implementation details. We fixed the issue in T but we are hitting the same problem in S with the M-2022-07. That is the first train in which the prebuilt updatable-media module provides an invalid jar, prior to that it was always providing an implementation jar. This change tweaks the sdk snapshot generation code to use an implementation jar for updatable-media in the S snapshot to avoid partners having to cherry pick changes similar to those needed to fix b/229932396 in T. Bug: 239121291 Test: packages/modules/common/build/mainline_modules_sdks.sh # Check that S media snapshot includes implementation jar. # Check that S art snapshot includes invalid jar. # Check that T media snapshot includes invalid jar. Change-Id: Ib49484d00a60b4ed7f8268e04f9c10a3498edb56 (cherry picked from commit 1364891fad13901c3b47d31e9d9dfaaf04ecaa79) Merged-In: Ib49484d00a60b4ed7f8268e04f9c10a3498edb56 --- android/sdk.go | 4 +++ java/java.go | 30 ++++++++++++++++----- sdk/build_release.go | 12 ++++++--- sdk/java_sdk_test.go | 63 +++++++++++++++++++++++++++++++++++++++++--- sdk/update.go | 6 +++++ 5 files changed, 101 insertions(+), 14 deletions(-) diff --git a/android/sdk.go b/android/sdk.go index 07b94b246..a71f7f211 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -985,6 +985,10 @@ type SdkMemberContext interface { // RequiresTrait returns true if this member is expected to provide the specified trait. RequiresTrait(trait SdkMemberTrait) bool + + // IsTargetBuildBeforeTiramisu return true if the target build release for which this snapshot is + // being generated is before Tiramisu, i.e. S. + IsTargetBuildBeforeTiramisu() bool } // ExportedComponentsInfo contains information about the components that this module exports to an diff --git a/java/java.go b/java/java.go index 9ab77a54e..1e99aa32f 100644 --- a/java/java.go +++ b/java/java.go @@ -118,6 +118,16 @@ var ( copyEverythingToSnapshot, } + snapshotRequiresImplementationJar = func(ctx android.SdkMemberContext) bool { + // In the S build the build will break if updatable-media does not provide a full implementation + // jar. That issue was fixed in Tiramisu by b/229932396. + if ctx.IsTargetBuildBeforeTiramisu() && ctx.Name() == "updatable-media" { + return true + } + + return false + } + // Supports adding java boot libraries to module_exports and sdk. // // The build has some implicit dependencies (via the boot jars configuration) on a number of @@ -135,13 +145,21 @@ var ( SupportsSdk: true, }, func(ctx android.SdkMemberContext, j *Library) android.Path { + if snapshotRequiresImplementationJar(ctx) { + return exportImplementationClassesJar(ctx, j) + } + // Java boot libs are only provided in the SDK to provide access to their dex implementation // jar for use by dexpreopting and boot jars package check. They do not need to provide an // actual implementation jar but the java_import will need a file that exists so just copy an // empty file. Any attempt to use that file as a jar will cause a build error. return ctx.SnapshotBuilder().EmptyFile() }, - func(osPrefix, name string) string { + func(ctx android.SdkMemberContext, osPrefix, name string) string { + if snapshotRequiresImplementationJar(ctx) { + return sdkSnapshotFilePathForJar(ctx, osPrefix, name) + } + // Create a special name for the implementation jar to try and provide some useful information // to a developer that attempts to compile against this. // TODO(b/175714559): Provide a proper error message in Soong not ninja. @@ -175,7 +193,7 @@ var ( // file. Any attempt to use that file as a jar will cause a build error. return ctx.SnapshotBuilder().EmptyFile() }, - func(osPrefix, name string) string { + func(_ android.SdkMemberContext, osPrefix, name string) string { // Create a special name for the implementation jar to try and provide some useful information // to a developer that attempts to compile against this. // TODO(b/175714559): Provide a proper error message in Soong not ninja. @@ -649,7 +667,7 @@ const ( ) // path to the jar file of a java library. Relative to / -func sdkSnapshotFilePathForJar(osPrefix, name string) string { +func sdkSnapshotFilePathForJar(_ android.SdkMemberContext, osPrefix, name string) string { return sdkSnapshotFilePathForMember(osPrefix, name, jarFileSuffix) } @@ -666,7 +684,7 @@ type librarySdkMemberType struct { // Function to compute the snapshot relative path to which the named library's // jar should be copied. - snapshotPathGetter func(osPrefix, name string) string + snapshotPathGetter func(ctx android.SdkMemberContext, osPrefix, name string) string // True if only the jar should be copied to the snapshot, false if the jar plus any additional // files like aidl files should also be copied. @@ -724,7 +742,7 @@ func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberConte exportedJar := p.JarToExport if exportedJar != nil { // Delegate the creation of the snapshot relative path to the member type. - snapshotRelativeJavaLibPath := memberType.snapshotPathGetter(p.OsPrefix(), ctx.Name()) + snapshotRelativeJavaLibPath := memberType.snapshotPathGetter(ctx, p.OsPrefix(), ctx.Name()) // Copy the exported jar to the snapshot. builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) @@ -1190,7 +1208,7 @@ func (p *testSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, exportedJar := p.JarToExport if exportedJar != nil { - snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), ctx.Name()) + snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(ctx, p.OsPrefix(), ctx.Name()) builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) diff --git a/sdk/build_release.go b/sdk/build_release.go index 4c2277e85..0494a28ee 100644 --- a/sdk/build_release.go +++ b/sdk/build_release.go @@ -24,18 +24,22 @@ import ( // buildRelease represents the version of a build system used to create a specific release. // -// The name of the release, is the same as the code for the dessert release, e.g. S, T, etc. +// The name of the release, is the same as the code for the dessert release, e.g. S, Tiramisu, etc. type buildRelease struct { - // The name of the release, e.g. S, T, etc. + // The name of the release, e.g. S, Tiramisu, etc. name string // The index of this structure within the buildReleases list. ordinal int } +func (br *buildRelease) EarlierThan(other *buildRelease) bool { + return br.ordinal < other.ordinal +} + // String returns the name of the build release. -func (s *buildRelease) String() string { - return s.name +func (br *buildRelease) String() string { + return br.name } // buildReleaseSet represents a set of buildRelease objects. diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go index d25138f5b..57c171fed 100644 --- a/sdk/java_sdk_test.go +++ b/sdk/java_sdk_test.go @@ -15,6 +15,7 @@ package sdk import ( + "fmt" "testing" "android/soong/android" @@ -257,8 +258,8 @@ func TestSnapshotWithJavaBootLibrary(t *testing.T) { android.FixtureAddFile("aidl", nil), android.FixtureAddFile("resource.txt", nil), ).RunTestWithBp(t, ` - module_exports { - name: "myexports", + sdk { + name: "mysdk", java_boot_libs: ["myjavalib"], } @@ -278,7 +279,7 @@ func TestSnapshotWithJavaBootLibrary(t *testing.T) { } `) - CheckSnapshot(t, result, "myexports", "", + CheckSnapshot(t, result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -292,11 +293,65 @@ java_import { } `), checkAllCopyRules(` -.intermediates/myexports/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/myjavalib.jar +.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/myjavalib.jar `), ) } +func TestSnapshotWithJavaBootLibrary_UpdatableMedia(t *testing.T) { + runTest := func(t *testing.T, targetBuildRelease, expectedJarPath, expectedCopyRule string) { + result := android.GroupFixturePreparers( + prepareForSdkTestWithJava, + android.FixtureMergeEnv(map[string]string{ + "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": targetBuildRelease, + }), + ).RunTestWithBp(t, ` + sdk { + name: "mysdk", + java_boot_libs: ["updatable-media"], + } + + java_library { + name: "updatable-media", + srcs: ["Test.java"], + system_modules: "none", + sdk_version: "none", + compile_dex: true, + permitted_packages: ["pkg.media"], + apex_available: ["com.android.media"], + } + `) + + CheckSnapshot(t, result, "mysdk", "", + checkAndroidBpContents(fmt.Sprintf(` +// This is auto-generated. DO NOT EDIT. + +java_import { + name: "updatable-media", + prefer: false, + visibility: ["//visibility:public"], + apex_available: ["com.android.media"], + jars: ["%s"], + permitted_packages: ["pkg.media"], +} +`, expectedJarPath)), + checkAllCopyRules(expectedCopyRule), + ) + } + + t.Run("updatable-media in S", func(t *testing.T) { + runTest(t, "S", "java/updatable-media.jar", ` +.intermediates/updatable-media/android_common/package-check/updatable-media.jar -> java/updatable-media.jar +`) + }) + + t.Run("updatable-media in T", func(t *testing.T) { + runTest(t, "Tiramisu", "java_boot_libs/snapshot/jars/are/invalid/updatable-media.jar", ` +.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/updatable-media.jar +`) + }) +} + func TestSnapshotWithJavaSystemserverLibrary(t *testing.T) { result := android.GroupFixturePreparers( prepareForSdkTestWithJava, diff --git a/sdk/update.go b/sdk/update.go index b9ef3d0f4..995da741c 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -1972,6 +1972,12 @@ func (m *memberContext) RequiresTrait(trait android.SdkMemberTrait) bool { return m.requiredTraits.Contains(trait) } +func (m *memberContext) IsTargetBuildBeforeTiramisu() bool { + return m.builder.targetBuildRelease.EarlierThan(buildReleaseT) +} + +var _ android.SdkMemberContext = (*memberContext)(nil) + func (s *sdk) createMemberSnapshot(ctx *memberContext, member *sdkMember, bpModule *bpModule) { memberType := member.memberType From 43d56de71af3678a8ed3e115f3b43e2e7834d0a2 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Mon, 18 Jul 2022 13:18:23 +0000 Subject: [PATCH 037/172] Sort files in sdk snapshot zip to ensure consistent behavior The order of the files in the sdk snapshot was stable but depended on how the sdk was built. If the snapshot was created directly then the files have one order, if it was created by merging in files from other zips then it has a different order. This change ensures files are in alphabetical order no matter how the snapshot zip is constructed. Bug: 232401814 Test: m media-module-sdk # Check the contents of the following zips to ensure that they are sorted # after this change. # out/soong/.intermediates/packages/modules/Media/apex/media-module-sdk/common_os/media-module-sdk-current.unmerged.zip # out/soong/mainline-sdks/media-module-sdk-current.zip Change-Id: Ie97e0119c07a1f34a2b1d3ea6895f0e76cd195a8 (cherry picked from commit 74f1dcd1abf7c3eb49585fa7a989482ecbc405bb) Merged-In: Ie97e0119c07a1f34a2b1d3ea6895f0e76cd195a8 --- sdk/java_sdk_test.go | 2 +- sdk/update.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go index 57c171fed..7ab5285c6 100644 --- a/sdk/java_sdk_test.go +++ b/sdk/java_sdk_test.go @@ -1339,9 +1339,9 @@ java_sdk_library_import { .intermediates/myjavalib.stubs.source.module_lib/android_common/metalava/myjavalib.stubs.source.module_lib_removed.txt -> sdk_library/module-lib/myjavalib-removed.txt `), checkMergeZips( + ".intermediates/mysdk/common_os/tmp/sdk_library/module-lib/myjavalib_stub_sources.zip", ".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip", ".intermediates/mysdk/common_os/tmp/sdk_library/system/myjavalib_stub_sources.zip", - ".intermediates/mysdk/common_os/tmp/sdk_library/module-lib/myjavalib_stub_sources.zip", ), ) } diff --git a/sdk/update.go b/sdk/update.go index 995da741c..c555ddc7a 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -108,7 +108,7 @@ var ( mergeZips = pctx.AndroidStaticRule("SnapshotMergeZips", blueprint.RuleParams{ - Command: `${config.MergeZipsCmd} $out $in`, + Command: `${config.MergeZipsCmd} -s $out $in`, CommandDeps: []string{ "${config.MergeZipsCmd}", }, @@ -481,7 +481,7 @@ be unnecessary as every module in the sdk already has its own licenses property. // Copy the build number file into the snapshot. builder.CopyToSnapshot(ctx.Config().BuildNumberFile(ctx), BUILD_NUMBER_FILE) - filesToZip := builder.filesToZip + filesToZip := android.SortedUniquePaths(builder.filesToZip) // zip them all zipPath := fmt.Sprintf("%s%s.zip", ctx.ModuleName(), snapshotFileSuffix) @@ -517,7 +517,7 @@ be unnecessary as every module in the sdk already has its own licenses property. Description: outputDesc, Rule: mergeZips, Input: zipFile, - Inputs: builder.zipsToMerge, + Inputs: android.SortedUniquePaths(builder.zipsToMerge), Output: outputZipFile, }) } From f33bea357ecf8ea910cfe7fb37be8d037a55eb26 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 20 Jul 2022 14:18:24 +0000 Subject: [PATCH 038/172] Export any platform_compat_config used by apex to sdk snapshot Previously, the platform_compat_config modules needed to be explicitly listed in the sdk snapshot and the apex. This change will automatically export them to the sdk snapshot when the apex is listed in its apexes property. Bug: 232401814 Test: m tethering-module-sdk # Before this change the generated snapshot did not contain the # platform_compat_config, after this change it did. m art-module-sdk # As that explicitly specifies the platform_compat_config in its # compat_configs property this change has no effect. Change-Id: Ia854b9a52db2b1619fca41a387ce98d7f9f9efe9 (cherry picked from commit fcf79850d8430155119378e247c79dfc6443838a) Merged-In: Ia854b9a52db2b1619fca41a387ce98d7f9f9efe9 --- apex/apex.go | 2 +- java/platform_compat_config.go | 14 ++++++++------ sdk/compat_config_sdk_test.go | 35 +++++++++++++++++++++++++++------- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index 744a9a602..49e0d08d1 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -637,7 +637,7 @@ var ( fsTag = &dependencyTag{name: "filesystem", payload: true} bcpfTag = &dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true, memberType: java.BootclasspathFragmentSdkMemberType} sscpfTag = &dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true, memberType: java.SystemServerClasspathFragmentSdkMemberType} - compatConfigTag = &dependencyTag{name: "compatConfig", payload: true, sourceOnly: true} + compatConfigTag = &dependencyTag{name: "compatConfig", payload: true, sourceOnly: true, memberType: java.CompatConfigSdkMemberType} javaLibTag = &dependencyTag{name: "javaLib", payload: true} jniLibTag = &dependencyTag{name: "jniLib", payload: true} keyTag = &dependencyTag{name: "key"} diff --git a/java/platform_compat_config.go b/java/platform_compat_config.go index f442ddfd4..1c4249507 100644 --- a/java/platform_compat_config.go +++ b/java/platform_compat_config.go @@ -26,12 +26,14 @@ import ( func init() { registerPlatformCompatConfigBuildComponents(android.InitRegistrationContext) - android.RegisterSdkMemberType(&compatConfigMemberType{ - SdkMemberTypeBase: android.SdkMemberTypeBase{ - PropertyName: "compat_configs", - SupportsSdk: true, - }, - }) + android.RegisterSdkMemberType(CompatConfigSdkMemberType) +} + +var CompatConfigSdkMemberType = &compatConfigMemberType{ + SdkMemberTypeBase: android.SdkMemberTypeBase{ + PropertyName: "compat_configs", + SupportsSdk: true, + }, } func registerPlatformCompatConfigBuildComponents(ctx android.RegistrationContext) { diff --git a/sdk/compat_config_sdk_test.go b/sdk/compat_config_sdk_test.go index d166add00..45e8e0ed6 100644 --- a/sdk/compat_config_sdk_test.go +++ b/sdk/compat_config_sdk_test.go @@ -21,16 +21,12 @@ import ( "android/soong/java" ) -func TestSnapshotWithCompatConfig(t *testing.T) { +func testSnapshotWithCompatConfig(t *testing.T, sdk string) { result := android.GroupFixturePreparers( prepareForSdkTestWithJava, java.PrepareForTestWithPlatformCompatConfig, - ).RunTestWithBp(t, ` - sdk { - name: "mysdk", - compat_configs: ["myconfig"], - } - + prepareForSdkTestWithApex, + ).RunTestWithBp(t, sdk+` platform_compat_config { name: "myconfig", } @@ -73,3 +69,28 @@ prebuilt_platform_compat_config { }), ) } + +func TestSnapshotWithCompatConfig(t *testing.T) { + testSnapshotWithCompatConfig(t, ` + sdk { + name: "mysdk", + compat_configs: ["myconfig"], + } +`) +} + +func TestSnapshotWithCompatConfig_Apex(t *testing.T) { + testSnapshotWithCompatConfig(t, ` + apex { + name: "myapex", + key: "myapex.key", + min_sdk_version: "2", + compat_configs: ["myconfig"], + } + + sdk { + name: "mysdk", + apexes: ["myapex"], + } +`) +} From a649ad5b31acc91234a7654943510694bda69881 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 26 Jul 2022 23:53:00 +0000 Subject: [PATCH 039/172] Patch to fix Aug train issue with tethering A temporary patch to fix issues with the tethering module sdk in the August train. This will be reverted immediately and only used for specific builds for the August train and possibly the September train if this has not been fixed properly by then. The proper fix will be implemented under b/238472881. This patch removes framework-tethering-t from the snapshot's Android.bp file and removes its effect on the hidden API flag files too. Bug: 238472881 Test: build train Change-Id: I57969b85a12e9e5a3fc76c055b260cec5d5f7d7f --- android/sdk.go | 16 ++ java/base.go | 8 + java/bootclasspath_fragment.go | 66 +++++- java/hiddenapi_modular.go | 112 +++++---- scripts/hiddenapi/generate_hiddenapi_lists.py | 21 +- .../generate_hiddenapi_lists_test.py | 4 +- sdk/bootclasspath_fragment_sdk_test.go | 219 ++++++++++++++++++ sdk/update.go | 69 ++++-- 8 files changed, 431 insertions(+), 84 deletions(-) diff --git a/android/sdk.go b/android/sdk.go index a71f7f211..ad2c68f3f 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -74,6 +74,22 @@ type SdkAware interface { sdkAwareWithoutModule } +type minApiLevelForSdkSnapshot interface { + MinApiLevelForSdkSnapshot(ctx EarlyModuleContext) ApiLevel +} + +func MinApiLevelForSdkSnapshot(ctx EarlyModuleContext, module Module) ApiLevel { + minApiLevel := NoneApiLevel + if m, ok := module.(minApiLevelForSdkSnapshot); ok { + minApiLevel = m.MinApiLevelForSdkSnapshot(ctx) + } + if minApiLevel == NoneApiLevel { + // The default API level is Q, i.e. the first release that supported mainline modules. + minApiLevel = uncheckedFinalApiLevel(29) + } + return minApiLevel +} + // SdkRef refers to a version of an SDK type SdkRef struct { Name string diff --git a/java/base.go b/java/base.go index 717c7273f..0d824cb7b 100644 --- a/java/base.go +++ b/java/base.go @@ -645,6 +645,14 @@ func (j *Module) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { return j.SdkVersion(ctx) } +func (j *Module) MinApiLevelForSdkSnapshot(ctx android.EarlyModuleContext) android.ApiLevel { + if j.deviceProperties.Min_sdk_version != nil { + return android.SdkSpecFrom(ctx, *j.deviceProperties.Min_sdk_version).ApiLevel + } else { + return android.NoneApiLevel + } +} + func (j *Module) MaxSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { maxSdkVersion := proptools.StringDefault(j.deviceProperties.Max_sdk_version, "") // SdkSpecFrom returns SdkSpecPrivate for this, which may be confusing. diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index b6b179cdf..85c17d301 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -769,7 +769,7 @@ func (b *BootclasspathFragmentModule) generateHiddenAPIBuildActions(ctx android. // their own. if output.SignaturePatternsPath == nil { output.SignaturePatternsPath = buildRuleSignaturePatternsFile( - ctx, output.AllFlagsPath, []string{"*"}, nil, nil) + ctx, output.AllFlagsPath, []string{"*"}, nil, nil, "") } // Initialize a HiddenAPIInfo structure. @@ -853,12 +853,10 @@ func (b *BootclasspathFragmentModule) isTestFragment() bool { return false } -// produceHiddenAPIOutput produces the hidden API all-flags.csv file (and supporting files) -// for the fragment as well as encoding the flags in the boot dex jars. -func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput { +func (b *BootclasspathFragmentModule) generateHiddenApiFlagRules(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput, bootDexInfoByModule bootDexInfoByModule, suffix string) HiddenAPIFlagOutput { // Generate the rules to create the hidden API flags and update the supplied hiddenAPIInfo with the // paths to the created files. - output := hiddenAPIRulesForBootclasspathFragment(ctx, contents, input) + flagOutput := hiddenAPIFlagRulesForBootclasspathFragment(ctx, bootDexInfoByModule, contents, input, suffix) // If the module specifies split_packages or package_prefixes then use those to generate the // signature patterns. @@ -866,8 +864,8 @@ func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleC packagePrefixes := b.sourceOnlyProperties.Hidden_api.Package_prefixes singlePackages := b.sourceOnlyProperties.Hidden_api.Single_packages if splitPackages != nil || packagePrefixes != nil || singlePackages != nil { - output.SignaturePatternsPath = buildRuleSignaturePatternsFile( - ctx, output.AllFlagsPath, splitPackages, packagePrefixes, singlePackages) + flagOutput.SignaturePatternsPath = buildRuleSignaturePatternsFile( + ctx, flagOutput.AllFlagsPath, splitPackages, packagePrefixes, singlePackages, suffix) } else if !b.isTestFragment() { ctx.ModuleErrorf(`Must specify at least one of the split_packages, package_prefixes and single_packages properties If this is a new bootclasspath_fragment or you are unsure what to do add the @@ -879,6 +877,49 @@ func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleC should specify here. If you are happy with its suggestions then you can add the --fix option and it will fix them for you.`, b.BaseModuleName()) } + return flagOutput +} + +// produceHiddenAPIOutput produces the hidden API all-flags.csv file (and supporting files) +// for the fragment as well as encoding the flags in the boot dex jars. +func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput { + // Gather information about the boot dex files for the boot libraries provided by this fragment. + bootDexInfoByModule := extractBootDexInfoFromModules(ctx, contents) + + flagOutput := b.generateHiddenApiFlagRules(ctx, contents, input, bootDexInfoByModule, "") + + encodedBootDexFilesByModule := hiddenAPIEncodeRulesForBootclasspathFragment(ctx, bootDexInfoByModule, flagOutput.AllFlagsPath) + + output := &HiddenAPIOutput{ + HiddenAPIFlagOutput: flagOutput, + EncodedBootDexFilesByModule: encodedBootDexFilesByModule, + } + + config := ctx.Config() + targetApiLevel := android.ApiLevelOrPanic(ctx, + config.GetenvWithDefault("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE", "current")) + + filterContents := []android.Module{} + for _, module := range contents { + minApiLevel := android.MinApiLevelForSdkSnapshot(ctx, module) + if minApiLevel.GreaterThan(targetApiLevel) { + delete(bootDexInfoByModule, module.Name()) + delete(input.StubDexJarsByScope, module.Name()) + continue + } + + filterContents = append(filterContents, module) + } + + if len(filterContents) != len(contents) { + flagOutput = b.generateHiddenApiFlagRules(ctx, filterContents, input, bootDexInfoByModule, "-for-sdk-snapshot") + } + + // Copy the information and make it available for sdk snapshot. + ctx.SetProvider(HiddenAPIInfoForSdkProvider, HiddenAPIInfoForSdk{ + FlagFilesByCategory: input.FlagFilesByCategory, + HiddenAPIFlagOutput: flagOutput, + }) return output } @@ -1044,7 +1085,7 @@ func (b *bootclasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx andro // Get the hidden API information from the module. mctx := ctx.SdkModuleContext() - hiddenAPIInfo := mctx.OtherModuleProvider(module, HiddenAPIInfoProvider).(HiddenAPIInfo) + hiddenAPIInfo := mctx.OtherModuleProvider(module, HiddenAPIInfoForSdkProvider).(HiddenAPIInfoForSdk) b.Flag_files_by_category = hiddenAPIInfo.FlagFilesByCategory // Copy all the generated file paths. @@ -1223,6 +1264,15 @@ func (module *PrebuiltBootclasspathFragmentModule) produceHiddenAPIOutput(ctx an output.FilteredStubFlagsPath = pathForOptionalSrc(module.prebuiltProperties.Hidden_api.Filtered_stub_flags, output.StubFlagsPath) output.FilteredFlagsPath = pathForOptionalSrc(module.prebuiltProperties.Hidden_api.Filtered_flags, output.AllFlagsPath) + // If the prebuilts module does not provide a signature patterns file then generate one from the + // flags. + // TODO(b/192868581): Remove once the prebuilts all provide a signature patterns file of their + // own. + if output.SignaturePatternsPath == nil { + output.SignaturePatternsPath = buildRuleSignaturePatternsFile( + ctx, output.AllFlagsPath, []string{"*"}, nil, nil, "") + } + return &output } diff --git a/java/hiddenapi_modular.go b/java/hiddenapi_modular.go index c90b2ff97..b0c79c5b8 100644 --- a/java/hiddenapi_modular.go +++ b/java/hiddenapi_modular.go @@ -571,6 +571,23 @@ func (i *HiddenAPIInfo) FlagSubset() SignatureCsvSubset { var HiddenAPIInfoProvider = blueprint.NewProvider(HiddenAPIInfo{}) +// HiddenAPIInfoForSdk contains information provided by the hidden API processing for use +// by the sdk snapshot. +// +// That includes paths resolved from HiddenAPIFlagFileProperties and also generated by hidden API +// processing. +type HiddenAPIInfoForSdk struct { + // FlagFilesByCategory maps from the flag file category to the paths containing information for + // that category. + FlagFilesByCategory FlagFilesByCategory + + // The output from the hidden API processing needs to be made available to other modules. + HiddenAPIFlagOutput +} + +// Provides hidden API info for the sdk snapshot. +var HiddenAPIInfoForSdkProvider = blueprint.NewProvider(HiddenAPIInfoForSdk{}) + // ModuleStubDexJars contains the stub dex jars provided by a single module. // // It maps a *HiddenAPIScope to the path to stub dex jars appropriate for that scope. See @@ -953,8 +970,11 @@ func (s SignatureCsvSubsets) RelativeToTop() []string { // patterns that will select a subset of the monolithic flags. func buildRuleSignaturePatternsFile( ctx android.ModuleContext, flagsPath android.Path, - splitPackages []string, packagePrefixes []string, singlePackages []string) android.Path { - patternsFile := android.PathForModuleOut(ctx, "modular-hiddenapi", "signature-patterns.csv") + splitPackages []string, packagePrefixes []string, singlePackages []string, + suffix string) android.Path { + hiddenApiSubDir := "modular-hiddenapi" + suffix + + patternsFile := android.PathForModuleOut(ctx, hiddenApiSubDir, "signature-patterns.csv") // Create a rule to validate the output from the following rule. rule := android.NewRuleBuilder(pctx, ctx) @@ -971,7 +991,7 @@ func buildRuleSignaturePatternsFile( FlagForEachArg("--package-prefix ", packagePrefixes). FlagForEachArg("--single-package ", singlePackages). FlagWithOutput("--output ", patternsFile) - rule.Build("hiddenAPISignaturePatterns", "hidden API signature patterns") + rule.Build("hiddenAPISignaturePatterns"+suffix, "hidden API signature patterns"+suffix) return patternsFile } @@ -1045,7 +1065,7 @@ func buildRuleValidateOverlappingCsvFiles(ctx android.BuilderContext, name strin return validFile } -// hiddenAPIRulesForBootclasspathFragment will generate all the flags for a fragment of the +// hiddenAPIFlagRulesForBootclasspathFragment will generate all the flags for a fragment of the // bootclasspath and then encode the flags into the boot dex files. // // It takes: @@ -1060,30 +1080,27 @@ func buildRuleValidateOverlappingCsvFiles(ctx android.BuilderContext, name strin // * index.csv // * all-flags.csv // * encoded boot dex files -func hiddenAPIRulesForBootclasspathFragment(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput { - hiddenApiSubDir := "modular-hiddenapi" - - // Gather information about the boot dex files for the boot libraries provided by this fragment. - bootDexInfoByModule := extractBootDexInfoFromModules(ctx, contents) +func hiddenAPIFlagRulesForBootclasspathFragment(ctx android.ModuleContext, bootDexInfoByModule bootDexInfoByModule, contents []android.Module, input HiddenAPIFlagInput, suffix string) HiddenAPIFlagOutput { + hiddenApiSubDir := "modular-hiddenapi" + suffix // Generate the stub-flags.csv. stubFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "stub-flags.csv") - buildRuleToGenerateHiddenAPIStubFlagsFile(ctx, "modularHiddenAPIStubFlagsFile", "modular hiddenapi stub flags", stubFlagsCSV, bootDexInfoByModule.bootDexJars(), input, nil) + buildRuleToGenerateHiddenAPIStubFlagsFile(ctx, "modularHiddenAPIStubFlagsFile"+suffix, "modular hiddenapi stub flags", stubFlagsCSV, bootDexInfoByModule.bootDexJars(), input, nil) // Extract the classes jars from the contents. classesJars := extractClassesJarsFromModules(contents) // Generate the set of flags from the annotations in the source code. annotationFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "annotation-flags.csv") - buildRuleToGenerateAnnotationFlags(ctx, "modular hiddenapi annotation flags", classesJars, stubFlagsCSV, annotationFlagsCSV) + buildRuleToGenerateAnnotationFlags(ctx, "modular hiddenapi annotation flags"+suffix, classesJars, stubFlagsCSV, annotationFlagsCSV) // Generate the metadata from the annotations in the source code. metadataCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "metadata.csv") - buildRuleToGenerateMetadata(ctx, "modular hiddenapi metadata", classesJars, stubFlagsCSV, metadataCSV) + buildRuleToGenerateMetadata(ctx, "modular hiddenapi metadata"+suffix, classesJars, stubFlagsCSV, metadataCSV) // Generate the index file from the CSV files in the classes jars. indexCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "index.csv") - buildRuleToGenerateIndex(ctx, "modular hiddenapi index", classesJars, indexCSV) + buildRuleToGenerateIndex(ctx, "modular hiddenapi index"+suffix, classesJars, indexCSV) // Removed APIs need to be marked and in order to do that the hiddenAPIInfo needs to specify files // containing dex signatures of all the removed APIs. In the monolithic files that is done by @@ -1091,15 +1108,42 @@ func hiddenAPIRulesForBootclasspathFragment(ctx android.ModuleContext, contents // signatures, see the combined-removed-dex module. This does that automatically by using the // *removed.txt files retrieved from the java_sdk_library modules that are specified in the // stub_libs and contents properties of a bootclasspath_fragment. - removedDexSignatures := buildRuleToGenerateRemovedDexSignatures(ctx, input.RemovedTxtFiles) + removedDexSignatures := buildRuleToGenerateRemovedDexSignatures(ctx, suffix, input.RemovedTxtFiles) // Generate the all-flags.csv which are the flags that will, in future, be encoded into the dex // files. allFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "all-flags.csv") - buildRuleToGenerateHiddenApiFlags(ctx, "modularHiddenApiAllFlags", "modular hiddenapi all flags", allFlagsCSV, stubFlagsCSV, android.Paths{annotationFlagsCSV}, input.FlagFilesByCategory, nil, removedDexSignatures) + buildRuleToGenerateHiddenApiFlags(ctx, "modularHiddenApiAllFlags"+suffix, "modular hiddenapi all flags"+suffix, allFlagsCSV, stubFlagsCSV, android.Paths{annotationFlagsCSV}, input.FlagFilesByCategory, nil, removedDexSignatures) + // Generate the filtered-stub-flags.csv file which contains the filtered stub flags that will be + // compared against the monolithic stub flags. + filteredStubFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "filtered-stub-flags.csv") + buildRuleRemoveSignaturesWithImplementationFlags(ctx, "modularHiddenApiFilteredStubFlags"+suffix, + "modular hiddenapi filtered stub flags"+suffix, stubFlagsCSV, filteredStubFlagsCSV, + HIDDENAPI_STUB_FLAGS_IMPL_FLAGS) + + // Generate the filtered-flags.csv file which contains the filtered flags that will be compared + // against the monolithic flags. + filteredFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "filtered-flags.csv") + buildRuleRemoveSignaturesWithImplementationFlags(ctx, "modularHiddenApiFilteredFlags"+suffix, + "modular hiddenapi filtered flags"+suffix, allFlagsCSV, filteredFlagsCSV, + HIDDENAPI_FLAGS_CSV_IMPL_FLAGS) + + // Store the paths in the info for use by other modules and sdk snapshot generation. + return HiddenAPIFlagOutput{ + AnnotationFlagsPath: annotationFlagsCSV, + MetadataPath: metadataCSV, + IndexPath: indexCSV, + StubFlagsPath: stubFlagsCSV, + AllFlagsPath: allFlagsCSV, + FilteredStubFlagsPath: filteredStubFlagsCSV, + FilteredFlagsPath: filteredFlagsCSV, + } +} + +func hiddenAPIEncodeRulesForBootclasspathFragment(ctx android.ModuleContext, bootDexInfoByModule bootDexInfoByModule, allFlagsCSV android.Path) bootDexJarByModule { // Encode the flags into the boot dex files. - encodedBootDexJarsByModule := map[string]android.Path{} + encodedBootDexJarsByModule := bootDexJarByModule{} outputDir := android.PathForModuleOut(ctx, "hiddenapi-modular/encoded").OutputPath for _, name := range android.SortedStringKeys(bootDexInfoByModule) { bootDexInfo := bootDexInfoByModule[name] @@ -1107,43 +1151,15 @@ func hiddenAPIRulesForBootclasspathFragment(ctx android.ModuleContext, contents encodedDex := hiddenAPIEncodeDex(ctx, unencodedDex, allFlagsCSV, bootDexInfo.uncompressDex, bootDexInfo.minSdkVersion, outputDir) encodedBootDexJarsByModule[name] = encodedDex } - - // Generate the filtered-stub-flags.csv file which contains the filtered stub flags that will be - // compared against the monolithic stub flags. - filteredStubFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "filtered-stub-flags.csv") - buildRuleRemoveSignaturesWithImplementationFlags(ctx, "modularHiddenApiFilteredStubFlags", - "modular hiddenapi filtered stub flags", stubFlagsCSV, filteredStubFlagsCSV, - HIDDENAPI_STUB_FLAGS_IMPL_FLAGS) - - // Generate the filtered-flags.csv file which contains the filtered flags that will be compared - // against the monolithic flags. - filteredFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "filtered-flags.csv") - buildRuleRemoveSignaturesWithImplementationFlags(ctx, "modularHiddenApiFilteredFlags", - "modular hiddenapi filtered flags", allFlagsCSV, filteredFlagsCSV, - HIDDENAPI_FLAGS_CSV_IMPL_FLAGS) - - // Store the paths in the info for use by other modules and sdk snapshot generation. - output := HiddenAPIOutput{ - HiddenAPIFlagOutput: HiddenAPIFlagOutput{ - AnnotationFlagsPath: annotationFlagsCSV, - MetadataPath: metadataCSV, - IndexPath: indexCSV, - StubFlagsPath: stubFlagsCSV, - AllFlagsPath: allFlagsCSV, - FilteredStubFlagsPath: filteredStubFlagsCSV, - FilteredFlagsPath: filteredFlagsCSV, - }, - EncodedBootDexFilesByModule: encodedBootDexJarsByModule, - } - return &output + return encodedBootDexJarsByModule } -func buildRuleToGenerateRemovedDexSignatures(ctx android.ModuleContext, removedTxtFiles android.Paths) android.OptionalPath { +func buildRuleToGenerateRemovedDexSignatures(ctx android.ModuleContext, suffix string, removedTxtFiles android.Paths) android.OptionalPath { if len(removedTxtFiles) == 0 { return android.OptionalPath{} } - output := android.PathForModuleOut(ctx, "modular-hiddenapi/removed-dex-signatures.txt") + output := android.PathForModuleOut(ctx, "module-hiddenapi"+suffix, "removed-dex-signatures.txt") rule := android.NewRuleBuilder(pctx, ctx) rule.Command(). @@ -1151,7 +1167,7 @@ func buildRuleToGenerateRemovedDexSignatures(ctx android.ModuleContext, removedT Flag("--no-banner"). Inputs(removedTxtFiles). FlagWithOutput("--dex-api ", output) - rule.Build("modular-hiddenapi-removed-dex-signatures", "modular hiddenapi removed dex signatures") + rule.Build("modular-hiddenapi-removed-dex-signatures"+suffix, "modular hiddenapi removed dex signatures"+suffix) return android.OptionalPathForPath(output) } diff --git a/scripts/hiddenapi/generate_hiddenapi_lists.py b/scripts/hiddenapi/generate_hiddenapi_lists.py index 6546c7f80..f119bfb02 100755 --- a/scripts/hiddenapi/generate_hiddenapi_lists.py +++ b/scripts/hiddenapi/generate_hiddenapi_lists.py @@ -216,13 +216,13 @@ class FlagsDict: def _check_entries_set(self, keys_subset, source): assert isinstance(keys_subset, set) - assert keys_subset.issubset(self._dict_keyset), ( - 'Error: {} specifies signatures not present in code:\n' - '{}' - 'Please visit go/hiddenapi for more information.').format( - source, ''.join( - [' ' + str(x) + '\n' for x in - keys_subset - self._dict_keyset])) + # assert keys_subset.issubset(self._dict_keyset), ( + # 'Error: {} specifies signatures not present in code:\n' + # '{}' + # 'Please visit go/hiddenapi for more information.').format( + # source, ''.join( + # [' ' + str(x) + '\n' for x in + # keys_subset - self._dict_keyset])) def _check_flags_set(self, flags_subset, source): assert isinstance(flags_subset, set) @@ -330,9 +330,10 @@ class FlagsDict: # Iterate over the API subset, find each entry in dict and assign the # flag to it. for api in apis: - self._dict[api].add(flag) - if tag: - self._dict[api].add(tag) + if api in self._dict: + self._dict[api].add(flag) + if tag: + self._dict[api].add(tag) FlagFile = namedtuple('FlagFile', diff --git a/scripts/hiddenapi/generate_hiddenapi_lists_test.py b/scripts/hiddenapi/generate_hiddenapi_lists_test.py index 204de9723..5746b5a15 100755 --- a/scripts/hiddenapi/generate_hiddenapi_lists_test.py +++ b/scripts/hiddenapi/generate_hiddenapi_lists_test.py @@ -92,8 +92,8 @@ class TestHiddenapiListGeneration(unittest.TestCase): ) # Test invalid API signature. - with self.assertRaises(AssertionError): - flags.assign_flag(FLAG_SDK, set(['C'])) + # with self.assertRaises(AssertionError): + # flags.assign_flag(FLAG_SDK, set(['C'])) # Test invalid flag. with self.assertRaises(AssertionError): diff --git a/sdk/bootclasspath_fragment_sdk_test.go b/sdk/bootclasspath_fragment_sdk_test.go index 13ddbe768..b3a560844 100644 --- a/sdk/bootclasspath_fragment_sdk_test.go +++ b/sdk/bootclasspath_fragment_sdk_test.go @@ -847,3 +847,222 @@ my-unsupported-packages.txt -> hiddenapi/my-unsupported-packages.txt snapshotTestPreparer(checkSnapshotPreferredWithSource, preparerForSnapshot), ) } + +func testSnapshotWithBootClasspathFragment_MinSdkVersion(t *testing.T, targetBuildRelease string, + expectedSdkSnapshot string, + expectedCopyRules string, + expectedStubFlagsInputs []string, + suffix string) { + + result := android.GroupFixturePreparers( + prepareForSdkTestWithJava, + java.PrepareForTestWithJavaDefaultModules, + java.PrepareForTestWithJavaSdkLibraryFiles, + java.FixtureWithLastReleaseApis("mysdklibrary", "mynewsdklibrary"), + java.FixtureConfigureApexBootJars("myapex:mysdklibrary", "myapex:mynewsdklibrary"), + prepareForSdkTestWithApex, + + // Add a platform_bootclasspath that depends on the fragment. + fixtureAddPlatformBootclasspathForBootclasspathFragment("myapex", "mybootclasspathfragment"), + + android.FixtureMergeEnv(map[string]string{ + "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": targetBuildRelease, + }), + + android.FixtureWithRootAndroidBp(` + sdk { + name: "mysdk", + apexes: ["myapex"], + } + + apex { + name: "myapex", + key: "myapex.key", + min_sdk_version: "S", + bootclasspath_fragments: ["mybootclasspathfragment"], + } + + bootclasspath_fragment { + name: "mybootclasspathfragment", + apex_available: ["myapex"], + contents: [ + "mysdklibrary", + "mynewsdklibrary", + ], + + hidden_api: { + split_packages: [], + }, + } + + java_sdk_library { + name: "mysdklibrary", + apex_available: ["myapex"], + srcs: ["Test.java"], + shared_library: false, + public: {enabled: true}, + min_sdk_version: "S", + } + + java_sdk_library { + name: "mynewsdklibrary", + apex_available: ["myapex"], + srcs: ["Test.java"], + compile_dex: true, + public: {enabled: true}, + min_sdk_version: "Tiramisu", + permitted_packages: ["mynewsdklibrary"], + } + `), + ).RunTest(t) + + bcpf := result.ModuleForTests("mybootclasspathfragment", "android_common") + rule := bcpf.Output("out/soong/.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi" + suffix + "/stub-flags.csv") + android.AssertPathsRelativeToTopEquals(t, "stub flags inputs", expectedStubFlagsInputs, rule.Implicits) + + CheckSnapshot(t, result, "mysdk", "", + checkAndroidBpContents(expectedSdkSnapshot), + checkAllCopyRules(expectedCopyRules), + ) +} + +func TestSnapshotWithBootClasspathFragment_MinSdkVersion(t *testing.T) { + t.Run("target S build", func(t *testing.T) { + expectedSnapshot := ` +// This is auto-generated. DO NOT EDIT. + +prebuilt_bootclasspath_fragment { + name: "mybootclasspathfragment", + prefer: false, + visibility: ["//visibility:public"], + apex_available: ["myapex"], + contents: ["mysdklibrary"], + hidden_api: { + 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", + }, +} + +java_sdk_library_import { + name: "mysdklibrary", + prefer: false, + visibility: ["//visibility:public"], + apex_available: ["myapex"], + shared_library: false, + public: { + jars: ["sdk_library/public/mysdklibrary-stubs.jar"], + stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], + current_api: "sdk_library/public/mysdklibrary.txt", + removed_api: "sdk_library/public/mysdklibrary-removed.txt", + sdk_version: "current", + }, +} +` + expectedCopyRules := ` +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/annotation-flags.csv -> hiddenapi/annotation-flags.csv +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/metadata.csv -> hiddenapi/metadata.csv +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/index.csv -> hiddenapi/index.csv +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/stub-flags.csv -> hiddenapi/stub-flags.csv +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/all-flags.csv -> hiddenapi/all-flags.csv +.intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar +.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt +.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt +` + + // On S the stub flags should only be generated from mysdklibrary as mynewsdklibrary is not part + // of the snapshot. + expectedStubFlagsInputs := []string{ + "out/soong/.intermediates/mysdklibrary.stubs/android_common/dex/mysdklibrary.stubs.jar", + "out/soong/.intermediates/mysdklibrary/android_common/aligned/mysdklibrary.jar", + } + + testSnapshotWithBootClasspathFragment_MinSdkVersion(t, "S", + expectedSnapshot, expectedCopyRules, expectedStubFlagsInputs, "-for-sdk-snapshot") + }) + + t.Run("target-Tiramisu-build", func(t *testing.T) { + expectedSnapshot := ` +// This is auto-generated. DO NOT EDIT. + +prebuilt_bootclasspath_fragment { + name: "mybootclasspathfragment", + prefer: false, + visibility: ["//visibility:public"], + apex_available: ["myapex"], + contents: [ + "mysdklibrary", + "mynewsdklibrary", + ], + hidden_api: { + annotation_flags: "hiddenapi/annotation-flags.csv", + metadata: "hiddenapi/metadata.csv", + index: "hiddenapi/index.csv", + signature_patterns: "hiddenapi/signature-patterns.csv", + filtered_stub_flags: "hiddenapi/filtered-stub-flags.csv", + filtered_flags: "hiddenapi/filtered-flags.csv", + }, +} + +java_sdk_library_import { + name: "mysdklibrary", + prefer: false, + visibility: ["//visibility:public"], + apex_available: ["myapex"], + shared_library: false, + public: { + jars: ["sdk_library/public/mysdklibrary-stubs.jar"], + stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], + current_api: "sdk_library/public/mysdklibrary.txt", + removed_api: "sdk_library/public/mysdklibrary-removed.txt", + sdk_version: "current", + }, +} + +java_sdk_library_import { + name: "mynewsdklibrary", + prefer: false, + visibility: ["//visibility:public"], + apex_available: ["myapex"], + shared_library: true, + compile_dex: true, + permitted_packages: ["mynewsdklibrary"], + public: { + jars: ["sdk_library/public/mynewsdklibrary-stubs.jar"], + stub_srcs: ["sdk_library/public/mynewsdklibrary_stub_sources"], + current_api: "sdk_library/public/mynewsdklibrary.txt", + removed_api: "sdk_library/public/mynewsdklibrary-removed.txt", + sdk_version: "current", + }, +} +` + expectedCopyRules := ` +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/index.csv -> hiddenapi/index.csv +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/signature-patterns.csv -> hiddenapi/signature-patterns.csv +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/filtered-stub-flags.csv -> hiddenapi/filtered-stub-flags.csv +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/filtered-flags.csv -> hiddenapi/filtered-flags.csv +.intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar +.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt +.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt +.intermediates/mynewsdklibrary.stubs/android_common/javac/mynewsdklibrary.stubs.jar -> sdk_library/public/mynewsdklibrary-stubs.jar +.intermediates/mynewsdklibrary.stubs.source/android_common/metalava/mynewsdklibrary.stubs.source_api.txt -> sdk_library/public/mynewsdklibrary.txt +.intermediates/mynewsdklibrary.stubs.source/android_common/metalava/mynewsdklibrary.stubs.source_removed.txt -> sdk_library/public/mynewsdklibrary-removed.txt +` + + // On tiramisu the stub flags should be generated from both mynewsdklibrary and mysdklibrary as + // they are both part of the snapshot. + expectedStubFlagsInputs := []string{ + "out/soong/.intermediates/mynewsdklibrary.stubs/android_common/dex/mynewsdklibrary.stubs.jar", + "out/soong/.intermediates/mynewsdklibrary/android_common/aligned/mynewsdklibrary.jar", + "out/soong/.intermediates/mysdklibrary.stubs/android_common/dex/mysdklibrary.stubs.jar", + "out/soong/.intermediates/mysdklibrary/android_common/aligned/mysdklibrary.jar", + } + + testSnapshotWithBootClasspathFragment_MinSdkVersion(t, "Tiramisu", + expectedSnapshot, expectedCopyRules, expectedStubFlagsInputs, "") + }) +} diff --git a/sdk/update.go b/sdk/update.go index c555ddc7a..bd2375021 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -183,6 +183,7 @@ func (gf *generatedFile) build(pctx android.PackageContext, ctx android.BuilderC // multilibs (32/64/both) are used by this sdk variant. func (s *sdk) collectMembers(ctx android.ModuleContext) { s.multilibUsages = multilibNone + ctx.WalkDeps(func(child android.Module, parent android.Module) bool { tag := ctx.OtherModuleDependencyTag(child) if memberTag, ok := tag.(android.SdkMemberDependencyTag); ok { @@ -211,11 +212,14 @@ func (s *sdk) collectMembers(ctx android.ModuleContext) { container = parent.(android.SdkAware) } + minApiLevel := android.MinApiLevelForSdkSnapshot(ctx, child) + export := memberTag.ExportMember() s.memberVariantDeps = append(s.memberVariantDeps, sdkMemberVariantDep{ sdkVariant: s, memberType: memberType, variant: child.(android.SdkAware), + minApiLevel: minApiLevel, container: container, export: export, exportedComponentsInfo: exportedComponentsInfo, @@ -332,10 +336,29 @@ const BUILD_NUMBER_FILE = "snapshot-creation-build-number.txt" // /lib/ // libFoo.so : a stub library +func (s sdk) targetBuildRelease(ctx android.ModuleContext) *buildRelease { + config := ctx.Config() + currentBuildRelease := latestBuildRelease() + targetBuildReleaseEnv := config.GetenvWithDefault("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE", currentBuildRelease.name) + targetBuildRelease, err := nameToRelease(targetBuildReleaseEnv) + if err != nil { + ctx.ModuleErrorf("invalid SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE: %s", err) + targetBuildRelease = currentBuildRelease + } + + return targetBuildRelease +} + // buildSnapshot is the main function in this source file. It creates rules to copy // the contents (header files, stub libraries, etc) into the zip file. func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) { + targetBuildRelease := s.targetBuildRelease(ctx) + targetApiLevel, err := android.ApiLevelFromUser(ctx, targetBuildRelease.name) + if err != nil { + targetApiLevel = android.FutureApiLevel + } + // Aggregate all the sdkMemberVariantDep instances from all the sdk variants. hasLicenses := false var memberVariantDeps []sdkMemberVariantDep @@ -346,12 +369,18 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) { // Filter out any sdkMemberVariantDep that is a component of another. memberVariantDeps = filterOutComponents(ctx, memberVariantDeps) - // Record the names of all the members, both explicitly specified and implicitly - // included. + // Record the names of all the members, both explicitly specified and implicitly included. Also, + // record the names of any members that should be excluded from this snapshot. allMembersByName := make(map[string]struct{}) exportedMembersByName := make(map[string]struct{}) + excludedMembersByName := make(map[string]struct{}) + + addMember := func(name string, export bool, exclude bool) { + if exclude { + excludedMembersByName[name] = struct{}{} + return + } - addMember := func(name string, export bool) { allMembersByName[name] = struct{}{} if export { exportedMembersByName[name] = struct{}{} @@ -362,11 +391,15 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) { name := memberVariantDep.variant.Name() export := memberVariantDep.export - addMember(name, export) + // If the minApiLevel of the member is greater than the target API level then exclude it from + // this snapshot. + exclude := memberVariantDep.minApiLevel.GreaterThan(targetApiLevel) + + addMember(name, export, exclude) // Add any components provided by the module. for _, component := range memberVariantDep.exportedComponentsInfo.Components { - addMember(component, export) + addMember(component, export, exclude) } if memberVariantDep.memberType == android.LicenseModuleSdkMemberType { @@ -382,19 +415,9 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) { modules: make(map[string]*bpModule), } - config := ctx.Config() - // Always add -current to the end snapshotFileSuffix := "-current" - currentBuildRelease := latestBuildRelease() - targetBuildReleaseEnv := config.GetenvWithDefault("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE", currentBuildRelease.name) - targetBuildRelease, err := nameToRelease(targetBuildReleaseEnv) - if err != nil { - ctx.ModuleErrorf("invalid SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE: %s", err) - targetBuildRelease = currentBuildRelease - } - builder := &snapshotBuilder{ ctx: ctx, sdk: s, @@ -405,6 +428,7 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) { prebuiltModules: make(map[string]*bpModule), allMembersByName: allMembersByName, exportedMembersByName: exportedMembersByName, + excludedMembersByName: excludedMembersByName, targetBuildRelease: targetBuildRelease, } s.builderForTests = builder @@ -438,6 +462,10 @@ be unnecessary as every module in the sdk already has its own licenses property. } name := member.name + if _, ok := excludedMembersByName[name]; ok { + continue + } + requiredTraits := traits[name] if requiredTraits == nil { requiredTraits = android.EmptySdkMemberTraitSet() @@ -472,7 +500,7 @@ be unnecessary as every module in the sdk already has its own licenses property. contents := bp.content.String() // If the snapshot is being generated for the current build release then check the syntax to make // sure that it is compatible. - if targetBuildRelease == currentBuildRelease { + if targetBuildRelease == latestBuildRelease() { syntaxCheckSnapshotBpFile(ctx, contents) } @@ -1035,6 +1063,9 @@ type snapshotBuilder struct { // The set of exported members by name. exportedMembersByName map[string]struct{} + // The set of members which have been excluded from this snapshot; by name. + excludedMembersByName map[string]struct{} + // The target build release for which the snapshot is to be generated. targetBuildRelease *buildRelease @@ -1219,6 +1250,9 @@ func (s *snapshotBuilder) snapshotSdkMemberName(name string, required bool) stri func (s *snapshotBuilder) snapshotSdkMemberNames(members []string, required bool) []string { var references []string = nil for _, m := range members { + if _, ok := s.excludedMembersByName[m]; ok { + continue + } references = append(references, s.snapshotSdkMemberName(m, required)) } return references @@ -1261,6 +1295,9 @@ type sdkMemberVariantDep struct { // The names of additional component modules provided by the variant. exportedComponentsInfo android.ExportedComponentsInfo + + // The minimum API level on which this module is supported. + minApiLevel android.ApiLevel } var _ android.SdkMember = (*sdkMember)(nil) From 9bcfe69743f227c6e10f5830d735835529b0c1c0 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 28 Jul 2022 10:07:30 +0000 Subject: [PATCH 040/172] Revert "Patch to fix Aug train issue with tethering" Revert "[automerge] Patch to fix Aug train issue with tethering ..." Revert submission 19432194-presubmit-am-5e598b33be884d9f98a29ce1c3c575fb Reason for revert: Not needed in tm-mainline-prod and breaks bluetooth. Reverted Changes: I57969b85a:Patch to fix Aug train issue with tethering Ie6560f201:[automerge] Patch to fix Aug train issue with teth... Change-Id: If44d16a00847a554862aa139c04370ad30166c74 --- android/sdk.go | 16 -- java/base.go | 8 - java/bootclasspath_fragment.go | 66 +----- java/hiddenapi_modular.go | 112 ++++----- scripts/hiddenapi/generate_hiddenapi_lists.py | 21 +- .../generate_hiddenapi_lists_test.py | 4 +- sdk/bootclasspath_fragment_sdk_test.go | 219 ------------------ sdk/update.go | 69 ++---- 8 files changed, 84 insertions(+), 431 deletions(-) diff --git a/android/sdk.go b/android/sdk.go index ad2c68f3f..a71f7f211 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -74,22 +74,6 @@ type SdkAware interface { sdkAwareWithoutModule } -type minApiLevelForSdkSnapshot interface { - MinApiLevelForSdkSnapshot(ctx EarlyModuleContext) ApiLevel -} - -func MinApiLevelForSdkSnapshot(ctx EarlyModuleContext, module Module) ApiLevel { - minApiLevel := NoneApiLevel - if m, ok := module.(minApiLevelForSdkSnapshot); ok { - minApiLevel = m.MinApiLevelForSdkSnapshot(ctx) - } - if minApiLevel == NoneApiLevel { - // The default API level is Q, i.e. the first release that supported mainline modules. - minApiLevel = uncheckedFinalApiLevel(29) - } - return minApiLevel -} - // SdkRef refers to a version of an SDK type SdkRef struct { Name string diff --git a/java/base.go b/java/base.go index 0d824cb7b..717c7273f 100644 --- a/java/base.go +++ b/java/base.go @@ -645,14 +645,6 @@ func (j *Module) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { return j.SdkVersion(ctx) } -func (j *Module) MinApiLevelForSdkSnapshot(ctx android.EarlyModuleContext) android.ApiLevel { - if j.deviceProperties.Min_sdk_version != nil { - return android.SdkSpecFrom(ctx, *j.deviceProperties.Min_sdk_version).ApiLevel - } else { - return android.NoneApiLevel - } -} - func (j *Module) MaxSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { maxSdkVersion := proptools.StringDefault(j.deviceProperties.Max_sdk_version, "") // SdkSpecFrom returns SdkSpecPrivate for this, which may be confusing. diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index 85c17d301..b6b179cdf 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -769,7 +769,7 @@ func (b *BootclasspathFragmentModule) generateHiddenAPIBuildActions(ctx android. // their own. if output.SignaturePatternsPath == nil { output.SignaturePatternsPath = buildRuleSignaturePatternsFile( - ctx, output.AllFlagsPath, []string{"*"}, nil, nil, "") + ctx, output.AllFlagsPath, []string{"*"}, nil, nil) } // Initialize a HiddenAPIInfo structure. @@ -853,10 +853,12 @@ func (b *BootclasspathFragmentModule) isTestFragment() bool { return false } -func (b *BootclasspathFragmentModule) generateHiddenApiFlagRules(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput, bootDexInfoByModule bootDexInfoByModule, suffix string) HiddenAPIFlagOutput { +// produceHiddenAPIOutput produces the hidden API all-flags.csv file (and supporting files) +// for the fragment as well as encoding the flags in the boot dex jars. +func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput { // Generate the rules to create the hidden API flags and update the supplied hiddenAPIInfo with the // paths to the created files. - flagOutput := hiddenAPIFlagRulesForBootclasspathFragment(ctx, bootDexInfoByModule, contents, input, suffix) + output := hiddenAPIRulesForBootclasspathFragment(ctx, contents, input) // If the module specifies split_packages or package_prefixes then use those to generate the // signature patterns. @@ -864,8 +866,8 @@ func (b *BootclasspathFragmentModule) generateHiddenApiFlagRules(ctx android.Mod packagePrefixes := b.sourceOnlyProperties.Hidden_api.Package_prefixes singlePackages := b.sourceOnlyProperties.Hidden_api.Single_packages if splitPackages != nil || packagePrefixes != nil || singlePackages != nil { - flagOutput.SignaturePatternsPath = buildRuleSignaturePatternsFile( - ctx, flagOutput.AllFlagsPath, splitPackages, packagePrefixes, singlePackages, suffix) + output.SignaturePatternsPath = buildRuleSignaturePatternsFile( + ctx, output.AllFlagsPath, splitPackages, packagePrefixes, singlePackages) } else if !b.isTestFragment() { ctx.ModuleErrorf(`Must specify at least one of the split_packages, package_prefixes and single_packages properties If this is a new bootclasspath_fragment or you are unsure what to do add the @@ -877,49 +879,6 @@ func (b *BootclasspathFragmentModule) generateHiddenApiFlagRules(ctx android.Mod should specify here. If you are happy with its suggestions then you can add the --fix option and it will fix them for you.`, b.BaseModuleName()) } - return flagOutput -} - -// produceHiddenAPIOutput produces the hidden API all-flags.csv file (and supporting files) -// for the fragment as well as encoding the flags in the boot dex jars. -func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput { - // Gather information about the boot dex files for the boot libraries provided by this fragment. - bootDexInfoByModule := extractBootDexInfoFromModules(ctx, contents) - - flagOutput := b.generateHiddenApiFlagRules(ctx, contents, input, bootDexInfoByModule, "") - - encodedBootDexFilesByModule := hiddenAPIEncodeRulesForBootclasspathFragment(ctx, bootDexInfoByModule, flagOutput.AllFlagsPath) - - output := &HiddenAPIOutput{ - HiddenAPIFlagOutput: flagOutput, - EncodedBootDexFilesByModule: encodedBootDexFilesByModule, - } - - config := ctx.Config() - targetApiLevel := android.ApiLevelOrPanic(ctx, - config.GetenvWithDefault("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE", "current")) - - filterContents := []android.Module{} - for _, module := range contents { - minApiLevel := android.MinApiLevelForSdkSnapshot(ctx, module) - if minApiLevel.GreaterThan(targetApiLevel) { - delete(bootDexInfoByModule, module.Name()) - delete(input.StubDexJarsByScope, module.Name()) - continue - } - - filterContents = append(filterContents, module) - } - - if len(filterContents) != len(contents) { - flagOutput = b.generateHiddenApiFlagRules(ctx, filterContents, input, bootDexInfoByModule, "-for-sdk-snapshot") - } - - // Copy the information and make it available for sdk snapshot. - ctx.SetProvider(HiddenAPIInfoForSdkProvider, HiddenAPIInfoForSdk{ - FlagFilesByCategory: input.FlagFilesByCategory, - HiddenAPIFlagOutput: flagOutput, - }) return output } @@ -1085,7 +1044,7 @@ func (b *bootclasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx andro // Get the hidden API information from the module. mctx := ctx.SdkModuleContext() - hiddenAPIInfo := mctx.OtherModuleProvider(module, HiddenAPIInfoForSdkProvider).(HiddenAPIInfoForSdk) + hiddenAPIInfo := mctx.OtherModuleProvider(module, HiddenAPIInfoProvider).(HiddenAPIInfo) b.Flag_files_by_category = hiddenAPIInfo.FlagFilesByCategory // Copy all the generated file paths. @@ -1264,15 +1223,6 @@ func (module *PrebuiltBootclasspathFragmentModule) produceHiddenAPIOutput(ctx an output.FilteredStubFlagsPath = pathForOptionalSrc(module.prebuiltProperties.Hidden_api.Filtered_stub_flags, output.StubFlagsPath) output.FilteredFlagsPath = pathForOptionalSrc(module.prebuiltProperties.Hidden_api.Filtered_flags, output.AllFlagsPath) - // If the prebuilts module does not provide a signature patterns file then generate one from the - // flags. - // TODO(b/192868581): Remove once the prebuilts all provide a signature patterns file of their - // own. - if output.SignaturePatternsPath == nil { - output.SignaturePatternsPath = buildRuleSignaturePatternsFile( - ctx, output.AllFlagsPath, []string{"*"}, nil, nil, "") - } - return &output } diff --git a/java/hiddenapi_modular.go b/java/hiddenapi_modular.go index b0c79c5b8..c90b2ff97 100644 --- a/java/hiddenapi_modular.go +++ b/java/hiddenapi_modular.go @@ -571,23 +571,6 @@ func (i *HiddenAPIInfo) FlagSubset() SignatureCsvSubset { var HiddenAPIInfoProvider = blueprint.NewProvider(HiddenAPIInfo{}) -// HiddenAPIInfoForSdk contains information provided by the hidden API processing for use -// by the sdk snapshot. -// -// That includes paths resolved from HiddenAPIFlagFileProperties and also generated by hidden API -// processing. -type HiddenAPIInfoForSdk struct { - // FlagFilesByCategory maps from the flag file category to the paths containing information for - // that category. - FlagFilesByCategory FlagFilesByCategory - - // The output from the hidden API processing needs to be made available to other modules. - HiddenAPIFlagOutput -} - -// Provides hidden API info for the sdk snapshot. -var HiddenAPIInfoForSdkProvider = blueprint.NewProvider(HiddenAPIInfoForSdk{}) - // ModuleStubDexJars contains the stub dex jars provided by a single module. // // It maps a *HiddenAPIScope to the path to stub dex jars appropriate for that scope. See @@ -970,11 +953,8 @@ func (s SignatureCsvSubsets) RelativeToTop() []string { // patterns that will select a subset of the monolithic flags. func buildRuleSignaturePatternsFile( ctx android.ModuleContext, flagsPath android.Path, - splitPackages []string, packagePrefixes []string, singlePackages []string, - suffix string) android.Path { - hiddenApiSubDir := "modular-hiddenapi" + suffix - - patternsFile := android.PathForModuleOut(ctx, hiddenApiSubDir, "signature-patterns.csv") + splitPackages []string, packagePrefixes []string, singlePackages []string) android.Path { + patternsFile := android.PathForModuleOut(ctx, "modular-hiddenapi", "signature-patterns.csv") // Create a rule to validate the output from the following rule. rule := android.NewRuleBuilder(pctx, ctx) @@ -991,7 +971,7 @@ func buildRuleSignaturePatternsFile( FlagForEachArg("--package-prefix ", packagePrefixes). FlagForEachArg("--single-package ", singlePackages). FlagWithOutput("--output ", patternsFile) - rule.Build("hiddenAPISignaturePatterns"+suffix, "hidden API signature patterns"+suffix) + rule.Build("hiddenAPISignaturePatterns", "hidden API signature patterns") return patternsFile } @@ -1065,7 +1045,7 @@ func buildRuleValidateOverlappingCsvFiles(ctx android.BuilderContext, name strin return validFile } -// hiddenAPIFlagRulesForBootclasspathFragment will generate all the flags for a fragment of the +// hiddenAPIRulesForBootclasspathFragment will generate all the flags for a fragment of the // bootclasspath and then encode the flags into the boot dex files. // // It takes: @@ -1080,27 +1060,30 @@ func buildRuleValidateOverlappingCsvFiles(ctx android.BuilderContext, name strin // * index.csv // * all-flags.csv // * encoded boot dex files -func hiddenAPIFlagRulesForBootclasspathFragment(ctx android.ModuleContext, bootDexInfoByModule bootDexInfoByModule, contents []android.Module, input HiddenAPIFlagInput, suffix string) HiddenAPIFlagOutput { - hiddenApiSubDir := "modular-hiddenapi" + suffix +func hiddenAPIRulesForBootclasspathFragment(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput { + hiddenApiSubDir := "modular-hiddenapi" + + // Gather information about the boot dex files for the boot libraries provided by this fragment. + bootDexInfoByModule := extractBootDexInfoFromModules(ctx, contents) // Generate the stub-flags.csv. stubFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "stub-flags.csv") - buildRuleToGenerateHiddenAPIStubFlagsFile(ctx, "modularHiddenAPIStubFlagsFile"+suffix, "modular hiddenapi stub flags", stubFlagsCSV, bootDexInfoByModule.bootDexJars(), input, nil) + buildRuleToGenerateHiddenAPIStubFlagsFile(ctx, "modularHiddenAPIStubFlagsFile", "modular hiddenapi stub flags", stubFlagsCSV, bootDexInfoByModule.bootDexJars(), input, nil) // Extract the classes jars from the contents. classesJars := extractClassesJarsFromModules(contents) // Generate the set of flags from the annotations in the source code. annotationFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "annotation-flags.csv") - buildRuleToGenerateAnnotationFlags(ctx, "modular hiddenapi annotation flags"+suffix, classesJars, stubFlagsCSV, annotationFlagsCSV) + buildRuleToGenerateAnnotationFlags(ctx, "modular hiddenapi annotation flags", classesJars, stubFlagsCSV, annotationFlagsCSV) // Generate the metadata from the annotations in the source code. metadataCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "metadata.csv") - buildRuleToGenerateMetadata(ctx, "modular hiddenapi metadata"+suffix, classesJars, stubFlagsCSV, metadataCSV) + buildRuleToGenerateMetadata(ctx, "modular hiddenapi metadata", classesJars, stubFlagsCSV, metadataCSV) // Generate the index file from the CSV files in the classes jars. indexCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "index.csv") - buildRuleToGenerateIndex(ctx, "modular hiddenapi index"+suffix, classesJars, indexCSV) + buildRuleToGenerateIndex(ctx, "modular hiddenapi index", classesJars, indexCSV) // Removed APIs need to be marked and in order to do that the hiddenAPIInfo needs to specify files // containing dex signatures of all the removed APIs. In the monolithic files that is done by @@ -1108,42 +1091,15 @@ func hiddenAPIFlagRulesForBootclasspathFragment(ctx android.ModuleContext, bootD // signatures, see the combined-removed-dex module. This does that automatically by using the // *removed.txt files retrieved from the java_sdk_library modules that are specified in the // stub_libs and contents properties of a bootclasspath_fragment. - removedDexSignatures := buildRuleToGenerateRemovedDexSignatures(ctx, suffix, input.RemovedTxtFiles) + removedDexSignatures := buildRuleToGenerateRemovedDexSignatures(ctx, input.RemovedTxtFiles) // Generate the all-flags.csv which are the flags that will, in future, be encoded into the dex // files. allFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "all-flags.csv") - buildRuleToGenerateHiddenApiFlags(ctx, "modularHiddenApiAllFlags"+suffix, "modular hiddenapi all flags"+suffix, allFlagsCSV, stubFlagsCSV, android.Paths{annotationFlagsCSV}, input.FlagFilesByCategory, nil, removedDexSignatures) + buildRuleToGenerateHiddenApiFlags(ctx, "modularHiddenApiAllFlags", "modular hiddenapi all flags", allFlagsCSV, stubFlagsCSV, android.Paths{annotationFlagsCSV}, input.FlagFilesByCategory, nil, removedDexSignatures) - // Generate the filtered-stub-flags.csv file which contains the filtered stub flags that will be - // compared against the monolithic stub flags. - filteredStubFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "filtered-stub-flags.csv") - buildRuleRemoveSignaturesWithImplementationFlags(ctx, "modularHiddenApiFilteredStubFlags"+suffix, - "modular hiddenapi filtered stub flags"+suffix, stubFlagsCSV, filteredStubFlagsCSV, - HIDDENAPI_STUB_FLAGS_IMPL_FLAGS) - - // Generate the filtered-flags.csv file which contains the filtered flags that will be compared - // against the monolithic flags. - filteredFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "filtered-flags.csv") - buildRuleRemoveSignaturesWithImplementationFlags(ctx, "modularHiddenApiFilteredFlags"+suffix, - "modular hiddenapi filtered flags"+suffix, allFlagsCSV, filteredFlagsCSV, - HIDDENAPI_FLAGS_CSV_IMPL_FLAGS) - - // Store the paths in the info for use by other modules and sdk snapshot generation. - return HiddenAPIFlagOutput{ - AnnotationFlagsPath: annotationFlagsCSV, - MetadataPath: metadataCSV, - IndexPath: indexCSV, - StubFlagsPath: stubFlagsCSV, - AllFlagsPath: allFlagsCSV, - FilteredStubFlagsPath: filteredStubFlagsCSV, - FilteredFlagsPath: filteredFlagsCSV, - } -} - -func hiddenAPIEncodeRulesForBootclasspathFragment(ctx android.ModuleContext, bootDexInfoByModule bootDexInfoByModule, allFlagsCSV android.Path) bootDexJarByModule { // Encode the flags into the boot dex files. - encodedBootDexJarsByModule := bootDexJarByModule{} + encodedBootDexJarsByModule := map[string]android.Path{} outputDir := android.PathForModuleOut(ctx, "hiddenapi-modular/encoded").OutputPath for _, name := range android.SortedStringKeys(bootDexInfoByModule) { bootDexInfo := bootDexInfoByModule[name] @@ -1151,15 +1107,43 @@ func hiddenAPIEncodeRulesForBootclasspathFragment(ctx android.ModuleContext, boo encodedDex := hiddenAPIEncodeDex(ctx, unencodedDex, allFlagsCSV, bootDexInfo.uncompressDex, bootDexInfo.minSdkVersion, outputDir) encodedBootDexJarsByModule[name] = encodedDex } - return encodedBootDexJarsByModule + + // Generate the filtered-stub-flags.csv file which contains the filtered stub flags that will be + // compared against the monolithic stub flags. + filteredStubFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "filtered-stub-flags.csv") + buildRuleRemoveSignaturesWithImplementationFlags(ctx, "modularHiddenApiFilteredStubFlags", + "modular hiddenapi filtered stub flags", stubFlagsCSV, filteredStubFlagsCSV, + HIDDENAPI_STUB_FLAGS_IMPL_FLAGS) + + // Generate the filtered-flags.csv file which contains the filtered flags that will be compared + // against the monolithic flags. + filteredFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "filtered-flags.csv") + buildRuleRemoveSignaturesWithImplementationFlags(ctx, "modularHiddenApiFilteredFlags", + "modular hiddenapi filtered flags", allFlagsCSV, filteredFlagsCSV, + HIDDENAPI_FLAGS_CSV_IMPL_FLAGS) + + // Store the paths in the info for use by other modules and sdk snapshot generation. + output := HiddenAPIOutput{ + HiddenAPIFlagOutput: HiddenAPIFlagOutput{ + AnnotationFlagsPath: annotationFlagsCSV, + MetadataPath: metadataCSV, + IndexPath: indexCSV, + StubFlagsPath: stubFlagsCSV, + AllFlagsPath: allFlagsCSV, + FilteredStubFlagsPath: filteredStubFlagsCSV, + FilteredFlagsPath: filteredFlagsCSV, + }, + EncodedBootDexFilesByModule: encodedBootDexJarsByModule, + } + return &output } -func buildRuleToGenerateRemovedDexSignatures(ctx android.ModuleContext, suffix string, removedTxtFiles android.Paths) android.OptionalPath { +func buildRuleToGenerateRemovedDexSignatures(ctx android.ModuleContext, removedTxtFiles android.Paths) android.OptionalPath { if len(removedTxtFiles) == 0 { return android.OptionalPath{} } - output := android.PathForModuleOut(ctx, "module-hiddenapi"+suffix, "removed-dex-signatures.txt") + output := android.PathForModuleOut(ctx, "modular-hiddenapi/removed-dex-signatures.txt") rule := android.NewRuleBuilder(pctx, ctx) rule.Command(). @@ -1167,7 +1151,7 @@ func buildRuleToGenerateRemovedDexSignatures(ctx android.ModuleContext, suffix s Flag("--no-banner"). Inputs(removedTxtFiles). FlagWithOutput("--dex-api ", output) - rule.Build("modular-hiddenapi-removed-dex-signatures"+suffix, "modular hiddenapi removed dex signatures"+suffix) + rule.Build("modular-hiddenapi-removed-dex-signatures", "modular hiddenapi removed dex signatures") return android.OptionalPathForPath(output) } diff --git a/scripts/hiddenapi/generate_hiddenapi_lists.py b/scripts/hiddenapi/generate_hiddenapi_lists.py index f119bfb02..6546c7f80 100755 --- a/scripts/hiddenapi/generate_hiddenapi_lists.py +++ b/scripts/hiddenapi/generate_hiddenapi_lists.py @@ -216,13 +216,13 @@ class FlagsDict: def _check_entries_set(self, keys_subset, source): assert isinstance(keys_subset, set) - # assert keys_subset.issubset(self._dict_keyset), ( - # 'Error: {} specifies signatures not present in code:\n' - # '{}' - # 'Please visit go/hiddenapi for more information.').format( - # source, ''.join( - # [' ' + str(x) + '\n' for x in - # keys_subset - self._dict_keyset])) + assert keys_subset.issubset(self._dict_keyset), ( + 'Error: {} specifies signatures not present in code:\n' + '{}' + 'Please visit go/hiddenapi for more information.').format( + source, ''.join( + [' ' + str(x) + '\n' for x in + keys_subset - self._dict_keyset])) def _check_flags_set(self, flags_subset, source): assert isinstance(flags_subset, set) @@ -330,10 +330,9 @@ class FlagsDict: # Iterate over the API subset, find each entry in dict and assign the # flag to it. for api in apis: - if api in self._dict: - self._dict[api].add(flag) - if tag: - self._dict[api].add(tag) + self._dict[api].add(flag) + if tag: + self._dict[api].add(tag) FlagFile = namedtuple('FlagFile', diff --git a/scripts/hiddenapi/generate_hiddenapi_lists_test.py b/scripts/hiddenapi/generate_hiddenapi_lists_test.py index 5746b5a15..204de9723 100755 --- a/scripts/hiddenapi/generate_hiddenapi_lists_test.py +++ b/scripts/hiddenapi/generate_hiddenapi_lists_test.py @@ -92,8 +92,8 @@ class TestHiddenapiListGeneration(unittest.TestCase): ) # Test invalid API signature. - # with self.assertRaises(AssertionError): - # flags.assign_flag(FLAG_SDK, set(['C'])) + with self.assertRaises(AssertionError): + flags.assign_flag(FLAG_SDK, set(['C'])) # Test invalid flag. with self.assertRaises(AssertionError): diff --git a/sdk/bootclasspath_fragment_sdk_test.go b/sdk/bootclasspath_fragment_sdk_test.go index b3a560844..13ddbe768 100644 --- a/sdk/bootclasspath_fragment_sdk_test.go +++ b/sdk/bootclasspath_fragment_sdk_test.go @@ -847,222 +847,3 @@ my-unsupported-packages.txt -> hiddenapi/my-unsupported-packages.txt snapshotTestPreparer(checkSnapshotPreferredWithSource, preparerForSnapshot), ) } - -func testSnapshotWithBootClasspathFragment_MinSdkVersion(t *testing.T, targetBuildRelease string, - expectedSdkSnapshot string, - expectedCopyRules string, - expectedStubFlagsInputs []string, - suffix string) { - - result := android.GroupFixturePreparers( - prepareForSdkTestWithJava, - java.PrepareForTestWithJavaDefaultModules, - java.PrepareForTestWithJavaSdkLibraryFiles, - java.FixtureWithLastReleaseApis("mysdklibrary", "mynewsdklibrary"), - java.FixtureConfigureApexBootJars("myapex:mysdklibrary", "myapex:mynewsdklibrary"), - prepareForSdkTestWithApex, - - // Add a platform_bootclasspath that depends on the fragment. - fixtureAddPlatformBootclasspathForBootclasspathFragment("myapex", "mybootclasspathfragment"), - - android.FixtureMergeEnv(map[string]string{ - "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": targetBuildRelease, - }), - - android.FixtureWithRootAndroidBp(` - sdk { - name: "mysdk", - apexes: ["myapex"], - } - - apex { - name: "myapex", - key: "myapex.key", - min_sdk_version: "S", - bootclasspath_fragments: ["mybootclasspathfragment"], - } - - bootclasspath_fragment { - name: "mybootclasspathfragment", - apex_available: ["myapex"], - contents: [ - "mysdklibrary", - "mynewsdklibrary", - ], - - hidden_api: { - split_packages: [], - }, - } - - java_sdk_library { - name: "mysdklibrary", - apex_available: ["myapex"], - srcs: ["Test.java"], - shared_library: false, - public: {enabled: true}, - min_sdk_version: "S", - } - - java_sdk_library { - name: "mynewsdklibrary", - apex_available: ["myapex"], - srcs: ["Test.java"], - compile_dex: true, - public: {enabled: true}, - min_sdk_version: "Tiramisu", - permitted_packages: ["mynewsdklibrary"], - } - `), - ).RunTest(t) - - bcpf := result.ModuleForTests("mybootclasspathfragment", "android_common") - rule := bcpf.Output("out/soong/.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi" + suffix + "/stub-flags.csv") - android.AssertPathsRelativeToTopEquals(t, "stub flags inputs", expectedStubFlagsInputs, rule.Implicits) - - CheckSnapshot(t, result, "mysdk", "", - checkAndroidBpContents(expectedSdkSnapshot), - checkAllCopyRules(expectedCopyRules), - ) -} - -func TestSnapshotWithBootClasspathFragment_MinSdkVersion(t *testing.T) { - t.Run("target S build", func(t *testing.T) { - expectedSnapshot := ` -// This is auto-generated. DO NOT EDIT. - -prebuilt_bootclasspath_fragment { - name: "mybootclasspathfragment", - prefer: false, - visibility: ["//visibility:public"], - apex_available: ["myapex"], - contents: ["mysdklibrary"], - hidden_api: { - 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", - }, -} - -java_sdk_library_import { - name: "mysdklibrary", - prefer: false, - visibility: ["//visibility:public"], - apex_available: ["myapex"], - shared_library: false, - public: { - jars: ["sdk_library/public/mysdklibrary-stubs.jar"], - stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], - current_api: "sdk_library/public/mysdklibrary.txt", - removed_api: "sdk_library/public/mysdklibrary-removed.txt", - sdk_version: "current", - }, -} -` - expectedCopyRules := ` -.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/annotation-flags.csv -> hiddenapi/annotation-flags.csv -.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/metadata.csv -> hiddenapi/metadata.csv -.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/index.csv -> hiddenapi/index.csv -.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/stub-flags.csv -> hiddenapi/stub-flags.csv -.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/all-flags.csv -> hiddenapi/all-flags.csv -.intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar -.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt -.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt -` - - // On S the stub flags should only be generated from mysdklibrary as mynewsdklibrary is not part - // of the snapshot. - expectedStubFlagsInputs := []string{ - "out/soong/.intermediates/mysdklibrary.stubs/android_common/dex/mysdklibrary.stubs.jar", - "out/soong/.intermediates/mysdklibrary/android_common/aligned/mysdklibrary.jar", - } - - testSnapshotWithBootClasspathFragment_MinSdkVersion(t, "S", - expectedSnapshot, expectedCopyRules, expectedStubFlagsInputs, "-for-sdk-snapshot") - }) - - t.Run("target-Tiramisu-build", func(t *testing.T) { - expectedSnapshot := ` -// This is auto-generated. DO NOT EDIT. - -prebuilt_bootclasspath_fragment { - name: "mybootclasspathfragment", - prefer: false, - visibility: ["//visibility:public"], - apex_available: ["myapex"], - contents: [ - "mysdklibrary", - "mynewsdklibrary", - ], - hidden_api: { - annotation_flags: "hiddenapi/annotation-flags.csv", - metadata: "hiddenapi/metadata.csv", - index: "hiddenapi/index.csv", - signature_patterns: "hiddenapi/signature-patterns.csv", - filtered_stub_flags: "hiddenapi/filtered-stub-flags.csv", - filtered_flags: "hiddenapi/filtered-flags.csv", - }, -} - -java_sdk_library_import { - name: "mysdklibrary", - prefer: false, - visibility: ["//visibility:public"], - apex_available: ["myapex"], - shared_library: false, - public: { - jars: ["sdk_library/public/mysdklibrary-stubs.jar"], - stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], - current_api: "sdk_library/public/mysdklibrary.txt", - removed_api: "sdk_library/public/mysdklibrary-removed.txt", - sdk_version: "current", - }, -} - -java_sdk_library_import { - name: "mynewsdklibrary", - prefer: false, - visibility: ["//visibility:public"], - apex_available: ["myapex"], - shared_library: true, - compile_dex: true, - permitted_packages: ["mynewsdklibrary"], - public: { - jars: ["sdk_library/public/mynewsdklibrary-stubs.jar"], - stub_srcs: ["sdk_library/public/mynewsdklibrary_stub_sources"], - current_api: "sdk_library/public/mynewsdklibrary.txt", - removed_api: "sdk_library/public/mynewsdklibrary-removed.txt", - sdk_version: "current", - }, -} -` - expectedCopyRules := ` -.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv -.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv -.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/index.csv -> hiddenapi/index.csv -.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/signature-patterns.csv -> hiddenapi/signature-patterns.csv -.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/filtered-stub-flags.csv -> hiddenapi/filtered-stub-flags.csv -.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/filtered-flags.csv -> hiddenapi/filtered-flags.csv -.intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar -.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt -.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt -.intermediates/mynewsdklibrary.stubs/android_common/javac/mynewsdklibrary.stubs.jar -> sdk_library/public/mynewsdklibrary-stubs.jar -.intermediates/mynewsdklibrary.stubs.source/android_common/metalava/mynewsdklibrary.stubs.source_api.txt -> sdk_library/public/mynewsdklibrary.txt -.intermediates/mynewsdklibrary.stubs.source/android_common/metalava/mynewsdklibrary.stubs.source_removed.txt -> sdk_library/public/mynewsdklibrary-removed.txt -` - - // On tiramisu the stub flags should be generated from both mynewsdklibrary and mysdklibrary as - // they are both part of the snapshot. - expectedStubFlagsInputs := []string{ - "out/soong/.intermediates/mynewsdklibrary.stubs/android_common/dex/mynewsdklibrary.stubs.jar", - "out/soong/.intermediates/mynewsdklibrary/android_common/aligned/mynewsdklibrary.jar", - "out/soong/.intermediates/mysdklibrary.stubs/android_common/dex/mysdklibrary.stubs.jar", - "out/soong/.intermediates/mysdklibrary/android_common/aligned/mysdklibrary.jar", - } - - testSnapshotWithBootClasspathFragment_MinSdkVersion(t, "Tiramisu", - expectedSnapshot, expectedCopyRules, expectedStubFlagsInputs, "") - }) -} diff --git a/sdk/update.go b/sdk/update.go index bd2375021..c555ddc7a 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -183,7 +183,6 @@ func (gf *generatedFile) build(pctx android.PackageContext, ctx android.BuilderC // multilibs (32/64/both) are used by this sdk variant. func (s *sdk) collectMembers(ctx android.ModuleContext) { s.multilibUsages = multilibNone - ctx.WalkDeps(func(child android.Module, parent android.Module) bool { tag := ctx.OtherModuleDependencyTag(child) if memberTag, ok := tag.(android.SdkMemberDependencyTag); ok { @@ -212,14 +211,11 @@ func (s *sdk) collectMembers(ctx android.ModuleContext) { container = parent.(android.SdkAware) } - minApiLevel := android.MinApiLevelForSdkSnapshot(ctx, child) - export := memberTag.ExportMember() s.memberVariantDeps = append(s.memberVariantDeps, sdkMemberVariantDep{ sdkVariant: s, memberType: memberType, variant: child.(android.SdkAware), - minApiLevel: minApiLevel, container: container, export: export, exportedComponentsInfo: exportedComponentsInfo, @@ -336,29 +332,10 @@ const BUILD_NUMBER_FILE = "snapshot-creation-build-number.txt" // /lib/ // libFoo.so : a stub library -func (s sdk) targetBuildRelease(ctx android.ModuleContext) *buildRelease { - config := ctx.Config() - currentBuildRelease := latestBuildRelease() - targetBuildReleaseEnv := config.GetenvWithDefault("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE", currentBuildRelease.name) - targetBuildRelease, err := nameToRelease(targetBuildReleaseEnv) - if err != nil { - ctx.ModuleErrorf("invalid SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE: %s", err) - targetBuildRelease = currentBuildRelease - } - - return targetBuildRelease -} - // buildSnapshot is the main function in this source file. It creates rules to copy // the contents (header files, stub libraries, etc) into the zip file. func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) { - targetBuildRelease := s.targetBuildRelease(ctx) - targetApiLevel, err := android.ApiLevelFromUser(ctx, targetBuildRelease.name) - if err != nil { - targetApiLevel = android.FutureApiLevel - } - // Aggregate all the sdkMemberVariantDep instances from all the sdk variants. hasLicenses := false var memberVariantDeps []sdkMemberVariantDep @@ -369,18 +346,12 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) { // Filter out any sdkMemberVariantDep that is a component of another. memberVariantDeps = filterOutComponents(ctx, memberVariantDeps) - // Record the names of all the members, both explicitly specified and implicitly included. Also, - // record the names of any members that should be excluded from this snapshot. + // Record the names of all the members, both explicitly specified and implicitly + // included. allMembersByName := make(map[string]struct{}) exportedMembersByName := make(map[string]struct{}) - excludedMembersByName := make(map[string]struct{}) - - addMember := func(name string, export bool, exclude bool) { - if exclude { - excludedMembersByName[name] = struct{}{} - return - } + addMember := func(name string, export bool) { allMembersByName[name] = struct{}{} if export { exportedMembersByName[name] = struct{}{} @@ -391,15 +362,11 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) { name := memberVariantDep.variant.Name() export := memberVariantDep.export - // If the minApiLevel of the member is greater than the target API level then exclude it from - // this snapshot. - exclude := memberVariantDep.minApiLevel.GreaterThan(targetApiLevel) - - addMember(name, export, exclude) + addMember(name, export) // Add any components provided by the module. for _, component := range memberVariantDep.exportedComponentsInfo.Components { - addMember(component, export, exclude) + addMember(component, export) } if memberVariantDep.memberType == android.LicenseModuleSdkMemberType { @@ -415,9 +382,19 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) { modules: make(map[string]*bpModule), } + config := ctx.Config() + // Always add -current to the end snapshotFileSuffix := "-current" + currentBuildRelease := latestBuildRelease() + targetBuildReleaseEnv := config.GetenvWithDefault("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE", currentBuildRelease.name) + targetBuildRelease, err := nameToRelease(targetBuildReleaseEnv) + if err != nil { + ctx.ModuleErrorf("invalid SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE: %s", err) + targetBuildRelease = currentBuildRelease + } + builder := &snapshotBuilder{ ctx: ctx, sdk: s, @@ -428,7 +405,6 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) { prebuiltModules: make(map[string]*bpModule), allMembersByName: allMembersByName, exportedMembersByName: exportedMembersByName, - excludedMembersByName: excludedMembersByName, targetBuildRelease: targetBuildRelease, } s.builderForTests = builder @@ -462,10 +438,6 @@ be unnecessary as every module in the sdk already has its own licenses property. } name := member.name - if _, ok := excludedMembersByName[name]; ok { - continue - } - requiredTraits := traits[name] if requiredTraits == nil { requiredTraits = android.EmptySdkMemberTraitSet() @@ -500,7 +472,7 @@ be unnecessary as every module in the sdk already has its own licenses property. contents := bp.content.String() // If the snapshot is being generated for the current build release then check the syntax to make // sure that it is compatible. - if targetBuildRelease == latestBuildRelease() { + if targetBuildRelease == currentBuildRelease { syntaxCheckSnapshotBpFile(ctx, contents) } @@ -1063,9 +1035,6 @@ type snapshotBuilder struct { // The set of exported members by name. exportedMembersByName map[string]struct{} - // The set of members which have been excluded from this snapshot; by name. - excludedMembersByName map[string]struct{} - // The target build release for which the snapshot is to be generated. targetBuildRelease *buildRelease @@ -1250,9 +1219,6 @@ func (s *snapshotBuilder) snapshotSdkMemberName(name string, required bool) stri func (s *snapshotBuilder) snapshotSdkMemberNames(members []string, required bool) []string { var references []string = nil for _, m := range members { - if _, ok := s.excludedMembersByName[m]; ok { - continue - } references = append(references, s.snapshotSdkMemberName(m, required)) } return references @@ -1295,9 +1261,6 @@ type sdkMemberVariantDep struct { // The names of additional component modules provided by the variant. exportedComponentsInfo android.ExportedComponentsInfo - - // The minimum API level on which this module is supported. - minApiLevel android.ApiLevel } var _ android.SdkMember = (*sdkMember)(nil) From 9dc59c9e30492532661e5d3952e0d88df6ff7ee3 Mon Sep 17 00:00:00 2001 From: Alexei Nicoara Date: Wed, 27 Jul 2022 14:52:12 +0100 Subject: [PATCH 041/172] Moving default version outside of apex package The default version needs to be used by both apex and apk updatable modules. Moving it to android package so it can be accessed without circular dependencies. Test: presubmit Bug: 231691162 Change-Id: Icafd50d0b065e89a115ae9c9b6ea55adf2730b49 --- android/Android.bp | 1 + apex/constants.go => android/updatable_modules.go | 4 ++-- apex/Android.bp | 1 - apex/builder.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename apex/constants.go => android/updatable_modules.go (96%) diff --git a/android/Android.bp b/android/Android.bp index cbd345945..f58a47296 100644 --- a/android/Android.bp +++ b/android/Android.bp @@ -88,6 +88,7 @@ bootstrap_go_package { "test_asserts.go", "test_suites.go", "testing.go", + "updatable_modules.go", "util.go", "variable.go", "visibility.go", diff --git a/apex/constants.go b/android/updatable_modules.go similarity index 96% rename from apex/constants.go rename to android/updatable_modules.go index 82eebffde..1548170f9 100644 --- a/apex/constants.go +++ b/android/updatable_modules.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package apex +package android // This file contains branch specific constants. They are stored in a separate // file to minimise the potential of merge conflicts between branches when @@ -33,4 +33,4 @@ package apex // * AOSP - xx9990000 // * x-mainline-prod - xx9990000 // * master - 990090000 -const defaultManifestVersion = "990090000" +const DefaultUpdatableModuleVersion = "990090000" diff --git a/apex/Android.bp b/apex/Android.bp index 6533c6103..480ad0662 100644 --- a/apex/Android.bp +++ b/apex/Android.bp @@ -26,7 +26,6 @@ bootstrap_go_package { "apex_sdk_member.go", "apex_singleton.go", "builder.go", - "constants.go", "deapexer.go", "key.go", "prebuilt.go", diff --git a/apex/builder.go b/apex/builder.go index 1956b4447..d1f269139 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -214,7 +214,7 @@ func (a *apexBundle) buildManifest(ctx android.ModuleContext, provideNativeLibs, Args: map[string]string{ "provideNativeLibs": strings.Join(provideNativeLibs, " "), "requireNativeLibs": strings.Join(requireNativeLibs, " "), - "default_version": defaultManifestVersion, + "default_version": android.DefaultUpdatableModuleVersion, "opt": strings.Join(optCommands, " "), }, }) From affdd1e06def95eaf8c0b8100523164c1b32507d Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Mon, 25 Jul 2022 12:32:32 +0900 Subject: [PATCH 042/172] Allow libwifi-hal to use makefile_goal To migrate libwifi-hal from make to soong, its dependencis (libwifi-hal-) are wrapped in makefile_goal until they are migrated to soong as well. Bug: 239984067 Test: m Change-Id: Icb09ef1bf40311498db04b7358634eadd0fed5fa --- android/neverallow.go | 7 ++++++- android/neverallow_test.go | 27 ++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/android/neverallow.go b/android/neverallow.go index aa47bcaeb..00078a025 100644 --- a/android/neverallow.go +++ b/android/neverallow.go @@ -212,11 +212,16 @@ func createUncompressDexRules() []Rule { } func createMakefileGoalRules() []Rule { + allowlist := []string{ + // libwifi_hal uses makefile_goal for its dependencies + "frameworks/opt/net/wifi/libwifi_hal", + } return []Rule{ NeverAllow(). ModuleType("makefile_goal"). WithoutMatcher("product_out_path", Regexp("^boot[0-9a-zA-Z.-]*[.]img$")). - Because("Only boot images may be imported as a makefile goal."), + NotIn(allowlist...). + Because("Only boot images may be imported as a makefile goal if not in allowed projects"), } } diff --git a/android/neverallow_test.go b/android/neverallow_test.go index 86f1a378f..477279979 100644 --- a/android/neverallow_test.go +++ b/android/neverallow_test.go @@ -324,7 +324,32 @@ var neverallowTests = []struct { `), }, expectedErrors: []string{ - "Only boot images may be imported as a makefile goal.", + "Only boot images.* may be imported as a makefile goal", + }, + }, + { + name: "disallowed makefile_goal outside external", + fs: map[string][]byte{ + "project/Android.bp": []byte(` + makefile_goal { + name: "foo", + product_out_path: "obj/EXE/foo", + } + `), + }, + expectedErrors: []string{ + "not in allowed projects", + }, + }, + { + name: "allow makefile_goal within external", + fs: map[string][]byte{ + "frameworks/opt/net/wifi/libwifi_hal/Android.bp": []byte(` + makefile_goal { + name: "foo", + product_out_path: "obj/EXE/foo", + } + `), }, }, // Tests for the rule prohibiting the use of framework From 919855091cf5a9860d81c0eadd45d5109e4b14d8 Mon Sep 17 00:00:00 2001 From: Bob Badour Date: Mon, 16 May 2022 12:20:04 -0700 Subject: [PATCH 043/172] Add gen_notice module. Refactor notices to support notices for multiple modules. Enforce visibility and handle missing dependencies. Test: m cts dist reportmissinglicenses Test: m droid dist Bug: 213388645 Bug: 240342946 Change-Id: Id6a81987f087419ad37d0cce57a71e8a7c4cd6e0 Merged-in: Id6a81987f087419ad37d0cce57a71e8a7c4cd6e0 Merged-in: I07963c83eaddfe363a04871e813b56fe7f1465ad Merged-in: Ib2f8d0ad46ffe795d392166a74a7c6309b1246e2 Merged-in: I1d630c3d14d27b7605ab13d204d34b6851a24d33 --- android/Android.bp | 2 + android/gen_notice.go | 212 ++++++++++ android/gen_notice_test.go | 164 ++++++++ android/licenses.go | 1 + android/singleton.go | 31 ++ android/testing.go | 2 + android/visibility.go | 8 +- android/visibility_test.go | 816 +++++++++++++++++++++++++++++++++++-- java/app.go | 15 +- 9 files changed, 1210 insertions(+), 41 deletions(-) create mode 100644 android/gen_notice.go create mode 100644 android/gen_notice_test.go diff --git a/android/Android.bp b/android/Android.bp index d58370391..65332b2d8 100644 --- a/android/Android.bp +++ b/android/Android.bp @@ -49,6 +49,7 @@ bootstrap_go_package { "expand.go", "filegroup.go", "fixture.go", + "gen_notice.go", "hooks.go", "image.go", "license.go", @@ -106,6 +107,7 @@ bootstrap_go_package { "deptag_test.go", "expand_test.go", "fixture_test.go", + "gen_notice_test.go", "license_kind_test.go", "license_test.go", "licenses_test.go", diff --git a/android/gen_notice.go b/android/gen_notice.go new file mode 100644 index 000000000..e2b839f69 --- /dev/null +++ b/android/gen_notice.go @@ -0,0 +1,212 @@ +// Copyright 2020 Google Inc. All rights reserved. +// +// 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 android + +import ( + "fmt" + "strings" + + "github.com/google/blueprint/proptools" +) + +func init() { + RegisterGenNoticeBuildComponents(InitRegistrationContext) +} + +// Register the gen_notice module type. +func RegisterGenNoticeBuildComponents(ctx RegistrationContext) { + ctx.RegisterSingletonType("gen_notice_build_rules", GenNoticeBuildRulesFactory) + ctx.RegisterModuleType("gen_notice", GenNoticeFactory) +} + +type genNoticeBuildRules struct{} + +func (s *genNoticeBuildRules) GenerateBuildActions(ctx SingletonContext) { + ctx.VisitAllModules(func(m Module) { + gm, ok := m.(*genNoticeModule) + if !ok { + return + } + if len(gm.missing) > 0 { + missingReferencesRule(ctx, gm) + return + } + out := BuildNoticeTextOutputFromLicenseMetadata + if proptools.Bool(gm.properties.Xml) { + out = BuildNoticeXmlOutputFromLicenseMetadata + } else if proptools.Bool(gm.properties.Html) { + out = BuildNoticeHtmlOutputFromLicenseMetadata + } + defaultName := "" + if len(gm.properties.For) > 0 { + defaultName = gm.properties.For[0] + } + + modules := make([]Module, 0) + for _, name := range gm.properties.For { + mods := ctx.ModuleVariantsFromName(gm, name) + for _, mod := range mods { + if mod == nil { + continue + } + modules = append(modules, mod) + } + } + if ctx.Failed() { + return + } + out(ctx, gm.output, ctx.ModuleName(gm), + proptools.StringDefault(gm.properties.ArtifactName, defaultName), + []string{ + ctx.Config().OutDir() + "/", + ctx.Config().SoongOutDir() + "/", + }, modules...) + }) +} + +func GenNoticeBuildRulesFactory() Singleton { + return &genNoticeBuildRules{} +} + +type genNoticeProperties struct { + // For specifies the modules for which to generate a notice file. + For []string + // ArtifactName specifies the internal name to use for the notice file. + // It appears in the "used by:" list for targets whose entire name is stripped by --strip_prefix. + ArtifactName *string + // Stem specifies the base name of the output file. + Stem *string `android:"arch_variant"` + // Html indicates an html-format file is needed. The default is text. Can be Html or Xml but not both. + Html *bool + // Xml indicates an xml-format file is needed. The default is text. Can be Html or Xml but not both. + Xml *bool + // Gzipped indicates the output file must be compressed with gzip. Will append .gz to suffix if not there. + Gzipped *bool + // Suffix specifies the file extension to use. Defaults to .html for html, .xml for xml, or no extension for text. + Suffix *string + // Visibility specifies where this license can be used + Visibility []string +} + +type genNoticeModule struct { + ModuleBase + DefaultableModuleBase + + properties genNoticeProperties + + output OutputPath + missing []string +} + +func (m *genNoticeModule) DepsMutator(ctx BottomUpMutatorContext) { + if proptools.Bool(m.properties.Html) && proptools.Bool(m.properties.Xml) { + ctx.ModuleErrorf("can be html or xml but not both") + } + if !ctx.Config().AllowMissingDependencies() { + var missing []string + // Verify the modules for which to generate notices exist. + for _, otherMod := range m.properties.For { + if !ctx.OtherModuleExists(otherMod) { + missing = append(missing, otherMod) + } + } + if len(missing) == 1 { + ctx.PropertyErrorf("for", "no %q module exists", missing[0]) + } else if len(missing) > 1 { + ctx.PropertyErrorf("for", "modules \"%s\" do not exist", strings.Join(missing, "\", \"")) + } + } +} + +func (m *genNoticeModule) getStem() string { + stem := m.base().BaseModuleName() + if m.properties.Stem != nil { + stem = proptools.String(m.properties.Stem) + } + return stem +} + +func (m *genNoticeModule) getSuffix() string { + suffix := "" + if m.properties.Suffix == nil { + if proptools.Bool(m.properties.Html) { + suffix = ".html" + } else if proptools.Bool(m.properties.Xml) { + suffix = ".xml" + } + } else { + suffix = proptools.String(m.properties.Suffix) + } + if proptools.Bool(m.properties.Gzipped) && !strings.HasSuffix(suffix, ".gz") { + suffix += ".gz" + } + return suffix +} + +func (m *genNoticeModule) GenerateAndroidBuildActions(ctx ModuleContext) { + if ctx.Config().AllowMissingDependencies() { + // Verify the modules for which to generate notices exist. + for _, otherMod := range m.properties.For { + if !ctx.OtherModuleExists(otherMod) { + m.missing = append(m.missing, otherMod) + } + } + m.missing = append(m.missing, ctx.GetMissingDependencies()...) + m.missing = FirstUniqueStrings(m.missing) + } + out := m.getStem() + m.getSuffix() + m.output = PathForModuleOut(ctx, out).OutputPath +} + +func GenNoticeFactory() Module { + module := &genNoticeModule{} + + base := module.base() + module.AddProperties(&base.nameProperties, &module.properties) + + // The visibility property needs to be checked and parsed by the visibility module. + setPrimaryVisibilityProperty(module, "visibility", &module.properties.Visibility) + + initAndroidModuleBase(module) + InitDefaultableModule(module) + + return module +} + +var _ OutputFileProducer = (*genNoticeModule)(nil) + +// Implements OutputFileProducer +func (m *genNoticeModule) OutputFiles(tag string) (Paths, error) { + if tag == "" { + return Paths{m.output}, nil + } + return nil, fmt.Errorf("unrecognized tag %q", tag) +} + +// missingReferencesRule emits an ErrorRule for missing module references. +func missingReferencesRule(ctx BuilderContext, m *genNoticeModule) { + if len(m.missing) < 1 { + panic(fmt.Errorf("missing references rule requested with no missing references")) + } + + ctx.Build(pctx, BuildParams{ + Rule: ErrorRule, + Output: m.output, + Description: "notice for " + proptools.StringDefault(m.properties.ArtifactName, "container"), + Args: map[string]string{ + "error": m.Name() + " references missing module(s): " + strings.Join(m.missing, ", "), + }, + }) +} diff --git a/android/gen_notice_test.go b/android/gen_notice_test.go new file mode 100644 index 000000000..4ad2ecfa9 --- /dev/null +++ b/android/gen_notice_test.go @@ -0,0 +1,164 @@ +package android + +import ( + "testing" + + "github.com/google/blueprint" +) + +var genNoticeTests = []struct { + name string + fs MockFS + expectedErrors []string +}{ + { + name: "gen_notice must not accept licenses property", + fs: map[string][]byte{ + "top/Android.bp": []byte(` + gen_notice { + name: "top_license", + licenses: ["other_license"], + }`), + }, + expectedErrors: []string{ + `unrecognized property "licenses"`, + }, + }, + { + name: "bad gen_notice", + fs: map[string][]byte{ + "top/Android.bp": []byte(` + gen_notice { + name: "top_notice", + for: ["top_rule"], + }`), + "other/Android.bp": []byte(` + mock_genrule { + name: "other_rule", + dep: ["top_notice"], + }`), + }, + expectedErrors: []string{ + `module "top_notice": for: no "top_rule" module exists`, + }, + }, + { + name: "doubly bad gen_notice", + fs: map[string][]byte{ + "top/Android.bp": []byte(` + gen_notice { + name: "top_notice", + for: ["top_rule", "other_rule"], + }`), + }, + expectedErrors: []string{ + `module "top_notice": for: modules "top_rule", "other_rule" do not exist`, + }, + }, + { + name: "good gen_notice", + fs: map[string][]byte{ + "top/Android.bp": []byte(` + gen_notice { + name: "top_notice", + for: ["top_rule"], + } + + mock_genrule { + name: "top_rule", + dep: ["top_notice"], + }`), + "other/Android.bp": []byte(` + mock_genrule { + name: "other_rule", + dep: ["top_notice"], + }`), + }, + }, + { + name: "multiple license kinds", + fs: map[string][]byte{ + "top/Android.bp": []byte(` + gen_notice { + name: "top_notice", + for: ["top_rule"], + } + + gen_notice { + name: "top_html_notice", + html: true, + for: ["top_rule"], + } + + gen_notice { + name: "top_xml_notice", + xml: true, + for: ["top_notice"], + } + + mock_genrule { + name: "top_rule", + dep: [ + "top_notice", + "top_html_notice", + "top_xml_notice", + ], + }`), + "other/Android.bp": []byte(` + mock_genrule { + name: "other_rule", + dep: ["top_xml_notice"], + }`), + }, + }, +} + +func TestGenNotice(t *testing.T) { + for _, test := range genNoticeTests { + t.Run(test.name, func(t *testing.T) { + GroupFixturePreparers( + PrepareForTestWithGenNotice, + FixtureRegisterWithContext(func(ctx RegistrationContext) { + ctx.RegisterModuleType("mock_genrule", newMockGenruleModule) + }), + test.fs.AddToFixture(), + ). + ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)). + RunTest(t) + }) + } +} + +type mockGenruleProperties struct { + Dep []string +} + +type mockGenruleModule struct { + ModuleBase + DefaultableModuleBase + + properties mockGenruleProperties +} + +func newMockGenruleModule() Module { + m := &mockGenruleModule{} + m.AddProperties(&m.properties) + InitAndroidArchModule(m, HostAndDeviceSupported, MultilibCommon) + InitDefaultableModule(m) + return m +} + +type genruleDepTag struct { + blueprint.BaseDependencyTag +} + +func (j *mockGenruleModule) DepsMutator(ctx BottomUpMutatorContext) { + m, ok := ctx.Module().(Module) + if !ok { + return + } + ctx.AddDependency(m, genruleDepTag{}, j.properties.Dep...) +} + +func (p *mockGenruleModule) GenerateAndroidBuildActions(ModuleContext) { +} diff --git a/android/licenses.go b/android/licenses.go index bd14b26ca..81c557e72 100644 --- a/android/licenses.go +++ b/android/licenses.go @@ -303,6 +303,7 @@ func exemptFromRequiredApplicableLicensesProperty(module Module) bool { switch reflect.TypeOf(module).String() { case "*android.licenseModule": // is a license, doesn't need one case "*android.licenseKindModule": // is a license, doesn't need one + case "*android.genNoticeModule": // contains license texts as data case "*android.NamespaceModule": // just partitions things, doesn't add anything case "*android.soongConfigModuleTypeModule": // creates aliases for modules with licenses case "*android.soongConfigModuleTypeImport": // creates aliases for modules with licenses diff --git a/android/singleton.go b/android/singleton.go index 7ff96c9d5..7c6cf4fd6 100644 --- a/android/singleton.go +++ b/android/singleton.go @@ -29,6 +29,10 @@ type SingletonContext interface { ModuleType(module blueprint.Module) string BlueprintFile(module blueprint.Module) string + // ModuleVariantsFromName returns the list of module variants named `name` in the same namespace as `referer` enforcing visibility rules. + // Allows generating build actions for `referer` based on the metadata for `name` deferred until the singleton context. + ModuleVariantsFromName(referer Module, name string) []Module + // ModuleProvider returns the value, if any, for the provider for a module. If the value for the // provider was not set it returns the zero value of the type of the provider, which means the // return value can always be type-asserted to the type of the provider. The return value should @@ -251,3 +255,30 @@ func (s *singletonContextAdaptor) PrimaryModule(module Module) Module { func (s *singletonContextAdaptor) FinalModule(module Module) Module { return s.SingletonContext.FinalModule(module).(Module) } + +func (s *singletonContextAdaptor) ModuleVariantsFromName(referer Module, name string) []Module { + // get qualified module name for visibility enforcement + qualified := createQualifiedModuleName(s.ModuleName(referer), s.ModuleDir(referer)) + + modules := s.SingletonContext.ModuleVariantsFromName(referer, name) + result := make([]Module, 0, len(modules)) + for _, m := range modules { + if module, ok := m.(Module); ok { + // enforce visibility + depName := s.ModuleName(module) + depDir := s.ModuleDir(module) + depQualified := qualifiedModuleName{depDir, depName} + // Targets are always visible to other targets in their own package. + if depQualified.pkg != qualified.pkg { + rule := effectiveVisibilityRules(s.Config(), depQualified) + if !rule.matches(qualified) { + s.ModuleErrorf(referer, "module %q references %q which is not visible to this module\nYou may need to add %q to its visibility", + referer.Name(), depQualified, "//"+s.ModuleDir(referer)) + continue + } + } + result = append(result, module) + } + } + return result +} diff --git a/android/testing.go b/android/testing.go index ac02db9af..85bdca475 100644 --- a/android/testing.go +++ b/android/testing.go @@ -83,6 +83,8 @@ var PrepareForTestWithLicenses = GroupFixturePreparers( FixtureRegisterWithContext(registerLicenseMutators), ) +var PrepareForTestWithGenNotice = FixtureRegisterWithContext(RegisterGenNoticeBuildComponents) + func registerLicenseMutators(ctx RegistrationContext) { ctx.PreArchMutators(RegisterLicensesPackageMapper) ctx.PreArchMutators(RegisterLicensesPropertyGatherer) diff --git a/android/visibility.go b/android/visibility.go index 5d1be6b47..b20959944 100644 --- a/android/visibility.go +++ b/android/visibility.go @@ -234,7 +234,7 @@ func RegisterVisibilityRuleEnforcer(ctx RegisterMutatorsContext) { // Checks the per-module visibility rule lists before defaults expansion. func visibilityRuleChecker(ctx BottomUpMutatorContext) { - qualified := createQualifiedModuleName(ctx) + qualified := createQualifiedModuleName(ctx.ModuleName(), ctx.ModuleDir()) if m, ok := ctx.Module().(Module); ok { visibilityProperties := m.visibilityProperties() for _, p := range visibilityProperties { @@ -435,7 +435,7 @@ func visibilityRuleEnforcer(ctx TopDownMutatorContext) { return } - qualified := createQualifiedModuleName(ctx) + qualified := createQualifiedModuleName(ctx.ModuleName(), ctx.ModuleDir()) // Visit all the dependencies making sure that this module has access to them all. ctx.VisitDirectDeps(func(dep Module) { @@ -486,9 +486,7 @@ func effectiveVisibilityRules(config Config, qualified qualifiedModuleName) comp return rule } -func createQualifiedModuleName(ctx BaseModuleContext) qualifiedModuleName { - moduleName := ctx.ModuleName() - dir := ctx.ModuleDir() +func createQualifiedModuleName(moduleName, dir string) qualifiedModuleName { qualified := qualifiedModuleName{dir, moduleName} return qualified } diff --git a/android/visibility_test.go b/android/visibility_test.go index 714c92a71..a66f0b698 100644 --- a/android/visibility_test.go +++ b/android/visibility_test.go @@ -135,7 +135,49 @@ var visibilityTests = []struct { name: "libexample", visibility: ["//visibility:public"], } - + + mock_library { + name: "libsamepackage", + deps: ["libexample"], + } + + gen_notice { + name: "libexample-notice", + for: ["libexample"], + }`), + "top/nested/Android.bp": []byte(` + mock_library { + name: "libnested", + deps: ["libexample"], + } + + gen_notice { + name: "nested-notice", + for: ["libexample"], + }`), + "other/Android.bp": []byte(` + mock_library { + name: "libother", + deps: ["libexample"], + } + + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + }, + }, + { + // Verify that //visibility:private allows the module to be referenced from the current + // directory only. + name: "//visibility:private", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_library { + name: "libexample", + visibility: ["//visibility:private"], + } + mock_library { name: "libsamepackage", deps: ["libexample"], @@ -151,18 +193,61 @@ var visibilityTests = []struct { deps: ["libexample"], }`), }, + expectedErrors: []string{ + `module "libnested" variant "android_common": depends on //top:libexample which is not` + + ` visible to this module`, + `module "libother" variant "android_common": depends on //top:libexample which is not` + + ` visible to this module`, + }, }, { // Verify that //visibility:private allows the module to be referenced from the current // directory only. - name: "//visibility:private", + name: "//visibility:private (notices)", fs: MockFS{ "top/Android.bp": []byte(` mock_library { name: "libexample", visibility: ["//visibility:private"], } - + + mock_library { + name: "libsamepackage", + deps: ["libexample"], + } + + gen_notice { + name: "libexample-notice", + for: ["libexample"], + }`), + "top/nested/Android.bp": []byte(` + gen_notice { + name: "nested-notice", + for: ["libexample"], + }`), + "other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "nested-notice" references "//top:libexample" which is not visible to this` + + ` module\nYou may need to add "//top/nested" to its visibility`, + `module "other-notice" references "//top:libexample" which is not visible to this module\n` + + `You may need to add "//other" to its visibility`, + }, + }, + { + // Verify that :__pkg__ allows the module to be referenced from the current directory only. + name: ":__pkg__", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_library { + name: "libexample", + visibility: [":__pkg__"], + } + mock_library { name: "libsamepackage", deps: ["libexample"], @@ -187,34 +272,32 @@ var visibilityTests = []struct { }, { // Verify that :__pkg__ allows the module to be referenced from the current directory only. - name: ":__pkg__", + name: ":__pkg__ (notices)", fs: MockFS{ "top/Android.bp": []byte(` mock_library { name: "libexample", visibility: [":__pkg__"], } - - mock_library { - name: "libsamepackage", - deps: ["libexample"], + + gen_notice { + name: "libexample-notice", + for: ["libexample"], }`), "top/nested/Android.bp": []byte(` - mock_library { - name: "libnested", - deps: ["libexample"], + gen_notice { + name: "nested-notice", + for: ["libexample"], }`), "other/Android.bp": []byte(` - mock_library { - name: "libother", - deps: ["libexample"], + gen_notice { + name: "other-notice", + for: ["libexample"], }`), }, expectedErrors: []string{ - `module "libnested" variant "android_common": depends on //top:libexample which is not` + - ` visible to this module`, - `module "libother" variant "android_common": depends on //top:libexample which is not` + - ` visible to this module`, + `module "nested-notice" references "//top:libexample" which is not visible to this module`, + `module "other-notice" references "//top:libexample" which is not visible to this module`, }, }, { @@ -227,7 +310,7 @@ var visibilityTests = []struct { name: "libexample", visibility: ["//top/nested"], } - + mock_library { name: "libsamepackage", deps: ["libexample"], @@ -255,6 +338,42 @@ var visibilityTests = []struct { ` visible to this module`, }, }, + { + // Verify that //top/nested allows the module to be referenced from the current directory and + // the top/nested directory only, not a subdirectory of top/nested and not peak directory. + name: "//top/nested (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_library { + name: "libexample", + visibility: ["//top/nested"], + } + + gen_notice { + name: "libexample-notice", + for: ["libexample"], + }`), + "top/nested/Android.bp": []byte(` + gen_notice { + name: "nested-notice", + for: ["libexample"], + }`), + "top/nested/again/Android.bp": []byte(` + gen_notice { + name: "nestedagain-notice", + for: ["libexample"], + }`), + "peak/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "other-notice" references "//top:libexample" which is not visible to this module`, + `module "nestedagain-notice" references "//top:libexample" which is not visible to this module`, + }, + }, { // Verify that :__subpackages__ allows the module to be referenced from the current directory // and sub directories but nowhere else. @@ -265,7 +384,7 @@ var visibilityTests = []struct { name: "libexample", visibility: [":__subpackages__"], } - + mock_library { name: "libsamepackage", deps: ["libexample"], @@ -286,6 +405,36 @@ var visibilityTests = []struct { ` visible to this module`, }, }, + { + // Verify that :__subpackages__ allows the module to be referenced from the current directory + // and sub directories but nowhere else. + name: ":__subpackages__ (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_library { + name: "libexample", + visibility: [":__subpackages__"], + } + + gen_notice { + name: "libexample-notice", + for: ["libexample"], + }`), + "top/nested/Android.bp": []byte(` + gen_notice { + name: "nested-notice", + for: ["libexample"], + }`), + "peak/other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "other-notice" references "//top:libexample" which is not visible to this module`, + }, + }, { // Verify that //top/nested:__subpackages__ allows the module to be referenced from the current // directory and sub directories but nowhere else. @@ -296,7 +445,7 @@ var visibilityTests = []struct { name: "libexample", visibility: ["//top/nested:__subpackages__", "//other"], } - + mock_library { name: "libsamepackage", deps: ["libexample"], @@ -317,6 +466,36 @@ var visibilityTests = []struct { ` visible to this module`, }, }, + { + // Verify that //top/nested:__subpackages__ allows the module to be referenced from the current + // directory and sub directories but nowhere else. + name: "//top/nested:__subpackages__ (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_library { + name: "libexample", + visibility: ["//top/nested:__subpackages__", "//other"], + } + + gen_notice { + name: "libexample-notice", + for: ["libexample"], + }`), + "top/nested/Android.bp": []byte(` + gen_notice { + name: "nested-notice", + for: ["libexample"], + }`), + "top/other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "other-notice" references "//top:libexample" which is not visible to this module`, + }, + }, { // Verify that ["//top/nested", "//peak:__subpackages"] allows the module to be referenced from // the current directory, top/nested and peak and all its subpackages. @@ -327,7 +506,7 @@ var visibilityTests = []struct { name: "libexample", visibility: ["//top/nested", "//peak:__subpackages__"], } - + mock_library { name: "libsamepackage", deps: ["libexample"], @@ -344,6 +523,33 @@ var visibilityTests = []struct { }`), }, }, + { + // Verify that ["//top/nested", "//peak:__subpackages"] allows the module to be referenced from + // the current directory, top/nested and peak and all its subpackages. + name: `["//top/nested", "//peak:__subpackages__ (notices)"]`, + fs: MockFS{ + "top/Android.bp": []byte(` + mock_library { + name: "libexample", + visibility: ["//top/nested", "//peak:__subpackages__"], + } + + gen_notice { + name: "libexample-notice", + for: ["libexample"], + }`), + "top/nested/Android.bp": []byte(` + gen_notice { + name: "nested-notice", + for: ["libexample"], + }`), + "peak/other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + }, + }, { // Verify that //vendor... cannot be used outside vendor apart from //vendor:__subpackages__ name: `//vendor`, @@ -353,7 +559,7 @@ var visibilityTests = []struct { name: "libexample", visibility: ["//vendor:__subpackages__"], } - + mock_library { name: "libsamepackage", visibility: ["//vendor/apps/AcmeSettings"], @@ -417,6 +623,45 @@ var visibilityTests = []struct { ` visible to this module`, }, }, + { + // Check that visibility is the union of the defaults modules. + name: "defaults union, basic (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults", + visibility: ["//other"], + } + mock_library { + name: "libexample", + visibility: ["//top/nested"], + defaults: ["libexample_defaults"], + } + + gen_notice { + name: "libexample-notice", + for: ["libexample"], + }`), + "top/nested/Android.bp": []byte(` + gen_notice { + name: "nested-notice", + for: ["libexample"], + }`), + "other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "outsider-notice" references "//top:libexample" which is not visible to this module`, + }, + }, { name: "defaults union, multiple defaults", fs: MockFS{ @@ -458,6 +703,47 @@ var visibilityTests = []struct { ` visible to this module`, }, }, + { + name: "defaults union, multiple defaults (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults_1", + visibility: ["//other"], + } + mock_defaults { + name: "libexample_defaults_2", + visibility: ["//top/nested"], + } + mock_library { + name: "libexample", + defaults: ["libexample_defaults_1", "libexample_defaults_2"], + } + + gen_notice { + name: "libexample-notice", + for: ["libexample"], + }`), + "top/nested/Android.bp": []byte(` + gen_notice { + name: "nested-notice", + for: ["libexample"], + }`), + "other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "outsider-notice" references "//top:libexample" which is not visible to this module`, + }, + }, { name: "//visibility:public mixed with other in defaults", fs: MockFS{ @@ -499,6 +785,29 @@ var visibilityTests = []struct { qualifiedModuleName{pkg: "top", name: "libexample"}: {"//visibility:public"}, }, }, + { + name: "//visibility:public overriding defaults (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults", + visibility: ["//namespace"], + } + mock_library { + name: "libexample", + visibility: ["//visibility:public"], + defaults: ["libexample_defaults"], + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libexample"], + }`), + }, + effectiveVisibility: map[qualifiedModuleName][]string{ + qualifiedModuleName{pkg: "top", name: "libexample"}: {"//visibility:public"}, + }, + }, { name: "//visibility:public mixed with other from different defaults 1", fs: MockFS{ @@ -522,6 +831,34 @@ var visibilityTests = []struct { }`), }, }, + { + name: "//visibility:public mixed with other from different defaults 1", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults_1", + visibility: ["//namespace"], + } + mock_defaults { + name: "libexample_defaults_2", + visibility: ["//visibility:public"], + } + mock_library { + name: "libexample", + defaults: ["libexample_defaults_1", "libexample_defaults_2"], + } + + gen_notice { + name: "libexample-notice", + for: ["libexample"], + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libexample"], + }`), + }, + }, { name: "//visibility:public mixed with other from different defaults 2", fs: MockFS{ @@ -545,6 +882,29 @@ var visibilityTests = []struct { }`), }, }, + { + name: "//visibility:public mixed with other from different defaults 2 (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults_1", + visibility: ["//visibility:public"], + } + mock_defaults { + name: "libexample_defaults_2", + visibility: ["//namespace"], + } + mock_library { + name: "libexample", + defaults: ["libexample_defaults_1", "libexample_defaults_2"], + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libexample"], + }`), + }, + }, { name: "//visibility:private in defaults", fs: MockFS{ @@ -579,6 +939,39 @@ var visibilityTests = []struct { ` visible to this module`, }, }, + { + name: "//visibility:private in defaults (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults", + visibility: ["//visibility:private"], + } + mock_library { + name: "libexample", + defaults: ["libexample_defaults"], + } + + gen_notice { + name: "libexample-notice", + for: ["libexample"], + }`), + "top/nested/Android.bp": []byte(` + gen_notice { + name: "nested-notice", + for: ["libexample"], + }`), + "other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "nested-notice" references "//top:libexample" which is not visible to this module`, + `module "other-notice" references "//top:libexample" which is not visible to this module`, + }, + }, { name: "//visibility:private mixed with other in defaults", fs: MockFS{ @@ -705,6 +1098,27 @@ var visibilityTests = []struct { }`), }, }, + { + name: "//visibility:override discards //visibility:private (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults", + visibility: ["//visibility:private"], + } + mock_library { + name: "libexample", + // Make this visibility to //other but not //visibility:private + visibility: ["//visibility:override", "//other"], + defaults: ["libexample_defaults"], + }`), + "other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + }, + }, { name: "//visibility:override discards //visibility:public", fs: MockFS{ @@ -734,6 +1148,35 @@ var visibilityTests = []struct { `module "libnamespace" variant "android_common": depends on //top:libexample which is not visible to this module\nYou may need to add "//namespace" to its visibility`, }, }, + { + name: "//visibility:override discards //visibility:public (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults", + visibility: ["//visibility:public"], + } + mock_library { + name: "libexample", + // Make this visibility to //other but not //visibility:public + visibility: ["//visibility:override", "//other"], + defaults: ["libexample_defaults"], + }`), + "other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + "namespace/Android.bp": []byte(` + gen_notice { + name: "namespace-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "namespace-notice" references "//top:libexample" which is not visible to this module\nYou may need to add "//namespace" to its visibility`, + }, + }, { name: "//visibility:override discards defaults supplied rules", fs: MockFS{ @@ -763,6 +1206,35 @@ var visibilityTests = []struct { `module "libnamespace" variant "android_common": depends on //top:libexample which is not visible to this module\nYou may need to add "//namespace" to its visibility`, }, }, + { + name: "//visibility:override discards defaults supplied rules (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults", + visibility: ["//namespace"], + } + mock_library { + name: "libexample", + // Make this visibility to //other but not //namespace + visibility: ["//visibility:override", "//other"], + defaults: ["libexample_defaults"], + }`), + "other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + "namespace/Android.bp": []byte(` + gen_notice { + name: "namespace-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "namespace-notice" references "//top:libexample" which is not visible to this module\nYou may need to add "//namespace" to its visibility`, + }, + }, { name: "//visibility:override can override //visibility:public with //visibility:private", fs: MockFS{ @@ -786,6 +1258,29 @@ var visibilityTests = []struct { `module "libnamespace" variant "android_common": depends on //top:libexample which is not visible to this module`, }, }, + { + name: "//visibility:override can override //visibility:public with //visibility:private (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults", + visibility: ["//visibility:public"], + } + mock_library { + name: "libexample", + visibility: ["//visibility:override", "//visibility:private"], + defaults: ["libexample_defaults"], + }`), + "namespace/Android.bp": []byte(` + gen_notice { + name: "namespace-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "namespace-notice" references "//top:libexample" which is not visible to this module`, + }, + }, { name: "//visibility:override can override //visibility:private with //visibility:public", fs: MockFS{ @@ -806,6 +1301,26 @@ var visibilityTests = []struct { }`), }, }, + { + name: "//visibility:override can override //visibility:private with //visibility:public (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults", + visibility: ["//visibility:private"], + } + mock_library { + name: "libexample", + visibility: ["//visibility:override", "//visibility:public"], + defaults: ["libexample_defaults"], + }`), + "namespace/Android.bp": []byte(` + gen_notice { + name: "namespace-notice", + for: ["libexample"], + }`), + }, + }, { name: "//visibility:private mixed with itself", fs: MockFS{ @@ -834,6 +1349,33 @@ var visibilityTests = []struct { ` visible to this module`, }, }, + { + name: "//visibility:private mixed with itself (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults_1", + visibility: ["//visibility:private"], + } + mock_defaults { + name: "libexample_defaults_2", + visibility: ["//visibility:private"], + } + mock_library { + name: "libexample", + visibility: ["//visibility:private"], + defaults: ["libexample_defaults_1", "libexample_defaults_2"], + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "outsider-notice" references "//top:libexample" which is not visible to this module`, + }, + }, // Defaults module's defaults_visibility tests { @@ -902,6 +1444,28 @@ var visibilityTests = []struct { ` visible to this module`, }, }, + { + // This test relies on the default visibility being legacy_public. + name: "package default_visibility property used when no visibility specified (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + package { + default_visibility: ["//visibility:private"], + } + + mock_library { + name: "libexample", + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "outsider-notice" references "//top:libexample" which is not visible to this module`, + }, + }, { name: "package default_visibility public does not override visibility private", fs: MockFS{ @@ -925,6 +1489,28 @@ var visibilityTests = []struct { ` visible to this module`, }, }, + { + name: "package default_visibility public does not override visibility private (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + package { + default_visibility: ["//visibility:public"], + } + + mock_library { + name: "libexample", + visibility: ["//visibility:private"], + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "outsider-notice" references "//top:libexample" which is not visible to this module`, + }, + }, { name: "package default_visibility private does not override visibility public", fs: MockFS{ @@ -944,6 +1530,25 @@ var visibilityTests = []struct { }`), }, }, + { + name: "package default_visibility private does not override visibility public (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + package { + default_visibility: ["//visibility:private"], + } + + mock_library { + name: "libexample", + visibility: ["//visibility:public"], + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libexample"], + }`), + }, + }, { name: "package default_visibility :__subpackages__", fs: MockFS{ @@ -971,6 +1576,32 @@ var visibilityTests = []struct { ` visible to this module`, }, }, + { + name: "package default_visibility :__subpackages__ (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + package { + default_visibility: [":__subpackages__"], + } + + mock_library { + name: "libexample", + }`), + "top/nested/Android.bp": []byte(` + gen_notice { + name: "nested-notice", + for: ["libexample"], + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "outsider-notice" references "//top:libexample" which is not visible to this module`, + }, + }, { name: "package default_visibility inherited to subpackages", fs: MockFS{ @@ -981,7 +1612,7 @@ var visibilityTests = []struct { mock_library { name: "libexample", - visibility: [":__subpackages__"], + visibility: [":__subpackages__"], }`), "top/nested/Android.bp": []byte(` mock_library { @@ -999,6 +1630,38 @@ var visibilityTests = []struct { ` visible to this module`, }, }, + { + name: "package default_visibility inherited to subpackages (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + package { + default_visibility: ["//outsider"], + } + + mock_library { + name: "libexample", + visibility: [":__subpackages__"], + }`), + "top/nested/Android.bp": []byte(` + mock_library { + name: "libnested", + deps: ["libexample"], + } + + gen_notice { + name: "nested-notice", + for: ["libexample"], + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libexample", "libnested"], + }`), + }, + expectedErrors: []string{ + `module "outsider-notice" references "//top:libexample" which is not visible to this module`, + }, + }, { name: "package default_visibility inherited to subpackages", fs: MockFS{ @@ -1029,6 +1692,41 @@ var visibilityTests = []struct { ` not visible to this module`, }, }, + { + name: "package default_visibility inherited to subpackages (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + package { + default_visibility: ["//visibility:private"], + }`), + "top/nested/Android.bp": []byte(` + package { + default_visibility: ["//outsider"], + } + + mock_library { + name: "libnested", + }`), + "top/other/Android.bp": []byte(` + mock_library { + name: "libother", + } + + gen_notice { + name: "other-notice", + for: ["libother"], + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libother", "libnested"], + }`), + }, + expectedErrors: []string{ + `module "outsider-notice" references "//top/other:libother" which is not visible to this` + + ` module\nYou may need to add "//outsider" to its visibility`, + }, + }, { name: "verify that prebuilt dependencies are ignored for visibility reasons (not preferred)", fs: MockFS{ @@ -1051,6 +1749,28 @@ var visibilityTests = []struct { }`), }, }, + { + name: "verify that prebuilt dependencies are ignored for visibility reasons (not preferred) (notices)", + fs: MockFS{ + "prebuilts/Android.bp": []byte(` + prebuilt { + name: "module", + visibility: ["//top/other"], + }`), + "top/sources/source_file": nil, + "top/sources/Android.bp": []byte(` + source { + name: "module", + visibility: ["//top/other"], + }`), + "top/other/source_file": nil, + "top/other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["module"], + }`), + }, + }, { name: "verify that prebuilt dependencies are ignored for visibility reasons (preferred)", fs: MockFS{ @@ -1074,6 +1794,29 @@ var visibilityTests = []struct { }`), }, }, + { + name: "verify that prebuilt dependencies are ignored for visibility reasons (preferred) (notices)", + fs: MockFS{ + "prebuilts/Android.bp": []byte(` + prebuilt { + name: "module", + visibility: ["//top/other"], + prefer: true, + }`), + "top/sources/source_file": nil, + "top/sources/Android.bp": []byte(` + source { + name: "module", + visibility: ["//top/other"], + }`), + "top/other/source_file": nil, + "top/other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["module"], + }`), + }, + }, { name: "ensure visibility properties are checked for correctness", fs: MockFS{ @@ -1137,6 +1880,30 @@ var visibilityTests = []struct { }`), }, }, + { + name: "automatic visibility inheritance enabled (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_parent { + name: "parent", + visibility: ["//top/nested"], + child: { + name: "libchild", + visibility: ["//top/other"], + }, + }`), + "top/nested/Android.bp": []byte(` + gen_notice { + name: "nested-notice", + for: ["libchild"], + }`), + "top/other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libchild"], + }`), + }, + }, } func TestVisibility(t *testing.T) { @@ -1147,6 +1914,7 @@ func TestVisibility(t *testing.T) { // registration order. PrepareForTestWithArchMutator, PrepareForTestWithDefaults, + PrepareForTestWithGenNotice, PrepareForTestWithOverrides, PrepareForTestWithPackageModule, PrepareForTestWithPrebuilts, diff --git a/java/app.go b/java/app.go index 41419ba78..94e6fb950 100755 --- a/java/app.go +++ b/java/app.go @@ -589,16 +589,6 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { a.classLoaderContexts = a.usesLibrary.classLoaderContextForUsesLibDeps(ctx) - var noticeAssetPath android.WritablePath - if Bool(a.appProperties.Embed_notices) || ctx.Config().IsEnvTrue("ALWAYS_EMBED_NOTICES") { - // The rule to create the notice file can't be generated yet, as the final output path - // for the apk isn't known yet. Add the path where the notice file will be generated to the - // aapt rules now before calling aaptBuildActions, the rule to create the notice file will - // be generated later. - noticeAssetPath = android.PathForModuleOut(ctx, "NOTICE", "NOTICE.html.gz") - a.aapt.noticeFile = android.OptionalPathForPath(noticeAssetPath) - } - // Process all building blocks, from AAPT to certificates. a.aaptBuildActions(ctx) @@ -673,8 +663,7 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { a.extraOutputFiles = append(a.extraOutputFiles, v4SignatureFile) } - if a.aapt.noticeFile.Valid() { - // Generating the notice file rule has to be here after a.outputFile is known. + if Bool(a.appProperties.Embed_notices) || ctx.Config().IsEnvTrue("ALWAYS_EMBED_NOTICES") { noticeFile := android.PathForModuleOut(ctx, "NOTICE.html.gz") android.BuildNoticeHtmlOutputFromLicenseMetadata( ctx, noticeFile, "", "", @@ -683,11 +672,13 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { android.PathForModuleInstall(ctx).String() + "/", a.outputFile.String(), }) + noticeAssetPath := android.PathForModuleOut(ctx, "NOTICE", "NOTICE.html.gz") builder := android.NewRuleBuilder(pctx, ctx) builder.Command().Text("cp"). Input(noticeFile). Output(noticeAssetPath) builder.Build("notice_dir", "Building notice dir") + a.aapt.noticeFile = android.OptionalPathForPath(noticeAssetPath) } for _, split := range a.aapt.splits { From 65ebcd772e76f057c3268096c94579f7265b2776 Mon Sep 17 00:00:00 2001 From: Bob Badour Date: Wed, 13 Apr 2022 11:27:19 -0700 Subject: [PATCH 044/172] Make sure dist files have license metadata. Bug: 151177513 Bug: 210912771 Bug: 240342946 Test: m droid dist reportmissinglicenses Change-Id: I0c85f6c49a3e9d9bb3219ed6ddfb939d90f80656 Merged-in: I0c85f6c49a3e9d9bb3219ed6ddfb939d90f80656 --- android/androidmk.go | 8 ++++++++ android/androidmk_test.go | 15 ++++++++++++++- apex/androidmk.go | 1 + java/androidmk.go | 1 + java/platform_bootclasspath_test.go | 4 +++- 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/android/androidmk.go b/android/androidmk.go index 5c715b473..6b675a66c 100644 --- a/android/androidmk.go +++ b/android/androidmk.go @@ -288,6 +288,8 @@ func (a *AndroidMkEntries) AddCompatibilityTestSuites(suites ...string) { // The contributions to the dist. type distContributions struct { + // Path to license metadata file. + licenseMetadataFile Path // List of goals and the dist copy instructions. copiesForGoals []*copiesForGoals } @@ -364,6 +366,8 @@ func (a *AndroidMkEntries) getDistContributions(mod blueprint.Module) *distContr // Collate the contributions this module makes to the dist. distContributions := &distContributions{} + distContributions.licenseMetadataFile = amod.licenseMetadataFile + // Iterate over this module's dist structs, merged from the dist and dists properties. for _, dist := range amod.Dists() { // Get the list of goals this dist should be enabled for. e.g. sdk, droidcore @@ -454,6 +458,10 @@ func generateDistContributionsForMake(distContributions *distContributions) []st ret = append(ret, fmt.Sprintf(".PHONY: %s\n", d.goals)) // Create dist-for-goals calls for each of the copy instructions. for _, c := range d.copies { + ret = append( + ret, + fmt.Sprintf("$(if $(strip $(ALL_TARGETS.%s.META_LIC)),,$(eval ALL_TARGETS.%s.META_LIC := %s))\n", + c.from.String(), c.from.String(), distContributions.licenseMetadataFile.String())) ret = append( ret, fmt.Sprintf("$(call dist-for-goals,%s,%s:%s)\n", d.goals, c.from.String(), c.dest)) diff --git a/android/androidmk_test.go b/android/androidmk_test.go index caf11f10f..ae2187f48 100644 --- a/android/androidmk_test.go +++ b/android/androidmk_test.go @@ -50,6 +50,8 @@ const ( func (m *customModule) GenerateAndroidBuildActions(ctx ModuleContext) { + m.base().licenseMetadataFile = PathForOutput(ctx, "meta_lic") + // If the dist_output_file: true then create an output file that is stored in // the OutputFile property of the AndroidMkEntry. if proptools.BoolDefault(m.properties.Dist_output_file, true) { @@ -198,10 +200,13 @@ func TestGenerateDistContributionsForMake(t *testing.T) { }, } + dc.licenseMetadataFile = PathForTesting("meta_lic") makeOutput := generateDistContributionsForMake(dc) assertStringEquals(t, `.PHONY: my_goal +$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic)) $(call dist-for-goals,my_goal,one.out:one.out) +$(if $(strip $(ALL_TARGETS.two.out.META_LIC)),,$(eval ALL_TARGETS.two.out.META_LIC := meta_lic)) $(call dist-for-goals,my_goal,two.out:other.out) `, strings.Join(makeOutput, "")) } @@ -243,18 +248,26 @@ func TestGetDistForGoals(t *testing.T) { expectedAndroidMkLines := []string{ ".PHONY: my_second_goal\n", + "$(if $(strip $(ALL_TARGETS.two.out.META_LIC)),,$(eval ALL_TARGETS.two.out.META_LIC := meta_lic))\n", "$(call dist-for-goals,my_second_goal,two.out:two.out)\n", + "$(if $(strip $(ALL_TARGETS.three/four.out.META_LIC)),,$(eval ALL_TARGETS.three/four.out.META_LIC := meta_lic))\n", "$(call dist-for-goals,my_second_goal,three/four.out:four.out)\n", ".PHONY: my_third_goal\n", + "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))\n", "$(call dist-for-goals,my_third_goal,one.out:test/dir/one.out)\n", ".PHONY: my_fourth_goal\n", + "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))\n", "$(call dist-for-goals,my_fourth_goal,one.out:one.suffix.out)\n", ".PHONY: my_fifth_goal\n", + "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))\n", "$(call dist-for-goals,my_fifth_goal,one.out:new-name)\n", ".PHONY: my_sixth_goal\n", + "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))\n", "$(call dist-for-goals,my_sixth_goal,one.out:some/dir/new-name.suffix)\n", ".PHONY: my_goal my_other_goal\n", + "$(if $(strip $(ALL_TARGETS.two.out.META_LIC)),,$(eval ALL_TARGETS.two.out.META_LIC := meta_lic))\n", "$(call dist-for-goals,my_goal my_other_goal,two.out:two.out)\n", + "$(if $(strip $(ALL_TARGETS.three/four.out.META_LIC)),,$(eval ALL_TARGETS.three/four.out.META_LIC := meta_lic))\n", "$(call dist-for-goals,my_goal my_other_goal,three/four.out:four.out)\n", } @@ -274,7 +287,7 @@ func TestGetDistForGoals(t *testing.T) { ) } for idx, line := range androidMkLines { - expectedLine := expectedAndroidMkLines[idx] + expectedLine := strings.ReplaceAll(expectedAndroidMkLines[idx], "meta_lic", module.base().licenseMetadataFile.String()) if line != expectedLine { t.Errorf( "Expected AndroidMk line to be '%s', got '%s'", diff --git a/apex/androidmk.go b/apex/androidmk.go index e094a1276..938c8edd3 100644 --- a/apex/androidmk.go +++ b/apex/androidmk.go @@ -412,6 +412,7 @@ func (a *apexBundle) androidMkForType() android.AndroidMkData { fmt.Fprintln(w, ".PHONY:", goal) fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n", goal, a.installedFilesFile.String(), distFile) + fmt.Fprintf(w, "$(call declare-0p-target,%s)\n", a.installedFilesFile.String()) } for _, dist := range data.Entries.GetDistForGoals(a) { fmt.Fprintf(w, dist) diff --git a/java/androidmk.go b/java/androidmk.go index 7322637a7..a9a21b648 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -618,6 +618,7 @@ func (dstubs *Droidstubs) AndroidMkEntries() []android.AndroidMkEntries { if dstubs.apiLintReport != nil { fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n", dstubs.Name()+"-api-lint", dstubs.apiLintReport.String(), "apilint/"+dstubs.Name()+"-lint-report.txt") + fmt.Fprintf(w, "$(call declare-0p-target,%s)\n", dstubs.apiLintReport.String()) } } if dstubs.checkNullabilityWarningsTimestamp != nil { diff --git a/java/platform_bootclasspath_test.go b/java/platform_bootclasspath_test.go index 1c2a3aee5..cb0902079 100644 --- a/java/platform_bootclasspath_test.go +++ b/java/platform_bootclasspath_test.go @@ -271,7 +271,9 @@ func TestPlatformBootclasspath_Dist(t *testing.T) { entries := android.AndroidMkEntriesForTest(t, result.TestContext, platformBootclasspath) goals := entries[0].GetDistForGoals(platformBootclasspath) android.AssertStringEquals(t, "platform dist goals phony", ".PHONY: droidcore\n", goals[0]) - android.AssertStringEquals(t, "platform dist goals call", "$(call dist-for-goals,droidcore,out/soong/hiddenapi/hiddenapi-flags.csv:hiddenapi-flags.csv)\n", android.StringRelativeToTop(result.Config, goals[1])) + android.AssertStringDoesContain(t, "platform dist goals meta check", goals[1], "$(if $(strip $(ALL_TARGETS.") + android.AssertStringDoesContain(t, "platform dist goals meta assign", goals[1], "),,$(eval ALL_TARGETS.") + android.AssertStringEquals(t, "platform dist goals call", "$(call dist-for-goals,droidcore,out/soong/hiddenapi/hiddenapi-flags.csv:hiddenapi-flags.csv)\n", android.StringRelativeToTop(result.Config, goals[2])) } func TestPlatformBootclasspath_HiddenAPIMonolithicFiles(t *testing.T) { From 877d5ee596a517b8094f11c3689ba257232c938a Mon Sep 17 00:00:00 2001 From: Bob Badour Date: Fri, 27 May 2022 19:42:16 -0700 Subject: [PATCH 045/172] Tool to create license metadata for copied target. Bug: 213388645 Bug: 240342946 Test: m copy_license_metadata Test: m cts dist reportmissinglicenses Change-Id: I75c196ceca221effb2d6c972e250f5d42854e42f Merged-in: I75c196ceca221effb2d6c972e250f5d42854e42f --- android/licenses.go | 2 + compliance/copy_license_metadata/Android.bp | 30 ++++ .../copy_license_metadata.go | 144 ++++++++++++++++++ 3 files changed, 176 insertions(+) create mode 100644 compliance/copy_license_metadata/Android.bp create mode 100644 compliance/copy_license_metadata/copy_license_metadata.go diff --git a/android/licenses.go b/android/licenses.go index 81c557e72..c47b3e63d 100644 --- a/android/licenses.go +++ b/android/licenses.go @@ -331,6 +331,8 @@ func init() { func licensesMakeVarsProvider(ctx MakeVarsContext) { ctx.Strict("BUILD_LICENSE_METADATA", ctx.Config().HostToolPath(ctx, "build_license_metadata").String()) + ctx.Strict("COPY_LICENSE_METADATA", + ctx.Config().HostToolPath(ctx, "copy_license_metadata").String()) ctx.Strict("HTMLNOTICE", ctx.Config().HostToolPath(ctx, "htmlnotice").String()) ctx.Strict("XMLNOTICE", ctx.Config().HostToolPath(ctx, "xmlnotice").String()) ctx.Strict("TEXTNOTICE", ctx.Config().HostToolPath(ctx, "textnotice").String()) diff --git a/compliance/copy_license_metadata/Android.bp b/compliance/copy_license_metadata/Android.bp new file mode 100644 index 000000000..83019eb2f --- /dev/null +++ b/compliance/copy_license_metadata/Android.bp @@ -0,0 +1,30 @@ +// Copyright 2022 Google Inc. All rights reserved. +// +// 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 { + default_applicable_licenses: ["Android-Apache-2.0"], +} + +blueprint_go_binary { + name: "copy_license_metadata", + srcs: [ + "copy_license_metadata.go", + ], + deps: [ + "license_metadata_proto", + "golang-protobuf-proto", + "golang-protobuf-encoding-prototext", + "soong-response", + ], +} diff --git a/compliance/copy_license_metadata/copy_license_metadata.go b/compliance/copy_license_metadata/copy_license_metadata.go new file mode 100644 index 000000000..36b94898c --- /dev/null +++ b/compliance/copy_license_metadata/copy_license_metadata.go @@ -0,0 +1,144 @@ +// Copyright 2022 Google Inc. All rights reserved. +// +// 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 main + +import ( + "flag" + "fmt" + "io/ioutil" + "os" + "strings" + + "google.golang.org/protobuf/encoding/prototext" + "google.golang.org/protobuf/proto" + + "android/soong/compliance/license_metadata_proto" + "android/soong/response" +) + +func newMultiString(flags *flag.FlagSet, name, usage string) *multiString { + var f multiString + flags.Var(&f, name, usage) + return &f +} + +type multiString []string + +func (ms *multiString) String() string { return strings.Join(*ms, ", ") } +func (ms *multiString) Set(s string) error { *ms = append(*ms, s); return nil } + +func main() { + var expandedArgs []string + for _, arg := range os.Args[1:] { + if strings.HasPrefix(arg, "@") { + f, err := os.Open(strings.TrimPrefix(arg, "@")) + if err != nil { + fmt.Fprintln(os.Stderr, err.Error()) + os.Exit(1) + } + + respArgs, err := response.ReadRspFile(f) + f.Close() + if err != nil { + fmt.Fprintln(os.Stderr, err.Error()) + os.Exit(1) + } + expandedArgs = append(expandedArgs, respArgs...) + } else { + expandedArgs = append(expandedArgs, arg) + } + } + + flags := flag.NewFlagSet("flags", flag.ExitOnError) + + installed := flags.String("i", "", "installed target") + sources := newMultiString(flags, "s", "source (input) file") + dep := flags.String("d", "", "license metadata file dependency") + outFile := flags.String("o", "", "output file") + + flags.Parse(expandedArgs) + + if len(*dep) == 0 || len(*installed) == 0 || len(*sources) == 0 { + flags.Usage() + if len(*dep) == 0 { + fmt.Fprintf(os.Stderr, "source license metadata (-d flag) required\n") + } + if len(*sources) == 0 { + fmt.Fprintf(os.Stderr, "source copy (-s flag required\n") + } + if len(*installed) == 0 { + fmt.Fprintf(os.Stderr, "installed copy (-i flag) required\n") + } + os.Exit(1) + } + + src_metadata := license_metadata_proto.LicenseMetadata{} + err := readMetadata(*dep, &src_metadata) + if err != nil { + fmt.Fprintf(os.Stderr, "error: %s\n", err.Error()) + os.Exit(2) + } + + metadata := src_metadata + metadata.Built = nil + metadata.InstallMap = nil + metadata.Installed = []string{*installed} + metadata.Sources = *sources + metadata.Deps = []*license_metadata_proto.AnnotatedDependency{&license_metadata_proto.AnnotatedDependency{ + File: proto.String(*dep), + Annotations: []string{"static"}, + }} + + err = writeMetadata(*outFile, &metadata) + if err != nil { + fmt.Fprintf(os.Stderr, "error: %s\n", err.Error()) + os.Exit(2) + } +} + +func readMetadata(file string, metadata *license_metadata_proto.LicenseMetadata) error { + if file == "" { + return fmt.Errorf("source metadata file (-d) required") + } + buf, err := ioutil.ReadFile(file) + if err != nil { + return fmt.Errorf("error reading textproto %q: %w", file, err) + } + + err = prototext.Unmarshal(buf, metadata) + if err != nil { + return fmt.Errorf("error unmarshalling textproto: %w", err) + } + + return nil +} + +func writeMetadata(file string, metadata *license_metadata_proto.LicenseMetadata) error { + buf, err := prototext.MarshalOptions{Multiline: true}.Marshal(metadata) + if err != nil { + return fmt.Errorf("error marshalling textproto: %w", err) + } + + if file != "" { + err = ioutil.WriteFile(file, buf, 0666) + if err != nil { + return fmt.Errorf("error writing textproto %q: %w", file, err) + } + } else { + _, _ = os.Stdout.Write(buf) + } + + return nil +} From c2b6dec6d15241433e319ba96cfe0342580c0a1f Mon Sep 17 00:00:00 2001 From: Bob Badour Date: Tue, 21 Jun 2022 11:12:01 -0700 Subject: [PATCH 046/172] Fix escaping for package_name Bug: 235333302 Bug: 240342946 Test: m droid dist Change-Id: I6e52b960be4171a9510edd4f2857f13cc3f54bc0 Merged-in: I6e52b960be4171a9510edd4f2857f13cc3f54bc0 --- android/license_metadata.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/license_metadata.go b/android/license_metadata.go index 48c1383f6..f2ab0a44c 100644 --- a/android/license_metadata.go +++ b/android/license_metadata.go @@ -105,7 +105,7 @@ func buildLicenseMetadata(ctx ModuleContext, licenseMetadataFile WritablePath) { if p := base.commonProperties.Effective_package_name; p != nil { args = append(args, - `-p "`+proptools.NinjaAndShellEscape(*p)+`"`) + `-p `+proptools.NinjaAndShellEscapeIncludingSpaces(*p)) } args = append(args, From c4d437c6bf161b2c6b1d80bba1fc5b045ee287c7 Mon Sep 17 00:00:00 2001 From: Bob Badour Date: Thu, 14 Jul 2022 10:38:27 -0700 Subject: [PATCH 047/172] Keep Notice property from erasing license texts. Remove "default to file in directory". Use explicit applicable license. Bug: 192434786 Bug: 240342946 Test: m droid dist Change-Id: Id3d845b2073f151a8c0bad874e7ab005771bdfcb Merged-in: Id3d845b2073f151a8c0bad874e7ab005771bdfcb --- android/androidmk.go | 2 +- android/module.go | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/android/androidmk.go b/android/androidmk.go index 6b675a66c..1a9cabd6b 100644 --- a/android/androidmk.go +++ b/android/androidmk.go @@ -605,7 +605,7 @@ func (a *AndroidMkEntries) fillInEntries(ctx fillInEntriesContext, mod blueprint } if len(base.noticeFiles) > 0 { - a.SetString("LOCAL_NOTICE_FILE", strings.Join(base.noticeFiles.Strings(), " ")) + a.AddStrings("LOCAL_NOTICE_FILE", strings.Join(base.noticeFiles.Strings(), " ")) } if host { diff --git a/android/module.go b/android/module.go index 7285a2f21..6f27f79a7 100644 --- a/android/module.go +++ b/android/module.go @@ -2260,14 +2260,6 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) } if optPath.Valid() { m.noticeFiles = append(m.noticeFiles, optPath.Path()) - } else { - for _, notice = range []string{"LICENSE", "LICENCE", "NOTICE"} { - noticePath := filepath.Join(ctx.ModuleDir(), notice) - optPath = ExistentPathForSource(ctx, noticePath) - if optPath.Valid() { - m.noticeFiles = append(m.noticeFiles, optPath.Path()) - } - } } licensesPropertyFlattener(ctx) From 4987e7e3973f092cf919e58ffda572a48439ad10 Mon Sep 17 00:00:00 2001 From: Remi NGUYEN VAN Date: Thu, 4 Aug 2022 13:19:03 +0900 Subject: [PATCH 048/172] Make ignorewarnings optional in optimize This allows targets to opt-in to running R8 without the -ignorewarnings flag. Ignored warnings can cause code to be optimized incorrectly, so this makes the build safer for such targets. Ideally ignore_warnings should default to false, but all targets need to be fixed for that to happen. As a first step, provide a mechanism for individual targets to ensure they do not introduce regressions. Bug: 229727645 Bug: 180878971 Bug: 226127213 Bug: 239990030 Test: m (runs dex_test) Change-Id: Ic0eef29598c1ee47e958da8a5048d9696165a235 (cherry picked from commit bdad314f978cf52a9e3f5c1db5f39169fcecc610) Merged-In: Ic0eef29598c1ee47e958da8a5048d9696165a235 --- java/dex.go | 8 +++++++- java/dex_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/java/dex.go b/java/dex.go index 84665e7b5..1638376d8 100644 --- a/java/dex.go +++ b/java/dex.go @@ -42,6 +42,9 @@ type DexProperties struct { // True if the module containing this has it set by default. EnabledByDefault bool `blueprint:"mutated"` + // Whether to continue building even if warnings are emitted. Defaults to true. + Ignore_warnings *bool + // If true, runs R8 in Proguard compatibility mode (default). // Otherwise, runs R8 in full mode. Proguard_compatibility *bool @@ -293,7 +296,10 @@ func (d *dexer) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8Fl } // TODO(b/180878971): missing classes should be added to the relevant builds. - r8Flags = append(r8Flags, "-ignorewarnings") + // TODO(b/229727645): do not use true as default for Android platform builds. + if proptools.BoolDefault(opt.Ignore_warnings, true) { + r8Flags = append(r8Flags, "-ignorewarnings") + } return r8Flags, r8Deps } diff --git a/java/dex_test.go b/java/dex_test.go index fbdccb65d..a3e2deda4 100644 --- a/java/dex_test.go +++ b/java/dex_test.go @@ -59,6 +59,36 @@ func TestR8(t *testing.T) { appR8.Args["r8Flags"], libHeader.String()) android.AssertStringDoesNotContain(t, "expected no static_lib header jar in app javac classpath", appR8.Args["r8Flags"], staticLibHeader.String()) + android.AssertStringDoesContain(t, "expected -ignorewarnings in app r8 flags", + appR8.Args["r8Flags"], "-ignorewarnings") +} + +func TestR8Flags(t *testing.T) { + result := PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd.RunTestWithBp(t, ` + android_app { + name: "app", + srcs: ["foo.java"], + platform_apis: true, + optimize: { + shrink: false, + optimize: false, + obfuscate: false, + ignore_warnings: false, + }, + } + `) + + app := result.ModuleForTests("app", "android_common") + appR8 := app.Rule("r8") + android.AssertStringDoesContain(t, "expected -dontshrink in app r8 flags", + appR8.Args["r8Flags"], "-dontshrink") + android.AssertStringDoesContain(t, "expected -dontoptimize in app r8 flags", + appR8.Args["r8Flags"], "-dontoptimize") + android.AssertStringDoesContain(t, "expected -dontobfuscate in app r8 flags", + appR8.Args["r8Flags"], "-dontobfuscate") + android.AssertStringDoesNotContain(t, "expected no -ignorewarnings in app r8 flags", + appR8.Args["r8Flags"], "-ignorewarnings") + } func TestD8(t *testing.T) { From cf9b0070c02cf1a49229f6c946b14c66d2c8d32c Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Mon, 25 Jul 2022 00:34:18 +0000 Subject: [PATCH 049/172] Set targetSdkVersion to 10000 for MTS tests targeting current MTS tests built on unstable branches (e.g. git_master) should be testable on old system images (e.g. S). However, they run into an error during installation on older images: `Requires development platform $, but this is a release platform` This CL fixes this issue by updating the target_sdk_version of MTS test apps targeting current to the magical sdk_version 10000 Bug: 227473065 Test: go build ./java Test: TH Change-Id: Ic0358a48a19dc239defbb4ee8ec99225cce75584 Merged-In: Ic0358a48a19dc239defbb4ee8ec99225cce75584 --- java/android_manifest.go | 15 +++++++++- java/app.go | 12 ++++++++ java/app_test.go | 62 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) diff --git a/java/android_manifest.go b/java/android_manifest.go index 7772b7090..1553564c2 100644 --- a/java/android_manifest.go +++ b/java/android_manifest.go @@ -45,7 +45,11 @@ var manifestMergerRule = pctx.AndroidStaticRule("manifestMerger", // This enables release builds (that run with TARGET_BUILD_APPS=[val...]) to target APIs that have not yet been finalized as part of an SDK func targetSdkVersionForManifestFixer(ctx android.ModuleContext, sdkContext android.SdkContext) string { targetSdkVersionSpec := sdkContext.TargetSdkVersion(ctx) - if ctx.Config().UnbundledBuildApps() && targetSdkVersionSpec.ApiLevel.IsPreview() { + // Return 10000 for modules targeting "current" if either + // 1. The module is built in unbundled mode (TARGET_BUILD_APPS not empty) + // 2. The module is run as part of MTS, and should be testable on stable branches + // TODO(b/240294501): Determine the rules for handling test apexes + if targetSdkVersionSpec.ApiLevel.IsPreview() && (ctx.Config().UnbundledBuildApps() || includedInMts(ctx.Module())) { return strconv.Itoa(android.FutureApiLevel.FinalOrFutureInt()) } targetSdkVersion, err := targetSdkVersionSpec.EffectiveVersionString(ctx) @@ -55,6 +59,15 @@ func targetSdkVersionForManifestFixer(ctx android.ModuleContext, sdkContext andr return targetSdkVersion } +// Helper function that casts android.Module to java.androidTestApp +// If this type conversion is possible, it queries whether the test app is included in an MTS suite +func includedInMts(module android.Module) bool { + if test, ok := module.(androidTestApp); ok { + return test.includedInTestSuite("mts") + } + return false +} + type ManifestFixerParams struct { SdkContext android.SdkContext ClassLoaderContexts dexpreopt.ClassLoaderContextMap diff --git a/java/app.go b/java/app.go index 94e6fb950..1eda694f3 100755 --- a/java/app.go +++ b/java/app.go @@ -954,6 +954,18 @@ func (a *AndroidTest) InstallInTestcases() bool { return true } +type androidTestApp interface { + includedInTestSuite(searchPrefix string) bool +} + +func (a *AndroidTest) includedInTestSuite(searchPrefix string) bool { + return android.PrefixInList(a.testProperties.Test_suites, searchPrefix) +} + +func (a *AndroidTestHelperApp) includedInTestSuite(searchPrefix string) bool { + return android.PrefixInList(a.appTestHelperAppProperties.Test_suites, searchPrefix) +} + func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { var configs []tradefed.Config if a.appTestProperties.Instrumentation_target_package != nil { diff --git a/java/app_test.go b/java/app_test.go index 8e331d46e..2297ea993 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -3069,3 +3069,65 @@ func TestAppMissingCertificateAllowMissingDependencies(t *testing.T) { } android.AssertStringDoesContain(t, "expected error rule message", fooApk.Args["error"], "missing dependencies: missing_certificate\n") } + +func TestTargetSdkVersionMtsTests(t *testing.T) { + platformSdkCodename := "Tiramisu" + android_test := "android_test" + android_test_helper_app := "android_test_helper_app" + bpTemplate := ` + %v { + name: "mytest", + target_sdk_version: "%v", + test_suites: ["othersuite", "%v"], + } + ` + testCases := []struct { + desc string + moduleType string + targetSdkVersionInBp string + targetSdkVersionExpected string + testSuites string + }{ + { + desc: "Non-MTS android_test_apps targeting current should not be upgraded to 10000", + moduleType: android_test, + targetSdkVersionInBp: "current", + targetSdkVersionExpected: platformSdkCodename, + testSuites: "non-mts-suite", + }, + { + desc: "MTS android_test_apps targeting released sdks should not be upgraded to 10000", + moduleType: android_test, + targetSdkVersionInBp: "29", + targetSdkVersionExpected: "29", + testSuites: "mts-suite", + }, + { + desc: "MTS android_test_apps targeting current should be upgraded to 10000", + moduleType: android_test, + targetSdkVersionInBp: "current", + targetSdkVersionExpected: "10000", + testSuites: "mts-suite", + }, + { + desc: "MTS android_test_helper_apps targeting current should be upgraded to 10000", + moduleType: android_test_helper_app, + targetSdkVersionInBp: "current", + targetSdkVersionExpected: "10000", + testSuites: "mts-suite", + }, + } + fixture := android.GroupFixturePreparers( + prepareForJavaTest, + android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + variables.Platform_sdk_codename = &platformSdkCodename + variables.Platform_version_active_codenames = []string{platformSdkCodename} + }), + ) + for _, testCase := range testCases { + result := fixture.RunTestWithBp(t, fmt.Sprintf(bpTemplate, testCase.moduleType, testCase.targetSdkVersionInBp, testCase.testSuites)) + mytest := result.ModuleForTests("mytest", "android_common") + manifestFixerArgs := mytest.Output("manifest_fixer/AndroidManifest.xml").Args["args"] + android.AssertStringDoesContain(t, testCase.desc, manifestFixerArgs, "--targetSdkVersion "+testCase.targetSdkVersionExpected) + } +} From be6873f8134508350972f87fd96a5db7c965c148 Mon Sep 17 00:00:00 2001 From: Ivan Lozano Date: Mon, 27 Jun 2022 16:00:26 -0400 Subject: [PATCH 050/172] rust: Allow rust_ffi_shared in jni_libs Allow listing rust_ffi_shared modules as a jni_libs dependency in conjunction with platform_api: true. This allows inclusion by android_app modules. Bug: 237304791 Test: android_app module builds with a rust_ffi_shared dependency. Change-Id: I3a28e1baa522ad8f9c2aa86f1d23b19ce9f967e1 Merged-In: I3a28e1baa522ad8f9c2aa86f1d23b19ce9f967e1 --- cc/linkable.go | 9 +++++++++ java/app.go | 2 +- rust/rust.go | 13 +++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cc/linkable.go b/cc/linkable.go index 6bec30c54..bad4b4ab9 100644 --- a/cc/linkable.go +++ b/cc/linkable.go @@ -113,6 +113,9 @@ type LinkableInterface interface { UnstrippedOutputFile() android.Path CoverageFiles() android.Paths + // CoverageOutputFile returns the output archive of gcno coverage information files. + CoverageOutputFile() android.OptionalPath + NonCcVariants() bool SelectedStl() string @@ -140,6 +143,12 @@ type LinkableInterface interface { UseSdk() bool + // IsNdk returns true if the library is in the configs known NDK list. + IsNdk(config android.Config) bool + + // IsStubs returns true if the this is a stubs library. + IsStubs() bool + // IsLlndk returns true for both LLNDK (public) and LLNDK-private libs. IsLlndk() bool diff --git a/java/app.go b/java/app.go index 41419ba78..2a455de30 100755 --- a/java/app.go +++ b/java/app.go @@ -749,7 +749,7 @@ func collectAppDeps(ctx android.ModuleContext, app appDepsInterface, tag := ctx.OtherModuleDependencyTag(module) if IsJniDepTag(tag) || cc.IsSharedDepTag(tag) { - if dep, ok := module.(*cc.Module); ok { + if dep, ok := module.(cc.LinkableInterface); ok { if dep.IsNdk(ctx.Config()) || dep.IsStubs() { return false } diff --git a/rust/rust.go b/rust/rust.go index c4fd14859..7c644dd92 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -682,6 +682,19 @@ func (mod *Module) CoverageFiles() android.Paths { panic(fmt.Errorf("CoverageFiles called on non-library module: %q", mod.BaseModuleName())) } +// Rust does not produce gcno files, and therefore does not produce a coverage archive. +func (mod *Module) CoverageOutputFile() android.OptionalPath { + return android.OptionalPath{} +} + +func (mod *Module) IsNdk(config android.Config) bool { + return false +} + +func (mod *Module) IsStubs() bool { + return false +} + func (mod *Module) installable(apexInfo android.ApexInfo) bool { if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) { return false From 719cc628ce796966fd9a43096ab41696bbf08a16 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 16 Aug 2022 15:43:20 +0000 Subject: [PATCH 051/172] Revert "Check that API is up-to-date when building java_sdk_library" This reverts commit c166b6858947161d6e958090f11fe33001427c05. Bug: 234113632 Bug: 236187167 Reason for revert: causes problems with update-api, see b/236187167 Change-Id: I4c88151cb5e2c86bb6c1a955c5065966a4fbb3e0 (cherry picked from commit e7a8664a6a37be95d8b6b55c35b74c8b8b7e8765) Merged-In: I4c88151cb5e2c86bb6c1a955c5065966a4fbb3e0 --- java/droidstubs.go | 165 ++++++++++++++++++++++----------------------- 1 file changed, 79 insertions(+), 86 deletions(-) diff --git a/java/droidstubs.go b/java/droidstubs.go index 20ea5ff96..3b1f7c041 100644 --- a/java/droidstubs.go +++ b/java/droidstubs.go @@ -675,16 +675,87 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) { zipSyncCleanupCmd(rule, srcJarDir) - if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") { - d.generateCheckCurrentCheckedInApiIsUpToDateBuildRules(ctx) - - // Make sure that whenever the API stubs are generated that the current checked in API files are - // checked to make sure that they are up-to-date. - cmd.Validation(d.checkCurrentApiTimestamp) - } - rule.Build("metalava", "metalava merged") + if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") { + + if len(d.Javadoc.properties.Out) > 0 { + ctx.PropertyErrorf("out", "out property may not be combined with check_api") + } + + apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file)) + removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file)) + baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Current.Baseline_file) + + if baselineFile.Valid() { + ctx.PropertyErrorf("baseline_file", "current API check can't have a baseline file. (module %s)", ctx.ModuleName()) + } + + d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "metalava", "check_current_api.timestamp") + + rule := android.NewRuleBuilder(pctx, ctx) + + // Diff command line. + // -F matches the closest "opening" line, such as "package android {" + // and " public class Intent {". + diff := `diff -u -F '{ *$'` + + rule.Command().Text("( true") + rule.Command(). + Text(diff). + Input(apiFile).Input(d.apiFile) + + rule.Command(). + Text(diff). + Input(removedApiFile).Input(d.removedApiFile) + + msg := fmt.Sprintf(`\n******************************\n`+ + `You have tried to change the API from what has been previously approved.\n\n`+ + `To make these errors go away, you have two choices:\n`+ + ` 1. You can add '@hide' javadoc comments (and remove @SystemApi/@TestApi/etc)\n`+ + ` to the new methods, etc. shown in the above diff.\n\n`+ + ` 2. You can update current.txt and/or removed.txt by executing the following command:\n`+ + ` m %s-update-current-api\n\n`+ + ` To submit the revised current.txt to the main Android repository,\n`+ + ` you will need approval.\n`+ + `******************************\n`, ctx.ModuleName()) + + rule.Command(). + Text("touch").Output(d.checkCurrentApiTimestamp). + Text(") || ("). + Text("echo").Flag("-e").Flag(`"` + msg + `"`). + Text("; exit 38"). + Text(")") + + rule.Build("metalavaCurrentApiCheck", "check current API") + + d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "metalava", "update_current_api.timestamp") + + // update API rule + rule = android.NewRuleBuilder(pctx, ctx) + + rule.Command().Text("( true") + + rule.Command(). + Text("cp").Flag("-f"). + Input(d.apiFile).Flag(apiFile.String()) + + rule.Command(). + Text("cp").Flag("-f"). + Input(d.removedApiFile).Flag(removedApiFile.String()) + + msg = "failed to update public API" + + rule.Command(). + Text("touch").Output(d.updateCurrentApiTimestamp). + Text(") || ("). + Text("echo").Flag("-e").Flag(`"` + msg + `"`). + Text("; exit 38"). + Text(")") + + rule.Build("metalavaCurrentApiUpdate", "update current API") + } + if String(d.properties.Check_nullability_warnings) != "" { if d.nullabilityWarningsFile == nil { ctx.PropertyErrorf("check_nullability_warnings", @@ -721,84 +792,6 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) { } } -func (d *Droidstubs) generateCheckCurrentCheckedInApiIsUpToDateBuildRules(ctx android.ModuleContext) { - if len(d.Javadoc.properties.Out) > 0 { - ctx.PropertyErrorf("out", "out property may not be combined with check_api") - } - - apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file)) - removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file)) - baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Current.Baseline_file) - - if baselineFile.Valid() { - ctx.PropertyErrorf("baseline_file", "current API check can't have a baseline file. (module %s)", ctx.ModuleName()) - } - - d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "metalava", "check_current_api.timestamp") - - rule := android.NewRuleBuilder(pctx, ctx) - - // Diff command line. - // -F matches the closest "opening" line, such as "package android {" - // and " public class Intent {". - diff := `diff -u -F '{ *$'` - - rule.Command().Text("( true") - rule.Command(). - Text(diff). - Input(apiFile).Input(d.apiFile) - - rule.Command(). - Text(diff). - Input(removedApiFile).Input(d.removedApiFile) - - msg := fmt.Sprintf(`\n******************************\n`+ - `You have tried to change the API from what has been previously approved.\n\n`+ - `To make these errors go away, you have two choices:\n`+ - ` 1. You can add '@hide' javadoc comments (and remove @SystemApi/@TestApi/etc)\n`+ - ` to the new methods, etc. shown in the above diff.\n\n`+ - ` 2. You can update current.txt and/or removed.txt by executing the following command:\n`+ - ` m %s-update-current-api\n\n`+ - ` To submit the revised current.txt to the main Android repository,\n`+ - ` you will need approval.\n`+ - `******************************\n`, ctx.ModuleName()) - - rule.Command(). - Text("touch").Output(d.checkCurrentApiTimestamp). - Text(") || ("). - Text("echo").Flag("-e").Flag(`"` + msg + `"`). - Text("; exit 38"). - Text(")") - - rule.Build("metalavaCurrentApiCheck", "check current API") - - d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "metalava", "update_current_api.timestamp") - - // update API rule - rule = android.NewRuleBuilder(pctx, ctx) - - rule.Command().Text("( true") - - rule.Command(). - Text("cp").Flag("-f"). - Input(d.apiFile).Flag(apiFile.String()) - - rule.Command(). - Text("cp").Flag("-f"). - Input(d.removedApiFile).Flag(removedApiFile.String()) - - msg = "failed to update public API" - - rule.Command(). - Text("touch").Output(d.updateCurrentApiTimestamp). - Text(") || ("). - Text("echo").Flag("-e").Flag(`"` + msg + `"`). - Text("; exit 38"). - Text(")") - - rule.Build("metalavaCurrentApiUpdate", "update current API") -} - func StubsDefaultsFactory() android.Module { module := &DocDefaults{} From 710a9edf21d7307bfd644b86920d1b59418e123d Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 27 Jul 2022 15:55:06 +0000 Subject: [PATCH 052/172] Refactor handling of hidden API property provided information In preparation for adding hidden API properties to individual java_sdk_library modules this change refactors the handling of that information. 1. Renames HiddenApiPackageProperties to HiddenAPIPackageProperties to be consistent with other similar structs. 2. Creates a new HiddenAPIPropertyInfo struct to be used to provide property derived information from one module to another. It includes both flag files as well as the information about which packages are used. 3. The HiddenAPIPropertyInfo is embedded within the existing HiddenAPIFlagInput in place of the existing flag files field. 4. The fields in the HiddenAPIPropertyInfo struct are populated from the HiddenAPI*Properties structs. 5. Access to package information is retrieved from the info struct instead of directly from the properties. That means that no changes will be needed to this code when info from other modules is merged into the struct in a follow up change. Bug: 240406019 Test: packages/modules/common/build/mainline_modules_sdks.sh # Ran the previous command with and without this change to make # sure that this change does not change the sdk snapshot # contents. Change-Id: I773279a4b621bcc3c40e3bfe193f2c7b0caeccd6 (cherry picked from commit 1e9e9388d8dd6838c3cf1244257c43815840c790) Merged-In: I773279a4b621bcc3c40e3bfe193f2c7b0caeccd6 --- java/bootclasspath_fragment.go | 17 ++++++----- java/hiddenapi_modular.go | 56 +++++++++++++++++++++++++--------- 2 files changed, 52 insertions(+), 21 deletions(-) diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index b6b179cdf..d78918bff 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -145,7 +145,7 @@ type bootclasspathFragmentProperties struct { BootclasspathFragmentsDepsProperties } -type HiddenApiPackageProperties struct { +type HiddenAPIPackageProperties struct { Hidden_api struct { // Contains prefixes of a package hierarchy that is provided solely by this // bootclasspath_fragment. @@ -222,8 +222,8 @@ type HiddenApiPackageProperties struct { } type SourceOnlyBootclasspathProperties struct { - HiddenApiPackageProperties - Coverage HiddenApiPackageProperties + HiddenAPIPackageProperties + Coverage HiddenAPIPackageProperties } type BootclasspathFragmentModule struct { @@ -293,7 +293,7 @@ func bootclasspathFragmentFactory() android.Module { return } - err = proptools.AppendProperties(&m.sourceOnlyProperties.HiddenApiPackageProperties, &m.sourceOnlyProperties.Coverage, nil) + err = proptools.AppendProperties(&m.sourceOnlyProperties.HiddenAPIPackageProperties, &m.sourceOnlyProperties.Coverage, nil) if err != nil { ctx.PropertyErrorf("coverage", "error trying to append hidden api coverage specific properties: %s", err) return @@ -827,6 +827,9 @@ func (b *BootclasspathFragmentModule) createHiddenAPIFlagInput(ctx android.Modul // Populate with flag file paths from the properties. input.extractFlagFilesFromProperties(ctx, &b.properties.Hidden_api) + // Populate with package rules from the properties. + input.extractPackageRulesFromProperties(&b.sourceOnlyProperties.HiddenAPIPackageProperties) + // Add the stub dex jars from this module's fragment dependencies. input.DependencyStubDexJarsByScope.addStubDexJarsByModule(dependencyHiddenApiInfo.TransitiveStubDexJarsByScope) @@ -862,9 +865,9 @@ func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleC // If the module specifies split_packages or package_prefixes then use those to generate the // signature patterns. - splitPackages := b.sourceOnlyProperties.Hidden_api.Split_packages - packagePrefixes := b.sourceOnlyProperties.Hidden_api.Package_prefixes - singlePackages := b.sourceOnlyProperties.Hidden_api.Single_packages + splitPackages := input.SplitPackages + packagePrefixes := input.PackagePrefixes + singlePackages := input.SinglePackages if splitPackages != nil || packagePrefixes != nil || singlePackages != nil { output.SignaturePatternsPath = buildRuleSignaturePatternsFile( ctx, output.AllFlagsPath, splitPackages, packagePrefixes, singlePackages) diff --git a/java/hiddenapi_modular.go b/java/hiddenapi_modular.go index c90b2ff97..8b77f367b 100644 --- a/java/hiddenapi_modular.go +++ b/java/hiddenapi_modular.go @@ -686,13 +686,50 @@ func (s StubDexJarsByModule) StubDexJarsForScope(scope *HiddenAPIScope) android. return stubDexJars } -// HiddenAPIFlagInput encapsulates information obtained from a module and its dependencies that are -// needed for hidden API flag generation. -type HiddenAPIFlagInput struct { +type HiddenAPIPropertyInfo struct { // FlagFilesByCategory contains the flag files that override the initial flags that are derived // from the stub dex files. FlagFilesByCategory FlagFilesByCategory + // See HiddenAPIFlagFileProperties.Package_prefixes + PackagePrefixes []string + + // See HiddenAPIFlagFileProperties.Single_packages + SinglePackages []string + + // See HiddenAPIFlagFileProperties.Split_packages + SplitPackages []string +} + +// newHiddenAPIPropertyInfo creates a new initialized HiddenAPIPropertyInfo struct. +func newHiddenAPIPropertyInfo() HiddenAPIPropertyInfo { + return HiddenAPIPropertyInfo{ + FlagFilesByCategory: FlagFilesByCategory{}, + } +} + +// extractFlagFilesFromProperties extracts the paths to flag files that are specified in the +// supplied properties and stores them in this struct. +func (i *HiddenAPIPropertyInfo) extractFlagFilesFromProperties(ctx android.ModuleContext, p *HiddenAPIFlagFileProperties) { + for _, category := range HiddenAPIFlagFileCategories { + paths := android.PathsForModuleSrc(ctx, category.propertyValueReader(p)) + i.FlagFilesByCategory[category] = paths + } +} + +// extractPackageRulesFromProperties extracts the package rules that are specified in the supplied +// properties and stores them in this struct. +func (i *HiddenAPIPropertyInfo) extractPackageRulesFromProperties(p *HiddenAPIPackageProperties) { + i.PackagePrefixes = p.Hidden_api.Package_prefixes + i.SinglePackages = p.Hidden_api.Single_packages + i.SplitPackages = p.Hidden_api.Split_packages +} + +// HiddenAPIFlagInput encapsulates information obtained from a module and its dependencies that are +// needed for hidden API flag generation. +type HiddenAPIFlagInput struct { + HiddenAPIPropertyInfo + // StubDexJarsByScope contains the stub dex jars for different *HiddenAPIScope and which determine // the initial flags for each dex member. StubDexJarsByScope StubDexJarsByModule @@ -714,10 +751,10 @@ type HiddenAPIFlagInput struct { RemovedTxtFiles android.Paths } -// newHiddenAPIFlagInput creates a new initialize HiddenAPIFlagInput struct. +// newHiddenAPIFlagInput creates a new initialized HiddenAPIFlagInput struct. func newHiddenAPIFlagInput() HiddenAPIFlagInput { input := HiddenAPIFlagInput{ - FlagFilesByCategory: FlagFilesByCategory{}, + HiddenAPIPropertyInfo: newHiddenAPIPropertyInfo(), StubDexJarsByScope: StubDexJarsByModule{}, DependencyStubDexJarsByScope: StubDexJarsByModule{}, AdditionalStubDexJarsByScope: StubDexJarsByModule{}, @@ -773,15 +810,6 @@ func (i *HiddenAPIFlagInput) gatherStubLibInfo(ctx android.ModuleContext, conten i.RemovedTxtFiles = android.SortedUniquePaths(i.RemovedTxtFiles) } -// extractFlagFilesFromProperties extracts the paths to flag files that are specified in the -// supplied properties and stores them in this struct. -func (i *HiddenAPIFlagInput) extractFlagFilesFromProperties(ctx android.ModuleContext, p *HiddenAPIFlagFileProperties) { - for _, category := range HiddenAPIFlagFileCategories { - paths := android.PathsForModuleSrc(ctx, category.propertyValueReader(p)) - i.FlagFilesByCategory[category] = paths - } -} - func (i *HiddenAPIFlagInput) transitiveStubDexJarsByScope() StubDexJarsByModule { transitive := i.DependencyStubDexJarsByScope transitive.addStubDexJarsByModule(i.StubDexJarsByScope) From 04beaabb467962b9f7aecfb766e1e98aa178fc92 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 27 Jul 2022 16:16:54 +0000 Subject: [PATCH 053/172] Push Hidden_api inside HiddenAPIFlagFileProperties All usages of HiddenAPIFlagFileProperties use it as the type of a Hidden_api field. This change pushes the field inside the struct and just embeds the struct inside the structs that need it making it simpler and more consistent with how the HiddenApiPackageProperties struct is used. This is extracted as a separate change as while the change is simple it does affect a lot of lines. Keeping it separate makes it easier to review the changes. Bug: 240406019 Test: packages/modules/common/build/mainline_modules_sdks.sh # Ran the previous command with and without this change to make # sure that this change does not change the sdk snapshot # contents. Change-Id: I664453029574ef68dc5712f7bf137a1a6e78e864 (cherry picked from commit 9b61abbd840503dd9bd2eebf7fee8be627be4eb5) Merged-In: I664453029574ef68dc5712f7bf137a1a6e78e864 --- java/bootclasspath_fragment.go | 4 +-- java/hiddenapi_modular.go | 59 ++++++++++++++++++---------------- java/platform_bootclasspath.go | 4 +-- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index d78918bff..024c4fa50 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -128,7 +128,7 @@ type bootclasspathFragmentProperties struct { Coverage BootclasspathFragmentCoverageAffectedProperties // Hidden API related properties. - Hidden_api HiddenAPIFlagFileProperties + HiddenAPIFlagFileProperties // The list of additional stub libraries which this fragment's contents use but which are not // provided by another bootclasspath_fragment. @@ -825,7 +825,7 @@ func (b *BootclasspathFragmentModule) createHiddenAPIFlagInput(ctx android.Modul input.gatherStubLibInfo(ctx, contents) // Populate with flag file paths from the properties. - input.extractFlagFilesFromProperties(ctx, &b.properties.Hidden_api) + input.extractFlagFilesFromProperties(ctx, &b.properties.HiddenAPIFlagFileProperties) // Populate with package rules from the properties. input.extractPackageRulesFromProperties(&b.sourceOnlyProperties.HiddenAPIPackageProperties) diff --git a/java/hiddenapi_modular.go b/java/hiddenapi_modular.go index 8b77f367b..3a58675ec 100644 --- a/java/hiddenapi_modular.go +++ b/java/hiddenapi_modular.go @@ -378,32 +378,37 @@ func buildRuleToGenerateHiddenAPIStubFlagsFile(ctx android.BuilderContext, name, // with one Java package per line. All members of all classes within that package (but not nested // packages) will be updated in a property specific way. type HiddenAPIFlagFileProperties struct { - // Marks each signature in the referenced files as being unsupported. - Unsupported []string `android:"path"` + Hidden_api struct { + // Marks each signature in the referenced files as being unsupported. + Unsupported []string `android:"path"` - // Marks each signature in the referenced files as being unsupported because it has been removed. - // Any conflicts with other flags are ignored. - Removed []string `android:"path"` + // Marks each signature in the referenced files as being unsupported because it has been + // removed. Any conflicts with other flags are ignored. + Removed []string `android:"path"` - // Marks each signature in the referenced files as being supported only for targetSdkVersion <= R - // and low priority. - Max_target_r_low_priority []string `android:"path"` + // Marks each signature in the referenced files as being supported only for + // targetSdkVersion <= R and low priority. + Max_target_r_low_priority []string `android:"path"` - // Marks each signature in the referenced files as being supported only for targetSdkVersion <= Q. - Max_target_q []string `android:"path"` + // Marks each signature in the referenced files as being supported only for + // targetSdkVersion <= Q. + Max_target_q []string `android:"path"` - // Marks each signature in the referenced files as being supported only for targetSdkVersion <= P. - Max_target_p []string `android:"path"` + // Marks each signature in the referenced files as being supported only for + // targetSdkVersion <= P. + Max_target_p []string `android:"path"` - // Marks each signature in the referenced files as being supported only for targetSdkVersion <= O - // and low priority. Any conflicts with other flags are ignored. - Max_target_o_low_priority []string `android:"path"` + // Marks each signature in the referenced files as being supported only for + // targetSdkVersion <= O + // and low priority. Any conflicts with other flags are ignored. + Max_target_o_low_priority []string `android:"path"` - // Marks each signature in the referenced files as being blocked. - Blocked []string `android:"path"` + // Marks each signature in the referenced files as being blocked. + Blocked []string `android:"path"` - // Marks each signature in every package in the referenced files as being unsupported. - Unsupported_packages []string `android:"path"` + // Marks each signature in every package in the referenced files as being unsupported. + Unsupported_packages []string `android:"path"` + } } type hiddenAPIFlagFileCategory struct { @@ -428,7 +433,7 @@ var hiddenAPIRemovedFlagFileCategory = &hiddenAPIFlagFileCategory{ // See HiddenAPIFlagFileProperties.Removed PropertyName: "removed", propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { - return properties.Removed + return properties.Hidden_api.Removed }, commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { command.FlagWithInput("--unsupported ", path).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "removed") @@ -440,7 +445,7 @@ var HiddenAPIFlagFileCategories = []*hiddenAPIFlagFileCategory{ { PropertyName: "unsupported", propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { - return properties.Unsupported + return properties.Hidden_api.Unsupported }, commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { command.FlagWithInput("--unsupported ", path) @@ -451,7 +456,7 @@ var HiddenAPIFlagFileCategories = []*hiddenAPIFlagFileCategory{ { PropertyName: "max_target_r_low_priority", propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { - return properties.Max_target_r_low_priority + return properties.Hidden_api.Max_target_r_low_priority }, commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { command.FlagWithInput("--max-target-r ", path).FlagWithArg("--tag ", "lo-prio") @@ -461,7 +466,7 @@ var HiddenAPIFlagFileCategories = []*hiddenAPIFlagFileCategory{ { PropertyName: "max_target_q", propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { - return properties.Max_target_q + return properties.Hidden_api.Max_target_q }, commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { command.FlagWithInput("--max-target-q ", path) @@ -471,7 +476,7 @@ var HiddenAPIFlagFileCategories = []*hiddenAPIFlagFileCategory{ { PropertyName: "max_target_p", propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { - return properties.Max_target_p + return properties.Hidden_api.Max_target_p }, commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { command.FlagWithInput("--max-target-p ", path) @@ -481,7 +486,7 @@ var HiddenAPIFlagFileCategories = []*hiddenAPIFlagFileCategory{ { PropertyName: "max_target_o_low_priority", propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { - return properties.Max_target_o_low_priority + return properties.Hidden_api.Max_target_o_low_priority }, commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { command.FlagWithInput("--max-target-o ", path).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "lo-prio") @@ -491,7 +496,7 @@ var HiddenAPIFlagFileCategories = []*hiddenAPIFlagFileCategory{ { PropertyName: "blocked", propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { - return properties.Blocked + return properties.Hidden_api.Blocked }, commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { command.FlagWithInput("--blocked ", path) @@ -501,7 +506,7 @@ var HiddenAPIFlagFileCategories = []*hiddenAPIFlagFileCategory{ { PropertyName: "unsupported_packages", propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { - return properties.Unsupported_packages + return properties.Hidden_api.Unsupported_packages }, commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { command.FlagWithInput("--unsupported ", path).Flag("--packages ") diff --git a/java/platform_bootclasspath.go b/java/platform_bootclasspath.go index 1e2723845..24f8253ae 100644 --- a/java/platform_bootclasspath.go +++ b/java/platform_bootclasspath.go @@ -62,7 +62,7 @@ type platformBootclasspathModule struct { type platformBootclasspathProperties struct { BootclasspathFragmentsDepsProperties - Hidden_api HiddenAPIFlagFileProperties + HiddenAPIFlagFileProperties } func platformBootclasspathFactory() android.SingletonModule { @@ -372,7 +372,7 @@ func (b *platformBootclasspathModule) createAndProvideMonolithicHiddenAPIInfo(ct temporaryInput := newHiddenAPIFlagInput() // Create paths to the flag files specified in the properties. - temporaryInput.extractFlagFilesFromProperties(ctx, &b.properties.Hidden_api) + temporaryInput.extractFlagFilesFromProperties(ctx, &b.properties.HiddenAPIFlagFileProperties) // Create the monolithic info, by starting with the flag files specified on this and then merging // in information from all the fragment dependencies of this. From 6cdfd3fcfb2735c44e78cb430aebb7b3044fedc6 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 16 Aug 2022 15:24:01 +0000 Subject: [PATCH 054/172] Dedup apiFile and removedApiFile fields Previously, there were two separate fields for each of the API and removed API files because in some cases it needed a WritablePath and in other cases it could only be a Path. This change refactors the code so that the WritablePath is no longer needed, the duplicate fields deleted and the remaining field is changed to Path. It also removes a few unused fields. Bug: 234113632 Test: m nothing Change-Id: If81f5fe2aa05d9d7b2bc23869fdb2397649d67b3 (cherry picked from commit c71d2b76296c009e94273e985ba32d4165049cfb) Merged-In: If81f5fe2aa05d9d7b2bc23869fdb2397649d67b3 --- java/droidstubs.go | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/java/droidstubs.go b/java/droidstubs.go index 3b1f7c041..d705a4d6b 100644 --- a/java/droidstubs.go +++ b/java/droidstubs.go @@ -50,11 +50,8 @@ type Droidstubs struct { android.SdkBase properties DroidstubsProperties - apiFile android.WritablePath - apiXmlFile android.WritablePath - lastReleasedApiXmlFile android.WritablePath - privateApiFile android.WritablePath - removedApiFile android.WritablePath + apiFile android.Path + removedApiFile android.Path nullabilityWarningsFile android.WritablePath checkCurrentApiTimestamp android.WritablePath @@ -68,9 +65,6 @@ type Droidstubs struct { annotationsZip android.WritablePath apiVersionsXml android.WritablePath - apiFilePath android.Path - removedApiFilePath android.Path - metadataZip android.WritablePath metadataDir android.WritablePath } @@ -203,9 +197,9 @@ func (d *Droidstubs) OutputFiles(tag string) (android.Paths, error) { return android.Paths{d.docZip}, nil case ".api.txt", android.DefaultDistTag: // This is the default dist path for dist properties that have no tag property. - return android.Paths{d.apiFilePath}, nil + return android.Paths{d.apiFile}, nil case ".removed-api.txt": - return android.Paths{d.removedApiFilePath}, nil + return android.Paths{d.removedApiFile}, nil case ".annotations.zip": return android.Paths{d.annotationsZip}, nil case ".api_versions.xml": @@ -220,11 +214,11 @@ func (d *Droidstubs) AnnotationsZip() android.Path { } func (d *Droidstubs) ApiFilePath() android.Path { - return d.apiFilePath + return d.apiFile } func (d *Droidstubs) RemovedApiFilePath() android.Path { - return d.removedApiFilePath + return d.removedApiFile } func (d *Droidstubs) StubsSrcJar() android.Path { @@ -262,24 +256,24 @@ func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuil apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") || String(d.properties.Api_filename) != "" { filename := proptools.StringDefault(d.properties.Api_filename, ctx.ModuleName()+"_api.txt") - d.apiFile = android.PathForModuleOut(ctx, "metalava", filename) - cmd.FlagWithOutput("--api ", d.apiFile) - d.apiFilePath = d.apiFile + uncheckedApiFile := android.PathForModuleOut(ctx, "metalava", filename) + cmd.FlagWithOutput("--api ", uncheckedApiFile) + d.apiFile = uncheckedApiFile } else if sourceApiFile := proptools.String(d.properties.Check_api.Current.Api_file); sourceApiFile != "" { // If check api is disabled then make the source file available for export. - d.apiFilePath = android.PathForModuleSrc(ctx, sourceApiFile) + d.apiFile = android.PathForModuleSrc(ctx, sourceApiFile) } if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") || apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") || String(d.properties.Removed_api_filename) != "" { filename := proptools.StringDefault(d.properties.Removed_api_filename, ctx.ModuleName()+"_removed.txt") - d.removedApiFile = android.PathForModuleOut(ctx, "metalava", filename) - cmd.FlagWithOutput("--removed-api ", d.removedApiFile) - d.removedApiFilePath = d.removedApiFile + uncheckedRemovedFile := android.PathForModuleOut(ctx, "metalava", filename) + cmd.FlagWithOutput("--removed-api ", uncheckedRemovedFile) + d.removedApiFile = uncheckedRemovedFile } else if sourceRemovedApiFile := proptools.String(d.properties.Check_api.Current.Removed_api_file); sourceRemovedApiFile != "" { // If check api is disabled then make the source removed api file available for export. - d.removedApiFilePath = android.PathForModuleSrc(ctx, sourceRemovedApiFile) + d.removedApiFile = android.PathForModuleSrc(ctx, sourceRemovedApiFile) } if Bool(d.properties.Write_sdk_values) { From b5e3c9802a43893259e1f56997f985a64ff7762a Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 27 Jul 2022 16:27:42 +0000 Subject: [PATCH 055/172] Add hidden API properties to java_sdk_library modules Previously, hidden API properties were only allowed on bootclasspath_fragment and platform_bootclasspath module types. This change allows them to be specified on java_sdk_library modules too. It involves the following changes: 1. Add the properties to the java.Module. 2. Populate and provide a HiddenAPIPropertyInfo struct from java_sdk_library modules. 3. Modify bootclasspath_fragment to merge information gathered from its content libraries as if it was specified on the fragment itself. Bug: 240406019 Test: m nothing packages/modules/common/build/mainline_modules_sdks.sh # Ran the previous command with and without this change to make # sure that this change does not change the sdk snapshot # contents. Change-Id: I64eb71c2039ddc14cf380689d0cec7ec221f5b88 (cherry picked from commit 3f1ae0b55acd7e727c6227c3ab3e4f34e885e478) Merged-In: I64eb71c2039ddc14cf380689d0cec7ec221f5b88 --- java/base.go | 17 ++++ java/bootclasspath_fragment.go | 2 + java/bootclasspath_fragment_test.go | 114 +++++++++++++++++++++++++ java/hiddenapi_modular.go | 42 ++++++++- java/java.go | 3 + sdk/bootclasspath_fragment_sdk_test.go | 60 +++++++++++-- 6 files changed, 230 insertions(+), 8 deletions(-) diff --git a/java/base.go b/java/base.go index 717c7273f..ddabbc0c3 100644 --- a/java/base.go +++ b/java/base.go @@ -263,6 +263,9 @@ type DeviceProperties struct { // Only for libraries created by a sysprop_library module, SyspropPublicStub is the name of the // public stubs library. SyspropPublicStub string `blueprint:"mutated"` + + HiddenAPIPackageProperties + HiddenAPIFlagFileProperties } // Device properties that can be overridden by overriding module (e.g. override_android_app) @@ -563,6 +566,20 @@ func (j *Module) addHostAndDeviceProperties() { ) } +// provideHiddenAPIPropertyInfo populates a HiddenAPIPropertyInfo from hidden API properties and +// makes it available through the hiddenAPIPropertyInfoProvider. +func (j *Module) provideHiddenAPIPropertyInfo(ctx android.ModuleContext) { + hiddenAPIInfo := newHiddenAPIPropertyInfo() + + // Populate with flag file paths from the properties. + hiddenAPIInfo.extractFlagFilesFromProperties(ctx, &j.deviceProperties.HiddenAPIFlagFileProperties) + + // Populate with package rules from the properties. + hiddenAPIInfo.extractPackageRulesFromProperties(&j.deviceProperties.HiddenAPIPackageProperties) + + ctx.SetProvider(hiddenAPIPropertyInfoProvider, hiddenAPIInfo) +} + func (j *Module) OutputFiles(tag string) (android.Paths, error) { switch tag { case "": diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index 024c4fa50..c3053f88d 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -830,6 +830,8 @@ func (b *BootclasspathFragmentModule) createHiddenAPIFlagInput(ctx android.Modul // Populate with package rules from the properties. input.extractPackageRulesFromProperties(&b.sourceOnlyProperties.HiddenAPIPackageProperties) + input.gatherPropertyInfo(ctx, contents) + // Add the stub dex jars from this module's fragment dependencies. input.DependencyStubDexJarsByScope.addStubDexJarsByModule(dependencyHiddenApiInfo.TransitiveStubDexJarsByScope) diff --git a/java/bootclasspath_fragment_test.go b/java/bootclasspath_fragment_test.go index 83beb6d23..f95c83fe7 100644 --- a/java/bootclasspath_fragment_test.go +++ b/java/bootclasspath_fragment_test.go @@ -15,6 +15,7 @@ package java import ( + "strings" "testing" "android/soong/android" @@ -285,6 +286,119 @@ func TestBootclasspathFragment_StubLibs(t *testing.T) { android.AssertPathsRelativeToTopEquals(t, "widest dex stubs jar", expectedWidestPaths, info.TransitiveStubDexJarsByScope.StubDexJarsForWidestAPIScope()) } +func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) { + result := android.GroupFixturePreparers( + prepareForTestWithBootclasspathFragment, + PrepareForTestWithJavaSdkLibraryFiles, + FixtureWithLastReleaseApis("mysdklibrary", "mynewlibrary"), + FixtureConfigureApexBootJars("myapex:mybootlib", "myapex:mynewlibrary"), + android.MockFS{ + "my-blocked.txt": nil, + "my-max-target-o-low-priority.txt": nil, + "my-max-target-p.txt": nil, + "my-max-target-q.txt": nil, + "my-max-target-r-low-priority.txt": nil, + "my-removed.txt": nil, + "my-unsupported-packages.txt": nil, + "my-unsupported.txt": nil, + "my-new-max-target-q.txt": nil, + }.AddToFixture(), + android.FixtureWithRootAndroidBp(` + bootclasspath_fragment { + name: "mybootclasspathfragment", + apex_available: ["myapex"], + contents: ["mybootlib", "mynewlibrary"], + hidden_api: { + unsupported: [ + "my-unsupported.txt", + ], + removed: [ + "my-removed.txt", + ], + max_target_r_low_priority: [ + "my-max-target-r-low-priority.txt", + ], + max_target_q: [ + "my-max-target-q.txt", + ], + max_target_p: [ + "my-max-target-p.txt", + ], + max_target_o_low_priority: [ + "my-max-target-o-low-priority.txt", + ], + blocked: [ + "my-blocked.txt", + ], + unsupported_packages: [ + "my-unsupported-packages.txt", + ], + split_packages: ["sdklibrary"], + package_prefixes: ["sdklibrary.all.mine"], + single_packages: ["sdklibrary.mine"], + }, + } + + java_library { + name: "mybootlib", + apex_available: ["myapex"], + srcs: ["Test.java"], + system_modules: "none", + sdk_version: "none", + min_sdk_version: "1", + compile_dex: true, + permitted_packages: ["mybootlib"], + } + + java_sdk_library { + name: "mynewlibrary", + apex_available: ["myapex"], + srcs: ["Test.java"], + min_sdk_version: "10", + compile_dex: true, + public: {enabled: true}, + permitted_packages: ["mysdklibrary"], + hidden_api: { + max_target_q: [ + "my-new-max-target-q.txt", + ], + split_packages: ["sdklibrary", "newlibrary"], + package_prefixes: ["newlibrary.all.mine"], + single_packages: ["newlibrary.mine"], + }, + } + `), + ).RunTest(t) + + // Make sure that the library exports hidden API properties for use by the bootclasspath_fragment. + library := result.Module("mynewlibrary", "android_common") + info := result.ModuleProvider(library, hiddenAPIPropertyInfoProvider).(HiddenAPIPropertyInfo) + android.AssertArrayString(t, "split packages", []string{"sdklibrary", "newlibrary"}, info.SplitPackages) + android.AssertArrayString(t, "package prefixes", []string{"newlibrary.all.mine"}, info.PackagePrefixes) + android.AssertArrayString(t, "single packages", []string{"newlibrary.mine"}, info.SinglePackages) + for _, c := range HiddenAPIFlagFileCategories { + expectedMaxTargetQPaths := []string(nil) + if c.PropertyName == "max_target_q" { + expectedMaxTargetQPaths = []string{"my-new-max-target-q.txt"} + } + android.AssertPathsRelativeToTopEquals(t, c.PropertyName, expectedMaxTargetQPaths, info.FlagFilesByCategory[c]) + } + + // Make sure that the signature-patterns.csv is passed all the appropriate package properties + // from the bootclasspath_fragment and its contents. + fragment := result.ModuleForTests("mybootclasspathfragment", "android_common") + rule := fragment.Output("modular-hiddenapi/signature-patterns.csv") + expectedCommand := strings.Join([]string{ + "--split-package newlibrary", + "--split-package sdklibrary", + "--package-prefix newlibrary.all.mine", + "--package-prefix sdklibrary.all.mine", + "--single-package newlibrary.mine", + "--single-package sdklibrary", + }, " ") + android.AssertStringDoesContain(t, "signature patterns command", rule.RuleParams.Command, expectedCommand) +} + func TestBootclasspathFragment_Test(t *testing.T) { result := android.GroupFixturePreparers( prepareForTestWithBootclasspathFragment, diff --git a/java/hiddenapi_modular.go b/java/hiddenapi_modular.go index 3a58675ec..7b678037c 100644 --- a/java/hiddenapi_modular.go +++ b/java/hiddenapi_modular.go @@ -440,7 +440,18 @@ var hiddenAPIRemovedFlagFileCategory = &hiddenAPIFlagFileCategory{ }, } -var HiddenAPIFlagFileCategories = []*hiddenAPIFlagFileCategory{ +type hiddenAPIFlagFileCategories []*hiddenAPIFlagFileCategory + +func (c hiddenAPIFlagFileCategories) byProperty(name string) *hiddenAPIFlagFileCategory { + for _, category := range c { + if category.PropertyName == name { + return category + } + } + panic(fmt.Errorf("no category exists with property name %q in %v", name, c)) +} + +var HiddenAPIFlagFileCategories = hiddenAPIFlagFileCategories{ // See HiddenAPIFlagFileProperties.Unsupported { PropertyName: "unsupported", @@ -517,13 +528,20 @@ var HiddenAPIFlagFileCategories = []*hiddenAPIFlagFileCategory{ // FlagFilesByCategory maps a hiddenAPIFlagFileCategory to the paths to the files in that category. type FlagFilesByCategory map[*hiddenAPIFlagFileCategory]android.Paths -// append appends the supplied flags files to the corresponding category in this map. +// append the supplied flags files to the corresponding category in this map. func (s FlagFilesByCategory) append(other FlagFilesByCategory) { for _, category := range HiddenAPIFlagFileCategories { s[category] = append(s[category], other[category]...) } } +// sort the paths for each category in this map. +func (s FlagFilesByCategory) sort() { + for category, value := range s { + s[category] = android.SortedUniquePaths(value) + } +} + // HiddenAPIInfo contains information provided by the hidden API processing. // // That includes paths resolved from HiddenAPIFlagFileProperties and also generated by hidden API @@ -706,6 +724,8 @@ type HiddenAPIPropertyInfo struct { SplitPackages []string } +var hiddenAPIPropertyInfoProvider = blueprint.NewProvider(HiddenAPIPropertyInfo{}) + // newHiddenAPIPropertyInfo creates a new initialized HiddenAPIPropertyInfo struct. func newHiddenAPIPropertyInfo() HiddenAPIPropertyInfo { return HiddenAPIPropertyInfo{ @@ -730,6 +750,24 @@ func (i *HiddenAPIPropertyInfo) extractPackageRulesFromProperties(p *HiddenAPIPa i.SplitPackages = p.Hidden_api.Split_packages } +func (i *HiddenAPIPropertyInfo) gatherPropertyInfo(ctx android.ModuleContext, contents []android.Module) { + for _, module := range contents { + if ctx.OtherModuleHasProvider(module, hiddenAPIPropertyInfoProvider) { + info := ctx.OtherModuleProvider(module, hiddenAPIPropertyInfoProvider).(HiddenAPIPropertyInfo) + i.FlagFilesByCategory.append(info.FlagFilesByCategory) + i.PackagePrefixes = append(i.PackagePrefixes, info.PackagePrefixes...) + i.SinglePackages = append(i.SinglePackages, info.SinglePackages...) + i.SplitPackages = append(i.SplitPackages, info.SplitPackages...) + } + } + + // Dedup and sort the information to ensure consistent builds. + i.FlagFilesByCategory.sort() + i.PackagePrefixes = android.SortedUniqueStrings(i.PackagePrefixes) + i.SinglePackages = android.SortedUniqueStrings(i.SinglePackages) + i.SplitPackages = android.SortedUniqueStrings(i.SplitPackages) +} + // HiddenAPIFlagInput encapsulates information obtained from a module and its dependencies that are // needed for hidden API flag generation. type HiddenAPIFlagInput struct { diff --git a/java/java.go b/java/java.go index 1e99aa32f..f98f1e88c 100644 --- a/java/java.go +++ b/java/java.go @@ -607,6 +607,9 @@ func setUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter, dexer } func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { + + j.provideHiddenAPIPropertyInfo(ctx) + j.sdkVersion = j.SdkVersion(ctx) j.minSdkVersion = j.MinSdkVersion(ctx) j.maxSdkVersion = j.MaxSdkVersion(ctx) diff --git a/sdk/bootclasspath_fragment_sdk_test.go b/sdk/bootclasspath_fragment_sdk_test.go index 13ddbe768..c93055a51 100644 --- a/sdk/bootclasspath_fragment_sdk_test.go +++ b/sdk/bootclasspath_fragment_sdk_test.go @@ -675,8 +675,8 @@ func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) { prepareForSdkTestWithJava, java.PrepareForTestWithJavaDefaultModules, java.PrepareForTestWithJavaSdkLibraryFiles, - java.FixtureWithLastReleaseApis("mysdklibrary"), - java.FixtureConfigureApexBootJars("myapex:mybootlib"), + java.FixtureWithLastReleaseApis("mysdklibrary", "mynewlibrary"), + java.FixtureConfigureApexBootJars("myapex:mybootlib", "myapex:mynewlibrary"), prepareForSdkTestWithApex, // Add a platform_bootclasspath that depends on the fragment. @@ -691,6 +691,7 @@ func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) { "my-removed.txt": nil, "my-unsupported-packages.txt": nil, "my-unsupported.txt": nil, + "my-new-max-target-q.txt": nil, }.AddToFixture(), android.FixtureWithRootAndroidBp(` sdk { @@ -708,7 +709,7 @@ func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) { bootclasspath_fragment { name: "mybootclasspathfragment", apex_available: ["myapex"], - contents: ["mybootlib"], + contents: ["mybootlib", "mynewlibrary"], api: { stub_libs: ["mysdklibrary"], }, @@ -737,7 +738,9 @@ func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) { unsupported_packages: [ "my-unsupported-packages.txt", ], - split_packages: ["*"], + split_packages: ["sdklibrary"], + package_prefixes: ["sdklibrary.all.mine"], + single_packages: ["sdklibrary.mine"], }, } @@ -759,6 +762,24 @@ func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) { public: {enabled: true}, permitted_packages: ["mysdklibrary"], } + + java_sdk_library { + name: "mynewlibrary", + apex_available: ["myapex"], + srcs: ["Test.java"], + min_sdk_version: "10", + compile_dex: true, + public: {enabled: true}, + permitted_packages: ["mysdklibrary"], + hidden_api: { + max_target_q: [ + "my-new-max-target-q.txt", + ], + split_packages: ["sdklibrary", "newlibrary"], + package_prefixes: ["newlibrary.all.mine"], + single_packages: ["newlibrary.mine"], + }, + } `), ).RunTest(t) @@ -774,7 +795,10 @@ prebuilt_bootclasspath_fragment { prefer: false, visibility: ["//visibility:public"], apex_available: ["myapex"], - contents: ["mybootlib"], + contents: [ + "mybootlib", + "mynewlibrary", + ], api: { stub_libs: ["mysdklibrary"], }, @@ -782,7 +806,10 @@ prebuilt_bootclasspath_fragment { unsupported: ["hiddenapi/my-unsupported.txt"], removed: ["hiddenapi/my-removed.txt"], max_target_r_low_priority: ["hiddenapi/my-max-target-r-low-priority.txt"], - max_target_q: ["hiddenapi/my-max-target-q.txt"], + max_target_q: [ + "hiddenapi/my-max-target-q.txt", + "hiddenapi/my-new-max-target-q.txt", + ], max_target_p: ["hiddenapi/my-max-target-p.txt"], max_target_o_low_priority: ["hiddenapi/my-max-target-o-low-priority.txt"], blocked: ["hiddenapi/my-blocked.txt"], @@ -805,6 +832,23 @@ java_import { permitted_packages: ["mybootlib"], } +java_sdk_library_import { + name: "mynewlibrary", + prefer: false, + visibility: ["//visibility:public"], + apex_available: ["myapex"], + shared_library: true, + compile_dex: true, + permitted_packages: ["mysdklibrary"], + public: { + jars: ["sdk_library/public/mynewlibrary-stubs.jar"], + stub_srcs: ["sdk_library/public/mynewlibrary_stub_sources"], + current_api: "sdk_library/public/mynewlibrary.txt", + removed_api: "sdk_library/public/mynewlibrary-removed.txt", + sdk_version: "current", + }, +} + java_sdk_library_import { name: "mysdklibrary", prefer: false, @@ -827,6 +871,7 @@ my-unsupported.txt -> hiddenapi/my-unsupported.txt my-removed.txt -> hiddenapi/my-removed.txt my-max-target-r-low-priority.txt -> hiddenapi/my-max-target-r-low-priority.txt my-max-target-q.txt -> hiddenapi/my-max-target-q.txt +my-new-max-target-q.txt -> hiddenapi/my-new-max-target-q.txt my-max-target-p.txt -> hiddenapi/my-max-target-p.txt my-max-target-o-low-priority.txt -> hiddenapi/my-max-target-o-low-priority.txt my-blocked.txt -> hiddenapi/my-blocked.txt @@ -838,6 +883,9 @@ my-unsupported-packages.txt -> hiddenapi/my-unsupported-packages.txt .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/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar +.intermediates/mynewlibrary.stubs/android_common/javac/mynewlibrary.stubs.jar -> sdk_library/public/mynewlibrary-stubs.jar +.intermediates/mynewlibrary.stubs.source/android_common/metalava/mynewlibrary.stubs.source_api.txt -> sdk_library/public/mynewlibrary.txt +.intermediates/mynewlibrary.stubs.source/android_common/metalava/mynewlibrary.stubs.source_removed.txt -> sdk_library/public/mynewlibrary-removed.txt .intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar .intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt .intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt From 4eed9816703fa5981ecc2e5f44296d308532cc7b Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 17 Aug 2022 22:09:55 +0000 Subject: [PATCH 056/172] Add current build release Previously, the build releases only included named releases so did not have a way to represent the latest build release. This adds the current build release (named after the current API level) to represent that. Bug: 240406019 Test: m nothing Change-Id: Ib8336da716b447448b23bc9684ce3be1ab78648a (cherry picked from commit 42a49f1278b50b6cd4971f9d40505a278461154e) Merged-In: Ib8336da716b447448b23bc9684ce3be1ab78648a --- sdk/build_release.go | 52 ++++++++++++++++++++++++++++++--------- sdk/build_release_test.go | 4 +-- sdk/testing.go | 3 +-- sdk/update.go | 7 +++--- 4 files changed, 46 insertions(+), 20 deletions(-) diff --git a/sdk/build_release.go b/sdk/build_release.go index 0494a28ee..149a34eb0 100644 --- a/sdk/build_release.go +++ b/sdk/build_release.go @@ -16,6 +16,7 @@ package sdk import ( "fmt" + "math" "reflect" "strings" ) @@ -29,7 +30,10 @@ type buildRelease struct { // The name of the release, e.g. S, Tiramisu, etc. name string - // The index of this structure within the buildReleases list. + // The index of this structure within the dessertBuildReleases list. + // + // The buildReleaseCurrent does not appear in the dessertBuildReleases list as it has an ordinal value + // that is larger than the size of the dessertBuildReleases. ordinal int } @@ -56,7 +60,7 @@ func (s *buildReleaseSet) addItem(release *buildRelease) { // addRange adds all the build releases from start (inclusive) to end (inclusive). func (s *buildReleaseSet) addRange(start *buildRelease, end *buildRelease) { for i := start.ordinal; i <= end.ordinal; i += 1 { - s.addItem(buildReleases[i]) + s.addItem(dessertBuildReleases[i]) } } @@ -69,11 +73,17 @@ func (s *buildReleaseSet) contains(release *buildRelease) bool { // String returns a string representation of the set, sorted from earliest to latest release. func (s *buildReleaseSet) String() string { list := []string{} - for _, release := range buildReleases { + addRelease := func(release *buildRelease) { if _, ok := s.contents[release]; ok { list = append(list, release.name) } } + // Add the names of the build releases in this set in the order in which they were created. + for _, release := range dessertBuildReleases { + addRelease(release) + } + // Always add "current" to the list of names last if it is present in the set. + addRelease(buildReleaseCurrent) return fmt.Sprintf("[%s]", strings.Join(list, ",")) } @@ -81,30 +91,46 @@ var ( // nameToBuildRelease contains a map from name to build release. nameToBuildRelease = map[string]*buildRelease{} - // buildReleases lists all the available build releases. - buildReleases = []*buildRelease{} + // dessertBuildReleases lists all the available dessert build releases, i.e. excluding current. + dessertBuildReleases = []*buildRelease{} // allBuildReleaseSet is the set of all build releases. allBuildReleaseSet = &buildReleaseSet{contents: map[*buildRelease]struct{}{}} - // Add the build releases from oldest to newest. + // Add the dessert build releases from oldest to newest. buildReleaseS = initBuildRelease("S") buildReleaseT = initBuildRelease("Tiramisu") + + // Add the current build release which is always treated as being more recent than any other + // build release, including those added in tests. + buildReleaseCurrent = initBuildRelease("current") ) // initBuildRelease creates a new build release with the specified name. func initBuildRelease(name string) *buildRelease { - ordinal := len(nameToBuildRelease) + ordinal := len(dessertBuildReleases) + if name == "current" { + // The current build release is more recent than all other build releases, including those + // created in tests so use the max int value. It cannot just rely on being created after all + // the other build releases as some are created in tests which run after the current build + // release has been created. + ordinal = math.MaxInt + } release := &buildRelease{name: name, ordinal: ordinal} nameToBuildRelease[name] = release - buildReleases = append(buildReleases, release) allBuildReleaseSet.addItem(release) + if name != "current" { + // As the current build release has an ordinal value that does not correspond to its position + // in the dessertBuildReleases list do not add it to the list. + dessertBuildReleases = append(dessertBuildReleases, release) + } return release } -// latestBuildRelease returns the latest build release, i.e. the last one added. -func latestBuildRelease() *buildRelease { - return buildReleases[len(buildReleases)-1] +// latestDessertBuildRelease returns the latest dessert release build name, i.e. the last dessert +// release added to the list, which does not include current. +func latestDessertBuildRelease() *buildRelease { + return dessertBuildReleases[len(dessertBuildReleases)-1] } // nameToRelease maps from build release name to the corresponding build release (if it exists) or @@ -134,8 +160,10 @@ func parseBuildReleaseSet(specification string) (*buildReleaseSet, error) { if err != nil { return nil, err } - end := latestBuildRelease() + end := latestDessertBuildRelease() set.addRange(start, end) + // An open-ended range always includes the current release. + set.addItem(buildReleaseCurrent) } else if strings.Contains(specification, "-") { limits := strings.SplitN(specification, "-", 2) start, err := nameToRelease(limits[0]) diff --git a/sdk/build_release_test.go b/sdk/build_release_test.go index 6f1ef9e30..13730cbca 100644 --- a/sdk/build_release_test.go +++ b/sdk/build_release_test.go @@ -42,7 +42,7 @@ func TestNameToRelease(t *testing.T) { android.AssertDeepEquals(t, "release", (*buildRelease)(nil), release) // Uses a wildcard in the error message to allow for additional build releases to be added to // the supported set without breaking this test. - android.FailIfNoMatchingErrors(t, `unknown release "A", expected one of \[S,T.*,F1,F2\]`, []error{err}) + android.FailIfNoMatchingErrors(t, `unknown release "A", expected one of \[S,Tiramisu,F1,F2,current\]`, []error{err}) }) } @@ -55,7 +55,7 @@ func TestParseBuildReleaseSet(t *testing.T) { t.Run("open range", func(t *testing.T) { set, err := parseBuildReleaseSet("F1+") android.AssertDeepEquals(t, "errors", nil, err) - android.AssertStringEquals(t, "set", "[F1,F2]", set.String()) + android.AssertStringEquals(t, "set", "[F1,F2,current]", set.String()) }) t.Run("closed range", func(t *testing.T) { set, err := parseBuildReleaseSet("S-F1") diff --git a/sdk/testing.go b/sdk/testing.go index bed11b27d..f4e2b031b 100644 --- a/sdk/testing.go +++ b/sdk/testing.go @@ -262,8 +262,7 @@ func CheckSnapshot(t *testing.T, result *android.TestResult, name string, dir st // If the generated snapshot builders not for the current release then it cannot be loaded by // the current release. - currentBuildRelease := latestBuildRelease() - if snapshotBuildInfo.targetBuildRelease != currentBuildRelease { + if snapshotBuildInfo.targetBuildRelease != buildReleaseCurrent { return } diff --git a/sdk/update.go b/sdk/update.go index c555ddc7a..5c9376b5d 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -387,12 +387,11 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) { // Always add -current to the end snapshotFileSuffix := "-current" - currentBuildRelease := latestBuildRelease() - targetBuildReleaseEnv := config.GetenvWithDefault("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE", currentBuildRelease.name) + targetBuildReleaseEnv := config.GetenvWithDefault("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE", buildReleaseCurrent.name) targetBuildRelease, err := nameToRelease(targetBuildReleaseEnv) if err != nil { ctx.ModuleErrorf("invalid SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE: %s", err) - targetBuildRelease = currentBuildRelease + targetBuildRelease = buildReleaseCurrent } builder := &snapshotBuilder{ @@ -472,7 +471,7 @@ be unnecessary as every module in the sdk already has its own licenses property. contents := bp.content.String() // If the snapshot is being generated for the current build release then check the syntax to make // sure that it is compatible. - if targetBuildRelease == currentBuildRelease { + if targetBuildRelease == buildReleaseCurrent { syntaxCheckSnapshotBpFile(ctx, contents) } From ac915891e6480bafa6334ea51289a11e6d098575 Mon Sep 17 00:00:00 2001 From: Tyler Freeman Date: Tue, 23 Aug 2022 15:01:35 -0700 Subject: [PATCH 057/172] docs: update Soong Clion docs to point to Aidegen docs since they are easier. Test: n/a Change-Id: Ibfc62bdfa637b4c2cf775a09f81828b523c7e036 --- docs/clion.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/clion.md b/docs/clion.md index d6ae19a82..110891b31 100644 --- a/docs/clion.md +++ b/docs/clion.md @@ -3,6 +3,10 @@ Soong can generate CLion projects. This is intended for source code editing only. Build should still be done via make/m/mm(a)/mmm(a). +Note: alternatively, you can use +[aidegen to generate a Clion or VSCode project](https://android.googlesource.com/platform/tools/asuite/+/refs/heads/master/aidegen/README.md) +with a single command, using the `-i c` flag. + CMakeLists.txt project file generation is enabled via environment variable: ```bash From cfd0caaf789a235e3b2256132bf77938662c3811 Mon Sep 17 00:00:00 2001 From: Sam Delmerico Date: Wed, 31 Aug 2022 15:57:52 -0400 Subject: [PATCH 058/172] jacoco libs dependency for instrumented libraries On coverage builds, R8 will fail to properly optimize and fail the build if ignore_warnings: false, because jacoco injects dependencies on jacocoagent classes, but the jacocoagent library is not part of the classpath libraries passed in to R8 in its arguments. Instead we can add jacocoagent as a libs dependency for these modules so that it will get pulled into the r8 flags. Bug: 243903417 Test: add optimize.ignore_warnings: false to NetworkStackAppDefaults && make SKIP_ABI_CHECKS=true PRODUCT=cf_x86_phone-userdebug \ EMMA_INSTRUMENT=true EMMA_INSTRUMENT_FRAMEWORK=true \ CLANG_COVERAGE=true COVERAGE_PATHS="" \ TARGET_USERDATAIMAGE_PARTITION_SIZE=17179869184 \ SKIP_BOOT_JARS_CHECK=true \ NetworkStack Change-Id: I71313b1fd35437ec52890f5c30b3fd1381c7c3d2 (cherry picked from commit c75937264b6d47630f23cb9f54b476e65bbf848d) Merged-In: I71313b1fd35437ec52890f5c30b3fd1381c7c3d2 --- apex/apex_test.go | 10 ++++++++++ java/base.go | 5 +++++ java/bootclasspath_fragment_test.go | 20 ++++++++++++++++---- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/apex/apex_test.go b/apex/apex_test.go index dbe918010..c425e9c04 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -8845,6 +8845,16 @@ func TestApexJavaCoverage(t *testing.T) { android.FixtureMergeEnv(map[string]string{ "EMMA_INSTRUMENT": "true", }), + // need to mock jacocoagent here to satisfy dependency added for + // instrumented libraries at build time + android.FixtureAddFile("jacocoagent/Android.bp", []byte(` + java_library { + name: "jacocoagent", + srcs: ["Test.java"], + system_modules: "none", + sdk_version: "none", + } + `)), ).RunTest(t) // Make sure jacoco ran on both mylib and mybootclasspathlib diff --git a/java/base.go b/java/base.go index ddabbc0c3..58c16492d 100644 --- a/java/base.go +++ b/java/base.go @@ -169,6 +169,8 @@ type CommonProperties struct { Output_params []string } + // If true, then jacocoagent is automatically added as a libs dependency so that + // r8 will not strip instrumentation classes out of dexed libraries. Instrument bool `blueprint:"mutated"` // If true, then the module supports statically including the jacocoagent // into the library. @@ -781,6 +783,9 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { } else if j.shouldInstrumentStatic(ctx) { ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent") } + if j.shouldInstrument(ctx) { + ctx.AddVariationDependencies(nil, libTag, "jacocoagent") + } if j.useCompose() { ctx.AddVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), kotlinPluginTag, diff --git a/java/bootclasspath_fragment_test.go b/java/bootclasspath_fragment_test.go index f95c83fe7..2bfb255af 100644 --- a/java/bootclasspath_fragment_test.go +++ b/java/bootclasspath_fragment_test.go @@ -96,10 +96,22 @@ func TestBootclasspathFragmentInconsistentArtConfiguration_ApexMixture(t *testin } func TestBootclasspathFragment_Coverage(t *testing.T) { - prepareForTestWithFrameworkCoverage := android.FixtureMergeEnv(map[string]string{ - "EMMA_INSTRUMENT": "true", - "EMMA_INSTRUMENT_FRAMEWORK": "true", - }) + prepareForTestWithFrameworkCoverage := android.GroupFixturePreparers( + android.FixtureMergeEnv(map[string]string{ + "EMMA_INSTRUMENT": "true", + "EMMA_INSTRUMENT_FRAMEWORK": "true", + }), + // need to mock jacocoagent here to satisfy dependency added for + // instrumented libraries at build time + android.FixtureAddFile("jacocoagent/Android.bp", []byte(` + java_library { + name: "jacocoagent", + srcs: ["Test.java"], + system_modules: "none", + sdk_version: "none", + } + `)), + ) prepareWithBp := android.FixtureWithRootAndroidBp(` bootclasspath_fragment { From 72da93e188cff69b4be448dbe46419d27c213362 Mon Sep 17 00:00:00 2001 From: William Escande Date: Thu, 18 Aug 2022 13:34:22 -0700 Subject: [PATCH 059/172] Bluetooth available hack The first hack has been introduced to facilitate the creation of the com.android.btservices apex without the need to upload 100+ cl close to the release date. We now want to delete com.android.bluetooth apex and replace all the apex_available rules to target the new apex name It will be way much easier to do this in separate CL and without forcing us into a single topic. Bug: 243054261 Bug: 245214856 Test: Build Change-Id: Ia03698db839db4684871eb38c088f88d6bdcba4b (cherry picked from commit 2ad6e84d6062d8b16a348839e3d75f2065d41fa9) Merged-In: Ia03698db839db4684871eb38c088f88d6bdcba4b --- android/apex.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/android/apex.go b/android/apex.go index 20c78eece..98b122eae 100644 --- a/android/apex.go +++ b/android/apex.go @@ -454,7 +454,8 @@ func CheckAvailableForApex(what string, apex_available []string) bool { } return InList(what, apex_available) || (what != AvailableToPlatform && InList(AvailableToAnyApex, apex_available)) || - (what == "com.android.btservices" && InList("com.android.bluetooth", apex_available)) || + (what == "com.android.btservices" && InList("com.android.bluetooth", apex_available)) || // TODO b/243054261 + (what == "com.android.bluetooth" && InList("com.android.btservices", apex_available)) || // TODO b/243054261 (strings.HasPrefix(what, "com.android.gki.") && InList(AvailableToGkiApex, apex_available)) } From 969f8f0a25f17c06e65ef658a47aef786482b60d Mon Sep 17 00:00:00 2001 From: Sam Delmerico Date: Tue, 26 Apr 2022 18:34:55 +0000 Subject: [PATCH 060/172] disable usage of plugins as static libs Test: m auto_value_plugin Test: m androidx.appsearch_appsearch-compiler Test: m intdef-annotation-processor-test Test: atest intdef-annotation-processor-test Test: m view-inspector-annotation-processor-test Test: atest view-inspector-annotation-processor-test Test: m Robolectric_processor_tests Test: atest Robolectric_processor_tests Bug: 225388628 Change-Id: I9e3dd81f44333b680f2e81283c02a9be5a4de15b (cherry picked from commit 0d1c4a0feeef13da40cb2f25a24923d48f87a473) Merged-In: I9e3dd81f44333b680f2e81283c02a9be5a4de15b --- java/base.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/java/base.go b/java/base.go index 58c16492d..73a364939 100644 --- a/java/base.go +++ b/java/base.go @@ -1937,6 +1937,9 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { case bootClasspathTag: deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars...) case libTag, instrumentationForTag: + if _, ok := module.(*Plugin); ok { + ctx.ModuleErrorf("a java_plugin (%s) cannot be used as a libs dependency", otherName) + } deps.classpath = append(deps.classpath, dep.HeaderJars...) deps.dexClasspath = append(deps.dexClasspath, dep.HeaderJars...) deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs...) @@ -1945,6 +1948,9 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { case java9LibTag: deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars...) case staticLibTag: + if _, ok := module.(*Plugin); ok { + ctx.ModuleErrorf("a java_plugin (%s) cannot be used as a static_libs dependency", otherName) + } deps.classpath = append(deps.classpath, dep.HeaderJars...) deps.staticJars = append(deps.staticJars, dep.ImplementationJars...) deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars...) From f15716ffab01cb1d1fcd9710c21243e56acf151a Mon Sep 17 00:00:00 2001 From: Sam Delmerico Date: Wed, 7 Sep 2022 12:07:07 -0400 Subject: [PATCH 061/172] add jacocoagent by default to Java modules On coverage builds, R8 will fail to properly optimize and fail the build if ignore_warnings: false, because jacoco injects dependencies on jacocoagent classes, but the jacocoagent library is not part of the classpath libraries passed in to R8 in its arguments. Instead we can add jacocoagent as a libs dependency for these modules so that it will get pulled into the r8 flags. Bug: 243903417 Test: cherry-pick ag/19866767 && make SKIP_ABI_CHECKS=true PRODUCT=cf_x86_phone-userdebug EMMA_INSTRUMENT=true EMMA_INSTRUMENT_FRAMEWORK=true CLANG_COVERAGE=true COVERAGE_PATHS="" TARGET_USERDATAIMAGE_PARTITION_SIZE=17179869184 SKIP_BOOT_JARS_CHECK=true service-uwb Change-Id: Icc24cc260b896fc800125a0318308d823ccf7a83 (cherry picked from commit 1e3f78f866504a99ecf30fd7dc81d2d374c544cf) Merged-In: Icc24cc260b896fc800125a0318308d823ccf7a83 --- apex/apex_test.go | 14 +--------- java/base.go | 11 +++----- java/bootclasspath_fragment_test.go | 19 +------------ java/jacoco.go | 28 +++++++++++++++++++ java/java.go | 2 ++ java/testing.go | 42 ++++++++++++++++++++++++----- 6 files changed, 71 insertions(+), 45 deletions(-) diff --git a/apex/apex_test.go b/apex/apex_test.go index c425e9c04..96e2f4c6c 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -8842,19 +8842,7 @@ func TestApexJavaCoverage(t *testing.T) { android.FixtureWithRootAndroidBp(bp), dexpreopt.FixtureSetApexBootJars("myapex:mybootclasspathlib"), dexpreopt.FixtureSetApexSystemServerJars("myapex:mysystemserverclasspathlib"), - android.FixtureMergeEnv(map[string]string{ - "EMMA_INSTRUMENT": "true", - }), - // need to mock jacocoagent here to satisfy dependency added for - // instrumented libraries at build time - android.FixtureAddFile("jacocoagent/Android.bp", []byte(` - java_library { - name: "jacocoagent", - srcs: ["Test.java"], - system_modules: "none", - sdk_version: "none", - } - `)), + java.PrepareForTestWithJacocoInstrumentation, ).RunTest(t) // Make sure jacoco ran on both mylib and mybootclasspathlib diff --git a/java/base.go b/java/base.go index 58c16492d..89776d8a5 100644 --- a/java/base.go +++ b/java/base.go @@ -649,6 +649,10 @@ func (j *Module) shouldInstrumentInApex(ctx android.BaseModuleContext) bool { return false } +func (j *Module) setInstrument(value bool) { + j.properties.Instrument = value +} + func (j *Module) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { return android.SdkSpecFrom(ctx, String(j.deviceProperties.Sdk_version)) } @@ -783,9 +787,6 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { } else if j.shouldInstrumentStatic(ctx) { ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent") } - if j.shouldInstrument(ctx) { - ctx.AddVariationDependencies(nil, libTag, "jacocoagent") - } if j.useCompose() { ctx.AddVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), kotlinPluginTag, @@ -1414,10 +1415,6 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { j.headerJarFile = j.implementationJarFile } - if j.shouldInstrumentInApex(ctx) { - j.properties.Instrument = true - } - // enforce syntax check to jacoco filters for any build (http://b/183622051) specs := j.jacocoModuleToZipCommand(ctx) if ctx.Failed() { diff --git a/java/bootclasspath_fragment_test.go b/java/bootclasspath_fragment_test.go index 2bfb255af..c63df599a 100644 --- a/java/bootclasspath_fragment_test.go +++ b/java/bootclasspath_fragment_test.go @@ -96,23 +96,6 @@ func TestBootclasspathFragmentInconsistentArtConfiguration_ApexMixture(t *testin } func TestBootclasspathFragment_Coverage(t *testing.T) { - prepareForTestWithFrameworkCoverage := android.GroupFixturePreparers( - android.FixtureMergeEnv(map[string]string{ - "EMMA_INSTRUMENT": "true", - "EMMA_INSTRUMENT_FRAMEWORK": "true", - }), - // need to mock jacocoagent here to satisfy dependency added for - // instrumented libraries at build time - android.FixtureAddFile("jacocoagent/Android.bp", []byte(` - java_library { - name: "jacocoagent", - srcs: ["Test.java"], - system_modules: "none", - sdk_version: "none", - } - `)), - ) - prepareWithBp := android.FixtureWithRootAndroidBp(` bootclasspath_fragment { name: "myfragment", @@ -191,7 +174,7 @@ func TestBootclasspathFragment_Coverage(t *testing.T) { t.Run("with coverage", func(t *testing.T) { result := android.GroupFixturePreparers( - prepareForTestWithFrameworkCoverage, + prepareForTestWithFrameworkJacocoInstrumentation, preparer, ).RunTest(t) checkContents(t, result, "mybootlib", "coveragelib") diff --git a/java/jacoco.go b/java/jacoco.go index e11c2ce69..f8012b852 100644 --- a/java/jacoco.go +++ b/java/jacoco.go @@ -47,6 +47,34 @@ var ( "strippedJar", "stripSpec", "tmpDir", "tmpJar") ) +func jacocoDepsMutator(ctx android.BottomUpMutatorContext) { + type instrumentable interface { + shouldInstrument(ctx android.BaseModuleContext) bool + shouldInstrumentInApex(ctx android.BaseModuleContext) bool + setInstrument(value bool) + } + + j, ok := ctx.Module().(instrumentable) + if !ctx.Module().Enabled() || !ok { + return + } + + if j.shouldInstrumentInApex(ctx) { + j.setInstrument(true) + } + + if j.shouldInstrument(ctx) && ctx.ModuleName() != "jacocoagent" { + // We can use AddFarVariationDependencies here because, since this dep + // is added as libs only (i.e. a compiletime CLASSPATH entry only), + // the first variant of jacocoagent is sufficient to prevent + // compile time errors. + // At this stage in the build, AddVariationDependencies is not always + // able to procure a variant of jacocoagent that matches the calling + // module. + ctx.AddFarVariationDependencies(ctx.Module().Target().Variations(), libTag, "jacocoagent") + } +} + // Instruments a jar using the Jacoco command line interface. Uses stripSpec to extract a subset // of the classes in inputJar into strippedJar, instruments strippedJar into tmpJar, and then // combines the classes in tmpJar with inputJar (preferring the instrumented classes in tmpJar) diff --git a/java/java.go b/java/java.go index f98f1e88c..e46712349 100644 --- a/java/java.go +++ b/java/java.go @@ -65,6 +65,8 @@ func registerJavaBuildComponents(ctx android.RegistrationContext) { // to support the checks in dexpreoptDisabled(). ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) { ctx.BottomUp("dexpreopt_tool_deps", dexpreoptToolDepsMutator).Parallel() + // needs access to ApexInfoProvider which is available after variant creation + ctx.BottomUp("jacoco_deps", jacocoDepsMutator).Parallel() }) ctx.RegisterSingletonType("logtags", LogtagsSingleton) diff --git a/java/testing.go b/java/testing.go index 511cc5ddb..1f411913b 100644 --- a/java/testing.go +++ b/java/testing.go @@ -59,11 +59,9 @@ var PrepareForTestWithJavaBuildComponents = android.GroupFixturePreparers( }.AddToFixture(), ) -// Test fixture preparer that will define all default java modules except the -// fake_tool_binary for dex2oatd. -var PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd = android.GroupFixturePreparers( - // Make sure that all the module types used in the defaults are registered. - PrepareForTestWithJavaBuildComponents, +var prepareForTestWithFrameworkDeps = android.GroupFixturePreparers( + // The java default module definitions. + android.FixtureAddTextFile(defaultJavaDir+"/Android.bp", gatherRequiredDepsForTest()), // Additional files needed when test disallows non-existent source. android.MockFS{ // Needed for framework-res @@ -77,8 +75,14 @@ var PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd = android.GroupFixtu "build/make/core/proguard.flags": nil, "build/make/core/proguard_basic_keeps.flags": nil, }.AddToFixture(), - // The java default module definitions. - android.FixtureAddTextFile(defaultJavaDir+"/Android.bp", gatherRequiredDepsForTest()), +) + +// Test fixture preparer that will define all default java modules except the +// fake_tool_binary for dex2oatd. +var PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd = android.GroupFixturePreparers( + // Make sure that all the module types used in the defaults are registered. + PrepareForTestWithJavaBuildComponents, + prepareForTestWithFrameworkDeps, // Add dexpreopt compat libs (android.test.base, etc.) and a fake dex2oatd module. dexpreopt.PrepareForTestWithDexpreoptCompatLibs, ) @@ -141,6 +145,30 @@ var PrepareForTestWithPrebuiltsOfCurrentApi = FixtureWithPrebuiltApis(map[string "30": {}, }) +var prepareForTestWithFrameworkJacocoInstrumentation = android.GroupFixturePreparers( + android.FixtureMergeEnv(map[string]string{ + "EMMA_INSTRUMENT_FRAMEWORK": "true", + }), + PrepareForTestWithJacocoInstrumentation, +) + +// PrepareForTestWithJacocoInstrumentation creates a mock jacocoagent library that can be +// depended on as part of the build process for instrumented Java modules. +var PrepareForTestWithJacocoInstrumentation = android.GroupFixturePreparers( + android.FixtureMergeEnv(map[string]string{ + "EMMA_INSTRUMENT": "true", + }), + android.FixtureAddFile("jacocoagent/Test.java", nil), + android.FixtureAddFile("jacocoagent/Android.bp", []byte(` + java_library { + name: "jacocoagent", + host_supported: true, + srcs: ["Test.java"], + sdk_version: "current", + } + `)), +) + // FixtureWithPrebuiltApis creates a preparer that will define prebuilt api modules for the // specified releases and modules. // From d6714adb8ca323152a3a406cb1d02e1d918db987 Mon Sep 17 00:00:00 2001 From: Bob Badour Date: Thu, 8 Sep 2022 12:01:57 -0700 Subject: [PATCH 062/172] Fix gen_notice init to support arch and dist. Incorrect init function was called so Stem property was not handled correctly and the dist properties were treated as unknown. Test: m droid dist Change-Id: I5eb8771afb4fda332df08cf1560df5c17d1316cc Merged-in: I5eb8771afb4fda332df08cf1560df5c17d1316cc --- android/gen_notice.go | 2 +- android/gen_notice_test.go | 13 ------------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/android/gen_notice.go b/android/gen_notice.go index e2b839f69..2eb6bec88 100644 --- a/android/gen_notice.go +++ b/android/gen_notice.go @@ -179,7 +179,7 @@ func GenNoticeFactory() Module { // The visibility property needs to be checked and parsed by the visibility module. setPrimaryVisibilityProperty(module, "visibility", &module.properties.Visibility) - initAndroidModuleBase(module) + InitAndroidArchModule(module, DeviceSupported, MultilibCommon) InitDefaultableModule(module) return module diff --git a/android/gen_notice_test.go b/android/gen_notice_test.go index 4ad2ecfa9..b45ce4f94 100644 --- a/android/gen_notice_test.go +++ b/android/gen_notice_test.go @@ -11,19 +11,6 @@ var genNoticeTests = []struct { fs MockFS expectedErrors []string }{ - { - name: "gen_notice must not accept licenses property", - fs: map[string][]byte{ - "top/Android.bp": []byte(` - gen_notice { - name: "top_license", - licenses: ["other_license"], - }`), - }, - expectedErrors: []string{ - `unrecognized property "licenses"`, - }, - }, { name: "bad gen_notice", fs: map[string][]byte{ From 27bf106c58b2401e6e2c58963db6d6a7ae36f8de Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 23 Jun 2022 10:46:28 -0700 Subject: [PATCH 063/172] Move embedded notice file path above aapt rule generation The embedded notice file generation for apps was moved below the aapt rules, which meant the added asset path was ignored. Move the code to pick the notice file path selection back above the aapt rules, and leave the code to generate the notice file rule where it is. Bug: 236006463 Test: m NetworkStack ALWAYS_EMBED_NOTICES=true Change-Id: I1421fb0dbcdb759281259abfae7bddc9aecdaa56 Merged-in: I1421fb0dbcdb759281259abfae7bddc9aecdaa56 (cherry picked from commit 3d6cfd14d330c827962cded6255031f0fc15f060) --- java/app.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/java/app.go b/java/app.go index c7fdc0c47..433bf08d9 100755 --- a/java/app.go +++ b/java/app.go @@ -589,6 +589,16 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { a.classLoaderContexts = a.usesLibrary.classLoaderContextForUsesLibDeps(ctx) + var noticeAssetPath android.WritablePath + if Bool(a.appProperties.Embed_notices) || ctx.Config().IsEnvTrue("ALWAYS_EMBED_NOTICES") { + // The rule to create the notice file can't be generated yet, as the final output path + // for the apk isn't known yet. Add the path where the notice file will be generated to the + // aapt rules now before calling aaptBuildActions, the rule to create the notice file will + // be generated later. + noticeAssetPath = android.PathForModuleOut(ctx, "NOTICE", "NOTICE.html.gz") + a.aapt.noticeFile = android.OptionalPathForPath(noticeAssetPath) + } + // Process all building blocks, from AAPT to certificates. a.aaptBuildActions(ctx) @@ -663,7 +673,8 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { a.extraOutputFiles = append(a.extraOutputFiles, v4SignatureFile) } - if Bool(a.appProperties.Embed_notices) || ctx.Config().IsEnvTrue("ALWAYS_EMBED_NOTICES") { + if a.aapt.noticeFile.Valid() { + // Generating the notice file rule has to be here after a.outputFile is known. noticeFile := android.PathForModuleOut(ctx, "NOTICE.html.gz") android.BuildNoticeHtmlOutputFromLicenseMetadata( ctx, noticeFile, "", "", @@ -672,13 +683,11 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { android.PathForModuleInstall(ctx).String() + "/", a.outputFile.String(), }) - noticeAssetPath := android.PathForModuleOut(ctx, "NOTICE", "NOTICE.html.gz") builder := android.NewRuleBuilder(pctx, ctx) builder.Command().Text("cp"). Input(noticeFile). Output(noticeAssetPath) builder.Build("notice_dir", "Building notice dir") - a.aapt.noticeFile = android.OptionalPathForPath(noticeAssetPath) } for _, split := range a.aapt.splits { From 0fcd2f3d9995f119cd3da4a248c2f53be4b7bd67 Mon Sep 17 00:00:00 2001 From: Bob Badour Date: Mon, 12 Sep 2022 16:06:03 -0700 Subject: [PATCH 064/172] Integrate gen_notice with Make for dist. Most exempt module types have no output. Support exempt module types with output by requiring they must be 0p and have no license metadata. Disallow `licenses: []` property on gen_notice. Test: m cts dist Change-Id: Ic992bd6420fa6898495866eac43495002ef4b6c8 Merged-in: Ic992bd6420fa6898495866eac43495002ef4b6c8 --- android/androidmk.go | 14 +++++++++----- android/gen_notice.go | 13 +++++++++++++ android/gen_notice_test.go | 13 +++++++++++++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/android/androidmk.go b/android/androidmk.go index 1a9cabd6b..69df3582d 100644 --- a/android/androidmk.go +++ b/android/androidmk.go @@ -366,7 +366,9 @@ func (a *AndroidMkEntries) getDistContributions(mod blueprint.Module) *distContr // Collate the contributions this module makes to the dist. distContributions := &distContributions{} - distContributions.licenseMetadataFile = amod.licenseMetadataFile + if !exemptFromRequiredApplicableLicensesProperty(mod.(Module)) { + distContributions.licenseMetadataFile = amod.licenseMetadataFile + } // Iterate over this module's dist structs, merged from the dist and dists properties. for _, dist := range amod.Dists() { @@ -458,10 +460,12 @@ func generateDistContributionsForMake(distContributions *distContributions) []st ret = append(ret, fmt.Sprintf(".PHONY: %s\n", d.goals)) // Create dist-for-goals calls for each of the copy instructions. for _, c := range d.copies { - ret = append( - ret, - fmt.Sprintf("$(if $(strip $(ALL_TARGETS.%s.META_LIC)),,$(eval ALL_TARGETS.%s.META_LIC := %s))\n", - c.from.String(), c.from.String(), distContributions.licenseMetadataFile.String())) + if distContributions.licenseMetadataFile != nil { + ret = append( + ret, + fmt.Sprintf("$(if $(strip $(ALL_TARGETS.%s.META_LIC)),,$(eval ALL_TARGETS.%s.META_LIC := %s))\n", + c.from.String(), c.from.String(), distContributions.licenseMetadataFile.String())) + } ret = append( ret, fmt.Sprintf("$(call dist-for-goals,%s,%s:%s)\n", d.goals, c.from.String(), c.dest)) diff --git a/android/gen_notice.go b/android/gen_notice.go index 2eb6bec88..008aac5e2 100644 --- a/android/gen_notice.go +++ b/android/gen_notice.go @@ -111,6 +111,9 @@ type genNoticeModule struct { } func (m *genNoticeModule) DepsMutator(ctx BottomUpMutatorContext) { + if ctx.ContainsProperty("licenses") { + ctx.PropertyErrorf("licenses", "not supported on \"gen_notice\" modules") + } if proptools.Bool(m.properties.Html) && proptools.Bool(m.properties.Xml) { ctx.ModuleErrorf("can be html or xml but not both") } @@ -195,6 +198,16 @@ func (m *genNoticeModule) OutputFiles(tag string) (Paths, error) { return nil, fmt.Errorf("unrecognized tag %q", tag) } +var _ AndroidMkEntriesProvider = (*genNoticeModule)(nil) + +// Implements AndroidMkEntriesProvider +func (m *genNoticeModule) AndroidMkEntries() []AndroidMkEntries { + return []AndroidMkEntries{AndroidMkEntries{ + Class: "ETC", + OutputFile: OptionalPathForPath(m.output), + }} +} + // missingReferencesRule emits an ErrorRule for missing module references. func missingReferencesRule(ctx BuilderContext, m *genNoticeModule) { if len(m.missing) < 1 { diff --git a/android/gen_notice_test.go b/android/gen_notice_test.go index b45ce4f94..99d982bda 100644 --- a/android/gen_notice_test.go +++ b/android/gen_notice_test.go @@ -11,6 +11,19 @@ var genNoticeTests = []struct { fs MockFS expectedErrors []string }{ + { + name: "gen_notice must not accept licenses property", + fs: map[string][]byte{ + "top/Android.bp": []byte(` + gen_notice { + name: "top_license", + licenses: ["other_license"], + }`), + }, + expectedErrors: []string{ + `not supported on "gen_notice" modules`, + }, + }, { name: "bad gen_notice", fs: map[string][]byte{ From 91c1676c8e62fd25c1a800f3e0b9579f70f6296b Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 14 Sep 2022 17:04:51 +0000 Subject: [PATCH 065/172] Revert "bootclasspath_fragment: Treat some specific modules as test" This reverts commit ff9b6faba2b9a949289c70657db87c0b1790cc07. Reason for revert: No longer needed Bug: 194063708 Test: m nothing Change-Id: Ic2f6761c9a0a00a612724cb429f002a16522e53f (cherry picked from commit d0fe1307aafc7714f3f9e9949a2c143be04fcf44) Merged-In: Ic2f6761c9a0a00a612724cb429f002a16522e53f --- java/bootclasspath_fragment.go | 17 +---------------- java/bootclasspath_fragment_test.go | 22 ---------------------- 2 files changed, 1 insertion(+), 38 deletions(-) diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index c3053f88d..34735c2d1 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -840,22 +840,7 @@ func (b *BootclasspathFragmentModule) createHiddenAPIFlagInput(ctx android.Modul // isTestFragment returns true if the current module is a test bootclasspath_fragment. func (b *BootclasspathFragmentModule) isTestFragment() bool { - if b.testFragment { - return true - } - - // TODO(b/194063708): Once test fragments all use bootclasspath_fragment_test - // Some temporary exceptions until all test fragments use the - // bootclasspath_fragment_test module type. - name := b.BaseModuleName() - if strings.HasPrefix(name, "test_") { - return true - } - if name == "apex.apexd_test_bootclasspath-fragment" { - return true - } - - return false + return b.testFragment } // produceHiddenAPIOutput produces the hidden API all-flags.csv file (and supporting files) diff --git a/java/bootclasspath_fragment_test.go b/java/bootclasspath_fragment_test.go index c63df599a..2541f14ff 100644 --- a/java/bootclasspath_fragment_test.go +++ b/java/bootclasspath_fragment_test.go @@ -408,22 +408,6 @@ func TestBootclasspathFragment_Test(t *testing.T) { }, } - bootclasspath_fragment { - name: "test_fragment", - contents: ["mysdklibrary"], - hidden_api: { - split_packages: [], - }, - } - - bootclasspath_fragment { - name: "apex.apexd_test_bootclasspath-fragment", - contents: ["mysdklibrary"], - hidden_api: { - split_packages: [], - }, - } - bootclasspath_fragment_test { name: "a_test_fragment", contents: ["mysdklibrary"], @@ -445,12 +429,6 @@ func TestBootclasspathFragment_Test(t *testing.T) { fragment := result.Module("myfragment", "android_common").(*BootclasspathFragmentModule) android.AssertBoolEquals(t, "not a test fragment", false, fragment.isTestFragment()) - fragment = result.Module("test_fragment", "android_common").(*BootclasspathFragmentModule) - android.AssertBoolEquals(t, "is a test fragment by prefix", true, fragment.isTestFragment()) - fragment = result.Module("a_test_fragment", "android_common").(*BootclasspathFragmentModule) android.AssertBoolEquals(t, "is a test fragment by type", true, fragment.isTestFragment()) - - fragment = result.Module("apex.apexd_test_bootclasspath-fragment", "android_common").(*BootclasspathFragmentModule) - android.AssertBoolEquals(t, "is a test fragment by name", true, fragment.isTestFragment()) } From 722e5ccb5192593262b5e9aa144c90af7bd76f4a Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 14 Sep 2022 11:47:34 +0100 Subject: [PATCH 066/172] Separate hidden API flag generation from encoding Previously, the rules for encoding hidden API flags into dex files were generated in the hiddenAPIRulesForBootclasspathFragment alongside the rules for creating the hidden API flag files. This change separates the encoding from the generation of the flags. This will allow a follow up change to generate API flags for the sdk snapshot separately without affecting the encoded dex files. Bug: 240406019 Test: m nothing Change-Id: I3ab3ff5780e7b2e322665d3ea15f1438f2e403bd (cherry picked from commit af70518189374b3a18ccc3cf4d9500fcce5e29df) Merged-In: I3ab3ff5780e7b2e322665d3ea15f1438f2e403bd --- java/bootclasspath_fragment.go | 32 ++++++++++++++++---- java/hiddenapi_modular.go | 55 ++++++++++++++++------------------ 2 files changed, 52 insertions(+), 35 deletions(-) diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index 34735c2d1..b18365102 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -843,12 +843,12 @@ func (b *BootclasspathFragmentModule) isTestFragment() bool { return b.testFragment } -// produceHiddenAPIOutput produces the hidden API all-flags.csv file (and supporting files) -// for the fragment as well as encoding the flags in the boot dex jars. -func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput { +// generateHiddenApiFlagRules generates rules to generate hidden API flags and compute the signature +// patterns file. +func (b *BootclasspathFragmentModule) generateHiddenApiFlagRules(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput, bootDexInfoByModule bootDexInfoByModule, suffix string) HiddenAPIFlagOutput { // Generate the rules to create the hidden API flags and update the supplied hiddenAPIInfo with the // paths to the created files. - output := hiddenAPIRulesForBootclasspathFragment(ctx, contents, input) + flagOutput := hiddenAPIFlagRulesForBootclasspathFragment(ctx, bootDexInfoByModule, contents, input) // If the module specifies split_packages or package_prefixes then use those to generate the // signature patterns. @@ -856,8 +856,8 @@ func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleC packagePrefixes := input.PackagePrefixes singlePackages := input.SinglePackages if splitPackages != nil || packagePrefixes != nil || singlePackages != nil { - output.SignaturePatternsPath = buildRuleSignaturePatternsFile( - ctx, output.AllFlagsPath, splitPackages, packagePrefixes, singlePackages) + flagOutput.SignaturePatternsPath = buildRuleSignaturePatternsFile( + ctx, flagOutput.AllFlagsPath, splitPackages, packagePrefixes, singlePackages) } else if !b.isTestFragment() { ctx.ModuleErrorf(`Must specify at least one of the split_packages, package_prefixes and single_packages properties If this is a new bootclasspath_fragment or you are unsure what to do add the @@ -869,6 +869,26 @@ func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleC should specify here. If you are happy with its suggestions then you can add the --fix option and it will fix them for you.`, b.BaseModuleName()) } + return flagOutput +} + +// produceHiddenAPIOutput produces the hidden API all-flags.csv file (and supporting files) +// for the fragment as well as encoding the flags in the boot dex jars. +func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput { + // Gather information about the boot dex files for the boot libraries provided by this fragment. + bootDexInfoByModule := extractBootDexInfoFromModules(ctx, contents) + + // Generate the flag file needed to encode into the dex files. + flagOutput := b.generateHiddenApiFlagRules(ctx, contents, input, bootDexInfoByModule, "") + + // Encode those flags into the dex files of the contents of this fragment. + encodedBootDexFilesByModule := hiddenAPIEncodeRulesForBootclasspathFragment(ctx, bootDexInfoByModule, flagOutput.AllFlagsPath) + + // Store that information for return for use by other rules. + output := &HiddenAPIOutput{ + HiddenAPIFlagOutput: flagOutput, + EncodedBootDexFilesByModule: encodedBootDexFilesByModule, + } return output } diff --git a/java/hiddenapi_modular.go b/java/hiddenapi_modular.go index 7b678037c..08e684c3b 100644 --- a/java/hiddenapi_modular.go +++ b/java/hiddenapi_modular.go @@ -1116,8 +1116,8 @@ func buildRuleValidateOverlappingCsvFiles(ctx android.BuilderContext, name strin return validFile } -// hiddenAPIRulesForBootclasspathFragment will generate all the flags for a fragment of the -// bootclasspath and then encode the flags into the boot dex files. +// hiddenAPIFlagRulesForBootclasspathFragment will generate all the flags for a fragment of the +// bootclasspath. // // It takes: // * Map from android.SdkKind to stub dex jar paths defining the API for that sdk kind. @@ -1130,13 +1130,9 @@ func buildRuleValidateOverlappingCsvFiles(ctx android.BuilderContext, name strin // * metadata.csv // * index.csv // * all-flags.csv -// * encoded boot dex files -func hiddenAPIRulesForBootclasspathFragment(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput { +func hiddenAPIFlagRulesForBootclasspathFragment(ctx android.ModuleContext, bootDexInfoByModule bootDexInfoByModule, contents []android.Module, input HiddenAPIFlagInput) HiddenAPIFlagOutput { hiddenApiSubDir := "modular-hiddenapi" - // Gather information about the boot dex files for the boot libraries provided by this fragment. - bootDexInfoByModule := extractBootDexInfoFromModules(ctx, contents) - // Generate the stub-flags.csv. stubFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "stub-flags.csv") buildRuleToGenerateHiddenAPIStubFlagsFile(ctx, "modularHiddenAPIStubFlagsFile", "modular hiddenapi stub flags", stubFlagsCSV, bootDexInfoByModule.bootDexJars(), input, nil) @@ -1169,16 +1165,6 @@ func hiddenAPIRulesForBootclasspathFragment(ctx android.ModuleContext, contents allFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "all-flags.csv") buildRuleToGenerateHiddenApiFlags(ctx, "modularHiddenApiAllFlags", "modular hiddenapi all flags", allFlagsCSV, stubFlagsCSV, android.Paths{annotationFlagsCSV}, input.FlagFilesByCategory, nil, removedDexSignatures) - // Encode the flags into the boot dex files. - encodedBootDexJarsByModule := map[string]android.Path{} - outputDir := android.PathForModuleOut(ctx, "hiddenapi-modular/encoded").OutputPath - for _, name := range android.SortedStringKeys(bootDexInfoByModule) { - bootDexInfo := bootDexInfoByModule[name] - unencodedDex := bootDexInfo.path - encodedDex := hiddenAPIEncodeDex(ctx, unencodedDex, allFlagsCSV, bootDexInfo.uncompressDex, bootDexInfo.minSdkVersion, outputDir) - encodedBootDexJarsByModule[name] = encodedDex - } - // Generate the filtered-stub-flags.csv file which contains the filtered stub flags that will be // compared against the monolithic stub flags. filteredStubFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "filtered-stub-flags.csv") @@ -1194,19 +1180,30 @@ func hiddenAPIRulesForBootclasspathFragment(ctx android.ModuleContext, contents HIDDENAPI_FLAGS_CSV_IMPL_FLAGS) // Store the paths in the info for use by other modules and sdk snapshot generation. - output := HiddenAPIOutput{ - HiddenAPIFlagOutput: HiddenAPIFlagOutput{ - AnnotationFlagsPath: annotationFlagsCSV, - MetadataPath: metadataCSV, - IndexPath: indexCSV, - StubFlagsPath: stubFlagsCSV, - AllFlagsPath: allFlagsCSV, - FilteredStubFlagsPath: filteredStubFlagsCSV, - FilteredFlagsPath: filteredFlagsCSV, - }, - EncodedBootDexFilesByModule: encodedBootDexJarsByModule, + return HiddenAPIFlagOutput{ + AnnotationFlagsPath: annotationFlagsCSV, + MetadataPath: metadataCSV, + IndexPath: indexCSV, + StubFlagsPath: stubFlagsCSV, + AllFlagsPath: allFlagsCSV, + FilteredStubFlagsPath: filteredStubFlagsCSV, + FilteredFlagsPath: filteredFlagsCSV, } - return &output +} + +// hiddenAPIEncodeRulesForBootclasspathFragment generates rules to encode hidden API flags into the +// dex jars in bootDexInfoByModule. +func hiddenAPIEncodeRulesForBootclasspathFragment(ctx android.ModuleContext, bootDexInfoByModule bootDexInfoByModule, allFlagsCSV android.Path) bootDexJarByModule { + // Encode the flags into the boot dex files. + encodedBootDexJarsByModule := bootDexJarByModule{} + outputDir := android.PathForModuleOut(ctx, "hiddenapi-modular/encoded").OutputPath + for _, name := range android.SortedStringKeys(bootDexInfoByModule) { + bootDexInfo := bootDexInfoByModule[name] + unencodedDex := bootDexInfo.path + encodedDex := hiddenAPIEncodeDex(ctx, unencodedDex, allFlagsCSV, bootDexInfo.uncompressDex, bootDexInfo.minSdkVersion, outputDir) + encodedBootDexJarsByModule[name] = encodedDex + } + return encodedBootDexJarsByModule } func buildRuleToGenerateRemovedDexSignatures(ctx android.ModuleContext, removedTxtFiles android.Paths) android.OptionalPath { From 311210cd651fc6487c4edefed3fc18e39918bb0e Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 14 Sep 2022 16:37:12 +0100 Subject: [PATCH 067/172] Separate hidden API flag info for sdk from platform_bootclasspath Previously, the sdk snapshot and platform_bootclasspath both used the HiddenAPIInfo/Provider to retrieve the hidden API related information they needed. This change separates them by adding a new HiddenAPIInfoForSdk/Provider that is used to provide the information needed by the sdk snapshot. This allows a follow up change to generate different information for the sdk and for the platform depending on the target build release of the sdk snapshot. Bug: 240406019 Test: packages/modules/common/build/mainline_modules_sdks.sh # Ran the previous command with and without this change to make # sure that this change does not change the sdk snapshot # contents. Change-Id: I30cea6cf8dae1be467b7063430d6197e5baa684b (cherry picked from commit 887efdd779ecf6b264ea1ca510e47ef74d66f03c) Merged-In: I30cea6cf8dae1be467b7063430d6197e5baa684b --- java/bootclasspath_fragment.go | 10 +++++++++- java/hiddenapi_modular.go | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index b18365102..81cbd2c02 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -890,6 +890,14 @@ func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleC EncodedBootDexFilesByModule: encodedBootDexFilesByModule, } + flagFilesByCategory := input.FlagFilesByCategory + + // Make the information available for the sdk snapshot. + ctx.SetProvider(HiddenAPIInfoForSdkProvider, HiddenAPIInfoForSdk{ + FlagFilesByCategory: flagFilesByCategory, + HiddenAPIFlagOutput: flagOutput, + }) + return output } @@ -1054,7 +1062,7 @@ func (b *bootclasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx andro // Get the hidden API information from the module. mctx := ctx.SdkModuleContext() - hiddenAPIInfo := mctx.OtherModuleProvider(module, HiddenAPIInfoProvider).(HiddenAPIInfo) + hiddenAPIInfo := mctx.OtherModuleProvider(module, HiddenAPIInfoForSdkProvider).(HiddenAPIInfoForSdk) b.Flag_files_by_category = hiddenAPIInfo.FlagFilesByCategory // Copy all the generated file paths. diff --git a/java/hiddenapi_modular.go b/java/hiddenapi_modular.go index 08e684c3b..af1188903 100644 --- a/java/hiddenapi_modular.go +++ b/java/hiddenapi_modular.go @@ -594,6 +594,23 @@ func (i *HiddenAPIInfo) FlagSubset() SignatureCsvSubset { var HiddenAPIInfoProvider = blueprint.NewProvider(HiddenAPIInfo{}) +// HiddenAPIInfoForSdk contains information provided by the hidden API processing for use +// by the sdk snapshot. +// +// That includes paths resolved from HiddenAPIFlagFileProperties and also generated by hidden API +// processing. +type HiddenAPIInfoForSdk struct { + // FlagFilesByCategory maps from the flag file category to the paths containing information for + // that category. + FlagFilesByCategory FlagFilesByCategory + + // The output from the hidden API processing needs to be made available to other modules. + HiddenAPIFlagOutput +} + +// Provides hidden API info for the sdk snapshot. +var HiddenAPIInfoForSdkProvider = blueprint.NewProvider(HiddenAPIInfoForSdk{}) + // ModuleStubDexJars contains the stub dex jars provided by a single module. // // It maps a *HiddenAPIScope to the path to stub dex jars appropriate for that scope. See From 28e66cac868726f68eac0acef73bc5fe1d71754f Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 26 Jul 2022 23:53:00 +0000 Subject: [PATCH 068/172] Exclude unsupported libraries from sdk snapshot (cherry picked from commit 1938dba8b62a15b9a589e7aaf8ec5a120b7915fe) When an sdk snapshot is targeted at release X then it cannot include bootclasspath fragment libraries which are not present in that build as otherwise it causes build failures. It should also not include any unsupported libraries, i.e. libraries that cannot work on that release. This change causes sdk snapshot to exclude libraries that have a min_sdk_version > target build release It also ensures that hidden API flags do not include any information from excluded libraries. Bug: 240406019 Test: BUILD_NUMBER=fixed packages/modules/common/build/mainline_modules_sdks.sh # Ran the previous command with and without this change to make # sure that this change excludes framework-connectivity-t library from the # tethering sdk snapshot for S, including from the hidden API flag files. Merged-In: I57969b85a12e9e5a3fc76c055b260cec5d5f7d7f Change-Id: Ie142db49aad8e82ada21c343a7563102e74566a2 --- android/sdk.go | 20 +++ java/bootclasspath_fragment.go | 50 +++++- java/hiddenapi_modular.go | 39 +++-- sdk/bootclasspath_fragment_sdk_test.go | 219 +++++++++++++++++++++++++ sdk/java_sdk_test.go | 2 +- sdk/sdk_test.go | 1 + sdk/update.go | 64 ++++++-- 7 files changed, 354 insertions(+), 41 deletions(-) diff --git a/android/sdk.go b/android/sdk.go index a71f7f211..ef49afe37 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -74,6 +74,26 @@ type SdkAware interface { sdkAwareWithoutModule } +// minApiLevelForSdkSnapshot provides access to the min_sdk_version for MinApiLevelForSdkSnapshot +type minApiLevelForSdkSnapshot interface { + MinSdkVersion(ctx EarlyModuleContext) SdkSpec +} + +// MinApiLevelForSdkSnapshot returns the ApiLevel of the min_sdk_version of the supplied module. +// +// If the module does not provide a min_sdk_version then it defaults to 1. +func MinApiLevelForSdkSnapshot(ctx EarlyModuleContext, module Module) ApiLevel { + minApiLevel := NoneApiLevel + if m, ok := module.(minApiLevelForSdkSnapshot); ok { + minApiLevel = m.MinSdkVersion(ctx).ApiLevel + } + if minApiLevel == NoneApiLevel { + // The default min API level is 1. + minApiLevel = uncheckedFinalApiLevel(1) + } + return minApiLevel +} + // SdkRef refers to a version of an SDK type SdkRef struct { Name string diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index 81cbd2c02..841489e80 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -257,7 +257,7 @@ type commonBootclasspathFragment interface { // Returns a *HiddenAPIOutput containing the paths for the generated files. Returns nil if the // module cannot contribute to hidden API processing, e.g. because it is a prebuilt module in a // versioned sdk. - produceHiddenAPIOutput(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput + produceHiddenAPIOutput(ctx android.ModuleContext, contents []android.Module, fragments []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput // produceBootImageFiles will attempt to produce rules to create the boot image files at the paths // predefined in the bootImageConfig. @@ -761,7 +761,7 @@ func (b *BootclasspathFragmentModule) generateHiddenAPIBuildActions(ctx android. // Delegate the production of the hidden API all-flags.csv file to a module type specific method. common := ctx.Module().(commonBootclasspathFragment) - output := common.produceHiddenAPIOutput(ctx, contents, input) + output := common.produceHiddenAPIOutput(ctx, contents, fragments, input) // If the source or prebuilts module does not provide a signature patterns file then generate one // from the flags. @@ -769,7 +769,7 @@ func (b *BootclasspathFragmentModule) generateHiddenAPIBuildActions(ctx android. // their own. if output.SignaturePatternsPath == nil { output.SignaturePatternsPath = buildRuleSignaturePatternsFile( - ctx, output.AllFlagsPath, []string{"*"}, nil, nil) + ctx, output.AllFlagsPath, []string{"*"}, nil, nil, "") } // Initialize a HiddenAPIInfo structure. @@ -848,7 +848,7 @@ func (b *BootclasspathFragmentModule) isTestFragment() bool { func (b *BootclasspathFragmentModule) generateHiddenApiFlagRules(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput, bootDexInfoByModule bootDexInfoByModule, suffix string) HiddenAPIFlagOutput { // Generate the rules to create the hidden API flags and update the supplied hiddenAPIInfo with the // paths to the created files. - flagOutput := hiddenAPIFlagRulesForBootclasspathFragment(ctx, bootDexInfoByModule, contents, input) + flagOutput := hiddenAPIFlagRulesForBootclasspathFragment(ctx, bootDexInfoByModule, contents, input, suffix) // If the module specifies split_packages or package_prefixes then use those to generate the // signature patterns. @@ -857,7 +857,7 @@ func (b *BootclasspathFragmentModule) generateHiddenApiFlagRules(ctx android.Mod singlePackages := input.SinglePackages if splitPackages != nil || packagePrefixes != nil || singlePackages != nil { flagOutput.SignaturePatternsPath = buildRuleSignaturePatternsFile( - ctx, flagOutput.AllFlagsPath, splitPackages, packagePrefixes, singlePackages) + ctx, flagOutput.AllFlagsPath, splitPackages, packagePrefixes, singlePackages, suffix) } else if !b.isTestFragment() { ctx.ModuleErrorf(`Must specify at least one of the split_packages, package_prefixes and single_packages properties If this is a new bootclasspath_fragment or you are unsure what to do add the @@ -874,7 +874,7 @@ func (b *BootclasspathFragmentModule) generateHiddenApiFlagRules(ctx android.Mod // produceHiddenAPIOutput produces the hidden API all-flags.csv file (and supporting files) // for the fragment as well as encoding the flags in the boot dex jars. -func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput { +func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleContext, contents []android.Module, fragments []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput { // Gather information about the boot dex files for the boot libraries provided by this fragment. bootDexInfoByModule := extractBootDexInfoFromModules(ctx, contents) @@ -890,7 +890,41 @@ func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleC EncodedBootDexFilesByModule: encodedBootDexFilesByModule, } - flagFilesByCategory := input.FlagFilesByCategory + // Get the ApiLevel associated with SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE, defaulting to current + // if not set. + config := ctx.Config() + targetApiLevel := android.ApiLevelOrPanic(ctx, + config.GetenvWithDefault("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE", "current")) + + // Filter the contents list to remove any modules that do not support the target build release. + // The current build release supports all the modules. + contentsForSdkSnapshot := []android.Module{} + for _, module := range contents { + // If the module has a min_sdk_version that is higher than the target build release then it will + // not work on the target build release and so must not be included in the sdk snapshot. + minApiLevel := android.MinApiLevelForSdkSnapshot(ctx, module) + if minApiLevel.GreaterThan(targetApiLevel) { + continue + } + + contentsForSdkSnapshot = append(contentsForSdkSnapshot, module) + } + + var flagFilesByCategory FlagFilesByCategory + if len(contentsForSdkSnapshot) != len(contents) { + // The sdk snapshot has different contents to the runtime fragment so it is not possible to + // reuse the hidden API information generated for the fragment. So, recompute that information + // for the sdk snapshot. + filteredInput := b.createHiddenAPIFlagInput(ctx, contentsForSdkSnapshot, fragments) + + // Gather information about the boot dex files for the boot libraries provided by this fragment. + filteredBootDexInfoByModule := extractBootDexInfoFromModules(ctx, contentsForSdkSnapshot) + flagOutput = b.generateHiddenApiFlagRules(ctx, contentsForSdkSnapshot, filteredInput, filteredBootDexInfoByModule, "-for-sdk-snapshot") + flagFilesByCategory = filteredInput.FlagFilesByCategory + } else { + // The sdk snapshot has the same contents as the runtime fragment so reuse that information. + flagFilesByCategory = input.FlagFilesByCategory + } // Make the information available for the sdk snapshot. ctx.SetProvider(HiddenAPIInfoForSdkProvider, HiddenAPIInfoForSdk{ @@ -1204,7 +1238,7 @@ func (module *PrebuiltBootclasspathFragmentModule) Name() string { } // produceHiddenAPIOutput returns a path to the prebuilt all-flags.csv or nil if none is specified. -func (module *PrebuiltBootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput { +func (module *PrebuiltBootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleContext, contents []android.Module, fragments []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput { pathForOptionalSrc := func(src *string, defaultPath android.Path) android.Path { if src == nil { return defaultPath diff --git a/java/hiddenapi_modular.go b/java/hiddenapi_modular.go index af1188903..5474ae11e 100644 --- a/java/hiddenapi_modular.go +++ b/java/hiddenapi_modular.go @@ -1041,8 +1041,11 @@ func (s SignatureCsvSubsets) RelativeToTop() []string { // patterns that will select a subset of the monolithic flags. func buildRuleSignaturePatternsFile( ctx android.ModuleContext, flagsPath android.Path, - splitPackages []string, packagePrefixes []string, singlePackages []string) android.Path { - patternsFile := android.PathForModuleOut(ctx, "modular-hiddenapi", "signature-patterns.csv") + splitPackages []string, packagePrefixes []string, singlePackages []string, + suffix string) android.Path { + hiddenApiSubDir := "modular-hiddenapi" + suffix + + patternsFile := android.PathForModuleOut(ctx, hiddenApiSubDir, "signature-patterns.csv") // Create a rule to validate the output from the following rule. rule := android.NewRuleBuilder(pctx, ctx) @@ -1059,7 +1062,7 @@ func buildRuleSignaturePatternsFile( FlagForEachArg("--package-prefix ", packagePrefixes). FlagForEachArg("--single-package ", singlePackages). FlagWithOutput("--output ", patternsFile) - rule.Build("hiddenAPISignaturePatterns", "hidden API signature patterns") + rule.Build("hiddenAPISignaturePatterns"+suffix, "hidden API signature patterns"+suffix) return patternsFile } @@ -1147,27 +1150,27 @@ func buildRuleValidateOverlappingCsvFiles(ctx android.BuilderContext, name strin // * metadata.csv // * index.csv // * all-flags.csv -func hiddenAPIFlagRulesForBootclasspathFragment(ctx android.ModuleContext, bootDexInfoByModule bootDexInfoByModule, contents []android.Module, input HiddenAPIFlagInput) HiddenAPIFlagOutput { - hiddenApiSubDir := "modular-hiddenapi" +func hiddenAPIFlagRulesForBootclasspathFragment(ctx android.ModuleContext, bootDexInfoByModule bootDexInfoByModule, contents []android.Module, input HiddenAPIFlagInput, suffix string) HiddenAPIFlagOutput { + hiddenApiSubDir := "modular-hiddenapi" + suffix // Generate the stub-flags.csv. stubFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "stub-flags.csv") - buildRuleToGenerateHiddenAPIStubFlagsFile(ctx, "modularHiddenAPIStubFlagsFile", "modular hiddenapi stub flags", stubFlagsCSV, bootDexInfoByModule.bootDexJars(), input, nil) + buildRuleToGenerateHiddenAPIStubFlagsFile(ctx, "modularHiddenAPIStubFlagsFile"+suffix, "modular hiddenapi stub flags", stubFlagsCSV, bootDexInfoByModule.bootDexJars(), input, nil) // Extract the classes jars from the contents. classesJars := extractClassesJarsFromModules(contents) // Generate the set of flags from the annotations in the source code. annotationFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "annotation-flags.csv") - buildRuleToGenerateAnnotationFlags(ctx, "modular hiddenapi annotation flags", classesJars, stubFlagsCSV, annotationFlagsCSV) + buildRuleToGenerateAnnotationFlags(ctx, "modular hiddenapi annotation flags"+suffix, classesJars, stubFlagsCSV, annotationFlagsCSV) // Generate the metadata from the annotations in the source code. metadataCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "metadata.csv") - buildRuleToGenerateMetadata(ctx, "modular hiddenapi metadata", classesJars, stubFlagsCSV, metadataCSV) + buildRuleToGenerateMetadata(ctx, "modular hiddenapi metadata"+suffix, classesJars, stubFlagsCSV, metadataCSV) // Generate the index file from the CSV files in the classes jars. indexCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "index.csv") - buildRuleToGenerateIndex(ctx, "modular hiddenapi index", classesJars, indexCSV) + buildRuleToGenerateIndex(ctx, "modular hiddenapi index"+suffix, classesJars, indexCSV) // Removed APIs need to be marked and in order to do that the hiddenAPIInfo needs to specify files // containing dex signatures of all the removed APIs. In the monolithic files that is done by @@ -1175,25 +1178,25 @@ func hiddenAPIFlagRulesForBootclasspathFragment(ctx android.ModuleContext, bootD // signatures, see the combined-removed-dex module. This does that automatically by using the // *removed.txt files retrieved from the java_sdk_library modules that are specified in the // stub_libs and contents properties of a bootclasspath_fragment. - removedDexSignatures := buildRuleToGenerateRemovedDexSignatures(ctx, input.RemovedTxtFiles) + removedDexSignatures := buildRuleToGenerateRemovedDexSignatures(ctx, suffix, input.RemovedTxtFiles) // Generate the all-flags.csv which are the flags that will, in future, be encoded into the dex // files. allFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "all-flags.csv") - buildRuleToGenerateHiddenApiFlags(ctx, "modularHiddenApiAllFlags", "modular hiddenapi all flags", allFlagsCSV, stubFlagsCSV, android.Paths{annotationFlagsCSV}, input.FlagFilesByCategory, nil, removedDexSignatures) + buildRuleToGenerateHiddenApiFlags(ctx, "modularHiddenApiAllFlags"+suffix, "modular hiddenapi all flags"+suffix, allFlagsCSV, stubFlagsCSV, android.Paths{annotationFlagsCSV}, input.FlagFilesByCategory, nil, removedDexSignatures) // Generate the filtered-stub-flags.csv file which contains the filtered stub flags that will be // compared against the monolithic stub flags. filteredStubFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "filtered-stub-flags.csv") - buildRuleRemoveSignaturesWithImplementationFlags(ctx, "modularHiddenApiFilteredStubFlags", - "modular hiddenapi filtered stub flags", stubFlagsCSV, filteredStubFlagsCSV, + buildRuleRemoveSignaturesWithImplementationFlags(ctx, "modularHiddenApiFilteredStubFlags"+suffix, + "modular hiddenapi filtered stub flags"+suffix, stubFlagsCSV, filteredStubFlagsCSV, HIDDENAPI_STUB_FLAGS_IMPL_FLAGS) // Generate the filtered-flags.csv file which contains the filtered flags that will be compared // against the monolithic flags. filteredFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "filtered-flags.csv") - buildRuleRemoveSignaturesWithImplementationFlags(ctx, "modularHiddenApiFilteredFlags", - "modular hiddenapi filtered flags", allFlagsCSV, filteredFlagsCSV, + buildRuleRemoveSignaturesWithImplementationFlags(ctx, "modularHiddenApiFilteredFlags"+suffix, + "modular hiddenapi filtered flags"+suffix, allFlagsCSV, filteredFlagsCSV, HIDDENAPI_FLAGS_CSV_IMPL_FLAGS) // Store the paths in the info for use by other modules and sdk snapshot generation. @@ -1223,12 +1226,12 @@ func hiddenAPIEncodeRulesForBootclasspathFragment(ctx android.ModuleContext, boo return encodedBootDexJarsByModule } -func buildRuleToGenerateRemovedDexSignatures(ctx android.ModuleContext, removedTxtFiles android.Paths) android.OptionalPath { +func buildRuleToGenerateRemovedDexSignatures(ctx android.ModuleContext, suffix string, removedTxtFiles android.Paths) android.OptionalPath { if len(removedTxtFiles) == 0 { return android.OptionalPath{} } - output := android.PathForModuleOut(ctx, "modular-hiddenapi/removed-dex-signatures.txt") + output := android.PathForModuleOut(ctx, "module-hiddenapi"+suffix, "removed-dex-signatures.txt") rule := android.NewRuleBuilder(pctx, ctx) rule.Command(). @@ -1236,7 +1239,7 @@ func buildRuleToGenerateRemovedDexSignatures(ctx android.ModuleContext, removedT Flag("--no-banner"). Inputs(removedTxtFiles). FlagWithOutput("--dex-api ", output) - rule.Build("modular-hiddenapi-removed-dex-signatures", "modular hiddenapi removed dex signatures") + rule.Build("modular-hiddenapi-removed-dex-signatures"+suffix, "modular hiddenapi removed dex signatures"+suffix) return android.OptionalPathForPath(output) } diff --git a/sdk/bootclasspath_fragment_sdk_test.go b/sdk/bootclasspath_fragment_sdk_test.go index c93055a51..4be0ace68 100644 --- a/sdk/bootclasspath_fragment_sdk_test.go +++ b/sdk/bootclasspath_fragment_sdk_test.go @@ -895,3 +895,222 @@ my-unsupported-packages.txt -> hiddenapi/my-unsupported-packages.txt snapshotTestPreparer(checkSnapshotPreferredWithSource, preparerForSnapshot), ) } + +func testSnapshotWithBootClasspathFragment_MinSdkVersion(t *testing.T, targetBuildRelease string, + expectedSdkSnapshot string, + expectedCopyRules string, + expectedStubFlagsInputs []string, + suffix string) { + + result := android.GroupFixturePreparers( + prepareForSdkTestWithJava, + java.PrepareForTestWithJavaDefaultModules, + java.PrepareForTestWithJavaSdkLibraryFiles, + java.FixtureWithLastReleaseApis("mysdklibrary", "mynewsdklibrary"), + java.FixtureConfigureApexBootJars("myapex:mysdklibrary", "myapex:mynewsdklibrary"), + prepareForSdkTestWithApex, + + // Add a platform_bootclasspath that depends on the fragment. + fixtureAddPlatformBootclasspathForBootclasspathFragment("myapex", "mybootclasspathfragment"), + + android.FixtureMergeEnv(map[string]string{ + "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": targetBuildRelease, + }), + + android.FixtureWithRootAndroidBp(` + sdk { + name: "mysdk", + apexes: ["myapex"], + } + + apex { + name: "myapex", + key: "myapex.key", + min_sdk_version: "S", + bootclasspath_fragments: ["mybootclasspathfragment"], + } + + bootclasspath_fragment { + name: "mybootclasspathfragment", + apex_available: ["myapex"], + contents: [ + "mysdklibrary", + "mynewsdklibrary", + ], + + hidden_api: { + split_packages: [], + }, + } + + java_sdk_library { + name: "mysdklibrary", + apex_available: ["myapex"], + srcs: ["Test.java"], + shared_library: false, + public: {enabled: true}, + min_sdk_version: "S", + } + + java_sdk_library { + name: "mynewsdklibrary", + apex_available: ["myapex"], + srcs: ["Test.java"], + compile_dex: true, + public: {enabled: true}, + min_sdk_version: "Tiramisu", + permitted_packages: ["mynewsdklibrary"], + } + `), + ).RunTest(t) + + bcpf := result.ModuleForTests("mybootclasspathfragment", "android_common") + rule := bcpf.Output("out/soong/.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi" + suffix + "/stub-flags.csv") + android.AssertPathsRelativeToTopEquals(t, "stub flags inputs", expectedStubFlagsInputs, rule.Implicits) + + CheckSnapshot(t, result, "mysdk", "", + checkAndroidBpContents(expectedSdkSnapshot), + checkAllCopyRules(expectedCopyRules), + ) +} + +func TestSnapshotWithBootClasspathFragment_MinSdkVersion(t *testing.T) { + t.Run("target S build", func(t *testing.T) { + expectedSnapshot := ` +// This is auto-generated. DO NOT EDIT. + +prebuilt_bootclasspath_fragment { + name: "mybootclasspathfragment", + prefer: false, + visibility: ["//visibility:public"], + apex_available: ["myapex"], + contents: ["mysdklibrary"], + hidden_api: { + 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", + }, +} + +java_sdk_library_import { + name: "mysdklibrary", + prefer: false, + visibility: ["//visibility:public"], + apex_available: ["myapex"], + shared_library: false, + public: { + jars: ["sdk_library/public/mysdklibrary-stubs.jar"], + stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], + current_api: "sdk_library/public/mysdklibrary.txt", + removed_api: "sdk_library/public/mysdklibrary-removed.txt", + sdk_version: "current", + }, +} +` + expectedCopyRules := ` +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/annotation-flags.csv -> hiddenapi/annotation-flags.csv +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/metadata.csv -> hiddenapi/metadata.csv +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/index.csv -> hiddenapi/index.csv +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/stub-flags.csv -> hiddenapi/stub-flags.csv +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/all-flags.csv -> hiddenapi/all-flags.csv +.intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar +.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt +.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt +` + + // On S the stub flags should only be generated from mysdklibrary as mynewsdklibrary is not part + // of the snapshot. + expectedStubFlagsInputs := []string{ + "out/soong/.intermediates/mysdklibrary.stubs/android_common/dex/mysdklibrary.stubs.jar", + "out/soong/.intermediates/mysdklibrary/android_common/aligned/mysdklibrary.jar", + } + + testSnapshotWithBootClasspathFragment_MinSdkVersion(t, "S", + expectedSnapshot, expectedCopyRules, expectedStubFlagsInputs, "-for-sdk-snapshot") + }) + + t.Run("target-Tiramisu-build", func(t *testing.T) { + expectedSnapshot := ` +// This is auto-generated. DO NOT EDIT. + +prebuilt_bootclasspath_fragment { + name: "mybootclasspathfragment", + prefer: false, + visibility: ["//visibility:public"], + apex_available: ["myapex"], + contents: [ + "mysdklibrary", + "mynewsdklibrary", + ], + hidden_api: { + annotation_flags: "hiddenapi/annotation-flags.csv", + metadata: "hiddenapi/metadata.csv", + index: "hiddenapi/index.csv", + signature_patterns: "hiddenapi/signature-patterns.csv", + filtered_stub_flags: "hiddenapi/filtered-stub-flags.csv", + filtered_flags: "hiddenapi/filtered-flags.csv", + }, +} + +java_sdk_library_import { + name: "mysdklibrary", + prefer: false, + visibility: ["//visibility:public"], + apex_available: ["myapex"], + shared_library: false, + public: { + jars: ["sdk_library/public/mysdklibrary-stubs.jar"], + stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], + current_api: "sdk_library/public/mysdklibrary.txt", + removed_api: "sdk_library/public/mysdklibrary-removed.txt", + sdk_version: "current", + }, +} + +java_sdk_library_import { + name: "mynewsdklibrary", + prefer: false, + visibility: ["//visibility:public"], + apex_available: ["myapex"], + shared_library: true, + compile_dex: true, + permitted_packages: ["mynewsdklibrary"], + public: { + jars: ["sdk_library/public/mynewsdklibrary-stubs.jar"], + stub_srcs: ["sdk_library/public/mynewsdklibrary_stub_sources"], + current_api: "sdk_library/public/mynewsdklibrary.txt", + removed_api: "sdk_library/public/mynewsdklibrary-removed.txt", + sdk_version: "current", + }, +} +` + expectedCopyRules := ` +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/index.csv -> hiddenapi/index.csv +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/signature-patterns.csv -> hiddenapi/signature-patterns.csv +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/filtered-stub-flags.csv -> hiddenapi/filtered-stub-flags.csv +.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/filtered-flags.csv -> hiddenapi/filtered-flags.csv +.intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar +.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt +.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt +.intermediates/mynewsdklibrary.stubs/android_common/javac/mynewsdklibrary.stubs.jar -> sdk_library/public/mynewsdklibrary-stubs.jar +.intermediates/mynewsdklibrary.stubs.source/android_common/metalava/mynewsdklibrary.stubs.source_api.txt -> sdk_library/public/mynewsdklibrary.txt +.intermediates/mynewsdklibrary.stubs.source/android_common/metalava/mynewsdklibrary.stubs.source_removed.txt -> sdk_library/public/mynewsdklibrary-removed.txt +` + + // On tiramisu the stub flags should be generated from both mynewsdklibrary and mysdklibrary as + // they are both part of the snapshot. + expectedStubFlagsInputs := []string{ + "out/soong/.intermediates/mynewsdklibrary.stubs/android_common/dex/mynewsdklibrary.stubs.jar", + "out/soong/.intermediates/mynewsdklibrary/android_common/aligned/mynewsdklibrary.jar", + "out/soong/.intermediates/mysdklibrary.stubs/android_common/dex/mysdklibrary.stubs.jar", + "out/soong/.intermediates/mysdklibrary/android_common/aligned/mysdklibrary.jar", + } + + testSnapshotWithBootClasspathFragment_MinSdkVersion(t, "Tiramisu", + expectedSnapshot, expectedCopyRules, expectedStubFlagsInputs, "") + }) +} diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go index 7ab5285c6..d59883435 100644 --- a/sdk/java_sdk_test.go +++ b/sdk/java_sdk_test.go @@ -1004,7 +1004,7 @@ func TestSnapshotWithJavaSdkLibrary_AnnotationsZip_PreT(t *testing.T) { java_sdk_library { name: "myjavalib", srcs: ["Test.java"], - sdk_version: "current", + sdk_version: "S", shared_library: false, annotations_enabled: true, public: { diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go index 1ec12c346..8b8e1d701 100644 --- a/sdk/sdk_test.go +++ b/sdk/sdk_test.go @@ -482,6 +482,7 @@ java_import { name: "mysdklibrary", srcs: ["Test.java"], compile_dex: true, + sdk_version: "S", public: {enabled: true}, permitted_packages: ["mysdklibrary"], } diff --git a/sdk/update.go b/sdk/update.go index 5c9376b5d..81f3672fc 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -211,11 +211,14 @@ func (s *sdk) collectMembers(ctx android.ModuleContext) { container = parent.(android.SdkAware) } + minApiLevel := android.MinApiLevelForSdkSnapshot(ctx, child) + export := memberTag.ExportMember() s.memberVariantDeps = append(s.memberVariantDeps, sdkMemberVariantDep{ sdkVariant: s, memberType: memberType, variant: child.(android.SdkAware), + minApiLevel: minApiLevel, container: container, export: export, exportedComponentsInfo: exportedComponentsInfo, @@ -332,10 +335,28 @@ const BUILD_NUMBER_FILE = "snapshot-creation-build-number.txt" // /lib/ // libFoo.so : a stub library +func (s sdk) targetBuildRelease(ctx android.ModuleContext) *buildRelease { + config := ctx.Config() + targetBuildReleaseEnv := config.GetenvWithDefault("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE", buildReleaseCurrent.name) + targetBuildRelease, err := nameToRelease(targetBuildReleaseEnv) + if err != nil { + ctx.ModuleErrorf("invalid SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE: %s", err) + targetBuildRelease = buildReleaseCurrent + } + + return targetBuildRelease +} + // buildSnapshot is the main function in this source file. It creates rules to copy // the contents (header files, stub libraries, etc) into the zip file. func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) { + targetBuildRelease := s.targetBuildRelease(ctx) + targetApiLevel, err := android.ApiLevelFromUser(ctx, targetBuildRelease.name) + if err != nil { + targetApiLevel = android.FutureApiLevel + } + // Aggregate all the sdkMemberVariantDep instances from all the sdk variants. hasLicenses := false var memberVariantDeps []sdkMemberVariantDep @@ -346,12 +367,18 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) { // Filter out any sdkMemberVariantDep that is a component of another. memberVariantDeps = filterOutComponents(ctx, memberVariantDeps) - // Record the names of all the members, both explicitly specified and implicitly - // included. + // Record the names of all the members, both explicitly specified and implicitly included. Also, + // record the names of any members that should be excluded from this snapshot. allMembersByName := make(map[string]struct{}) exportedMembersByName := make(map[string]struct{}) + excludedMembersByName := make(map[string]struct{}) + + addMember := func(name string, export bool, exclude bool) { + if exclude { + excludedMembersByName[name] = struct{}{} + return + } - addMember := func(name string, export bool) { allMembersByName[name] = struct{}{} if export { exportedMembersByName[name] = struct{}{} @@ -362,11 +389,15 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) { name := memberVariantDep.variant.Name() export := memberVariantDep.export - addMember(name, export) + // If the minApiLevel of the member is greater than the target API level then exclude it from + // this snapshot. + exclude := memberVariantDep.minApiLevel.GreaterThan(targetApiLevel) + + addMember(name, export, exclude) // Add any components provided by the module. for _, component := range memberVariantDep.exportedComponentsInfo.Components { - addMember(component, export) + addMember(component, export, exclude) } if memberVariantDep.memberType == android.LicenseModuleSdkMemberType { @@ -382,18 +413,9 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) { modules: make(map[string]*bpModule), } - config := ctx.Config() - // Always add -current to the end snapshotFileSuffix := "-current" - targetBuildReleaseEnv := config.GetenvWithDefault("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE", buildReleaseCurrent.name) - targetBuildRelease, err := nameToRelease(targetBuildReleaseEnv) - if err != nil { - ctx.ModuleErrorf("invalid SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE: %s", err) - targetBuildRelease = buildReleaseCurrent - } - builder := &snapshotBuilder{ ctx: ctx, sdk: s, @@ -404,6 +426,7 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) { prebuiltModules: make(map[string]*bpModule), allMembersByName: allMembersByName, exportedMembersByName: exportedMembersByName, + excludedMembersByName: excludedMembersByName, targetBuildRelease: targetBuildRelease, } s.builderForTests = builder @@ -437,6 +460,10 @@ be unnecessary as every module in the sdk already has its own licenses property. } name := member.name + if _, ok := excludedMembersByName[name]; ok { + continue + } + requiredTraits := traits[name] if requiredTraits == nil { requiredTraits = android.EmptySdkMemberTraitSet() @@ -1034,6 +1061,9 @@ type snapshotBuilder struct { // The set of exported members by name. exportedMembersByName map[string]struct{} + // The set of members which have been excluded from this snapshot; by name. + excludedMembersByName map[string]struct{} + // The target build release for which the snapshot is to be generated. targetBuildRelease *buildRelease @@ -1218,6 +1248,9 @@ func (s *snapshotBuilder) snapshotSdkMemberName(name string, required bool) stri func (s *snapshotBuilder) snapshotSdkMemberNames(members []string, required bool) []string { var references []string = nil for _, m := range members { + if _, ok := s.excludedMembersByName[m]; ok { + continue + } references = append(references, s.snapshotSdkMemberName(m, required)) } return references @@ -1260,6 +1293,9 @@ type sdkMemberVariantDep struct { // The names of additional component modules provided by the variant. exportedComponentsInfo android.ExportedComponentsInfo + + // The minimum API level on which this module is supported. + minApiLevel android.ApiLevel } var _ android.SdkMember = (*sdkMember)(nil) From f3ec7e0a828a2f010be30ac9a2a2370746f772e8 Mon Sep 17 00:00:00 2001 From: Dennis Shen Date: Wed, 3 Aug 2022 16:46:43 +0000 Subject: [PATCH 069/172] Cherrypick of aosp/2172270 BUG: 241096765 Change-Id: I4b3892508f54b9284c1cc70be83bffc9ee040d90 Merged-In: I2a5e7ea75a6e9a7af1932ff7dccb9dc3a3785db9 --- apex/apex.go | 9 ++++++ apex/builder.go | 82 +++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 74 insertions(+), 17 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index 49e0d08d1..125177551 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -190,6 +190,10 @@ type apexBundleProperties struct { // with the tool to sign payload contents. Custom_sign_tool *string + // Whether this is a dynamic common lib apex, if so the native shared libs will be placed + // in a special way that include the digest of the lib file under /lib(64)? + Dynamic_common_lib_apex *bool + // Canonical name of this APEX bundle. Used to determine the path to the // activated APEX on device (i.e. /apex/), and used for the // apex mutator variations. For override_apex modules, this is the name of the @@ -1454,6 +1458,11 @@ func (a *apexBundle) testOnlyShouldForceCompression() bool { return proptools.Bool(a.properties.Test_only_force_compression) } +// See the dynamic_common_lib_apex property +func (a *apexBundle) dynamic_common_lib_apex() bool { + return proptools.BoolDefault(a.properties.Dynamic_common_lib_apex, false) +} + // These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its // members) can be sanitized, either forcibly, or by the global configuration. For some of the // sanitizers, extra dependencies can be forcibly added as well. diff --git a/apex/builder.go b/apex/builder.go index 1956b4447..6fb2bb0c4 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -39,6 +39,7 @@ func init() { pctx.Import("android/soong/cc/config") pctx.Import("android/soong/java") pctx.HostBinToolVariable("apexer", "apexer") + pctx.HostBinToolVariable("apexer_with_DCLA_preprocessing", "apexer_with_DCLA_preprocessing") // ART minimal builds (using the master-art manifest) do not have the "frameworks/base" // projects, and hence cannot build 'aapt2'. Use the SDK prebuilt instead. hostBinToolVariableWithPrebuilt := func(name, prebuiltDir, tool string) { @@ -115,7 +116,35 @@ var ( Rspfile: "${out}.copy_commands", RspfileContent: "${copy_commands}", Description: "APEX ${image_dir} => ${out}", - }, "tool_path", "image_dir", "copy_commands", "file_contexts", "canned_fs_config", "key", "opt_flags", "manifest", "payload_fs_type") + }, "tool_path", "image_dir", "copy_commands", "file_contexts", "canned_fs_config", "key", + "opt_flags", "manifest") + + DCLAApexRule = pctx.StaticRule("DCLAApexRule", blueprint.RuleParams{ + Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` + + `(. ${out}.copy_commands) && ` + + `APEXER_TOOL_PATH=${tool_path} ` + + `${apexer_with_DCLA_preprocessing} ` + + `--apexer ${apexer} ` + + `--canned_fs_config ${canned_fs_config} ` + + `${image_dir} ` + + `${out} ` + + `-- ` + + `--include_build_info ` + + `--force ` + + `--payload_type image ` + + `--key ${key} ` + + `--file_contexts ${file_contexts} ` + + `--manifest ${manifest} ` + + `${opt_flags} `, + CommandDeps: []string{"${apexer_with_DCLA_preprocessing}", "${apexer}", "${avbtool}", "${e2fsdroid}", + "${merge_zips}", "${mke2fs}", "${resize2fs}", "${sefcontext_compile}", "${make_f2fs}", + "${sload_f2fs}", "${make_erofs}", "${soong_zip}", "${zipalign}", "${aapt2}", + "prebuilts/sdk/current/public/android.jar"}, + Rspfile: "${out}.copy_commands", + RspfileContent: "${copy_commands}", + Description: "APEX ${image_dir} => ${out}", + }, "tool_path", "image_dir", "copy_commands", "file_contexts", "canned_fs_config", "key", + "opt_flags", "manifest", "is_DCLA") zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{ Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` + @@ -659,22 +688,41 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { optFlags = append(optFlags, "--payload_fs_type "+a.payloadFsType.string()) - ctx.Build(pctx, android.BuildParams{ - Rule: apexRule, - Implicits: implicitInputs, - Output: unsignedOutputFile, - Description: "apex (" + apexType.name() + ")", - Args: map[string]string{ - "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir, - "image_dir": imageDir.String(), - "copy_commands": strings.Join(copyCommands, " && "), - "manifest": a.manifestPbOut.String(), - "file_contexts": fileContexts.String(), - "canned_fs_config": cannedFsConfig.String(), - "key": a.privateKeyFile.String(), - "opt_flags": strings.Join(optFlags, " "), - }, - }) + if a.dynamic_common_lib_apex() { + ctx.Build(pctx, android.BuildParams{ + Rule: DCLAApexRule, + Implicits: implicitInputs, + Output: unsignedOutputFile, + Description: "apex (" + apexType.name() + ")", + Args: map[string]string{ + "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir, + "image_dir": imageDir.String(), + "copy_commands": strings.Join(copyCommands, " && "), + "manifest": a.manifestPbOut.String(), + "file_contexts": fileContexts.String(), + "canned_fs_config": cannedFsConfig.String(), + "key": a.privateKeyFile.String(), + "opt_flags": strings.Join(optFlags, " "), + }, + }) + } else { + ctx.Build(pctx, android.BuildParams{ + Rule: apexRule, + Implicits: implicitInputs, + Output: unsignedOutputFile, + Description: "apex (" + apexType.name() + ")", + Args: map[string]string{ + "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir, + "image_dir": imageDir.String(), + "copy_commands": strings.Join(copyCommands, " && "), + "manifest": a.manifestPbOut.String(), + "file_contexts": fileContexts.String(), + "canned_fs_config": cannedFsConfig.String(), + "key": a.privateKeyFile.String(), + "opt_flags": strings.Join(optFlags, " "), + }, + }) + } // TODO(jiyong): make the two rules below as separate functions apexProtoFile := android.PathForModuleOut(ctx, a.Name()+".pb"+suffix) From 2a27c02737d1837163f9994c8ae4e29c472c451f Mon Sep 17 00:00:00 2001 From: Dennis Shen Date: Fri, 23 Sep 2022 20:47:34 +0000 Subject: [PATCH 070/172] Make native libs available to DCLA apexes For now, bypass apex available check for native shared libs used by DCLA apexes, for the long term, created b/248601389 to create AOSP version of DCLA and mark necessary native shared libs available to this AOSP DCLA apex. BUG: 239679485 TEST: local build of DCLA modules, no apex_available issue found Change-Id: Ie08d555177bf19ec7c57009b798a41ce454fdeda --- android/apex.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/android/apex.go b/android/apex.go index 98b122eae..883bf14b6 100644 --- a/android/apex.go +++ b/android/apex.go @@ -456,7 +456,9 @@ func CheckAvailableForApex(what string, apex_available []string) bool { (what != AvailableToPlatform && InList(AvailableToAnyApex, apex_available)) || (what == "com.android.btservices" && InList("com.android.bluetooth", apex_available)) || // TODO b/243054261 (what == "com.android.bluetooth" && InList("com.android.btservices", apex_available)) || // TODO b/243054261 - (strings.HasPrefix(what, "com.android.gki.") && InList(AvailableToGkiApex, apex_available)) + (strings.HasPrefix(what, "com.android.gki.") && InList(AvailableToGkiApex, apex_available)) || + (what == "com.google.mainline.primary.libs") || // TODO b/248601389 + (what == "com.google.mainline.go.primary.libs") // TODO b/248601389 } // Implements ApexModule @@ -712,8 +714,8 @@ type ApexContents struct { // NewApexContents creates and initializes an ApexContents that is suitable // for use with an apex module. -// * contents is a map from a module name to information about its membership within -// the apex. +// - contents is a map from a module name to information about its membership within +// the apex. func NewApexContents(contents map[string]ApexMembership) *ApexContents { return &ApexContents{ contents: contents, From 45fc9b2140a400b6e4b0a3f0ce105d294468a17c Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 22 Sep 2022 15:30:58 +0100 Subject: [PATCH 071/172] Rename sdk field tag "keep" to "ignore" "ignore" is a better description of the effect that this tag has on the optimization that is done as part of the sdk snapshot generation. "keep" implies that something special is done with the field during the optimization process but actually the optimization process completely ignores the property, just as it does with unexported fields. Bug: 248258460 Test: m nothing Change-Id: Idfdfd87f927d641d4d301cbbde72b463c89155bf (cherry picked from commit 02e25c85eb32c337b3f8a2033c6c092b8fea91d3) Merged-In: Idfdfd87f927d641d4d301cbbde72b463c89155bf --- android/sdk.go | 16 +++---- sdk/sdk_test.go | 108 ++++++++++++++++++++++++------------------------ sdk/update.go | 4 +- 3 files changed, 64 insertions(+), 64 deletions(-) diff --git a/android/sdk.go b/android/sdk.go index ef49afe37..5bff62ecf 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -736,8 +736,8 @@ type SdkMemberType interface { // have common values. Those fields are cleared and the common value added to the common // properties. // - // A field annotated with a tag of `sdk:"keep"` will be treated as if it - // was not capitalized, i.e. not optimized for common values. + // A field annotated with a tag of `sdk:"ignore"` will be treated as if it + // was not capitalized, i.e. ignored and not optimized for common values. // // A field annotated with a tag of `android:"arch_variant"` will be allowed to have // values that differ by arch, fields not tagged as such must have common values across @@ -924,18 +924,18 @@ type SdkMemberPropertiesBase struct { // the locations of any of their prebuilt files in the snapshot by os type to prevent them // from colliding. See OsPrefix(). // - // This property is the same for all variants of a member and so would be optimized away - // if it was not explicitly kept. - Os_count int `sdk:"keep"` + // Ignore this property during optimization. This is needed because this property is the same for + // all variants of a member and so would be optimized away if it was not ignored. + Os_count int `sdk:"ignore"` // The os type for which these properties refer. // // Provided to allow a member to differentiate between os types in the locations of their // prebuilt files when it supports more than one os type. // - // This property is the same for all os type specific variants of a member and so would be - // optimized away if it was not explicitly kept. - Os OsType `sdk:"keep"` + // Ignore this property during optimization. This is needed because this property is the same for + // all variants of a member and so would be optimized away if it was not ignored. + Os OsType `sdk:"ignore"` // The setting to use for the compile_multilib property. Compile_multilib string `android:"arch_variant"` diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go index 8b8e1d701..4be1e79a4 100644 --- a/sdk/sdk_test.go +++ b/sdk/sdk_test.go @@ -218,15 +218,15 @@ type EmbeddedPropertiesStruct struct { } type testPropertiesStruct struct { - name string - private string - Public_Kept string `sdk:"keep"` - S_Common string - S_Different string `android:"arch_variant"` - A_Common []string - A_Different []string `android:"arch_variant"` - F_Common *bool - F_Different *bool `android:"arch_variant"` + name string + private string + Public_Ignore string `sdk:"ignore"` + S_Common string + S_Different string `android:"arch_variant"` + A_Common []string + A_Different []string `android:"arch_variant"` + F_Common *bool + F_Different *bool `android:"arch_variant"` EmbeddedPropertiesStruct } @@ -244,30 +244,30 @@ func TestCommonValueOptimization(t *testing.T) { common := &testPropertiesStruct{name: "common"} structs := []propertiesContainer{ &testPropertiesStruct{ - name: "struct-0", - private: "common", - Public_Kept: "common", - S_Common: "common", - S_Different: "upper", - A_Common: []string{"first", "second"}, - A_Different: []string{"alpha", "beta"}, - F_Common: proptools.BoolPtr(false), - F_Different: proptools.BoolPtr(false), + name: "struct-0", + private: "common", + Public_Ignore: "common", + S_Common: "common", + S_Different: "upper", + A_Common: []string{"first", "second"}, + A_Different: []string{"alpha", "beta"}, + F_Common: proptools.BoolPtr(false), + F_Different: proptools.BoolPtr(false), EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ S_Embedded_Common: "embedded_common", S_Embedded_Different: "embedded_upper", }, }, &testPropertiesStruct{ - name: "struct-1", - private: "common", - Public_Kept: "common", - S_Common: "common", - S_Different: "lower", - A_Common: []string{"first", "second"}, - A_Different: []string{"alpha", "delta"}, - F_Common: proptools.BoolPtr(false), - F_Different: proptools.BoolPtr(true), + name: "struct-1", + private: "common", + Public_Ignore: "common", + S_Common: "common", + S_Different: "lower", + A_Common: []string{"first", "second"}, + A_Different: []string{"alpha", "delta"}, + F_Common: proptools.BoolPtr(false), + F_Different: proptools.BoolPtr(true), EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ S_Embedded_Common: "embedded_common", S_Embedded_Different: "embedded_lower", @@ -282,15 +282,15 @@ func TestCommonValueOptimization(t *testing.T) { android.AssertDeepEquals(t, "common properties not correct", &testPropertiesStruct{ - name: "common", - private: "", - Public_Kept: "", - S_Common: "common", - S_Different: "", - A_Common: []string{"first", "second"}, - A_Different: []string(nil), - F_Common: proptools.BoolPtr(false), - F_Different: nil, + name: "common", + private: "", + Public_Ignore: "", + S_Common: "common", + S_Different: "", + A_Common: []string{"first", "second"}, + A_Different: []string(nil), + F_Common: proptools.BoolPtr(false), + F_Different: nil, EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ S_Embedded_Common: "embedded_common", S_Embedded_Different: "", @@ -300,15 +300,15 @@ func TestCommonValueOptimization(t *testing.T) { android.AssertDeepEquals(t, "updated properties[0] not correct", &testPropertiesStruct{ - name: "struct-0", - private: "common", - Public_Kept: "common", - S_Common: "", - S_Different: "upper", - A_Common: nil, - A_Different: []string{"alpha", "beta"}, - F_Common: nil, - F_Different: proptools.BoolPtr(false), + name: "struct-0", + private: "common", + Public_Ignore: "common", + S_Common: "", + S_Different: "upper", + A_Common: nil, + A_Different: []string{"alpha", "beta"}, + F_Common: nil, + F_Different: proptools.BoolPtr(false), EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ S_Embedded_Common: "", S_Embedded_Different: "embedded_upper", @@ -318,15 +318,15 @@ func TestCommonValueOptimization(t *testing.T) { android.AssertDeepEquals(t, "updated properties[1] not correct", &testPropertiesStruct{ - name: "struct-1", - private: "common", - Public_Kept: "common", - S_Common: "", - S_Different: "lower", - A_Common: nil, - A_Different: []string{"alpha", "delta"}, - F_Common: nil, - F_Different: proptools.BoolPtr(true), + name: "struct-1", + private: "common", + Public_Ignore: "common", + S_Common: "", + S_Different: "lower", + A_Common: nil, + A_Different: []string{"alpha", "delta"}, + F_Common: nil, + F_Different: proptools.BoolPtr(true), EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ S_Embedded_Common: "", S_Embedded_Different: "embedded_lower", diff --git a/sdk/update.go b/sdk/update.go index 81f3672fc..f20f1d6e9 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -2217,8 +2217,8 @@ func (e *commonValueExtractor) gatherFields(structType reflect.Type, containingS continue } - // Ignore fields whose value should be kept. - if proptools.HasTag(field, "sdk", "keep") { + // Ignore fields tagged with sdk:"ignore". + if proptools.HasTag(field, "sdk", "ignore") { continue } From 2f0fddc0d162ed0f0b9f337cd794c09d6bc439a3 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 22 Sep 2022 16:21:54 +0100 Subject: [PATCH 072/172] Add sdk:"keep" tag support Fields tagged with `sdk:"keep"` will keep the value even if it would normally be cleared because it was common across a number of structs. This will allow a module type to specify the same value across all structs populated directly from variants and have it be copied into all common property structs without clearing it from the variant specific structs. Bug: 248258460 Test: m nothing Change-Id: I147d946b11fd8766a7d875d9206e8f5034f585d6 (cherry picked from commit bfdca968288c930a8d717ceb76349c19bef42fd1) Merged-In: I147d946b11fd8766a7d875d9206e8f5034f585d6 --- android/sdk.go | 5 +++++ sdk/sdk_test.go | 6 ++++++ sdk/update.go | 20 +++++++++++++++----- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/android/sdk.go b/android/sdk.go index 5bff62ecf..9f8d82e30 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -739,6 +739,11 @@ type SdkMemberType interface { // A field annotated with a tag of `sdk:"ignore"` will be treated as if it // was not capitalized, i.e. ignored and not optimized for common values. // + // A field annotated with a tag of `sdk:"keep"` will not be cleared even if the value is common + // across multiple structs. Common values will still be copied into the common property struct. + // So, if the same value is placed in all structs populated from variants that value would be + // copied into all common property structs and so be available in every instance. + // // A field annotated with a tag of `android:"arch_variant"` will be allowed to have // values that differ by arch, fields not tagged as such must have common values across // all variants. diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go index 4be1e79a4..2f9aee9da 100644 --- a/sdk/sdk_test.go +++ b/sdk/sdk_test.go @@ -221,6 +221,7 @@ type testPropertiesStruct struct { name string private string Public_Ignore string `sdk:"ignore"` + Public_Keep string `sdk:"keep"` S_Common string S_Different string `android:"arch_variant"` A_Common []string @@ -247,6 +248,7 @@ func TestCommonValueOptimization(t *testing.T) { name: "struct-0", private: "common", Public_Ignore: "common", + Public_Keep: "keep", S_Common: "common", S_Different: "upper", A_Common: []string{"first", "second"}, @@ -262,6 +264,7 @@ func TestCommonValueOptimization(t *testing.T) { name: "struct-1", private: "common", Public_Ignore: "common", + Public_Keep: "keep", S_Common: "common", S_Different: "lower", A_Common: []string{"first", "second"}, @@ -285,6 +288,7 @@ func TestCommonValueOptimization(t *testing.T) { name: "common", private: "", Public_Ignore: "", + Public_Keep: "keep", S_Common: "common", S_Different: "", A_Common: []string{"first", "second"}, @@ -303,6 +307,7 @@ func TestCommonValueOptimization(t *testing.T) { name: "struct-0", private: "common", Public_Ignore: "common", + Public_Keep: "keep", S_Common: "", S_Different: "upper", A_Common: nil, @@ -321,6 +326,7 @@ func TestCommonValueOptimization(t *testing.T) { name: "struct-1", private: "common", Public_Ignore: "common", + Public_Keep: "keep", S_Common: "", S_Different: "lower", A_Common: nil, diff --git a/sdk/update.go b/sdk/update.go index f20f1d6e9..92a13fa7f 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -2172,6 +2172,11 @@ type extractorProperty struct { // Retrieves the value on which common value optimization will be performed. getter fieldAccessorFunc + // True if the field should never be cleared. + // + // This is set to true if and only if the field is annotated with `sdk:"keep"`. + keep bool + // The empty value for the field. emptyValue reflect.Value @@ -2236,6 +2241,8 @@ func (e *commonValueExtractor) gatherFields(structType reflect.Type, containingS } } + keep := proptools.HasTag(field, "sdk", "keep") + // Save a copy of the field index for use in the function. fieldIndex := f @@ -2275,6 +2282,7 @@ func (e *commonValueExtractor) gatherFields(structType reflect.Type, containingS name, filter, fieldGetter, + keep, reflect.Zero(field.Type), proptools.HasTag(field, "android", "arch_variant"), } @@ -2394,11 +2402,13 @@ func (e *commonValueExtractor) extractCommonProperties(commonProperties interfac if commonValue != nil { emptyValue := property.emptyValue fieldGetter(commonStructValue).Set(*commonValue) - for i := 0; i < sliceValue.Len(); i++ { - container := sliceValue.Index(i).Interface().(propertiesContainer) - itemValue := reflect.ValueOf(container.optimizableProperties()) - fieldValue := fieldGetter(itemValue) - fieldValue.Set(emptyValue) + if !property.keep { + for i := 0; i < sliceValue.Len(); i++ { + container := sliceValue.Index(i).Interface().(propertiesContainer) + itemValue := reflect.ValueOf(container.optimizableProperties()) + fieldValue := fieldGetter(itemValue) + fieldValue.Set(emptyValue) + } } } From f7cd863c871b7e65fa7ec8bc285f4456c583ee4a Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 22 Sep 2022 16:24:46 +0100 Subject: [PATCH 073/172] java_sdk_library: Use dist_stem when generating sdk snapshot file names The API finalization process for platform releases copies various files from the apistubs/ dist directory into prebuilts/sdk//... Having them use the same name in both places makes that process simpler. For most modules the name of the file is derived from the name of the module by appending a suffix but unfortunately, for some modules that does not work. e.g. the conscrypt.txt file is produced by the conscrypt.module.public.api module. The dist_stem property was added to java_sdk_library to allow the stem name of the file to differ from the module name. The API finalization process for extension APIs does something similar as it extracts various files from the snapshots and copies them into the appropriate extension API specific directory in prebuilts/sdk/extensions/. Instead of copying files from the apistubs/ dist directory (which is not built for trains) it copies them from sdk snapshots that are built as part of the train. Previously, the sdk snapshot used to derive the name of the files within the snapshot from the name of the module, it ignored the dist_stem property. This change causes it to use the dist_stem property to make it consistent with the apistubs/ dist directory naming. The file name is created in sdkLibrarySdkMemberProperties.AddPropertyToSet() which does not have access to the dist_stem property. So, it has to be supplied in the sdkLibrarySdkMemberProperties instance in the new Stem property. Bug: 248258460 Test: m nothing BUILD_NUMBER=fixed packages/modules/common/build/mainline_modules_sdks.sh --build-release=latest # Ran the previous command before and after and make sure that the # conscrypt, art and icu sdk snapshots use the dist_stem value but # none of the other snapshots are affected. Change-Id: Ied52003de63dcdb86a252a39bb8781f85d51a6ff (cherry picked from commit e840995ac39040b1e6804e5067a5dde11fa85f8c) Merged-In: Ied52003de63dcdb86a252a39bb8781f85d51a6ff --- java/sdk_library.go | 33 ++++++++++++++++++++++------- sdk/java_sdk_test.go | 50 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 8 deletions(-) diff --git a/java/sdk_library.go b/java/sdk_library.go index 591e90f99..c8173a8b9 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -539,7 +539,7 @@ type sdkLibraryProperties struct { } // TODO: determines whether to create HTML doc or not - //Html_doc *bool + // Html_doc *bool } // Paths to outputs from java_sdk_library and java_sdk_library_import. @@ -1354,7 +1354,7 @@ func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) // Provide additional information for inclusion in an sdk's generated .info file. additionalSdkInfo := map[string]interface{}{} additionalSdkInfo["dist_stem"] = module.distStem() - baseModuleName := module.BaseModuleName() + baseModuleName := module.distStem() scopes := map[string]interface{}{} additionalSdkInfo["scopes"] = scopes for scope, scopePaths := range module.scopePaths { @@ -2905,6 +2905,18 @@ var javaSdkLibrarySdkMemberType = &sdkLibrarySdkMemberType{ type sdkLibrarySdkMemberProperties struct { android.SdkMemberPropertiesBase + // Stem name for files in the sdk snapshot. + // + // This is used to construct the path names of various sdk library files in the sdk snapshot to + // make sure that they match the finalized versions of those files in prebuilts/sdk. + // + // This property is marked as keep so that it will be kept in all instances of this struct, will + // not be cleared but will be copied to common structs. That is needed because this field is used + // to construct many file names for other parts of this struct and so it needs to be present in + // all structs. If it was not marked as keep then it would be cleared in some structs and so would + // be unavailable for generating file names if there were other properties that were still set. + Stem string `sdk:"keep"` + // Scope to per scope properties. Scopes map[*apiScope]*scopeProperties @@ -2966,6 +2978,9 @@ type scopeProperties struct { func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { sdk := variant.(*SdkLibrary) + // Copy the stem name for files in the sdk snapshot. + s.Stem = sdk.distStem() + s.Scopes = make(map[*apiScope]*scopeProperties) for _, apiScope := range allApiScopes { paths := sdk.findScopePaths(apiScope) @@ -3018,6 +3033,8 @@ func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberCo propertySet.AddProperty("permitted_packages", s.Permitted_packages) } + stem := s.Stem + for _, apiScope := range allApiScopes { if properties, ok := s.Scopes[apiScope]; ok { scopeSet := propertySet.AddPropertySet(apiScope.propertyName) @@ -3026,7 +3043,7 @@ func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberCo var jars []string for _, p := range properties.Jars { - dest := filepath.Join(scopeDir, ctx.Name()+"-stubs.jar") + dest := filepath.Join(scopeDir, stem+"-stubs.jar") ctx.SnapshotBuilder().CopyToSnapshot(p, dest) jars = append(jars, dest) } @@ -3034,31 +3051,31 @@ func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberCo if ctx.SdkModuleContext().Config().IsEnvTrue("SOONG_SDK_SNAPSHOT_USE_SRCJAR") { // Copy the stubs source jar into the snapshot zip as is. - srcJarSnapshotPath := filepath.Join(scopeDir, ctx.Name()+".srcjar") + srcJarSnapshotPath := filepath.Join(scopeDir, stem+".srcjar") ctx.SnapshotBuilder().CopyToSnapshot(properties.StubsSrcJar, srcJarSnapshotPath) scopeSet.AddProperty("stub_srcs", []string{srcJarSnapshotPath}) } else { // Merge the stubs source jar into the snapshot zip so that when it is unpacked // the source files are also unpacked. - snapshotRelativeDir := filepath.Join(scopeDir, ctx.Name()+"_stub_sources") + snapshotRelativeDir := filepath.Join(scopeDir, stem+"_stub_sources") ctx.SnapshotBuilder().UnzipToSnapshot(properties.StubsSrcJar, snapshotRelativeDir) scopeSet.AddProperty("stub_srcs", []string{snapshotRelativeDir}) } if properties.CurrentApiFile != nil { - currentApiSnapshotPath := apiScope.snapshotRelativeCurrentApiTxtPath(ctx.Name()) + currentApiSnapshotPath := apiScope.snapshotRelativeCurrentApiTxtPath(stem) ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, currentApiSnapshotPath) scopeSet.AddProperty("current_api", currentApiSnapshotPath) } if properties.RemovedApiFile != nil { - removedApiSnapshotPath := apiScope.snapshotRelativeRemovedApiTxtPath(ctx.Name()) + removedApiSnapshotPath := apiScope.snapshotRelativeRemovedApiTxtPath(stem) ctx.SnapshotBuilder().CopyToSnapshot(properties.RemovedApiFile, removedApiSnapshotPath) scopeSet.AddProperty("removed_api", removedApiSnapshotPath) } if properties.AnnotationsZip != nil { - annotationsSnapshotPath := filepath.Join(scopeDir, ctx.Name()+"_annotations.zip") + annotationsSnapshotPath := filepath.Join(scopeDir, stem+"_annotations.zip") ctx.SnapshotBuilder().CopyToSnapshot(properties.AnnotationsZip, annotationsSnapshotPath) scopeSet.AddProperty("annotations", annotationsSnapshotPath) } diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go index d59883435..51903ce39 100644 --- a/sdk/java_sdk_test.go +++ b/sdk/java_sdk_test.go @@ -889,6 +889,56 @@ java_sdk_library_import { ) } +func TestSnapshotWithJavaSdkLibrary_DistStem(t *testing.T) { + result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, ` + sdk { + name: "mysdk", + java_sdk_libs: ["myjavalib-foo"], + } + + java_sdk_library { + name: "myjavalib-foo", + apex_available: ["//apex_available:anyapex"], + srcs: ["Test.java"], + sdk_version: "current", + shared_library: false, + public: { + enabled: true, + }, + dist_stem: "myjavalib", + } + `) + + CheckSnapshot(t, result, "mysdk", "", + checkAndroidBpContents(` +// This is auto-generated. DO NOT EDIT. + +java_sdk_library_import { + name: "myjavalib-foo", + prefer: false, + visibility: ["//visibility:public"], + apex_available: ["//apex_available:anyapex"], + shared_library: false, + public: { + jars: ["sdk_library/public/myjavalib-stubs.jar"], + stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], + current_api: "sdk_library/public/myjavalib.txt", + removed_api: "sdk_library/public/myjavalib-removed.txt", + sdk_version: "current", + }, +} +`), + checkAllCopyRules(` +.intermediates/myjavalib-foo.stubs/android_common/javac/myjavalib-foo.stubs.jar -> sdk_library/public/myjavalib-stubs.jar +.intermediates/myjavalib-foo.stubs.source/android_common/metalava/myjavalib-foo.stubs.source_api.txt -> sdk_library/public/myjavalib.txt +.intermediates/myjavalib-foo.stubs.source/android_common/metalava/myjavalib-foo.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt +`), + checkMergeZips( + ".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip", + ), + ) +} + func TestSnapshotWithJavaSdkLibrary_UseSrcJar(t *testing.T) { result := android.GroupFixturePreparers( prepareForSdkTestWithJavaSdkLibrary, From d19b10b66991ed1bf43affba30d41a2758ecdffb Mon Sep 17 00:00:00 2001 From: Harshit Mahajan Date: Fri, 10 Jun 2022 11:24:05 +0000 Subject: [PATCH 074/172] Enforce mainline modules to have latest target sdk version by default. Due to GMS target SDK requirements (https://docs.partner.android.com/gms/policies/preview/mba#min-target-sdk) we need to ensure all the mainline packages to target latest API level. Currently, the team chases each module to bump their target API level. Updating the build code to make sure that mainline modules (i.e updatable modules) target the latest sdk version by default. It would be by default set to 10000 before SDK finalization and updated to the new API level after finalization. Effectively it would mean: 1. '10000' in aosp and internal master 2. Finalized number in development branches like "33" in "tm-dev" 3. As sdk hasn't been finalised in "udc-dev", it would be "10000" which would be automatically updated to finalized version after sdk finalization. For local development if the target sdk version is required to be set, users would need to set Updatable flag to false. Enforce_default_target_sdk_version flag needs to be used in bp file, if this feature needs to be tested locally when updatable: false. Bug: b/227460469 Test: m nothing Change-Id: I05e0ae74ae44fd73df75e91b926bcc924446253f Merged-In: I05e0ae74ae44fd73df75e91b926bcc924446253f --- android/config.go | 4 + java/aar.go | 21 ++--- java/android_manifest.go | 44 ++++++---- java/app.go | 31 ++++++- java/app_test.go | 173 +++++++++++++++++++++++++++++++++++++++ java/rro.go | 2 +- 6 files changed, 247 insertions(+), 28 deletions(-) diff --git a/android/config.go b/android/config.go index ba95c5a20..ddae886e5 100644 --- a/android/config.go +++ b/android/config.go @@ -749,6 +749,10 @@ func (c *config) PlatformSdkVersion() ApiLevel { return uncheckedFinalApiLevel(*c.productVariables.Platform_sdk_version) } +func (c *config) PlatformSdkFinal() bool { + return Bool(c.productVariables.Platform_sdk_final) +} + func (c *config) PlatformSdkCodename() string { return String(c.productVariables.Platform_sdk_codename) } diff --git a/java/aar.go b/java/aar.go index 00ff7e774..2ddd1882e 100644 --- a/java/aar.go +++ b/java/aar.go @@ -268,7 +268,7 @@ var extractAssetsRule = pctx.AndroidStaticRule("extractAssets", func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkContext, classLoaderContexts dexpreopt.ClassLoaderContextMap, excludedLibs []string, - extraLinkFlags ...string) { + enforceDefaultTargetSdkVersion bool, extraLinkFlags ...string) { transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assetPackages, libDeps, libFlags := aaptLibs(ctx, sdkContext, classLoaderContexts) @@ -281,14 +281,15 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkCon manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile) manifestPath := ManifestFixer(ctx, manifestSrcPath, ManifestFixerParams{ - SdkContext: sdkContext, - ClassLoaderContexts: classLoaderContexts, - IsLibrary: a.isLibrary, - UseEmbeddedNativeLibs: a.useEmbeddedNativeLibs, - UsesNonSdkApis: a.usesNonSdkApis, - UseEmbeddedDex: a.useEmbeddedDex, - HasNoCode: a.hasNoCode, - LoggingParent: a.LoggingParent, + SdkContext: sdkContext, + ClassLoaderContexts: classLoaderContexts, + IsLibrary: a.isLibrary, + UseEmbeddedNativeLibs: a.useEmbeddedNativeLibs, + UsesNonSdkApis: a.usesNonSdkApis, + UseEmbeddedDex: a.useEmbeddedDex, + HasNoCode: a.hasNoCode, + LoggingParent: a.LoggingParent, + EnforceDefaultTargetSdkVersion: enforceDefaultTargetSdkVersion, }) // Add additional manifest files to transitive manifests. @@ -531,7 +532,7 @@ func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { a.aapt.isLibrary = true a.classLoaderContexts = a.usesLibrary.classLoaderContextForUsesLibDeps(ctx) - a.aapt.buildActions(ctx, android.SdkContext(a), a.classLoaderContexts, nil) + a.aapt.buildActions(ctx, android.SdkContext(a), a.classLoaderContexts, nil, false) a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() diff --git a/java/android_manifest.go b/java/android_manifest.go index 1553564c2..cde7d1075 100644 --- a/java/android_manifest.go +++ b/java/android_manifest.go @@ -43,13 +43,12 @@ var manifestMergerRule = pctx.AndroidStaticRule("manifestMerger", // targetSdkVersion for manifest_fixer // When TARGET_BUILD_APPS is not empty, this method returns 10000 for modules targeting an unreleased SDK // This enables release builds (that run with TARGET_BUILD_APPS=[val...]) to target APIs that have not yet been finalized as part of an SDK -func targetSdkVersionForManifestFixer(ctx android.ModuleContext, sdkContext android.SdkContext) string { - targetSdkVersionSpec := sdkContext.TargetSdkVersion(ctx) - // Return 10000 for modules targeting "current" if either - // 1. The module is built in unbundled mode (TARGET_BUILD_APPS not empty) - // 2. The module is run as part of MTS, and should be testable on stable branches +func targetSdkVersionForManifestFixer(ctx android.ModuleContext, params ManifestFixerParams) string { + targetSdkVersionSpec := params.SdkContext.TargetSdkVersion(ctx) + + // Check if we want to return 10000 // TODO(b/240294501): Determine the rules for handling test apexes - if targetSdkVersionSpec.ApiLevel.IsPreview() && (ctx.Config().UnbundledBuildApps() || includedInMts(ctx.Module())) { + if shouldReturnFinalOrFutureInt(ctx, targetSdkVersionSpec, params.EnforceDefaultTargetSdkVersion) { return strconv.Itoa(android.FutureApiLevel.FinalOrFutureInt()) } targetSdkVersion, err := targetSdkVersionSpec.EffectiveVersionString(ctx) @@ -59,6 +58,17 @@ func targetSdkVersionForManifestFixer(ctx android.ModuleContext, sdkContext andr return targetSdkVersion } +// Return true for modules targeting "current" if either +// 1. The module is built in unbundled mode (TARGET_BUILD_APPS not empty) +// 2. The module is run as part of MTS, and should be testable on stable branches +// Do not return 10000 if we are enforcing default targetSdkVersion and sdk has been finalised +func shouldReturnFinalOrFutureInt(ctx android.ModuleContext, targetSdkVersionSpec android.SdkSpec, enforceDefaultTargetSdkVersion bool) bool { + if enforceDefaultTargetSdkVersion && ctx.Config().PlatformSdkFinal() { + return false + } + return targetSdkVersionSpec.ApiLevel.IsPreview() && (ctx.Config().UnbundledBuildApps() || includedInMts(ctx.Module())) +} + // Helper function that casts android.Module to java.androidTestApp // If this type conversion is possible, it queries whether the test app is included in an MTS suite func includedInMts(module android.Module) bool { @@ -69,15 +79,17 @@ func includedInMts(module android.Module) bool { } type ManifestFixerParams struct { - SdkContext android.SdkContext - ClassLoaderContexts dexpreopt.ClassLoaderContextMap - IsLibrary bool - UseEmbeddedNativeLibs bool - UsesNonSdkApis bool - UseEmbeddedDex bool - HasNoCode bool - TestOnly bool - LoggingParent string + SdkContext android.SdkContext + ClassLoaderContexts dexpreopt.ClassLoaderContextMap + IsLibrary bool + DefaultManifestVersion string + UseEmbeddedNativeLibs bool + UsesNonSdkApis bool + UseEmbeddedDex bool + HasNoCode bool + TestOnly bool + LoggingParent string + EnforceDefaultTargetSdkVersion bool } // Uses manifest_fixer.py to inject minSdkVersion, etc. into an AndroidManifest.xml @@ -136,7 +148,7 @@ func ManifestFixer(ctx android.ModuleContext, manifest android.Path, var argsMapper = make(map[string]string) if params.SdkContext != nil { - targetSdkVersion := targetSdkVersionForManifestFixer(ctx, params.SdkContext) + targetSdkVersion := targetSdkVersionForManifestFixer(ctx, params) args = append(args, "--targetSdkVersion ", targetSdkVersion) if UseApiFingerprint(ctx) && ctx.ModuleName() != "framework-res" { diff --git a/java/app.go b/java/app.go index 433bf08d9..04db0d4d8 100755 --- a/java/app.go +++ b/java/app.go @@ -101,6 +101,15 @@ type appProperties struct { PreventInstall bool `blueprint:"mutated"` IsCoverageVariant bool `blueprint:"mutated"` + // It can be set to test the behaviour of default target sdk version. + // Only required when updatable: false. It is an error if updatable: true and this is false. + Enforce_default_target_sdk_version *bool + + // If set, the targetSdkVersion for the target is set to the latest default API level. + // This would be by default false, unless updatable: true or + // enforce_default_target_sdk_version: true in which case this defaults to true. + EnforceDefaultTargetSdkVersion bool `blueprint:"mutated"` + // Whether this app is considered mainline updatable or not. When set to true, this will enforce // additional rules to make sure an app can safely be updated. Default is false. // Prefer using other specific properties if build behaviour must be changed; avoid using this @@ -296,6 +305,18 @@ func (a *AndroidApp) checkAppSdkVersions(ctx android.ModuleContext) { } else { ctx.PropertyErrorf("min_sdk_version", "%s", err.Error()) } + + if !BoolDefault(a.appProperties.Enforce_default_target_sdk_version, true) { + ctx.PropertyErrorf("enforce_default_target_sdk_version", "Updatable apps must enforce default target sdk version") + } + // TODO(b/227460469) after all the modules removes the target sdk version, throw an error if the target sdk version is explicitly set. + if a.deviceProperties.Target_sdk_version == nil { + a.SetEnforceDefaultTargetSdkVersion(true) + } + } + + if Bool(a.appProperties.Enforce_default_target_sdk_version) { + a.SetEnforceDefaultTargetSdkVersion(true) } a.checkPlatformAPI(ctx) @@ -424,7 +445,7 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) { a.aapt.splitNames = a.appProperties.Package_splits a.aapt.LoggingParent = String(a.overridableAppProperties.Logging_parent) a.aapt.buildActions(ctx, android.SdkContext(a), a.classLoaderContexts, - a.usesLibraryProperties.Exclude_uses_libs, aaptLinkFlags...) + a.usesLibraryProperties.Exclude_uses_libs, a.enforceDefaultTargetSdkVersion(), aaptLinkFlags...) // apps manifests are handled by aapt, don't let Module see them a.properties.Manifest = nil @@ -857,6 +878,14 @@ func (a *AndroidApp) buildAppDependencyInfo(ctx android.ModuleContext) { a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, a.MinSdkVersion(ctx).String(), depsInfo) } +func (a *AndroidApp) enforceDefaultTargetSdkVersion() bool { + return a.appProperties.EnforceDefaultTargetSdkVersion +} + +func (a *AndroidApp) SetEnforceDefaultTargetSdkVersion(val bool) { + a.appProperties.EnforceDefaultTargetSdkVersion = val +} + func (a *AndroidApp) Updatable() bool { return Bool(a.appProperties.Updatable) } diff --git a/java/app_test.go b/java/app_test.go index 2297ea993..83b47bdc9 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -3049,6 +3049,179 @@ func TestTargetSdkVersionManifestFixer(t *testing.T) { } } +func TestDefaultAppTargetSdkVersionForUpdatableModules(t *testing.T) { + platform_sdk_codename := "Tiramisu" + platform_sdk_version := 33 + testCases := []struct { + name string + platform_sdk_final bool + targetSdkVersionInBp *string + targetSdkVersionExpected *string + updatable bool + }{ + { + name: "Non-Updatable Module: Android.bp has older targetSdkVersion", + targetSdkVersionInBp: proptools.StringPtr("29"), + targetSdkVersionExpected: proptools.StringPtr("29"), + updatable: false, + }, + { + name: "Updatable Module: Android.bp has older targetSdkVersion", + targetSdkVersionInBp: proptools.StringPtr("30"), + targetSdkVersionExpected: proptools.StringPtr("30"), + updatable: true, + }, + { + name: "Updatable Module: Android.bp has no targetSdkVersion", + targetSdkVersionExpected: proptools.StringPtr("10000"), + updatable: true, + }, + { + name: "[SDK finalised] Non-Updatable Module: Android.bp has older targetSdkVersion", + platform_sdk_final: true, + targetSdkVersionInBp: proptools.StringPtr("30"), + targetSdkVersionExpected: proptools.StringPtr("30"), + updatable: false, + }, + { + name: "[SDK finalised] Updatable Module: Android.bp has older targetSdkVersion", + platform_sdk_final: true, + targetSdkVersionInBp: proptools.StringPtr("30"), + targetSdkVersionExpected: proptools.StringPtr("30"), + updatable: true, + }, + { + name: "[SDK finalised] Updatable Module: Android.bp has targetSdkVersion as platform sdk codename", + platform_sdk_final: true, + targetSdkVersionInBp: proptools.StringPtr(platform_sdk_codename), + targetSdkVersionExpected: proptools.StringPtr("33"), + updatable: true, + }, + { + name: "[SDK finalised] Updatable Module: Android.bp has no targetSdkVersion", + platform_sdk_final: true, + targetSdkVersionExpected: proptools.StringPtr("33"), + updatable: true, + }, + } + for _, testCase := range testCases { + bp := fmt.Sprintf(` + android_app { + name: "foo", + sdk_version: "current", + min_sdk_version: "29", + target_sdk_version: "%v", + updatable: %t, + enforce_default_target_sdk_version: %t + } + `, proptools.String(testCase.targetSdkVersionInBp), testCase.updatable, testCase.updatable) // enforce default target sdk version if app is updatable + + fixture := android.GroupFixturePreparers( + PrepareForTestWithJavaDefaultModules, + android.PrepareForTestWithAllowMissingDependencies, + android.PrepareForTestWithAndroidMk, + android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + // explicitly set following platform variables to make the test deterministic + variables.Platform_sdk_final = &testCase.platform_sdk_final + variables.Platform_sdk_version = &platform_sdk_version + variables.Platform_sdk_codename = &platform_sdk_codename + variables.Platform_version_active_codenames = []string{platform_sdk_codename} + variables.Unbundled_build_apps = []string{"sampleModule"} + }), + ) + + result := fixture.RunTestWithBp(t, bp) + foo := result.ModuleForTests("foo", "android_common") + + manifestFixerArgs := foo.Output("manifest_fixer/AndroidManifest.xml").Args["args"] + android.AssertStringDoesContain(t, testCase.name, manifestFixerArgs, "--targetSdkVersion "+*testCase.targetSdkVersionExpected) + } +} + +func TestEnforceDefaultAppTargetSdkVersionFlag(t *testing.T) { + platform_sdk_codename := "Tiramisu" + platform_sdk_version := 33 + testCases := []struct { + name string + enforceDefaultTargetSdkVersion bool + expectedError string + platform_sdk_final bool + targetSdkVersionInBp string + targetSdkVersionExpected string + updatable bool + }{ + { + name: "Not enforcing Target SDK Version: Android.bp has older targetSdkVersion", + enforceDefaultTargetSdkVersion: false, + targetSdkVersionInBp: "29", + targetSdkVersionExpected: "29", + updatable: false, + }, + { + name: "[SDK finalised] Enforce Target SDK Version: Android.bp has current targetSdkVersion", + enforceDefaultTargetSdkVersion: true, + platform_sdk_final: true, + targetSdkVersionInBp: "current", + targetSdkVersionExpected: "33", + updatable: true, + }, + { + name: "[SDK finalised] Enforce Target SDK Version: Android.bp has current targetSdkVersion", + enforceDefaultTargetSdkVersion: true, + platform_sdk_final: false, + targetSdkVersionInBp: "current", + targetSdkVersionExpected: "10000", + updatable: false, + }, + { + name: "Not enforcing Target SDK Version for Updatable app", + enforceDefaultTargetSdkVersion: false, + expectedError: "Updatable apps must enforce default target sdk version", + targetSdkVersionInBp: "29", + targetSdkVersionExpected: "29", + updatable: true, + }, + } + for _, testCase := range testCases { + errExpected := testCase.expectedError != "" + bp := fmt.Sprintf(` + android_app { + name: "foo", + enforce_default_target_sdk_version: %t, + sdk_version: "current", + min_sdk_version: "29", + target_sdk_version: "%v", + updatable: %t + } + `, testCase.enforceDefaultTargetSdkVersion, testCase.targetSdkVersionInBp, testCase.updatable) + + fixture := android.GroupFixturePreparers( + PrepareForTestWithJavaDefaultModules, + android.PrepareForTestWithAllowMissingDependencies, + android.PrepareForTestWithAndroidMk, + android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + // explicitly set following platform variables to make the test deterministic + variables.Platform_sdk_final = &testCase.platform_sdk_final + variables.Platform_sdk_version = &platform_sdk_version + variables.Platform_sdk_codename = &platform_sdk_codename + variables.Unbundled_build_apps = []string{"sampleModule"} + }), + ) + + errorHandler := android.FixtureExpectsNoErrors + if errExpected { + errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(testCase.expectedError) + } + result := fixture.ExtendWithErrorHandler(errorHandler).RunTestWithBp(t, bp) + + if !errExpected { + foo := result.ModuleForTests("foo", "android_common") + manifestFixerArgs := foo.Output("manifest_fixer/AndroidManifest.xml").Args["args"] + android.AssertStringDoesContain(t, testCase.name, manifestFixerArgs, "--targetSdkVersion "+testCase.targetSdkVersionExpected) + } + } +} + func TestAppMissingCertificateAllowMissingDependencies(t *testing.T) { result := android.GroupFixturePreparers( PrepareForTestWithJavaDefaultModules, diff --git a/java/rro.go b/java/rro.go index c98cbbd2d..b136e3f0d 100644 --- a/java/rro.go +++ b/java/rro.go @@ -142,7 +142,7 @@ func (r *RuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleC aaptLinkFlags = append(aaptLinkFlags, "--rename-overlay-target-package "+*r.overridableProperties.Target_package_name) } - r.aapt.buildActions(ctx, r, nil, nil, aaptLinkFlags...) + r.aapt.buildActions(ctx, r, nil, nil, false, aaptLinkFlags...) // Sign the built package _, certificates := collectAppDeps(ctx, r, false, false) From 397924a23b24eacb9e648e4f80239a651f88ea86 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 27 Sep 2022 12:41:52 +0100 Subject: [PATCH 075/172] java_sdk_library_import: Copy all prebuilt properties to child modules Previously, only the prefer property was copied from the java_sdk_library_import module to its child modules which meant that if the use_source_config_var property was used to control the prefer property that the child modules would never be used. That can cause build breakages when building against prebuilts as some parts of the build will use prebuilt files from java_sdk_library_import and some will use source files from the corresponding java_sdk_library. This change copies the use_source_config_var property too. It also adds tests to verify that dependencies on child modules of a java_sdk_library use the prebuilt child modules of the corresponding java_sdk_library_import. That revealed a bug with the handling of stub sources where the prefer property was set after creating the module which has also been fixed. Bug: 249192297 Test: m nothing # Cherry pick into branch broken by previous behavior and make # sure that it fixes it. Change-Id: I5719c257f8457bcb2238bc7965215512a20f1095 (cherry picked from commit bf4de041de611de4b3ec24c5f261c4293522961a) Merged-In: I5719c257f8457bcb2238bc7965215512a20f1095 --- android/prebuilt.go | 14 +++++++- java/sdk_library.go | 17 ++++++---- java/sdk_library_test.go | 70 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 91 insertions(+), 10 deletions(-) diff --git a/android/prebuilt.go b/android/prebuilt.go index 584348767..e7f221b6d 100644 --- a/android/prebuilt.go +++ b/android/prebuilt.go @@ -56,7 +56,9 @@ func (t prebuiltDependencyTag) ExcludeFromApexContents() {} var _ ExcludeFromVisibilityEnforcementTag = PrebuiltDepTag var _ ExcludeFromApexContentsTag = PrebuiltDepTag -type PrebuiltProperties struct { +// UserSuppliedPrebuiltProperties contains the prebuilt properties that can be specified in an +// Android.bp file. +type UserSuppliedPrebuiltProperties struct { // When prefer is set to true the prebuilt will be used instead of any source module with // a matching name. Prefer *bool `android:"arch_variant"` @@ -70,6 +72,16 @@ type PrebuiltProperties struct { // If specified then the prefer property is ignored in favor of the value of the Soong config // variable. Use_source_config_var *ConfigVarProperties +} + +// CopyUserSuppliedPropertiesFromPrebuilt copies the user supplied prebuilt properties from the +// prebuilt properties. +func (u *UserSuppliedPrebuiltProperties) CopyUserSuppliedPropertiesFromPrebuilt(p *Prebuilt) { + *u = p.properties.UserSuppliedPrebuiltProperties +} + +type PrebuiltProperties struct { + UserSuppliedPrebuiltProperties SourceExists bool `blueprint:"mutated"` UsePrebuilt bool `blueprint:"mutated"` diff --git a/java/sdk_library.go b/java/sdk_library.go index c8173a8b9..ec8079fc8 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -2235,8 +2235,9 @@ func (module *SdkLibraryImport) createJavaImportForStubs(mctx android.Defaultabl Sdk_version *string Libs []string Jars []string - Prefer *bool Compile_dex *bool + + android.UserSuppliedPrebuiltProperties }{} props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope)) props.Sdk_version = scopeProperties.Sdk_version @@ -2246,7 +2247,7 @@ func (module *SdkLibraryImport) createJavaImportForStubs(mctx android.Defaultabl props.Jars = scopeProperties.Jars // The imports are preferred if the java_sdk_library_import is preferred. - props.Prefer = proptools.BoolPtr(module.prebuilt.Prefer()) + props.CopyUserSuppliedPropertiesFromPrebuilt(&module.prebuilt) // The imports need to be compiled to dex if the java_sdk_library_import requests it. compileDex := module.properties.Compile_dex @@ -2260,16 +2261,18 @@ func (module *SdkLibraryImport) createJavaImportForStubs(mctx android.Defaultabl func (module *SdkLibraryImport) createPrebuiltStubsSources(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) { props := struct { - Name *string - Srcs []string - Prefer *bool + Name *string + Srcs []string + + android.UserSuppliedPrebuiltProperties }{} props.Name = proptools.StringPtr(module.stubsSourceModuleName(apiScope)) props.Srcs = scopeProperties.Stub_srcs - mctx.CreateModule(PrebuiltStubsSourcesFactory, &props) // The stubs source is preferred if the java_sdk_library_import is preferred. - props.Prefer = proptools.BoolPtr(module.prebuilt.Prefer()) + props.CopyUserSuppliedPropertiesFromPrebuilt(&module.prebuilt) + + mctx.CreateModule(PrebuiltStubsSourcesFactory, &props) } // Add the dependencies on the child module in the component deps mutator so that it diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go index 805bc226f..ea7b2f74f 100644 --- a/java/sdk_library_test.go +++ b/java/sdk_library_test.go @@ -875,11 +875,12 @@ func TestJavaSdkLibraryImport_WithSource(t *testing.T) { }) } -func TestJavaSdkLibraryImport_Preferred(t *testing.T) { +func testJavaSdkLibraryImport_Preferred(t *testing.T, prefer string, preparer android.FixturePreparer) { result := android.GroupFixturePreparers( prepareForJavaTest, PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("sdklib"), + preparer, ).RunTestWithBp(t, ` java_sdk_library { name: "sdklib", @@ -893,11 +894,37 @@ func TestJavaSdkLibraryImport_Preferred(t *testing.T) { java_sdk_library_import { name: "sdklib", - prefer: true, + `+prefer+` public: { jars: ["a.jar"], + stub_srcs: ["a.java"], + current_api: "current.txt", + removed_api: "removed.txt", + annotations: "annotations.zip", }, } + + java_library { + name: "combined", + static_libs: [ + "sdklib.stubs", + ], + java_resources: [ + ":sdklib.stubs.source", + ":sdklib{.public.api.txt}", + ":sdklib{.public.removed-api.txt}", + ":sdklib{.public.annotations.zip}", + ], + sdk_version: "none", + system_modules: "none", + } + + java_library { + name: "public", + srcs: ["a.java"], + libs: ["sdklib"], + sdk_version: "current", + } `) CheckModuleDependencies(t, result.TestContext, "sdklib", "android_common", []string{ @@ -913,9 +940,48 @@ func TestJavaSdkLibraryImport_Preferred(t *testing.T) { CheckModuleDependencies(t, result.TestContext, "prebuilt_sdklib", "android_common", []string{ `dex2oatd`, `prebuilt_sdklib.stubs`, + `prebuilt_sdklib.stubs.source`, `sdklib.impl`, `sdklib.xml`, }) + + // Make sure that dependencies on child modules use the prebuilt when preferred. + CheckModuleDependencies(t, result.TestContext, "combined", "android_common", []string{ + // Each use of :sdklib{...} adds a dependency onto prebuilt_sdklib. + `prebuilt_sdklib`, + `prebuilt_sdklib`, + `prebuilt_sdklib`, + `prebuilt_sdklib.stubs`, + `prebuilt_sdklib.stubs.source`, + }) + + // Make sure that dependencies on sdklib that resolve to one of the child libraries use the + // prebuilt library. + public := result.ModuleForTests("public", "android_common") + rule := public.Output("javac/public.jar") + inputs := rule.Implicits.Strings() + expected := "out/soong/.intermediates/prebuilt_sdklib.stubs/android_common/combined/sdklib.stubs.jar" + if !android.InList(expected, inputs) { + t.Errorf("expected %q to contain %q", inputs, expected) + } +} + +func TestJavaSdkLibraryImport_Preferred(t *testing.T) { + t.Run("prefer", func(t *testing.T) { + testJavaSdkLibraryImport_Preferred(t, "prefer: true,", android.NullFixturePreparer) + }) + + t.Run("use_source_config_var", func(t *testing.T) { + testJavaSdkLibraryImport_Preferred(t, + "use_source_config_var: {config_namespace: \"acme\", var_name: \"use_source\"},", + android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + variables.VendorVars = map[string]map[string]string{ + "acme": { + "use_source": "false", + }, + } + })) + }) } func TestJavaSdkLibraryEnforce(t *testing.T) { From 7e0a73544018ff0c8b8908b4b4f95dcf207303fa Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 29 Sep 2022 17:37:49 +0100 Subject: [PATCH 076/172] Add UpsideDownCake to the releases for which snapshots can be built Bug: 249769908 Test: packages/modules/common/mainline_modules_sdks.sh # With modification to add UpsideDownCake to list of releases # to build with. Change-Id: I050811e7d9a5d0a8cf54a42c03ad889defa3a251 (cherry picked from commit 03d2cef47b3535e43876923458338b5f7679d765) Merged-In: I050811e7d9a5d0a8cf54a42c03ad889defa3a251 --- sdk/build_release.go | 1 + sdk/build_release_test.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sdk/build_release.go b/sdk/build_release.go index 149a34eb0..e728afe6c 100644 --- a/sdk/build_release.go +++ b/sdk/build_release.go @@ -100,6 +100,7 @@ var ( // Add the dessert build releases from oldest to newest. buildReleaseS = initBuildRelease("S") buildReleaseT = initBuildRelease("Tiramisu") + buildReleaseU = initBuildRelease("UpsideDownCake") // Add the current build release which is always treated as being more recent than any other // build release, including those added in tests. diff --git a/sdk/build_release_test.go b/sdk/build_release_test.go index 13730cbca..5bf57b553 100644 --- a/sdk/build_release_test.go +++ b/sdk/build_release_test.go @@ -42,7 +42,7 @@ func TestNameToRelease(t *testing.T) { android.AssertDeepEquals(t, "release", (*buildRelease)(nil), release) // Uses a wildcard in the error message to allow for additional build releases to be added to // the supported set without breaking this test. - android.FailIfNoMatchingErrors(t, `unknown release "A", expected one of \[S,Tiramisu,F1,F2,current\]`, []error{err}) + android.FailIfNoMatchingErrors(t, `unknown release "A", expected one of \[S,Tiramisu,UpsideDownCake,F1,F2,current\]`, []error{err}) }) } @@ -60,7 +60,7 @@ func TestParseBuildReleaseSet(t *testing.T) { t.Run("closed range", func(t *testing.T) { set, err := parseBuildReleaseSet("S-F1") android.AssertDeepEquals(t, "errors", nil, err) - android.AssertStringEquals(t, "set", "[S,Tiramisu,F1]", set.String()) + android.AssertStringEquals(t, "set", "[S,Tiramisu,UpsideDownCake,F1]", set.String()) }) invalidAReleaseMessage := `unknown release "A", expected one of ` + allBuildReleaseSet.String() t.Run("invalid release", func(t *testing.T) { From 8aabd75cf977c07a4190082632884e513de5e2e6 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 16 Aug 2022 10:27:33 -0700 Subject: [PATCH 077/172] Reformat build/soong for go 1.19 (cherry picked from d079e0b2708ce0f4cce470db929f28dd8d2b0e80) Test: none Change-Id: I132368f0fcbdb5ea088b5b84dbe4ccfdd9e94cad Merged-In: I132368f0fcbdb5ea088b5b84dbe4ccfdd9e94cad --- android/apex.go | 4 +- android/arch.go | 89 +++++++------ android/bazel_paths.go | 37 +++--- android/bazel_test.go | 2 +- android/config_bp2build.go | 10 +- android/defaults.go | 12 +- android/fixture.go | 22 ++-- android/module.go | 2 +- android/paths.go | 53 ++++---- android/register.go | 18 +-- android/rule_builder.go | 6 +- android/sdk.go | 59 +++++---- android/soong_config_modules.go | 123 +++++++++--------- android/soongconfig/modules.go | 35 ++--- android/testing.go | 18 +-- android/variable.go | 42 +++--- androidmk/androidmk/androidmk.go | 6 +- androidmk/parser/make_strings.go | 8 +- apex/key.go | 2 +- apex/prebuilt.go | 51 ++++---- bazel/properties.go | 19 +-- .../cc_prebuilt_library_conversion_test.go | 2 +- bp2build/cc_prebuilt_library_static_test.go | 2 +- bpfix/bpfix/bpfix.go | 10 +- cc/afdo.go | 5 +- cc/fuzz.go | 8 +- cc/genrule.go | 10 +- cc/image.go | 2 +- cc/ndk_headers.go | 28 ++-- cc/ndk_library.go | 11 +- cc/prebuilt.go | 8 +- cc/snapshot_prebuilt.go | 17 +-- cc/snapshot_utils.go | 2 +- cc/vendor_public_library.go | 19 ++- cc/vendor_snapshot.go | 2 +- cc/vndk_prebuilt.go | 77 ++++++----- cmd/sbox/sbox.go | 1 - dexpreopt/class_loader_context.go | 32 +++-- etc/snapshot_etc.go | 2 +- finder/finder.go | 14 +- genrule/genrule.go | 2 - java/app_import.go | 26 ++-- java/classpath_element.go | 22 ++-- java/dexpreopt_bootjars.go | 1 - java/droiddoc.go | 10 -- java/droidstubs.go | 2 - java/genrule.go | 32 ++--- java/platform_compat_config.go | 2 +- java/sdk_library.go | 13 +- java/sdk_library_external.go | 7 +- mk2rbc/mk2rbc.go | 12 +- mk2rbc/soong_variables.go | 2 +- python/python.go | 6 +- scripts/build_broken_logs.go | 12 +- sdk/build_release.go | 4 +- sdk/member_trait.go | 1 - sdk/member_type.go | 1 - shared/env.go | 9 +- snapshot/recovery_snapshot.go | 2 +- snapshot/snapshot.go | 2 +- snapshot/snapshot_base.go | 2 +- snapshot/util.go | 2 +- snapshot/vendor_snapshot.go | 2 +- third_party/zip/reader_test.go | 1 - ui/signal/signal.go | 13 +- 65 files changed, 537 insertions(+), 521 deletions(-) diff --git a/android/apex.go b/android/apex.go index 98b122eae..4c89ea9a9 100644 --- a/android/apex.go +++ b/android/apex.go @@ -712,8 +712,8 @@ type ApexContents struct { // NewApexContents creates and initializes an ApexContents that is suitable // for use with an apex module. -// * contents is a map from a module name to information about its membership within -// the apex. +// - contents is a map from a module name to information about its membership within +// the apex. func NewApexContents(contents map[string]ApexMembership) *ApexContents { return &ApexContents{ contents: contents, diff --git a/android/arch.go b/android/arch.go index cbf77c758..483e2dcc4 100644 --- a/android/arch.go +++ b/android/arch.go @@ -572,26 +572,29 @@ var DarwinUniversalVariantTag = archDepTag{name: "darwin universal binary"} // archMutator splits a module into a variant for each Target requested by the module. Target selection // for a module is in three levels, OsClass, multilib, and then Target. // OsClass selection is determined by: -// - The HostOrDeviceSupported value passed in to InitAndroidArchModule by the module type factory, which selects -// whether the module type can compile for host, device or both. -// - The host_supported and device_supported properties on the module. +// - The HostOrDeviceSupported value passed in to InitAndroidArchModule by the module type factory, which selects +// whether the module type can compile for host, device or both. +// - The host_supported and device_supported properties on the module. +// // If host is supported for the module, the Host and HostCross OsClasses are selected. If device is supported // for the module, the Device OsClass is selected. // Within each selected OsClass, the multilib selection is determined by: -// - The compile_multilib property if it set (which may be overridden by target.android.compile_multilib or -// target.host.compile_multilib). -// - The default multilib passed to InitAndroidArchModule if compile_multilib was not set. +// - The compile_multilib property if it set (which may be overridden by target.android.compile_multilib or +// target.host.compile_multilib). +// - The default multilib passed to InitAndroidArchModule if compile_multilib was not set. +// // Valid multilib values include: -// "both": compile for all Targets supported by the OsClass (generally x86_64 and x86, or arm64 and arm). -// "first": compile for only a single preferred Target supported by the OsClass. This is generally x86_64 or arm64, -// but may be arm for a 32-bit only build. -// "32": compile for only a single 32-bit Target supported by the OsClass. -// "64": compile for only a single 64-bit Target supported by the OsClass. -// "common": compile a for a single Target that will work on all Targets supported by the OsClass (for example Java). -// "common_first": compile a for a Target that will work on all Targets supported by the OsClass -// (same as "common"), plus a second Target for the preferred Target supported by the OsClass -// (same as "first"). This is used for java_binary that produces a common .jar and a wrapper -// executable script. +// +// "both": compile for all Targets supported by the OsClass (generally x86_64 and x86, or arm64 and arm). +// "first": compile for only a single preferred Target supported by the OsClass. This is generally x86_64 or arm64, +// but may be arm for a 32-bit only build. +// "32": compile for only a single 32-bit Target supported by the OsClass. +// "64": compile for only a single 64-bit Target supported by the OsClass. +// "common": compile a for a single Target that will work on all Targets supported by the OsClass (for example Java). +// "common_first": compile a for a Target that will work on all Targets supported by the OsClass +// (same as "common"), plus a second Target for the preferred Target supported by the OsClass +// (same as "first"). This is used for java_binary that produces a common .jar and a wrapper +// executable script. // // Once the list of Targets is determined, the module is split into a variant for each Target. // @@ -1261,11 +1264,13 @@ func (m *ModuleBase) setOSProperties(ctx BottomUpMutatorContext) { // Returns the struct containing the properties specific to the given // architecture type. These look like this in Blueprint files: -// arch: { -// arm64: { -// key: value, -// }, -// }, +// +// arch: { +// arm64: { +// key: value, +// }, +// }, +// // This struct will also contain sub-structs containing to the architecture/CPU // variants and features that themselves contain properties specific to those. func getArchTypeStruct(ctx ArchVariantContext, archProperties interface{}, archType ArchType) (reflect.Value, bool) { @@ -1277,11 +1282,12 @@ func getArchTypeStruct(ctx ArchVariantContext, archProperties interface{}, archT // Returns the struct containing the properties specific to a given multilib // value. These look like this in the Blueprint file: -// multilib: { -// lib32: { -// key: value, -// }, -// }, +// +// multilib: { +// lib32: { +// key: value, +// }, +// }, func getMultilibStruct(ctx ArchVariantContext, archProperties interface{}, archType ArchType) (reflect.Value, bool) { archPropValues := reflect.ValueOf(archProperties).Elem() multilibProp := archPropValues.FieldByName("Multilib").Elem() @@ -2054,9 +2060,10 @@ type ConfigurationAxisToArchVariantProperties map[bazel.ConfigurationAxis]ArchVa // arch-variant properties correspond to the values of the properties of the 'propertySet' struct // that are specific to that axis/configuration. Each axis is independent, containing // non-overlapping configs that correspond to the various "arch-variant" support, at this time: -// arches (including multilib) -// oses -// arch+os combinations +// +// arches (including multilib) +// oses +// arch+os combinations // // For example, passing a struct { Foo bool, Bar string } will return an interface{} that can be // type asserted back into the same struct, containing the config-specific property value specified @@ -2209,17 +2216,21 @@ func (m *ModuleBase) GetArchVariantProperties(ctx ArchVariantContext, propertySe // Returns a struct matching the propertySet interface, containing properties specific to the targetName // For example, given these arguments: -// propertySet = BaseCompilerProperties -// targetName = "android_arm" +// +// propertySet = BaseCompilerProperties +// targetName = "android_arm" +// // And given this Android.bp fragment: -// target: -// android_arm: { -// srcs: ["foo.c"], -// } -// android_arm64: { -// srcs: ["bar.c"], -// } -// } +// +// target: +// android_arm: { +// srcs: ["foo.c"], +// } +// android_arm64: { +// srcs: ["bar.c"], +// } +// } +// // This would return a BaseCompilerProperties with BaseCompilerProperties.Srcs = ["foo.c"] func getTargetStructs(ctx ArchVariantContext, archProperties []interface{}, targetName string) []reflect.Value { var propertyStructs []reflect.Value diff --git a/android/bazel_paths.go b/android/bazel_paths.go index fa10f62b4..bacb4f642 100644 --- a/android/bazel_paths.go +++ b/android/bazel_paths.go @@ -221,9 +221,13 @@ func directoryHasBlueprint(fs pathtools.FileSystem, prefix string, components [] // Transform a path (if necessary) to acknowledge package boundaries // // e.g. something like -// async_safe/include/async_safe/CHECK.h +// +// async_safe/include/async_safe/CHECK.h +// // might become -// //bionic/libc/async_safe:include/async_safe/CHECK.h +// +// //bionic/libc/async_safe:include/async_safe/CHECK.h +// // if the "async_safe" directory is actually a package and not just a directory. // // In particular, paths that extend into packages are transformed into absolute labels beginning with //. @@ -303,20 +307,21 @@ func RootToModuleRelativePaths(ctx BazelConversionPathContext, paths Paths) []ba // directory and Bazel target labels, excluding those included in the excludes argument (which // should already be expanded to resolve references to Soong-modules). Valid elements of paths // include: -// * filepath, relative to local module directory, resolves as a filepath relative to the local -// source directory -// * glob, relative to the local module directory, resolves as filepath(s), relative to the local -// module directory. Because Soong does not have a concept of crossing package boundaries, the -// glob as computed by Soong may contain paths that cross package-boundaries that would be -// unknowingly omitted if the glob were handled by Bazel. To allow identification and detect -// (within Bazel) use of paths that cross package boundaries, we expand globs within Soong rather -// than converting Soong glob syntax to Bazel glob syntax. **Invalid for excludes.** -// * other modules using the ":name{.tag}" syntax. These modules must implement SourceFileProducer -// or OutputFileProducer. These resolve as a Bazel label for a target. If the Bazel target is in -// the local module directory, it will be returned relative to the current package (e.g. -// ":"). Otherwise, it will be returned as an absolute Bazel label (e.g. -// "//path/to/dir:"). If the reference to another module cannot be resolved,the function -// will panic. +// - filepath, relative to local module directory, resolves as a filepath relative to the local +// source directory +// - glob, relative to the local module directory, resolves as filepath(s), relative to the local +// module directory. Because Soong does not have a concept of crossing package boundaries, the +// glob as computed by Soong may contain paths that cross package-boundaries that would be +// unknowingly omitted if the glob were handled by Bazel. To allow identification and detect +// (within Bazel) use of paths that cross package boundaries, we expand globs within Soong rather +// than converting Soong glob syntax to Bazel glob syntax. **Invalid for excludes.** +// - other modules using the ":name{.tag}" syntax. These modules must implement SourceFileProducer +// or OutputFileProducer. These resolve as a Bazel label for a target. If the Bazel target is in +// the local module directory, it will be returned relative to the current package (e.g. +// ":"). Otherwise, it will be returned as an absolute Bazel label (e.g. +// "//path/to/dir:"). If the reference to another module cannot be resolved,the function +// will panic. +// // Properties passed as the paths or excludes argument must have been annotated with struct tag // `android:"path"` so that dependencies on other modules will have already been handled by the // path_deps mutator. diff --git a/android/bazel_test.go b/android/bazel_test.go index 482df2abd..87bd18e0a 100644 --- a/android/bazel_test.go +++ b/android/bazel_test.go @@ -4,7 +4,7 @@ // 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 +// 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, diff --git a/android/config_bp2build.go b/android/config_bp2build.go index 748be62cc..d6b2bcf97 100644 --- a/android/config_bp2build.go +++ b/android/config_bp2build.go @@ -240,10 +240,12 @@ func (m ExportedStringListDictVariables) asBazel(_ Config, _ ExportedStringVaria // ExportedVariableReferenceDictVariables is a mapping from variable names to a // dictionary which references previously defined variables. This is used to // create a Starlark output such as: -// string_var1 = "string1 -// var_ref_dict_var1 = { -// "key1": string_var1 -// } +// +// string_var1 = "string1 +// var_ref_dict_var1 = { +// "key1": string_var1 +// } +// // This type of variable collection must be expanded last so that it recognizes // previously defined variables. type ExportedVariableReferenceDictVariables map[string]map[string]string diff --git a/android/defaults.go b/android/defaults.go index 54f44bcec..03b2efbac 100644 --- a/android/defaults.go +++ b/android/defaults.go @@ -151,12 +151,12 @@ type DefaultsModuleBase struct { // retrieve the values it is necessary to iterate over properties(). E.g. to get // the commonProperties instance that have the real values: // -// d := myModule.(Defaults) -// for _, props := range d.properties() { -// if cp, ok := props.(*commonProperties); ok { -// ... access property values in cp ... -// } -// } +// d := myModule.(Defaults) +// for _, props := range d.properties() { +// if cp, ok := props.(*commonProperties); ok { +// ... access property values in cp ... +// } +// } // // The rationale is that the properties on a defaults module apply to the // defaultable modules using it, not to the defaults module itself. E.g. setting diff --git a/android/fixture.go b/android/fixture.go index 728f0318f..9cb26d69e 100644 --- a/android/fixture.go +++ b/android/fixture.go @@ -420,11 +420,13 @@ type FixturePreparer interface { // instances. // // base - a list of already flattened and deduped preparers that will be applied first before -// the list of additional preparers. Any duplicates of these in the additional preparers -// will be ignored. +// +// the list of additional preparers. Any duplicates of these in the additional preparers +// will be ignored. // // preparers - a list of additional unflattened, undeduped preparers that will be applied after the -// base preparers. +// +// base preparers. // // Returns a deduped and flattened list of the preparers starting with the ones in base with any // additional ones from the preparers list added afterwards. @@ -498,10 +500,10 @@ func newSimpleFixturePreparer(preparer func(fixture *fixture)) FixturePreparer { // FixtureErrorHandler determines how to respond to errors reported by the code under test. // // Some possible responses: -// * Fail the test if any errors are reported, see FixtureExpectsNoErrors. -// * Fail the test if at least one error that matches a pattern is not reported see -// FixtureExpectsAtLeastOneErrorMatchingPattern -// * Fail the test if any unexpected errors are reported. +// - Fail the test if any errors are reported, see FixtureExpectsNoErrors. +// - Fail the test if at least one error that matches a pattern is not reported see +// FixtureExpectsAtLeastOneErrorMatchingPattern +// - Fail the test if any unexpected errors are reported. // // Although at the moment all the error handlers are implemented as simply a wrapper around a // function this is defined as an interface to allow future enhancements, e.g. provide different @@ -854,10 +856,12 @@ func (r *TestResult) NormalizePathsForTesting(paths Paths) []string { // that produced this result. // // e.g. assuming that this result was created by running: -// GroupFixturePreparers(preparer1, preparer2, preparer3).RunTest(t) +// +// GroupFixturePreparers(preparer1, preparer2, preparer3).RunTest(t) // // Then this method will be equivalent to running: -// GroupFixturePreparers(preparer1, preparer2, preparer3) +// +// GroupFixturePreparers(preparer1, preparer2, preparer3) // // This is intended for use by tests whose output is Android.bp files to verify that those files // are valid, e.g. tests of the snapshots produced by the sdk module type. diff --git a/android/module.go b/android/module.go index 6f27f79a7..118ce5038 100644 --- a/android/module.go +++ b/android/module.go @@ -1113,7 +1113,7 @@ func InitAndroidModule(m Module) { // property structs for architecture-specific versions of generic properties tagged with // `android:"arch_variant"`. // -// InitAndroidModule should not be called if InitAndroidArchModule was called. +// InitAndroidModule should not be called if InitAndroidArchModule was called. func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) { InitAndroidModule(m) diff --git a/android/paths.go b/android/paths.go index e7829b961..c3ef7548a 100644 --- a/android/paths.go +++ b/android/paths.go @@ -387,20 +387,21 @@ func ExistentPathsForSources(ctx PathContext, paths []string) Paths { } // PathsForModuleSrc returns a Paths{} containing the resolved references in paths: -// * filepath, relative to local module directory, resolves as a filepath relative to the local -// source directory -// * glob, relative to the local module directory, resolves as filepath(s), relative to the local -// source directory. -// * other modules using the ":name{.tag}" syntax. These modules must implement SourceFileProducer -// or OutputFileProducer. These resolve as a filepath to an output filepath or generated source -// filepath. +// - filepath, relative to local module directory, resolves as a filepath relative to the local +// source directory +// - glob, relative to the local module directory, resolves as filepath(s), relative to the local +// source directory. +// - other modules using the ":name{.tag}" syntax. These modules must implement SourceFileProducer +// or OutputFileProducer. These resolve as a filepath to an output filepath or generated source +// filepath. +// // Properties passed as the paths argument must have been annotated with struct tag // `android:"path"` so that dependencies on SourceFileProducer modules will have already been handled by the // path_deps mutator. // If a requested module is not found as a dependency: -// * if ctx.Config().AllowMissingDependencies() is true, this module to be marked as having +// - if ctx.Config().AllowMissingDependencies() is true, this module to be marked as having // missing dependencies -// * otherwise, a ModuleError is thrown. +// - otherwise, a ModuleError is thrown. func PathsForModuleSrc(ctx ModuleMissingDepsPathContext, paths []string) Paths { return PathsForModuleSrcExcludes(ctx, paths, nil) } @@ -414,21 +415,22 @@ type SourceInput struct { // PathsForModuleSrcExcludes returns a Paths{} containing the resolved references in paths, minus // those listed in excludes. Elements of paths and excludes are resolved as: -// * filepath, relative to local module directory, resolves as a filepath relative to the local -// source directory -// * glob, relative to the local module directory, resolves as filepath(s), relative to the local -// source directory. Not valid in excludes. -// * other modules using the ":name{.tag}" syntax. These modules must implement SourceFileProducer -// or OutputFileProducer. These resolve as a filepath to an output filepath or generated source -// filepath. +// - filepath, relative to local module directory, resolves as a filepath relative to the local +// source directory +// - glob, relative to the local module directory, resolves as filepath(s), relative to the local +// source directory. Not valid in excludes. +// - other modules using the ":name{.tag}" syntax. These modules must implement SourceFileProducer +// or OutputFileProducer. These resolve as a filepath to an output filepath or generated source +// filepath. +// // excluding the items (similarly resolved // Properties passed as the paths argument must have been annotated with struct tag // `android:"path"` so that dependencies on SourceFileProducer modules will have already been handled by the // path_deps mutator. // If a requested module is not found as a dependency: -// * if ctx.Config().AllowMissingDependencies() is true, this module to be marked as having +// - if ctx.Config().AllowMissingDependencies() is true, this module to be marked as having // missing dependencies -// * otherwise, a ModuleError is thrown. +// - otherwise, a ModuleError is thrown. func PathsForModuleSrcExcludes(ctx ModuleMissingDepsPathContext, paths, excludes []string) Paths { return PathsRelativeToModuleSourceDir(SourceInput{ Context: ctx, @@ -548,13 +550,14 @@ func GetModuleFromPathDep(ctx ModuleWithDepsPathContext, moduleName, tag string) // PathsAndMissingDepsForModuleSrcExcludes returns a Paths{} containing the resolved references in // paths, minus those listed in excludes. Elements of paths and excludes are resolved as: -// * filepath, relative to local module directory, resolves as a filepath relative to the local -// source directory -// * glob, relative to the local module directory, resolves as filepath(s), relative to the local -// source directory. Not valid in excludes. -// * other modules using the ":name{.tag}" syntax. These modules must implement SourceFileProducer -// or OutputFileProducer. These resolve as a filepath to an output filepath or generated source -// filepath. +// - filepath, relative to local module directory, resolves as a filepath relative to the local +// source directory +// - glob, relative to the local module directory, resolves as filepath(s), relative to the local +// source directory. Not valid in excludes. +// - other modules using the ":name{.tag}" syntax. These modules must implement SourceFileProducer +// or OutputFileProducer. These resolve as a filepath to an output filepath or generated source +// filepath. +// // and a list of the module names of missing module dependencies are returned as the second return. // Properties passed as the paths argument must have been annotated with struct tag // `android:"path"` so that dependencies on SourceFileProducer modules will have already been handled by the diff --git a/android/register.go b/android/register.go index c50583322..c8715b1a1 100644 --- a/android/register.go +++ b/android/register.go @@ -257,20 +257,20 @@ type RegistrationContext interface { // Used to register build components from an init() method, e.g. // -// init() { -// RegisterBuildComponents(android.InitRegistrationContext) -// } +// init() { +// RegisterBuildComponents(android.InitRegistrationContext) +// } // -// func RegisterBuildComponents(ctx android.RegistrationContext) { -// ctx.RegisterModuleType(...) -// ... -// } +// func RegisterBuildComponents(ctx android.RegistrationContext) { +// ctx.RegisterModuleType(...) +// ... +// } // // Extracting the actual registration into a separate RegisterBuildComponents(ctx) function // allows it to be used to initialize test context, e.g. // -// ctx := android.NewTestContext(config) -// RegisterBuildComponents(ctx) +// ctx := android.NewTestContext(config) +// RegisterBuildComponents(ctx) var InitRegistrationContext RegistrationContext = &initRegistrationContext{ moduleTypes: make(map[string]ModuleFactory), singletonTypes: make(map[string]SingletonFactory), diff --git a/android/rule_builder.go b/android/rule_builder.go index 11da36cc0..155fbdf71 100644 --- a/android/rule_builder.go +++ b/android/rule_builder.go @@ -1031,7 +1031,8 @@ func (c *RuleBuilderCommand) ImplicitTools(paths Paths) *RuleBuilderCommand { // be also added to the dependencies returned by RuleBuilder.Tools. // // It is equivalent to: -// cmd.Tool(ctx.Config().HostToolPath(ctx, tool)) +// +// cmd.Tool(ctx.Config().HostToolPath(ctx, tool)) func (c *RuleBuilderCommand) BuiltTool(tool string) *RuleBuilderCommand { if c.rule.ctx.Config().UseHostMusl() { // If the host is using musl, assume that the tool was built against musl libc and include @@ -1053,7 +1054,8 @@ func (c *RuleBuilderCommand) builtToolWithoutDeps(tool string) *RuleBuilderComma // dependencies returned by RuleBuilder.Tools. // // It is equivalent to: -// cmd.Tool(ctx.Config().PrebuiltBuildTool(ctx, tool)) +// +// cmd.Tool(ctx.Config().PrebuiltBuildTool(ctx, tool)) func (c *RuleBuilderCommand) PrebuiltBuildTool(ctx PathContext, tool string) *RuleBuilderCommand { return c.Tool(ctx.Config().PrebuiltBuildTool(ctx, tool)) } diff --git a/android/sdk.go b/android/sdk.go index a71f7f211..a477cbaaf 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -430,13 +430,13 @@ func (r *sdkRegistry) uniqueOnceKey() OnceKey { // required for some members but not others. Traits can cause additional information to be output // to the sdk snapshot or replace the default information exported for a member with something else. // e.g. -// * By default cc libraries only export the default image variants to the SDK. However, for some -// members it may be necessary to export specific image variants, e.g. vendor, or recovery. -// * By default cc libraries export all the configured architecture variants except for the native -// bridge architecture variants. However, for some members it may be necessary to export the -// native bridge architecture variants as well. -// * By default cc libraries export the platform variant (i.e. sdk:). However, for some members it -// may be necessary to export the sdk variant (i.e. sdk:sdk). +// - By default cc libraries only export the default image variants to the SDK. However, for some +// members it may be necessary to export specific image variants, e.g. vendor, or recovery. +// - By default cc libraries export all the configured architecture variants except for the native +// bridge architecture variants. However, for some members it may be necessary to export the +// native bridge architecture variants as well. +// - By default cc libraries export the platform variant (i.e. sdk:). However, for some members it +// may be necessary to export the sdk variant (i.e. sdk:sdk). // // A sdk can request a module to provide no traits, one trait or a collection of traits. The exact // behavior of a trait is determined by how SdkMemberType implementations handle the traits. A trait @@ -447,17 +447,17 @@ func (r *sdkRegistry) uniqueOnceKey() OnceKey { // SdkPropertyName(). Each property contains a list of modules that are required to have that trait. // e.g. something like this: // -// sdk { -// name: "sdk", -// ... -// traits: { -// recovery_image: ["module1", "module4", "module5"], -// native_bridge: ["module1", "module2"], -// native_sdk: ["module1", "module3"], -// ... -// }, -// ... -// } +// sdk { +// name: "sdk", +// ... +// traits: { +// recovery_image: ["module1", "module4", "module5"], +// native_bridge: ["module1", "module2"], +// native_sdk: ["module1", "module3"], +// ... +// }, +// ... +// } type SdkMemberTrait interface { // SdkPropertyName returns the name of the traits property on an sdk module. SdkPropertyName() string @@ -639,20 +639,19 @@ func DependencyTagForSdkMemberType(memberType SdkMemberType, export bool) SdkMem // The basic implementation should look something like this, where ModuleType is // the name of the module type being supported. // -// type moduleTypeSdkMemberType struct { -// android.SdkMemberTypeBase -// } +// type moduleTypeSdkMemberType struct { +// android.SdkMemberTypeBase +// } // -// func init() { -// android.RegisterSdkMemberType(&moduleTypeSdkMemberType{ -// SdkMemberTypeBase: android.SdkMemberTypeBase{ -// PropertyName: "module_types", -// }, -// } -// } -// -// ...methods... +// func init() { +// android.RegisterSdkMemberType(&moduleTypeSdkMemberType{ +// SdkMemberTypeBase: android.SdkMemberTypeBase{ +// PropertyName: "module_types", +// }, +// } +// } // +// ...methods... type SdkMemberType interface { // SdkPropertyName returns the name of the member type property on an sdk module. SdkPropertyName() string diff --git a/android/soong_config_modules.go b/android/soong_config_modules.go index bd7364582..b25f24891 100644 --- a/android/soong_config_modules.go +++ b/android/soong_config_modules.go @@ -190,77 +190,78 @@ type soongConfigModuleTypeModule struct { // // Each soong_config_variable supports an additional value `conditions_default`. The properties // specified in `conditions_default` will only be used under the following conditions: -// bool variable: the variable is unspecified or not set to a true value -// value variable: the variable is unspecified -// string variable: the variable is unspecified or the variable is set to a string unused in the -// given module. For example, string variable `test` takes values: "a" and "b", -// if the module contains a property `a` and `conditions_default`, when test=b, -// the properties under `conditions_default` will be used. To specify that no -// properties should be amended for `b`, you can set `b: {},`. +// +// bool variable: the variable is unspecified or not set to a true value +// value variable: the variable is unspecified +// string variable: the variable is unspecified or the variable is set to a string unused in the +// given module. For example, string variable `test` takes values: "a" and "b", +// if the module contains a property `a` and `conditions_default`, when test=b, +// the properties under `conditions_default` will be used. To specify that no +// properties should be amended for `b`, you can set `b: {},`. // // For example, an Android.bp file could have: // -// soong_config_module_type { -// name: "acme_cc_defaults", -// module_type: "cc_defaults", -// config_namespace: "acme", -// variables: ["board"], -// bool_variables: ["feature"], -// value_variables: ["width"], -// properties: ["cflags", "srcs"], -// } +// soong_config_module_type { +// name: "acme_cc_defaults", +// module_type: "cc_defaults", +// config_namespace: "acme", +// variables: ["board"], +// bool_variables: ["feature"], +// value_variables: ["width"], +// properties: ["cflags", "srcs"], +// } // -// soong_config_string_variable { -// name: "board", -// values: ["soc_a", "soc_b"], -// } +// soong_config_string_variable { +// name: "board", +// values: ["soc_a", "soc_b"], +// } // -// acme_cc_defaults { -// name: "acme_defaults", -// cflags: ["-DGENERIC"], -// soong_config_variables: { -// board: { -// soc_a: { -// cflags: ["-DSOC_A"], -// }, -// soc_b: { -// cflags: ["-DSOC_B"], -// }, -// conditions_default: { -// cflags: ["-DSOC_DEFAULT"], -// }, -// }, -// feature: { -// cflags: ["-DFEATURE"], -// conditions_default: { -// cflags: ["-DFEATURE_DEFAULT"], -// }, -// }, -// width: { -// cflags: ["-DWIDTH=%s"], -// conditions_default: { -// cflags: ["-DWIDTH=DEFAULT"], -// }, -// }, -// }, -// } +// acme_cc_defaults { +// name: "acme_defaults", +// cflags: ["-DGENERIC"], +// soong_config_variables: { +// board: { +// soc_a: { +// cflags: ["-DSOC_A"], +// }, +// soc_b: { +// cflags: ["-DSOC_B"], +// }, +// conditions_default: { +// cflags: ["-DSOC_DEFAULT"], +// }, +// }, +// feature: { +// cflags: ["-DFEATURE"], +// conditions_default: { +// cflags: ["-DFEATURE_DEFAULT"], +// }, +// }, +// width: { +// cflags: ["-DWIDTH=%s"], +// conditions_default: { +// cflags: ["-DWIDTH=DEFAULT"], +// }, +// }, +// }, +// } // -// cc_library { -// name: "libacme_foo", -// defaults: ["acme_defaults"], -// srcs: ["*.cpp"], -// } +// cc_library { +// name: "libacme_foo", +// defaults: ["acme_defaults"], +// srcs: ["*.cpp"], +// } // // If an acme BoardConfig.mk file contained: // -// SOONG_CONFIG_NAMESPACES += acme -// SOONG_CONFIG_acme += \ -// board \ -// feature \ +// SOONG_CONFIG_NAMESPACES += acme +// SOONG_CONFIG_acme += \ +// board \ +// feature \ // -// SOONG_CONFIG_acme_board := soc_a -// SOONG_CONFIG_acme_feature := true -// SOONG_CONFIG_acme_width := 200 +// SOONG_CONFIG_acme_board := soc_a +// SOONG_CONFIG_acme_feature := true +// SOONG_CONFIG_acme_width := 200 // // Then libacme_foo would build with cflags "-DGENERIC -DSOC_A -DFEATURE". func SoongConfigModuleTypeFactory() Module { diff --git a/android/soongconfig/modules.go b/android/soongconfig/modules.go index 212b752d6..7d21b75bc 100644 --- a/android/soongconfig/modules.go +++ b/android/soongconfig/modules.go @@ -343,23 +343,26 @@ func (defs Bp2BuildSoongConfigDefinitions) String() string { // // For example, the acme_cc_defaults example above would // produce a reflect.Value whose type is: -// *struct { -// Soong_config_variables struct { -// Board struct { -// Soc_a interface{} -// Soc_b interface{} -// } -// } -// } +// +// *struct { +// Soong_config_variables struct { +// Board struct { +// Soc_a interface{} +// Soc_b interface{} +// } +// } +// } +// // And whose value is: -// &{ -// Soong_config_variables: { -// Board: { -// Soc_a: (*struct{ Cflags []string })(nil), -// Soc_b: (*struct{ Cflags []string })(nil), -// }, -// }, -// } +// +// &{ +// Soong_config_variables: { +// Board: { +// Soc_a: (*struct{ Cflags []string })(nil), +// Soc_b: (*struct{ Cflags []string })(nil), +// }, +// }, +// } func CreateProperties(factory blueprint.ModuleFactory, moduleType *ModuleType) reflect.Value { var fields []reflect.StructField diff --git a/android/testing.go b/android/testing.go index 85bdca475..b4429ca91 100644 --- a/android/testing.go +++ b/android/testing.go @@ -688,17 +688,17 @@ type TestingBuildParams struct { // // The parts of this structure which are changed are: // * BuildParams -// * Args -// * All Path, Paths, WritablePath and WritablePaths fields. +// - Args +// - All Path, Paths, WritablePath and WritablePaths fields. // // * RuleParams -// * Command -// * Depfile -// * Rspfile -// * RspfileContent -// * SymlinkOutputs -// * CommandDeps -// * CommandOrderOnly +// - Command +// - Depfile +// - Rspfile +// - RspfileContent +// - SymlinkOutputs +// - CommandDeps +// - CommandOrderOnly // // See PathRelativeToTop for more details. // diff --git a/android/variable.go b/android/variable.go index 373891ae4..d6a64d81a 100644 --- a/android/variable.go +++ b/android/variable.go @@ -694,20 +694,20 @@ func ProductVariableProperties(ctx BazelConversionPathContext) ProductConfigProp // // If the ProductConfigProperties map contains these items, as parsed from the .bp file: // -// library_linking_strategy: { -// prefer_static: { -// static_libs: [ -// "lib_a", -// "lib_b", -// ], -// }, -// conditions_default: { -// shared_libs: [ -// "lib_a", -// "lib_b", -// ], -// }, -// }, +// library_linking_strategy: { +// prefer_static: { +// static_libs: [ +// "lib_a", +// "lib_b", +// ], +// }, +// conditions_default: { +// shared_libs: [ +// "lib_a", +// "lib_b", +// ], +// }, +// }, // // Static_libs {Library_linking_strategy ANDROID prefer_static} [lib_a lib_b] // Shared_libs {Library_linking_strategy ANDROID conditions_default} [lib_a lib_b] @@ -720,13 +720,13 @@ func ProductVariableProperties(ctx BazelConversionPathContext) ProductConfigProp // instead of putting lib_a and lib_b directly into dynamic_deps without a // select: // -// dynamic_deps = select({ -// "//build/bazel/product_variables:android__library_linking_strategy__prefer_static": [], -// "//conditions:default": [ -// "//foo/bar:lib_a", -// "//foo/bar:lib_b", -// ], -// }), +// dynamic_deps = select({ +// "//build/bazel/product_variables:android__library_linking_strategy__prefer_static": [], +// "//conditions:default": [ +// "//foo/bar:lib_a", +// "//foo/bar:lib_b", +// ], +// }), func (props *ProductConfigProperties) zeroValuesForNamespacedVariables() { // A map of product config properties to the zero values of their respective // property value. diff --git a/androidmk/androidmk/androidmk.go b/androidmk/androidmk/androidmk.go index aaafdc758..2e8810fe8 100644 --- a/androidmk/androidmk/androidmk.go +++ b/androidmk/androidmk/androidmk.go @@ -421,9 +421,9 @@ func makeVariableToBlueprint(file *bpFile, val *mkparser.MakeString, // For example, if prefix is "foo" and name is "bar" with a value of "baz", then // the following variable will be generated: // -// foo { -// bar: "baz" -// } +// foo { +// bar: "baz" +// } // // If prefix is the empty string and name is "foo" with a value of "bar", the // following variable will be generated (if it is a property): diff --git a/androidmk/parser/make_strings.go b/androidmk/parser/make_strings.go index 803032649..9391117fb 100644 --- a/androidmk/parser/make_strings.go +++ b/androidmk/parser/make_strings.go @@ -38,10 +38,10 @@ import ( // For example, "$(FOO)/bar/baz" will be represented as the // following lists: // -// { -// Strings: ["", "/bar/baz"], -// Variables: ["FOO"] -// } +// { +// Strings: ["", "/bar/baz"], +// Variables: ["FOO"] +// } type MakeString struct { StringPos Pos Strings []string diff --git a/apex/key.go b/apex/key.go index 829410ed2..6090b65d6 100644 --- a/apex/key.go +++ b/apex/key.go @@ -105,7 +105,7 @@ func (m *apexKey) GenerateAndroidBuildActions(ctx android.ModuleContext) { m.keyName = pubKeyName } -//////////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////////// // apex_keys_text type apexKeysText struct { output android.OutputPath diff --git a/apex/prebuilt.go b/apex/prebuilt.go index 187e0df09..172a2012d 100644 --- a/apex/prebuilt.go +++ b/apex/prebuilt.go @@ -364,16 +364,16 @@ func (p *prebuiltCommon) DepIsInSameApex(ctx android.BaseModuleContext, dep andr // While it may be possible to provide sufficient information to determine whether two prebuilt_apex // modules were compatible it would be a lot of work and would not provide much benefit for a couple // of reasons: -// * The number of prebuilt_apex modules that will be exporting files for the same module will be -// low as the prebuilt_apex only exports files for the direct dependencies that require it and -// very few modules are direct dependencies of multiple prebuilt_apex modules, e.g. there are a -// few com.android.art* apex files that contain the same contents and could export files for the -// same modules but only one of them needs to do so. Contrast that with source apex modules which -// need apex specific variants for every module that contributes code to the apex, whether direct -// or indirect. -// * The build cost of a prebuilt_apex variant is generally low as at worst it will involve some -// extra copying of files. Contrast that with source apex modules that has to build each variant -// from source. +// - The number of prebuilt_apex modules that will be exporting files for the same module will be +// low as the prebuilt_apex only exports files for the direct dependencies that require it and +// very few modules are direct dependencies of multiple prebuilt_apex modules, e.g. there are a +// few com.android.art* apex files that contain the same contents and could export files for the +// same modules but only one of them needs to do so. Contrast that with source apex modules which +// need apex specific variants for every module that contributes code to the apex, whether direct +// or indirect. +// - The build cost of a prebuilt_apex variant is generally low as at worst it will involve some +// extra copying of files. Contrast that with source apex modules that has to build each variant +// from source. func (p *prebuiltCommon) apexInfoMutator(mctx android.TopDownMutatorContext) { // Collect direct dependencies into contents. @@ -703,28 +703,29 @@ var _ prebuiltApexModuleCreator = (*Prebuilt)(nil) // e.g. make dex implementation jars available for java_import modules listed in exported_java_libs, // it does so as follows: // -// 1. It creates a `deapexer` module that actually extracts the files from the `.apex` file and -// makes them available for use by other modules, at both Soong and ninja levels. +// 1. It creates a `deapexer` module that actually extracts the files from the `.apex` file and +// makes them available for use by other modules, at both Soong and ninja levels. // -// 2. It adds a dependency onto those modules and creates an apex specific variant similar to what -// an `apex` module does. That ensures that code which looks for specific apex variant, e.g. -// dexpreopt, will work the same way from source and prebuilt. +// 2. It adds a dependency onto those modules and creates an apex specific variant similar to what +// an `apex` module does. That ensures that code which looks for specific apex variant, e.g. +// dexpreopt, will work the same way from source and prebuilt. // -// 3. The `deapexer` module adds a dependency from the modules that require the exported files onto -// itself so that they can retrieve the file paths to those files. +// 3. The `deapexer` module adds a dependency from the modules that require the exported files onto +// itself so that they can retrieve the file paths to those files. // // It also creates a child module `selector` that is responsible for selecting the appropriate // input apex for both the prebuilt_apex and the deapexer. That is needed for a couple of reasons: -// 1. To dedup the selection logic so it only runs in one module. -// 2. To allow the deapexer to be wired up to a different source for the input apex, e.g. an -// `apex_set`. // -// prebuilt_apex -// / | \ -// / | \ -// V V V -// selector <--- deapexer <--- exported java lib +// 1. To dedup the selection logic so it only runs in one module. // +// 2. To allow the deapexer to be wired up to a different source for the input apex, e.g. an +// `apex_set`. +// +// prebuilt_apex +// / | \ +// / | \ +// V V V +// selector <--- deapexer <--- exported java lib func (p *Prebuilt) createPrebuiltApexModules(ctx android.TopDownMutatorContext) { baseModuleName := p.BaseModuleName() diff --git a/bazel/properties.go b/bazel/properties.go index f9560319e..a3555f87d 100644 --- a/bazel/properties.go +++ b/bazel/properties.go @@ -1071,15 +1071,18 @@ func (sla *StringListAttribute) SortedConfigurationAxes() []ConfigurationAxis { // DeduplicateAxesFromBase ensures no duplication of items between the no-configuration value and // configuration-specific values. For example, if we would convert this StringListAttribute as: -// ["a", "b", "c"] + select({ -// "//condition:one": ["a", "d"], -// "//conditions:default": [], -// }) +// +// ["a", "b", "c"] + select({ +// "//condition:one": ["a", "d"], +// "//conditions:default": [], +// }) +// // after this function, we would convert this StringListAttribute as: -// ["a", "b", "c"] + select({ -// "//condition:one": ["d"], -// "//conditions:default": [], -// }) +// +// ["a", "b", "c"] + select({ +// "//condition:one": ["d"], +// "//conditions:default": [], +// }) func (sla *StringListAttribute) DeduplicateAxesFromBase() { base := sla.Value for axis, configToList := range sla.ConfigurableValues { diff --git a/bp2build/cc_prebuilt_library_conversion_test.go b/bp2build/cc_prebuilt_library_conversion_test.go index 3cf896903..41dbe6a5a 100644 --- a/bp2build/cc_prebuilt_library_conversion_test.go +++ b/bp2build/cc_prebuilt_library_conversion_test.go @@ -4,7 +4,7 @@ // 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 +// 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, diff --git a/bp2build/cc_prebuilt_library_static_test.go b/bp2build/cc_prebuilt_library_static_test.go index 3feb1f155..b1a937840 100644 --- a/bp2build/cc_prebuilt_library_static_test.go +++ b/bp2build/cc_prebuilt_library_static_test.go @@ -4,7 +4,7 @@ // 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 +// 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, diff --git a/bpfix/bpfix/bpfix.go b/bpfix/bpfix/bpfix.go index 94b28dc50..ddaa98aa3 100644 --- a/bpfix/bpfix/bpfix.go +++ b/bpfix/bpfix/bpfix.go @@ -553,7 +553,9 @@ func indicateAttributeError(mod *parser.Module, attributeName string, format str // If a variable is LOCAL_MODULE, get its value from the 'name' attribute. // This handles the statement -// LOCAL_SRC_FILES := $(LOCAL_MODULE) +// +// LOCAL_SRC_FILES := $(LOCAL_MODULE) +// // which occurs often. func resolveLocalModule(mod *parser.Module, val parser.Expression) parser.Expression { if varLocalName, ok := val.(*parser.Variable); ok { @@ -567,9 +569,9 @@ func resolveLocalModule(mod *parser.Module, val parser.Expression) parser.Expres } // etcPrebuiltModuleUpdate contains information on updating certain parts of a defined module such as: -// * changing the module type from prebuilt_etc to a different one -// * stripping the prefix of the install path based on the module type -// * appending additional boolean properties to the prebuilt module +// - changing the module type from prebuilt_etc to a different one +// - stripping the prefix of the install path based on the module type +// - appending additional boolean properties to the prebuilt module type etcPrebuiltModuleUpdate struct { // The prefix of the install path defined in local_module_path. The prefix is removed from local_module_path // before setting the 'filename' attribute. diff --git a/cc/afdo.go b/cc/afdo.go index 66e973284..fb66bbe52 100644 --- a/cc/afdo.go +++ b/cc/afdo.go @@ -66,8 +66,9 @@ func (afdo *afdo) AfdoEnabled() bool { } // Get list of profile file names, ordered by level of specialisation. For example: -// 1. libfoo_arm64.afdo -// 2. libfoo.afdo +// 1. libfoo_arm64.afdo +// 2. libfoo.afdo +// // Add more specialisation as needed. func getProfileFiles(ctx android.BaseModuleContext, moduleName string) []string { var files []string diff --git a/cc/fuzz.go b/cc/fuzz.go index 23d81d600..1cbd5572b 100644 --- a/cc/fuzz.go +++ b/cc/fuzz.go @@ -93,10 +93,10 @@ func UnstrippedOutputFile(module android.Module) android.Path { // IsValidSharedDependency takes a module and determines if it is a unique shared library // that should be installed in the fuzz target output directories. This function // returns true, unless: -// - The module is not an installable shared library, or -// - The module is a header or stub, or -// - The module is a prebuilt and its source is available, or -// - The module is a versioned member of an SDK snapshot. +// - The module is not an installable shared library, or +// - The module is a header or stub, or +// - The module is a prebuilt and its source is available, or +// - The module is a versioned member of an SDK snapshot. func IsValidSharedDependency(dependency android.Module) bool { // TODO(b/144090547): We should be parsing these modules using // ModuleDependencyTag instead of the current brute-force checking. diff --git a/cc/genrule.go b/cc/genrule.go index 239064f1c..4ef990c35 100644 --- a/cc/genrule.go +++ b/cc/genrule.go @@ -41,13 +41,13 @@ type GenruleExtraProperties struct { // variations. The following environment variables will be set when the command // execute: // -// CC_ARCH the name of the architecture the command is being executed for +// CC_ARCH the name of the architecture the command is being executed for // -// CC_MULTILIB "lib32" if the architecture the command is being executed for is 32-bit, -// "lib64" if it is 64-bit. +// CC_MULTILIB "lib32" if the architecture the command is being executed for is 32-bit, +// "lib64" if it is 64-bit. // -// CC_NATIVE_BRIDGE the name of the subdirectory that native bridge libraries are stored in if -// the architecture has native bridge enabled, empty if it is disabled. +// CC_NATIVE_BRIDGE the name of the subdirectory that native bridge libraries are stored in if +// the architecture has native bridge enabled, empty if it is disabled. func GenRuleFactory() android.Module { module := genrule.NewGenRule() diff --git a/cc/image.go b/cc/image.go index 3a0857b21..cb7f3c927 100644 --- a/cc/image.go +++ b/cc/image.go @@ -4,7 +4,7 @@ // 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 +// 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, diff --git a/cc/ndk_headers.go b/cc/ndk_headers.go index 56fd5fc81..ef38a064a 100644 --- a/cc/ndk_headers.go +++ b/cc/ndk_headers.go @@ -148,12 +148,12 @@ func (m *headerModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { // to the sysroot base + "usr/include" + to directory + directory component. // ndk_headers requires the license file to be specified. Example: // -// Given: -// sysroot base = "ndk/sysroot" -// from = "include/foo" -// to = "bar" -// header = "include/foo/woodly/doodly.h" -// output path = "ndk/sysroot/usr/include/bar/woodly/doodly.h" +// Given: +// sysroot base = "ndk/sysroot" +// from = "include/foo" +// to = "bar" +// header = "include/foo/woodly/doodly.h" +// output path = "ndk/sysroot/usr/include/bar/woodly/doodly.h" func ndkHeadersFactory() android.Module { module := &headerModule{} module.AddProperties(&module.properties) @@ -275,15 +275,17 @@ func versionedNdkHeadersFactory() android.Module { return module } -// preprocessed_ndk_header { -// name: "foo", -// preprocessor: "foo.sh", -// srcs: [...], -// to: "android", -// } +// preprocessed_ndk_header { +// name: "foo", +// preprocessor: "foo.sh", +// srcs: [...], +// to: "android", +// } // // Will invoke the preprocessor as: -// $preprocessor -o $SYSROOT/usr/include/android/needs_preproc.h $src +// +// $preprocessor -o $SYSROOT/usr/include/android/needs_preproc.h $src +// // For each src in srcs. type preprocessedHeadersProperties struct { // The preprocessor to run. Must be a program inside the source directory diff --git a/cc/ndk_library.go b/cc/ndk_library.go index 5ef41eae5..241054058 100644 --- a/cc/ndk_library.go +++ b/cc/ndk_library.go @@ -84,12 +84,11 @@ var ( // // Example: // -// ndk_library { -// name: "libfoo", -// symbol_file: "libfoo.map.txt", -// first_version: "9", -// } -// +// ndk_library { +// name: "libfoo", +// symbol_file: "libfoo.map.txt", +// first_version: "9", +// } type libraryProperties struct { // Relative path to the symbol map. // An example file can be seen here: TODO(danalbert): Make an example. diff --git a/cc/prebuilt.go b/cc/prebuilt.go index f54c6f8d6..e0c28cefb 100644 --- a/cc/prebuilt.go +++ b/cc/prebuilt.go @@ -341,10 +341,10 @@ type bazelPrebuiltLibraryStaticAttributes struct { // TODO(b/228623543): The below is not entirely true until the bug is fixed. For now, both targets are always generated // Implements bp2build for cc_prebuilt_library modules. This will generate: -// * Only a prebuilt_library_static if the shared.enabled property is set to false across all variants. -// * Only a prebuilt_library_shared if the static.enabled property is set to false across all variants -// * Both a prebuilt_library_static and prebuilt_library_shared if the aforementioned properties are not false across -// all variants +// - Only a prebuilt_library_static if the shared.enabled property is set to false across all variants. +// - Only a prebuilt_library_shared if the static.enabled property is set to false across all variants +// - Both a prebuilt_library_static and prebuilt_library_shared if the aforementioned properties are not false across +// all variants // // In all cases, prebuilt_library_static target names will be appended with "_bp2build_cc_library_static". func prebuiltLibraryBp2Build(ctx android.TopDownMutatorContext, module *Module) { diff --git a/cc/snapshot_prebuilt.go b/cc/snapshot_prebuilt.go index 9d40ad058..792ffe364 100644 --- a/cc/snapshot_prebuilt.go +++ b/cc/snapshot_prebuilt.go @@ -4,7 +4,7 @@ // 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 +// 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, @@ -263,12 +263,12 @@ type BaseSnapshotDecoratorProperties struct { // version, snapshot arch, etc. It also adds a special suffix to Soong module name, so it doesn't // collide with source modules. e.g. the following example module, // -// vendor_snapshot_static { -// name: "libbase", -// arch: "arm64", -// version: 30, -// ... -// } +// vendor_snapshot_static { +// name: "libbase", +// arch: "arm64", +// version: 30, +// ... +// } // // will be seen as "libbase.vendor_static.30.arm64" by Soong. type BaseSnapshotDecorator struct { @@ -370,7 +370,6 @@ func vendorSnapshotLoadHook(ctx android.LoadHookContext, p *BaseSnapshotDecorato } } -// // Module definitions for snapshots of libraries (shared, static, header). // // Modules (vendor|recovery)_snapshot_(shared|static|header) are defined here. Shared libraries and @@ -630,7 +629,6 @@ func RecoverySnapshotHeaderFactory() android.Module { var _ snapshotSanitizer = (*snapshotLibraryDecorator)(nil) -// // Module definitions for snapshots of executable binaries. // // Modules (vendor|recovery)_snapshot_binary are defined here. They have their prebuilt executable @@ -728,7 +726,6 @@ func snapshotBinaryFactory(image SnapshotImage, moduleSuffix string) android.Mod return module.Init() } -// // Module definitions for snapshots of object files (*.o). // // Modules (vendor|recovery)_snapshot_object are defined here. They have their prebuilt object diff --git a/cc/snapshot_utils.go b/cc/snapshot_utils.go index de50ef50f..cf4617da3 100644 --- a/cc/snapshot_utils.go +++ b/cc/snapshot_utils.go @@ -4,7 +4,7 @@ // 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 +// 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, diff --git a/cc/vendor_public_library.go b/cc/vendor_public_library.go index 65a2b0c9e..f2c8545bc 100644 --- a/cc/vendor_public_library.go +++ b/cc/vendor_public_library.go @@ -28,17 +28,16 @@ var ( // // Example: // -// vendor_public_library { -// name: "libfoo", -// symbol_file: "libfoo.map.txt", -// export_public_headers: ["libfoo_headers"], -// } -// -// cc_headers { -// name: "libfoo_headers", -// export_include_dirs: ["include"], -// } +// vendor_public_library { +// name: "libfoo", +// symbol_file: "libfoo.map.txt", +// export_public_headers: ["libfoo_headers"], +// } // +// cc_headers { +// name: "libfoo_headers", +// export_include_dirs: ["include"], +// } type vendorPublicLibraryProperties struct { // Relative path to the symbol map. Symbol_file *string diff --git a/cc/vendor_snapshot.go b/cc/vendor_snapshot.go index e7c05aca8..77e6f6ffe 100644 --- a/cc/vendor_snapshot.go +++ b/cc/vendor_snapshot.go @@ -4,7 +4,7 @@ // 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 +// 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, diff --git a/cc/vndk_prebuilt.go b/cc/vndk_prebuilt.go index 31b6d10dd..37819a4be 100644 --- a/cc/vndk_prebuilt.go +++ b/cc/vndk_prebuilt.go @@ -29,26 +29,25 @@ var ( // // Example: // -// vndk_prebuilt_shared { -// name: "libfoo", -// version: "27", -// target_arch: "arm64", -// vendor_available: true, -// product_available: true, -// vndk: { -// enabled: true, -// }, -// export_include_dirs: ["include/external/libfoo/vndk_include"], -// arch: { -// arm64: { -// srcs: ["arm/lib64/libfoo.so"], -// }, -// arm: { -// srcs: ["arm/lib/libfoo.so"], -// }, -// }, -// } -// +// vndk_prebuilt_shared { +// name: "libfoo", +// version: "27", +// target_arch: "arm64", +// vendor_available: true, +// product_available: true, +// vndk: { +// enabled: true, +// }, +// export_include_dirs: ["include/external/libfoo/vndk_include"], +// arch: { +// arm64: { +// srcs: ["arm/lib64/libfoo.so"], +// }, +// arm: { +// srcs: ["arm/lib/libfoo.so"], +// }, +// }, +// } type vndkPrebuiltProperties struct { // VNDK snapshot version. Version *string @@ -250,25 +249,25 @@ func vndkPrebuiltSharedLibrary() *Module { // vndk_prebuilt_shared installs Vendor Native Development kit (VNDK) snapshot // shared libraries for system build. Example: // -// vndk_prebuilt_shared { -// name: "libfoo", -// version: "27", -// target_arch: "arm64", -// vendor_available: true, -// product_available: true, -// vndk: { -// enabled: true, -// }, -// export_include_dirs: ["include/external/libfoo/vndk_include"], -// arch: { -// arm64: { -// srcs: ["arm/lib64/libfoo.so"], -// }, -// arm: { -// srcs: ["arm/lib/libfoo.so"], -// }, -// }, -// } +// vndk_prebuilt_shared { +// name: "libfoo", +// version: "27", +// target_arch: "arm64", +// vendor_available: true, +// product_available: true, +// vndk: { +// enabled: true, +// }, +// export_include_dirs: ["include/external/libfoo/vndk_include"], +// arch: { +// arm64: { +// srcs: ["arm/lib64/libfoo.so"], +// }, +// arm: { +// srcs: ["arm/lib/libfoo.so"], +// }, +// }, +// } func VndkPrebuiltSharedFactory() android.Module { module := vndkPrebuiltSharedLibrary() return module.Init() diff --git a/cmd/sbox/sbox.go b/cmd/sbox/sbox.go index 4f7451d0c..91e3540dd 100644 --- a/cmd/sbox/sbox.go +++ b/cmd/sbox/sbox.go @@ -208,7 +208,6 @@ func run() error { // // returns an exec.Cmd that can be ran from within sbox context if no error, or nil if error. // caller must ensure script is cleaned up if function succeeds. -// func createCommandScript(rawCommand, scriptPath, scriptPathInSandbox string) (*exec.Cmd, error) { err := os.WriteFile(scriptPath, []byte(rawCommand), 0644) if err != nil { diff --git a/dexpreopt/class_loader_context.go b/dexpreopt/class_loader_context.go index 36513b64b..6000cf4be 100644 --- a/dexpreopt/class_loader_context.go +++ b/dexpreopt/class_loader_context.go @@ -25,11 +25,11 @@ import ( ) // This comment describes the following: -// 1. the concept of class loader context (CLC) and its relation to classpath -// 2. how PackageManager constructs CLC from shared libraries and their dependencies -// 3. build-time vs. run-time CLC and why this matters for dexpreopt -// 4. manifest fixer: a tool that adds missing tags to the manifests -// 5. build system support for CLC +// 1. the concept of class loader context (CLC) and its relation to classpath +// 2. how PackageManager constructs CLC from shared libraries and their dependencies +// 3. build-time vs. run-time CLC and why this matters for dexpreopt +// 4. manifest fixer: a tool that adds missing tags to the manifests +// 5. build system support for CLC // // 1. Class loader context // ----------------------- @@ -59,15 +59,16 @@ import ( // loaders are not duplicated (at runtime there is a single class loader instance for each library). // // Example: A has tags B, C and D; C has B and D; -// D has E; B and E have no dependencies. The CLC is: -// A -// ├── B -// ├── C -// │ ├── B -// │ └── D -// │ └── E -// └── D -// └── E +// +// D has E; B and E have no dependencies. The CLC is: +// A +// ├── B +// ├── C +// │ ├── B +// │ └── D +// │ └── E +// └── D +// └── E // // CLC defines the lookup order of libraries when resolving Java classes used by the library/app. // The lookup order is important because libraries may contain duplicate classes, and the class is @@ -188,7 +189,6 @@ import ( // rule generation phase. // // ClassLoaderContext is a structure that represents CLC. -// type ClassLoaderContext struct { // The name of the library. Name string @@ -253,7 +253,6 @@ func (c *ClassLoaderContext) excludeLibs(excludedLibs []string) (*ClassLoaderCon // generates a build rule that includes conditional CLC for all versions, extracts the target SDK // version from the manifest, and filters the CLCs based on that version. Exact final CLC that is // passed to dex2oat is unknown to the build system, and gets known only at Ninja stage. -// type ClassLoaderContextMap map[int][]*ClassLoaderContext // Compatibility libraries. Some are optional, and some are required: this is the default that @@ -502,7 +501,6 @@ func (clcMap ClassLoaderContextMap) ExcludeLibs(excludedLibs []string) ClassLoad // constructs class loader context on device. // // TODO(b/132357300): remove "android.hidl.manager" and "android.hidl.base" for non-system apps. -// func fixClassLoaderContext(clcMap ClassLoaderContextMap) { required, optional := clcMap.UsesLibs() usesLibs := append(required, optional...) diff --git a/etc/snapshot_etc.go b/etc/snapshot_etc.go index b54a8a6ec..0d65ab6b6 100644 --- a/etc/snapshot_etc.go +++ b/etc/snapshot_etc.go @@ -4,7 +4,7 @@ // 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 +// 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, diff --git a/finder/finder.go b/finder/finder.go index b4834b16b..596129088 100644 --- a/finder/finder.go +++ b/finder/finder.go @@ -732,15 +732,15 @@ func (f *Finder) parseCacheEntry(bytes []byte) ([]dirFullInfo, error) { // because we know this separator won't appear in the json that we're parsing. // // The newline byte can only appear in a UTF-8 stream if the newline character appears, because: -// - The newline character is encoded as "0000 1010" in binary ("0a" in hex) -// - UTF-8 dictates that bytes beginning with a "0" bit are never emitted as part of a multibyte -// character. +// - The newline character is encoded as "0000 1010" in binary ("0a" in hex) +// - UTF-8 dictates that bytes beginning with a "0" bit are never emitted as part of a multibyte +// character. // // We know that the newline character will never appear in our json string, because: -// - If a newline character appears as part of a data string, then json encoding will -// emit two characters instead: '\' and 'n'. -// - The json encoder that we use doesn't emit the optional newlines between any of its -// other outputs. +// - If a newline character appears as part of a data string, then json encoding will +// emit two characters instead: '\' and 'n'. +// - The json encoder that we use doesn't emit the optional newlines between any of its +// other outputs. const lineSeparator = byte('\n') func (f *Finder) readLine(reader *bufio.Reader) ([]byte, error) { diff --git a/genrule/genrule.go b/genrule/genrule.go index c52ddee53..d54274346 100644 --- a/genrule/genrule.go +++ b/genrule/genrule.go @@ -912,9 +912,7 @@ func (m *Module) ConvertWithBp2build(ctx android.TopDownMutatorContext) { var Bool = proptools.Bool var String = proptools.String -// // Defaults -// type Defaults struct { android.ModuleBase android.DefaultsModuleBase diff --git a/java/app_import.go b/java/app_import.go index 58c01a447..52e37b053 100644 --- a/java/app_import.go +++ b/java/app_import.go @@ -461,19 +461,19 @@ func createVariantGroupType(variants []string, variantGroupName string) reflect. // android_app_import imports a prebuilt apk with additional processing specified in the module. // DPI-specific apk source files can be specified using dpi_variants. Example: // -// android_app_import { -// name: "example_import", -// apk: "prebuilts/example.apk", -// dpi_variants: { -// mdpi: { -// apk: "prebuilts/example_mdpi.apk", -// }, -// xhdpi: { -// apk: "prebuilts/example_xhdpi.apk", -// }, -// }, -// presigned: true, -// } +// android_app_import { +// name: "example_import", +// apk: "prebuilts/example.apk", +// dpi_variants: { +// mdpi: { +// apk: "prebuilts/example_mdpi.apk", +// }, +// xhdpi: { +// apk: "prebuilts/example_xhdpi.apk", +// }, +// }, +// presigned: true, +// } func AndroidAppImportFactory() android.Module { module := &AndroidAppImport{} module.AddProperties(&module.properties) diff --git a/java/classpath_element.go b/java/classpath_element.go index 753e7f888..496291678 100644 --- a/java/classpath_element.go +++ b/java/classpath_element.go @@ -97,11 +97,11 @@ type ClasspathElementContext interface { // the list with its Contents field. // // Requirements/Assumptions: -// * A fragment can be associated with more than one apex but each apex must only be associated with -// a single fragment from the fragments list. -// * All of a fragment's contents must appear as a contiguous block in the same order in the -// libraries list. -// * Each library must only appear in a single fragment. +// - A fragment can be associated with more than one apex but each apex must only be associated with +// a single fragment from the fragments list. +// - All of a fragment's contents must appear as a contiguous block in the same order in the +// libraries list. +// - Each library must only appear in a single fragment. // // The apex is used to identify which libraries belong to which fragment. First a mapping is created // from apex to fragment. Then the libraries are iterated over and any library in an apex is @@ -109,13 +109,15 @@ type ClasspathElementContext interface { // standalone and have their own element. // // e.g. Given the following input: -// libraries: com.android.art:core-oj, com.android.art:core-libart, framework, ext -// fragments: com.android.art:art-bootclasspath-fragment +// +// libraries: com.android.art:core-oj, com.android.art:core-libart, framework, ext +// fragments: com.android.art:art-bootclasspath-fragment // // Then this will return: -// ClasspathFragmentElement(art-bootclasspath-fragment, [core-oj, core-libart]), -// ClasspathLibraryElement(framework), -// ClasspathLibraryElement(ext), +// +// ClasspathFragmentElement(art-bootclasspath-fragment, [core-oj, core-libart]), +// ClasspathLibraryElement(framework), +// ClasspathLibraryElement(ext), func CreateClasspathElements(ctx ClasspathElementContext, libraries []android.Module, fragments []android.Module) ClasspathElements { // Create a map from apex name to the fragment module. This makes it easy to find the fragment // associated with a particular apex. diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go index 3d91aec91..2d6ee758c 100644 --- a/java/dexpreopt_bootjars.go +++ b/java/dexpreopt_bootjars.go @@ -424,7 +424,6 @@ func (image *bootImageConfig) shouldInstallInApex() bool { // // The location is passed as an argument to the ART tools like dex2oat instead of the real path. // ART tools will then reconstruct the architecture-specific real path. -// func (image *bootImageVariant) imageLocations() (imageLocationsOnHost []string, imageLocationsOnDevice []string) { if image.extends != nil { imageLocationsOnHost, imageLocationsOnDevice = image.extends.getVariant(image.target).imageLocations() diff --git a/java/droiddoc.go b/java/droiddoc.go index 023d61912..c1182652f 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -158,9 +158,7 @@ type DroiddocProperties struct { Compat_config *string `android:"path"` } -// // Common flags passed down to build rule -// type droiddocBuilderFlags struct { bootClasspathArgs string classpathArgs string @@ -193,9 +191,7 @@ func apiCheckEnabled(ctx android.ModuleContext, apiToCheck ApiToCheck, apiVersio return false } -// // Javadoc -// type Javadoc struct { android.ModuleBase android.DefaultableModuleBase @@ -544,9 +540,7 @@ func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) { rule.Build("javadoc", "javadoc") } -// // Droiddoc -// type Droiddoc struct { Javadoc @@ -823,9 +817,7 @@ func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) { rule.Build("javadoc", desc) } -// // Exported Droiddoc Directory -// var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"} type ExportedDroiddocDirProperties struct { @@ -858,9 +850,7 @@ func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleCont d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")}) } -// // Defaults -// type DocDefaults struct { android.ModuleBase android.DefaultsModuleBase diff --git a/java/droidstubs.go b/java/droidstubs.go index d705a4d6b..ec554ac89 100644 --- a/java/droidstubs.go +++ b/java/droidstubs.go @@ -42,9 +42,7 @@ func RegisterStubsBuildComponents(ctx android.RegistrationContext) { ctx.RegisterModuleType("prebuilt_stubs_sources", PrebuiltStubsSourcesFactory) } -// // Droidstubs -// type Droidstubs struct { Javadoc android.SdkBase diff --git a/java/genrule.go b/java/genrule.go index 5047c412f..208e1f43b 100644 --- a/java/genrule.go +++ b/java/genrule.go @@ -43,23 +43,23 @@ func RegisterGenRuleBuildComponents(ctx android.RegistrationContext) { // // Use a java_genrule to package generated java resources: // -// java_genrule { -// name: "generated_resources", -// tools: [ -// "generator", -// "soong_zip", -// ], -// srcs: ["generator_inputs/**/*"], -// out: ["generated_android_icu4j_resources.jar"], -// cmd: "$(location generator) $(in) -o $(genDir) " + -// "&& $(location soong_zip) -o $(out) -C $(genDir)/res -D $(genDir)/res", -// } +// java_genrule { +// name: "generated_resources", +// tools: [ +// "generator", +// "soong_zip", +// ], +// srcs: ["generator_inputs/**/*"], +// out: ["generated_android_icu4j_resources.jar"], +// cmd: "$(location generator) $(in) -o $(genDir) " + +// "&& $(location soong_zip) -o $(out) -C $(genDir)/res -D $(genDir)/res", +// } // -// java_library { -// name: "lib_with_generated_resources", -// srcs: ["src/**/*.java"], -// static_libs: ["generated_resources"], -// } +// java_library { +// name: "lib_with_generated_resources", +// srcs: ["src/**/*.java"], +// static_libs: ["generated_resources"], +// } func GenRuleFactory() android.Module { module := genrule.NewGenRule() diff --git a/java/platform_compat_config.go b/java/platform_compat_config.go index 1c4249507..655021fc4 100644 --- a/java/platform_compat_config.go +++ b/java/platform_compat_config.go @@ -280,7 +280,7 @@ func platformCompatConfigSingletonFactory() android.Singleton { return &platformCompatConfigSingleton{} } -//============== merged_compat_config ================= +// ============== merged_compat_config ================= type globalCompatConfigProperties struct { // name of the file into which the metadata will be copied. Filename *string diff --git a/java/sdk_library.go b/java/sdk_library.go index 591e90f99..975363974 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -2129,11 +2129,12 @@ var _ SdkLibraryDependency = (*SdkLibraryImport)(nil) // The type of a structure that contains a field of type sdkLibraryScopeProperties // for each apiscope in allApiScopes, e.g. something like: -// struct { -// Public sdkLibraryScopeProperties -// System sdkLibraryScopeProperties -// ... -// } +// +// struct { +// Public sdkLibraryScopeProperties +// System sdkLibraryScopeProperties +// ... +// } var allScopeStructType = createAllScopePropertiesStructType() // Dynamically create a structure type for each apiscope in allApiScopes. @@ -2556,9 +2557,7 @@ func (module *SdkLibraryImport) RequiredFilesFromPrebuiltApex(ctx android.BaseMo return requiredFilesFromPrebuiltApexForImport(name) } -// // java_sdk_library_xml -// type sdkLibraryXml struct { android.ModuleBase android.DefaultableModuleBase diff --git a/java/sdk_library_external.go b/java/sdk_library_external.go index 0acaa13b2..4f8398194 100644 --- a/java/sdk_library_external.go +++ b/java/sdk_library_external.go @@ -49,9 +49,10 @@ func (g partitionGroup) String() string { // Get partition group of java module that can be used at inter-partition dependency check. // We currently have three groups -// (system, system_ext) => system partition group -// (vendor, odm) => vendor partition group -// (product) => product partition group +// +// (system, system_ext) => system partition group +// (vendor, odm) => vendor partition group +// (product) => product partition group func (j *Module) partitionGroup(ctx android.EarlyModuleContext) partitionGroup { // system and system_ext partition can be treated as the same in terms of inter-partition dependency. if j.Platform() || j.SystemExtSpecific() { diff --git a/mk2rbc/mk2rbc.go b/mk2rbc/mk2rbc.go index 8f4fea4b1..8dc014928 100644 --- a/mk2rbc/mk2rbc.go +++ b/mk2rbc/mk2rbc.go @@ -14,13 +14,13 @@ // Convert makefile containing device configuration to Starlark file // The conversion can handle the following constructs in a makefile: -// * comments -// * simple variable assignments -// * $(call init-product,) -// * $(call inherit-product-if-exists -// * if directives -// All other constructs are carried over to the output starlark file as comments. +// - comments +// - simple variable assignments +// - $(call init-product,) +// - $(call inherit-product-if-exists +// - if directives // +// All other constructs are carried over to the output starlark file as comments. package mk2rbc import ( diff --git a/mk2rbc/soong_variables.go b/mk2rbc/soong_variables.go index de4692528..a52ec4f2a 100644 --- a/mk2rbc/soong_variables.go +++ b/mk2rbc/soong_variables.go @@ -32,8 +32,8 @@ type context struct { // Scans the makefile Soong uses to generate soong.variables file, // collecting variable names and types from the lines that look like this: -// $(call add_json_XXX, <...>, $(VAR)) // +// $(call add_json_XXX, <...>, $(VAR)) func FindSoongVariables(mkFile string, includeFileScope mkparser.Scope, registrar variableRegistrar) error { ctx := context{includeFileScope, registrar} return ctx.doFind(mkFile) diff --git a/python/python.go b/python/python.go index b100cc318..548510842 100644 --- a/python/python.go +++ b/python/python.go @@ -387,9 +387,9 @@ func (p *Module) anySrcHasExt(ctx android.BottomUpMutatorContext, ext string) bo } // DepsMutator mutates dependencies for this module: -// * handles proto dependencies, -// * if required, specifies launcher and adds launcher dependencies, -// * applies python version mutations to Python dependencies +// - handles proto dependencies, +// - if required, specifies launcher and adds launcher dependencies, +// - applies python version mutations to Python dependencies func (p *Module) DepsMutator(ctx android.BottomUpMutatorContext) { android.ProtoDeps(ctx, &p.protoProperties) diff --git a/scripts/build_broken_logs.go b/scripts/build_broken_logs.go index 82ba7491e..bb4b9fdd9 100644 --- a/scripts/build_broken_logs.go +++ b/scripts/build_broken_logs.go @@ -19,12 +19,12 @@ // To use, download the logs.zip from one or more branches, and extract them // into subdirectories of the current directory. So for example, I have: // -// ./aosp-master/aosp_arm/std_full.log -// ./aosp-master/aosp_arm64/std_full.log -// ./aosp-master/... -// ./internal-master/aosp_arm/std_full.log -// ./internal-master/aosp_arm64/std_full.log -// ./internal-master/... +// ./aosp-master/aosp_arm/std_full.log +// ./aosp-master/aosp_arm64/std_full.log +// ./aosp-master/... +// ./internal-master/aosp_arm/std_full.log +// ./internal-master/aosp_arm64/std_full.log +// ./internal-master/... // // Then I use `go run path/to/build_broken_logs.go *` package main diff --git a/sdk/build_release.go b/sdk/build_release.go index 149a34eb0..ac57a3279 100644 --- a/sdk/build_release.go +++ b/sdk/build_release.go @@ -397,7 +397,9 @@ func newPropertyPrunerForStructType(structType reflect.Type, selector fieldSelec // structure which are not supported by the specified target build release. // // A property is pruned if its field has a tag of the form: -// `supported_build_releases:""` +// +// `supported_build_releases:""` +// // and the resulting build release set does not contain the target build release. Properties that // have no such tag are assumed to be supported by all releases. func newPropertyPrunerByBuildRelease(propertiesStruct interface{}, targetBuildRelease *buildRelease) *propertyPruner { diff --git a/sdk/member_trait.go b/sdk/member_trait.go index 4229ca82b..0843306a8 100644 --- a/sdk/member_trait.go +++ b/sdk/member_trait.go @@ -68,7 +68,6 @@ func getDynamicSdkMemberTraits(key android.OnceKey, registeredTraits []android.S // A list of sdkMemberTraitListProperty instances is created, one per member trait that provides: // * a reference to the member trait. // * a getter for the corresponding field in the properties struct. -// func createDynamicSdkMemberTraits(sdkMemberTraits []android.SdkMemberTrait) *dynamicSdkMemberTraits { var listProperties []*sdkMemberTraitListProperty diff --git a/sdk/member_type.go b/sdk/member_type.go index 10669fe23..98f59820b 100644 --- a/sdk/member_type.go +++ b/sdk/member_type.go @@ -80,7 +80,6 @@ func getDynamicSdkMemberTypes(key android.OnceKey, registeredTypes []android.Sdk // * a reference to the member type. // * a getter for the corresponding field in the properties struct. // * a dependency tag that identifies the member type of a resolved dependency. -// func createDynamicSdkMemberTypes(sdkMemberTypes []android.SdkMemberType) *dynamicSdkMemberTypes { var listProperties []*sdkMemberTypeListProperty diff --git a/shared/env.go b/shared/env.go index 152729ba0..b7d3bafb4 100644 --- a/shared/env.go +++ b/shared/env.go @@ -32,10 +32,11 @@ type envFileData []envFileEntry // // e.g. OUT_DIR = "out" // is converted to: -// { -// "Key": "OUT_DIR", -// "Value": "out", -// }, +// +// { +// "Key": "OUT_DIR", +// "Value": "out", +// }, func EnvFileContents(envDeps map[string]string) ([]byte, error) { contents := make(envFileData, 0, len(envDeps)) for key, value := range envDeps { diff --git a/snapshot/recovery_snapshot.go b/snapshot/recovery_snapshot.go index f1e31ca03..ac002be9c 100644 --- a/snapshot/recovery_snapshot.go +++ b/snapshot/recovery_snapshot.go @@ -4,7 +4,7 @@ // 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 +// 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, diff --git a/snapshot/snapshot.go b/snapshot/snapshot.go index 294f8b611..206ecc947 100644 --- a/snapshot/snapshot.go +++ b/snapshot/snapshot.go @@ -4,7 +4,7 @@ // 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 +// 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, diff --git a/snapshot/snapshot_base.go b/snapshot/snapshot_base.go index 4a14f2e03..8e5dfe4a2 100644 --- a/snapshot/snapshot_base.go +++ b/snapshot/snapshot_base.go @@ -4,7 +4,7 @@ // 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 +// 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, diff --git a/snapshot/util.go b/snapshot/util.go index f44705227..806ac90fa 100644 --- a/snapshot/util.go +++ b/snapshot/util.go @@ -4,7 +4,7 @@ // 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 +// 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, diff --git a/snapshot/vendor_snapshot.go b/snapshot/vendor_snapshot.go index 9bd26c201..8f7b8c215 100644 --- a/snapshot/vendor_snapshot.go +++ b/snapshot/vendor_snapshot.go @@ -4,7 +4,7 @@ // 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 +// 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, diff --git a/third_party/zip/reader_test.go b/third_party/zip/reader_test.go index 11c6d6e66..5f97f5c5f 100644 --- a/third_party/zip/reader_test.go +++ b/third_party/zip/reader_test.go @@ -615,7 +615,6 @@ func returnRecursiveZip() (r io.ReaderAt, size int64) { // // It's here in hex for the same reason as rZipBytes above: to avoid // problems with on-disk virus scanners or other zip processors. -// func biggestZipBytes() []byte { s := ` 0000000 50 4b 03 04 14 00 08 00 08 00 00 00 00 00 00 00 diff --git a/ui/signal/signal.go b/ui/signal/signal.go index 4929a7bfe..552545d8b 100644 --- a/ui/signal/signal.go +++ b/ui/signal/signal.go @@ -31,13 +31,12 @@ import ( // same time we do. Most of the time this means we just need to ignore the signal and we'll // just see errors from all of our subprocesses. But in case that fails, when we get a signal: // -// 1. Wait two seconds to exit normally. -// 2. Call cancel() which is normally the cancellation of a Context. This will send a SIGKILL -// to any subprocesses attached to that context. -// 3. Wait two seconds to exit normally. -// 4. Call cleanup() to close the log/trace buffers, then panic. -// 5. If another two seconds passes (if cleanup got stuck, etc), then panic. -// +// 1. Wait two seconds to exit normally. +// 2. Call cancel() which is normally the cancellation of a Context. This will send a SIGKILL +// to any subprocesses attached to that context. +// 3. Wait two seconds to exit normally. +// 4. Call cleanup() to close the log/trace buffers, then panic. +// 5. If another two seconds passes (if cleanup got stuck, etc), then panic. func SetupSignals(log logger.Logger, cancel, cleanup func()) { signals := make(chan os.Signal, 5) signal.Notify(signals, os.Interrupt, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM) From 1dd5061d2c7146f7155f2b97c08907cbff3b2499 Mon Sep 17 00:00:00 2001 From: Alan Viverette Date: Mon, 19 Sep 2022 16:26:00 +0000 Subject: [PATCH 078/172] Make writing command-line arguments as a comment in the generated file optional Bug: 246630004 Test: ./update_prebuilts.py -x ###### Merged-In: Ic7d5d5ba55f5bba5cc2d0866a7a25f753f3428f8 Change-Id: Ic7d5d5ba55f5bba5cc2d0866a7a25f753f3428f8 --- cmd/pom2bp/pom2bp.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/pom2bp/pom2bp.go b/cmd/pom2bp/pom2bp.go index f8844fc94..e0638b8ed 100644 --- a/cmd/pom2bp/pom2bp.go +++ b/cmd/pom2bp/pom2bp.go @@ -150,6 +150,7 @@ var sdkVersion string var defaultMinSdkVersion string var useVersion string var staticDeps bool +var writeCmd bool var jetifier bool func InList(s string, list []string) bool { @@ -810,6 +811,9 @@ Usage: %s [--rewrite =] [--exclude ] [--extra-static-lib -use-version If the maven directory contains multiple versions of artifacts and their pom files, -use-version can be used to only write Android.bp files for a specific version of those artifacts. + -write-cmd + Whether to write the command line arguments used to generate the build file as a comment at + the top of the build file itself. -jetifier Sets jetifier: true for all modules. @@ -836,6 +840,7 @@ Usage: %s [--rewrite =] [--exclude ] [--extra-static-lib flag.StringVar(&defaultMinSdkVersion, "default-min-sdk-version", "24", "Default min_sdk_version to use, if one is not available from AndroidManifest.xml. Default: 24") flag.StringVar(&useVersion, "use-version", "", "Only read artifacts of a specific version") flag.BoolVar(&staticDeps, "static-deps", false, "Statically include direct dependencies") + flag.BoolVar(&writeCmd, "write-cmd", true, "Write command line arguments as a comment") flag.BoolVar(&jetifier, "jetifier", false, "Sets jetifier: true on all modules") flag.StringVar(®en, "regen", "", "Rewrite specified file") flag.BoolVar(&pom2build, "pom2build", false, "If true, will generate a Bazel BUILD file *instead* of a .bp file") @@ -962,8 +967,13 @@ Usage: %s [--rewrite =] [--exclude ] [--extra-static-lib if pom2build { commentString = "#" } - fmt.Fprintln(buf, commentString, "Automatically generated with:") - fmt.Fprintln(buf, commentString, "pom2bp", strings.Join(proptools.ShellEscapeList(os.Args[1:]), " ")) + + fmt.Fprintln(buf, commentString, "This is a generated file. Do not modify directly.") + + if writeCmd { + fmt.Fprintln(buf, commentString, "Automatically generated with:") + fmt.Fprintln(buf, commentString, "pom2bp", strings.Join(proptools.ShellEscapeList(os.Args[1:]), " ")) + } depsTemplate := bpDepsTemplate template := bpTemplate From ccb8c8de7910a6fa89e14c82b2a25fe4563ba8bc Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 30 Sep 2022 18:11:41 +0100 Subject: [PATCH 079/172] Allow sdk_version: "system_server_current" modules to access module-lib APIs Previously, a java module with sdk_version: "system_server_current", would only be able to access the system server or public API of a java_sdk_library. This change allows it to access the system server, module lib, system and public APIs in that order. The apiScope structs define the characteristics of each of the different API scopes used as required by the java_sdk_library. They are organized into a hierarchy which is used for two different purposes. The first purpose is to define an extension hierachy. If scope X extends Y then X provides a superset of all API elements (classes, fields, methods, etc) provided by Y. That is reflected in the fact that the .txt file for X would be a delta on the .txt file for Y. So, system extends public and so system_current.txt only contains additional API elements to add to current.txt. The second purpose is when a java_sdk_library/import is asked to provide a specific API scope. e.g. a library that has: sdk_version: "module_current" will ask each of the SDK libraries it depends upon for a module-lib API. However, not all of them will provide an API for that scope. In that case it will find the closest suitable API scope. Previously, it did that by traversing up the API extension until it found an API scope that it did provide and return that. As system_server_current extended the public API that meant that a library which has: sdk_version: "system_server_current" would provide a system server API if available, and if not fall straight back to public. That meant that the library could not access system or module-lib APIs even though it is running in the system server which should be able to access all APIs. One way to fix this would have been to just have system server API scope extend module-lib but that would have had a number of nasty side effects: * It would have created a significant overhead as every module that provides a system server API would also have to provide a module-lib and system API, along with their corresponding .txt files. * Each existing java_sdk_library that provided a system server API would need those .txt files created. * Generating sdk snapshots for older releases would have been more complicated. * It would have confused developers. All of that would be unnecessary because the system server API scope is intended to be provided by libraries that are used solely by the system server so there is no point in them providing anything other than a system server API. So, instead a separate access hierarchy was added which is the same as the extension hierarchy for all existing scopes except for the system server scope, which instead of just being able to access the public API will be able to access the module-lib scope, which can in turn access system and it can in turn access public. That achieves what we want which is a library that is loaded into the system server to be able to access all API scopes. Bug: 204176972 Test: m nothing Change-Id: I854df63fcaeba32afbc1eb0d1a501238022673d0 (cherry picked from commit d0b9fca6d21eaf4f0e34b1608006111fcf06546a) Merged-In: I854df63fcaeba32afbc1eb0d1a501238022673d0 --- java/sdk_library.go | 36 +++++++++++++++++-- java/sdk_library_test.go | 75 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 2 deletions(-) diff --git a/java/sdk_library.go b/java/sdk_library.go index b4ebee970..a2fc04482 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -65,8 +65,27 @@ type apiScope struct { name string // The api scope that this scope extends. + // + // This organizes the scopes into an extension hierarchy. + // + // If set this means that the API provided by this scope includes the API provided by the scope + // set in this field. extends *apiScope + // The next api scope that a library that uses this scope can access. + // + // This organizes the scopes into an access hierarchy. + // + // If set this means that a library that can access this API can also access the API provided by + // the scope set in this field. + // + // A module that sets sdk_version: "_current" should have access to the API of + // every java_sdk_library that it depends on. If the library does not provide an API for + // then it will traverse up this access hierarchy to find an API that it does provide. + // + // If this is not set then it defaults to the scope set in extends. + canAccess *apiScope + // The legacy enabled status for a specific scope can be dependent on other // properties that have been specified on the library so it is provided by // a function that can determine the status by examining those properties. @@ -107,7 +126,7 @@ type apiScope struct { // The scope specific prefix to add to the api file base of "current.txt" or "removed.txt". apiFilePrefix string - // The scope specific prefix to add to the sdk library module name to construct a scope specific + // The scope specific suffix to add to the sdk library module name to construct a scope specific // module name. moduleSuffix string @@ -193,6 +212,11 @@ func initApiScope(scope *apiScope) *apiScope { } } + // By default, a library that can access a scope can also access the scope it extends. + if scope.canAccess == nil { + scope.canAccess = scope.extends + } + // Escape any special characters in the arguments. This is needed because droidstubs // passes these directly to the shell command. scope.droidstubsArgs = proptools.ShellEscapeList(scopeSpecificArgs) @@ -310,6 +334,14 @@ var ( apiScopeSystemServer = initApiScope(&apiScope{ name: "system-server", extends: apiScopePublic, + + // The system-server scope can access the module-lib scope. + // + // A module that provides a system-server API is appended to the standard bootclasspath that is + // used by the system server. So, it should be able to access module-lib APIs provided by + // libraries on the bootclasspath. + canAccess: apiScopeModuleLib, + // The system-server scope is disabled by default in legacy mode. // // Enabling this would break existing usages. @@ -926,7 +958,7 @@ func (c *commonToSdkLibraryAndImport) findScopePaths(scope *apiScope) *scopePath // If this does not support the requested api scope then find the closest available // scope it does support. Returns nil if no such scope is available. func (c *commonToSdkLibraryAndImport) findClosestScopePath(scope *apiScope) *scopePaths { - for s := scope; s != nil; s = s.extends { + for s := scope; s != nil; s = s.canAccess { if paths := c.findScopePaths(s); paths != nil { return paths } diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go index ea7b2f74f..096bca8a1 100644 --- a/java/sdk_library_test.go +++ b/java/sdk_library_test.go @@ -18,6 +18,7 @@ import ( "fmt" "path/filepath" "regexp" + "strings" "testing" "android/soong/android" @@ -699,6 +700,80 @@ func TestJavaSdkLibrary_SystemServer(t *testing.T) { `) } +func TestJavaSdkLibrary_SystemServer_AccessToStubScopeLibs(t *testing.T) { + result := android.GroupFixturePreparers( + prepareForJavaTest, + PrepareForTestWithJavaSdkLibraryFiles, + FixtureWithLastReleaseApis("foo-public", "foo-system", "foo-module-lib", "foo-system-server"), + ).RunTestWithBp(t, ` + java_sdk_library { + name: "foo-public", + srcs: ["a.java"], + api_packages: ["foo"], + public: { + enabled: true, + }, + } + + java_sdk_library { + name: "foo-system", + srcs: ["a.java"], + api_packages: ["foo"], + system: { + enabled: true, + }, + } + + java_sdk_library { + name: "foo-module-lib", + srcs: ["a.java"], + api_packages: ["foo"], + system: { + enabled: true, + }, + module_lib: { + enabled: true, + }, + } + + java_sdk_library { + name: "foo-system-server", + srcs: ["a.java"], + api_packages: ["foo"], + system_server: { + enabled: true, + }, + } + + java_library { + name: "bar", + srcs: ["a.java"], + libs: ["foo-public", "foo-system", "foo-module-lib", "foo-system-server"], + sdk_version: "system_server_current", + } + `) + + stubsPath := func(name string, scope *apiScope) string { + name = scope.stubsLibraryModuleName(name) + return fmt.Sprintf("out/soong/.intermediates/%[1]s/android_common/turbine-combined/%[1]s.jar", name) + } + + // The bar library should depend on the highest (where system server is highest and public is + // lowest) API scopes provided by each of the foo-* modules. The highest API scope provided by the + // foo- module is . + barLibrary := result.ModuleForTests("bar", "android_common").Rule("javac") + stubLibraries := []string{ + stubsPath("foo-public", apiScopePublic), + stubsPath("foo-system", apiScopeSystem), + stubsPath("foo-module-lib", apiScopeModuleLib), + stubsPath("foo-system-server", apiScopeSystemServer), + } + expectedPattern := fmt.Sprintf(`^-classpath .*:\Q%s\E$`, strings.Join(stubLibraries, ":")) + if expected, actual := expectedPattern, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { + t.Errorf("expected pattern %q to match %#q", expected, actual) + } +} + func TestJavaSdkLibrary_MissingScope(t *testing.T) { prepareForJavaTest. ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`requires api scope module-lib from foo but it only has \[\] available`)). From 74920cf6ee18d7f82cd27501719cac823313bdaf Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 4 Oct 2022 15:21:47 +0100 Subject: [PATCH 080/172] Document bootImageConfig and bootImageVariant structs Add warnings to the structs to explain how they are supposed to be used and deprecate fields that are used incorrectly. Bug: 245956352 Test: m nothing Change-Id: I090698287b96fd37102b88beb5d7252977bddc54 (cherry picked from commit a8df7e1c5bfce9115293ddd3bee9682c3c2c5728) Merged-In: I090698287b96fd37102b88beb5d7252977bddc54 --- java/dexpreopt_bootjars.go | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go index 2d6ee758c..d6f74b1b0 100644 --- a/java/dexpreopt_bootjars.go +++ b/java/dexpreopt_bootjars.go @@ -234,6 +234,11 @@ func init() { } // Target-independent description of a boot image. +// +// WARNING: All fields in this struct should be initialized in the genBootImageConfigs function. +// Failure to do so can lead to data races if there is no synchronization enforced ordering between +// the writer and the reader. Fields which break this rule are marked as deprecated and should be +// removed and replaced with something else, e.g. providers. type bootImageConfig struct { // If this image is an extension, the image that it extends. extends *bootImageConfig @@ -274,12 +279,18 @@ type bootImageConfig struct { zip android.WritablePath // Rules which should be used in make to install the outputs. + // + // Deprecated: Not initialized correctly, see struct comment. profileInstalls android.RuleBuilderInstalls // Path to the license metadata file for the module that built the profile. + // + // Deprecated: Not initialized correctly, see struct comment. profileLicenseMetadataFile android.OptionalPath // Path to the image profile file on host (or empty, if profile is not generated). + // + // Deprecated: Not initialized correctly, see struct comment. profilePathOnHost android.Path // Target-dependent fields. @@ -290,6 +301,8 @@ type bootImageConfig struct { } // Target-dependent description of a boot image. +// +// WARNING: The warning comment on bootImageConfig applies here too. type bootImageVariant struct { *bootImageConfig @@ -320,14 +333,28 @@ type bootImageVariant struct { primaryImagesDeps android.Paths // Rules which should be used in make to install the outputs on host. - installs android.RuleBuilderInstalls - vdexInstalls android.RuleBuilderInstalls + // + // Deprecated: Not initialized correctly, see struct comment. + installs android.RuleBuilderInstalls + + // Rules which should be used in make to install the vdex outputs on host. + // + // Deprecated: Not initialized correctly, see struct comment. + vdexInstalls android.RuleBuilderInstalls + + // Rules which should be used in make to install the unstripped outputs on host. + // + // Deprecated: Not initialized correctly, see struct comment. unstrippedInstalls android.RuleBuilderInstalls // Rules which should be used in make to install the outputs on device. + // + // Deprecated: Not initialized correctly, see struct comment. deviceInstalls android.RuleBuilderInstalls // Path to the license metadata file for the module that built the image. + // + // Deprecated: Not initialized correctly, see struct comment. licenseMetadataFile android.OptionalPath } From 5fe904240e32d7122543ac47a1ac9a5197533fd0 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 4 Oct 2022 15:36:44 +0100 Subject: [PATCH 081/172] Remove profilePathOnHost from bootImageConfig The use of this field to return information from bootImageProfileRule up the call stack to one of the users resulted in data races being detected. This change simply returns the profile path back up the call stack. Bug: 245956352 Test: m nothing go test -race ./sdk/... -run TestSnapshotWithBootclasspathFragment_ImageName -test.count 100 # Run the previous command without this change and sometimes it # shows the data race around profilePathOnHost. With this change # that data race is not reported. Although there is still another # data race. Change-Id: I03b09e514cc94f2a6c9d5117d3b2f130cc2e4f5b (cherry picked from commit 9f6ac0bb42a8c229c6a1f85b10f4881b7cbe551f) Merged-In: I03b09e514cc94f2a6c9d5117d3b2f130cc2e4f5b --- java/bootclasspath_fragment.go | 45 ++++++++++++++++++---------------- java/dexpreopt_bootjars.go | 26 ++++++++++++-------- java/platform_bootclasspath.go | 4 +-- 3 files changed, 42 insertions(+), 33 deletions(-) diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index 841489e80..d9a85e668 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -264,7 +264,7 @@ type commonBootclasspathFragment interface { // // If it could not create the files then it will return nil. Otherwise, it will return a map from // android.ArchType to the predefined paths of the boot image files. - produceBootImageFiles(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageFilesByArch + produceBootImageFiles(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageOutputs } var _ commonBootclasspathFragment = (*BootclasspathFragmentModule)(nil) @@ -583,16 +583,16 @@ func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.Mo // Perform hidden API processing. hiddenAPIOutput := b.generateHiddenAPIBuildActions(ctx, contents, fragments) - var bootImageFilesByArch bootImageFilesByArch + var bootImageFiles bootImageOutputs if imageConfig != nil { // Delegate the production of the boot image files to a module type specific method. common := ctx.Module().(commonBootclasspathFragment) - bootImageFilesByArch = common.produceBootImageFiles(ctx, imageConfig) + bootImageFiles = common.produceBootImageFiles(ctx, imageConfig) if shouldCopyBootFilesToPredefinedLocations(ctx, imageConfig) { // Zip the boot image files up, if available. This will generate the zip file in a // predefined location. - buildBootImageZipInPredefinedLocation(ctx, imageConfig, bootImageFilesByArch) + buildBootImageZipInPredefinedLocation(ctx, imageConfig, bootImageFiles.byArch) // Copy the dex jars of this fragment's content modules to their predefined locations. copyBootJarsToPredefinedLocations(ctx, hiddenAPIOutput.EncodedBootDexFilesByModule, imageConfig.dexPathsByModule) @@ -620,7 +620,7 @@ func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.Mo // A prebuilt fragment cannot contribute to an apex. if !android.IsModulePrebuilt(ctx.Module()) { // Provide the apex content info. - b.provideApexContentInfo(ctx, imageConfig, hiddenAPIOutput, bootImageFilesByArch) + b.provideApexContentInfo(ctx, imageConfig, hiddenAPIOutput, bootImageFiles) } } else { // Versioned fragments are not needed by make. @@ -663,7 +663,7 @@ func shouldCopyBootFilesToPredefinedLocations(ctx android.ModuleContext, imageCo // provideApexContentInfo creates, initializes and stores the apex content info for use by other // modules. -func (b *BootclasspathFragmentModule) provideApexContentInfo(ctx android.ModuleContext, imageConfig *bootImageConfig, hiddenAPIOutput *HiddenAPIOutput, bootImageFilesByArch bootImageFilesByArch) { +func (b *BootclasspathFragmentModule) provideApexContentInfo(ctx android.ModuleContext, imageConfig *bootImageConfig, hiddenAPIOutput *HiddenAPIOutput, bootImageFiles bootImageOutputs) { // Construct the apex content info from the config. info := BootclasspathFragmentApexContentInfo{ // Populate the apex content info with paths to the dex jars. @@ -674,14 +674,14 @@ func (b *BootclasspathFragmentModule) provideApexContentInfo(ctx android.ModuleC info.modules = imageConfig.modules global := dexpreopt.GetGlobalConfig(ctx) if !global.DisableGenerateProfile { - info.profilePathOnHost = imageConfig.profilePathOnHost + info.profilePathOnHost = bootImageFiles.profile info.profileInstallPathInApex = imageConfig.profileInstallPathInApex } info.shouldInstallBootImageInApex = imageConfig.shouldInstallInApex() } - info.bootImageFilesByArch = bootImageFilesByArch + info.bootImageFilesByArch = bootImageFiles.byArch // Make the apex content info available for other modules. ctx.SetProvider(BootclasspathFragmentApexContentInfoProvider, info) @@ -936,9 +936,9 @@ func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleC } // produceBootImageFiles builds the boot image files from the source if it is required. -func (b *BootclasspathFragmentModule) produceBootImageFiles(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageFilesByArch { +func (b *BootclasspathFragmentModule) produceBootImageFiles(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageOutputs { if SkipDexpreoptBootJars(ctx) { - return nil + return bootImageOutputs{} } // Only generate the boot image if the configuration does not skip it. @@ -950,21 +950,21 @@ func (b *BootclasspathFragmentModule) produceBootImageFiles(ctx android.ModuleCo // // If it could not create the files then it will return nil. Otherwise, it will return a map from // android.ArchType to the predefined paths of the boot image files. -func (b *BootclasspathFragmentModule) generateBootImageBuildActions(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageFilesByArch { +func (b *BootclasspathFragmentModule) generateBootImageBuildActions(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageOutputs { global := dexpreopt.GetGlobalConfig(ctx) if !shouldBuildBootImages(ctx.Config(), global) { - return nil + return bootImageOutputs{} } // Bootclasspath fragment modules that are for the platform do not produce a boot image. apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) if apexInfo.IsForPlatform() { - return nil + return bootImageOutputs{} } // Bootclasspath fragment modules that are versioned do not produce a boot image. if android.IsModuleInVersionedSdk(ctx.Module()) { - return nil + return bootImageOutputs{} } // Build a profile for the image config and then use that to build the boot image. @@ -974,11 +974,11 @@ func (b *BootclasspathFragmentModule) generateBootImageBuildActions(ctx android. buildBootImageVariantsForBuildOs(ctx, imageConfig, profile) // Build boot image files for the android variants. - androidBootImageFilesByArch := buildBootImageVariantsForAndroidOs(ctx, imageConfig, profile) + bootImageFiles := buildBootImageVariantsForAndroidOs(ctx, imageConfig, profile) // Return the boot image files for the android variants for inclusion in an APEX and to be zipped // up for the dist. - return androidBootImageFilesByArch + return bootImageFiles } func (b *BootclasspathFragmentModule) AndroidMkEntries() []android.AndroidMkEntries { @@ -1279,14 +1279,14 @@ func (module *PrebuiltBootclasspathFragmentModule) produceHiddenAPIOutput(ctx an } // produceBootImageFiles extracts the boot image files from the APEX if available. -func (module *PrebuiltBootclasspathFragmentModule) produceBootImageFiles(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageFilesByArch { +func (module *PrebuiltBootclasspathFragmentModule) produceBootImageFiles(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageOutputs { if !shouldCopyBootFilesToPredefinedLocations(ctx, imageConfig) { - return nil + return bootImageOutputs{} } di := android.FindDeapexerProviderForModule(ctx) if di == nil { - return nil // An error has been reported by FindDeapexerProviderForModule. + return bootImageOutputs{} // An error has been reported by FindDeapexerProviderForModule. } profile := (android.WritablePath)(nil) @@ -1323,11 +1323,14 @@ func (module *PrebuiltBootclasspathFragmentModule) produceBootImageFiles(ctx and }) } } - return files + return bootImageOutputs{ + files, + profile, + } } else { if profile == nil { ctx.ModuleErrorf("Unable to produce boot image files: neither boot image files nor profiles exists in the prebuilt apex") - return nil + return bootImageOutputs{} } // Build boot image files for the android variants from the dex files provided by the contents // of this module. diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go index d6f74b1b0..744ae23ac 100644 --- a/java/dexpreopt_bootjars.go +++ b/java/dexpreopt_bootjars.go @@ -288,11 +288,6 @@ type bootImageConfig struct { // Deprecated: Not initialized correctly, see struct comment. profileLicenseMetadataFile android.OptionalPath - // Path to the image profile file on host (or empty, if profile is not generated). - // - // Deprecated: Not initialized correctly, see struct comment. - profilePathOnHost android.Path - // Target-dependent fields. variants []*bootImageVariant @@ -581,7 +576,7 @@ func copyBootJarsToPredefinedLocations(ctx android.ModuleContext, srcBootDexJars // boot image files. // // The paths are returned because they are needed elsewhere in Soong, e.g. for populating an APEX. -func buildBootImageVariantsForAndroidOs(ctx android.ModuleContext, image *bootImageConfig, profile android.WritablePath) bootImageFilesByArch { +func buildBootImageVariantsForAndroidOs(ctx android.ModuleContext, image *bootImageConfig, profile android.WritablePath) bootImageOutputs { return buildBootImageForOsType(ctx, image, profile, android.Android) } @@ -596,12 +591,22 @@ func buildBootImageVariantsForBuildOs(ctx android.ModuleContext, image *bootImag buildBootImageForOsType(ctx, image, profile, ctx.Config().BuildOS) } +// bootImageOutputs encapsulates information about boot images that were created/obtained by +// commonBootclasspathFragment.produceBootImageFiles. +type bootImageOutputs struct { + // Map from arch to the paths to the boot image files created/obtained for that arch. + byArch bootImageFilesByArch + + // The path to the profile file created/obtained for the boot image. + profile android.WritablePath +} + // buildBootImageForOsType takes a bootImageConfig, a profile file and an android.OsType // boot image files are required for and it creates rules to build the boot image // files for all the required architectures for them. // // It returns a map from android.ArchType to the predefined paths of the boot image files. -func buildBootImageForOsType(ctx android.ModuleContext, image *bootImageConfig, profile android.WritablePath, requiredOsType android.OsType) bootImageFilesByArch { +func buildBootImageForOsType(ctx android.ModuleContext, image *bootImageConfig, profile android.WritablePath, requiredOsType android.OsType) bootImageOutputs { filesByArch := bootImageFilesByArch{} for _, variant := range image.variants { if variant.target.Os == requiredOsType { @@ -610,7 +615,10 @@ func buildBootImageForOsType(ctx android.ModuleContext, image *bootImageConfig, } } - return filesByArch + return bootImageOutputs{ + filesByArch, + profile, + } } // buildBootImageZipInPredefinedLocation generates a zip file containing all the boot image files. @@ -855,8 +863,6 @@ func bootImageProfileRule(ctx android.ModuleContext, image *bootImageConfig) and rule.Build("bootJarsProfile", "profile boot jars") - image.profilePathOnHost = profile - return profile } diff --git a/java/platform_bootclasspath.go b/java/platform_bootclasspath.go index 24f8253ae..f0de7a4d8 100644 --- a/java/platform_bootclasspath.go +++ b/java/platform_bootclasspath.go @@ -436,10 +436,10 @@ func (b *platformBootclasspathModule) generateBootImageBuildActions(ctx android. profile := bootImageProfileRule(ctx, imageConfig) // Build boot image files for the android variants. - androidBootImageFilesByArch := buildBootImageVariantsForAndroidOs(ctx, imageConfig, profile) + androidBootImageFiles := buildBootImageVariantsForAndroidOs(ctx, imageConfig, profile) // Zip the android variant boot image files up. - buildBootImageZipInPredefinedLocation(ctx, imageConfig, androidBootImageFilesByArch) + buildBootImageZipInPredefinedLocation(ctx, imageConfig, androidBootImageFiles.byArch) // Build boot image files for the host variants. There are use directly by ART host side tests. buildBootImageVariantsForBuildOs(ctx, imageConfig, profile) From 9d8b46abab26f9f2449fb2bcf2f44abd3f5d603b Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 4 Oct 2022 16:39:18 +0100 Subject: [PATCH 082/172] Remove deviceInstalls from bootImageVariant The use of this field to return information from buildBootImageVariant up the call stack to one of the callers resulted in data races being detected. This change simply passes the deviceInstalls up the call stack. Bug: 245956352 Test: m nothing go test -race ./sdk/... -run TestSnapshotWithBootclasspathFragment_ImageName -test.count 100 # Run the previous command without this change and sometimes it # shows the data race around deviceInstalls. When run with this # change it reports no data races. Change-Id: I3c73920dcb17a6c89a63c6a9c3a0bb049a98a690 (cherry picked from commit e10a9f2e5e1b853e834debc692c3802540777533) Merged-In: I3c73920dcb17a6c89a63c6a9c3a0bb049a98a690 --- java/bootclasspath_fragment.go | 19 +++++++++++++------ java/dexpreopt_bootjars.go | 32 ++++++++++++++++++++------------ 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index d9a85e668..6bd98d482 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -598,8 +598,9 @@ func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.Mo copyBootJarsToPredefinedLocations(ctx, hiddenAPIOutput.EncodedBootDexFilesByModule, imageConfig.dexPathsByModule) } - for _, variant := range imageConfig.apexVariants() { - arch := variant.target.Arch.ArchType.String() + for _, variant := range bootImageFiles.variants { + archType := variant.config.target.Arch.ArchType + arch := archType.String() for _, install := range variant.deviceInstalls { // Remove the "/" prefix because the path should be relative to $ANDROID_PRODUCT_OUT. installDir := strings.TrimPrefix(filepath.Dir(install.To), "/") @@ -1304,8 +1305,17 @@ func (module *PrebuiltBootclasspathFragmentModule) produceBootImageFiles(ctx and // If the boot image files for the android variants are in the prebuilt apex, we must use those // rather than building new ones because those boot image files are going to be used on device. files := bootImageFilesByArch{} + bootImageFiles := bootImageOutputs{ + byArch: files, + profile: profile, + } for _, variant := range imageConfig.apexVariants() { arch := variant.target.Arch.ArchType + bootImageFiles.variants = append(bootImageFiles.variants, bootImageVariantOutputs{ + variant, + // No device installs needed when installed in APEX. + nil, + }) for _, toPath := range variant.imagesDeps { apexRelativePath := apexRootRelativePathToBootImageFile(arch, toPath.Base()) // Get the path to the file that the deapexer extracted from the prebuilt apex file. @@ -1323,10 +1333,7 @@ func (module *PrebuiltBootclasspathFragmentModule) produceBootImageFiles(ctx and }) } } - return bootImageOutputs{ - files, - profile, - } + return bootImageFiles } else { if profile == nil { ctx.ModuleErrorf("Unable to produce boot image files: neither boot image files nor profiles exists in the prebuilt apex") diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go index 744ae23ac..323423d0a 100644 --- a/java/dexpreopt_bootjars.go +++ b/java/dexpreopt_bootjars.go @@ -342,11 +342,6 @@ type bootImageVariant struct { // Deprecated: Not initialized correctly, see struct comment. unstrippedInstalls android.RuleBuilderInstalls - // Rules which should be used in make to install the outputs on device. - // - // Deprecated: Not initialized correctly, see struct comment. - deviceInstalls android.RuleBuilderInstalls - // Path to the license metadata file for the module that built the image. // // Deprecated: Not initialized correctly, see struct comment. @@ -597,6 +592,8 @@ type bootImageOutputs struct { // Map from arch to the paths to the boot image files created/obtained for that arch. byArch bootImageFilesByArch + variants []bootImageVariantOutputs + // The path to the profile file created/obtained for the boot image. profile android.WritablePath } @@ -608,17 +605,19 @@ type bootImageOutputs struct { // It returns a map from android.ArchType to the predefined paths of the boot image files. func buildBootImageForOsType(ctx android.ModuleContext, image *bootImageConfig, profile android.WritablePath, requiredOsType android.OsType) bootImageOutputs { filesByArch := bootImageFilesByArch{} + imageOutputs := bootImageOutputs{ + byArch: filesByArch, + profile: profile, + } for _, variant := range image.variants { if variant.target.Os == requiredOsType { - buildBootImageVariant(ctx, variant, profile) + variantOutputs := buildBootImageVariant(ctx, variant, profile) + imageOutputs.variants = append(imageOutputs.variants, variantOutputs) filesByArch[variant.target.Arch.ArchType] = variant.imagesDeps.Paths() } } - return bootImageOutputs{ - filesByArch, - profile, - } + return imageOutputs } // buildBootImageZipInPredefinedLocation generates a zip file containing all the boot image files. @@ -646,8 +645,13 @@ func buildBootImageZipInPredefinedLocation(ctx android.ModuleContext, image *boo rule.Build("zip_"+image.name, "zip "+image.name+" image") } +type bootImageVariantOutputs struct { + config *bootImageVariant + deviceInstalls android.RuleBuilderInstalls +} + // Generate boot image build rules for a specific target. -func buildBootImageVariant(ctx android.ModuleContext, image *bootImageVariant, profile android.Path) { +func buildBootImageVariant(ctx android.ModuleContext, image *bootImageVariant, profile android.Path) bootImageVariantOutputs { globalSoong := dexpreopt.GetGlobalSoongConfig(ctx) global := dexpreopt.GetGlobalConfig(ctx) @@ -808,8 +812,12 @@ func buildBootImageVariant(ctx android.ModuleContext, image *bootImageVariant, p image.installs = rule.Installs() image.vdexInstalls = vdexInstalls image.unstrippedInstalls = unstrippedInstalls - image.deviceInstalls = deviceInstalls image.licenseMetadataFile = android.OptionalPathForPath(ctx.LicenseMetadataFile()) + + return bootImageVariantOutputs{ + image, + deviceInstalls, + } } const failureMessage = `ERROR: Dex2oat failed to compile a boot image. From a47df7fe25d1f2e3a0ea5ed4895c1aa266150784 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 6 Oct 2022 11:01:59 +0100 Subject: [PATCH 083/172] Add Config,RunningInsideUnitTest Sometimes it is necessary for some functionality to be disabled while running in unit tests, e.g. functionality that requires external information such as error prone tools and configuration. Sometimes it is necessary for some functionality to be enabled while running in unit tests, e.g. functionality that makes state available for testing but which is not necessary at runtime. Previously, that was done by checking to see if TestProductVariables was nil. This change adds a method to abstract that. Bug: 245956352 Test: m nothing Change-Id: I7845b79328e7180623161a9bf897568089da4e4f (cherry picked from commit 741355826fc314796b3e5ca4cb89e4d196e96b20) Merged-In: I7845b79328e7180623161a9bf897568089da4e4f --- android/config.go | 5 +++++ java/base.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/android/config.go b/android/config.go index ddae886e5..0bca7210b 100644 --- a/android/config.go +++ b/android/config.go @@ -93,6 +93,11 @@ func (c Config) PrimaryBuilderInvocations() []bootstrap.PrimaryBuilderInvocation return []bootstrap.PrimaryBuilderInvocation{} } +// RunningInsideUnitTest returns true if this code is being run as part of a Soong unit test. +func (c Config) RunningInsideUnitTest() bool { + return c.config.TestProductVariables != nil +} + // A DeviceConfig object represents the configuration for a particular device // being built. For now there will only be one of these, but in the future there // may be multiple devices being built. diff --git a/java/base.go b/java/base.go index b629f0f19..4e7b18c46 100644 --- a/java/base.go +++ b/java/base.go @@ -881,7 +881,7 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB epEnabled := j.properties.Errorprone.Enabled if (ctx.Config().RunErrorProne() && epEnabled == nil) || Bool(epEnabled) { - if config.ErrorProneClasspath == nil && ctx.Config().TestProductVariables == nil { + if config.ErrorProneClasspath == nil && !ctx.Config().RunningInsideUnitTest() { ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?") } From 1459deac793b2dd8b962e05b6aad75331a60876c Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 5 Oct 2022 15:47:25 +0100 Subject: [PATCH 084/172] Add CommonOs to Config.Targets (cherry picked from commit de13a3a23264683e187983ff2d5199af5321caf2) Previously, CommonOs was not added to Config.Targets for the test which caused AndroidMk to crash when trying to determine if a target needed the 2ND_ prefix added to some make variables. Bug: 245956352 Test: m nothing Change-Id: Ie0e9e1fa88e2f96fd66b154da319b1839916e77c Merged-In: Ia815537ee5ce8e83df9a01c57250aa888453d138 --- android/config.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/android/config.go b/android/config.go index ddae886e5..9b522ecea 100644 --- a/android/config.go +++ b/android/config.go @@ -403,6 +403,9 @@ func modifyTestConfigToSupportArchMutator(testConfig Config) { }, } + // Make the CommonOS OsType available for all products. + config.Targets[CommonOS] = []Target{commonTargetMap[CommonOS.Name]} + if runtime.GOOS == "darwin" { config.Targets[config.BuildOS] = config.Targets[config.BuildOS][:1] } From 1456504fbaf84b6fcd8f423b21fdf50ccf9bede6 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 4 Oct 2022 19:03:31 +0100 Subject: [PATCH 085/172] Test bootImageConfig/Variant fields Most of the fields in the bootImageConfig/Variant structs are assigned inside a Once func so are guaranteed to be only set once. However, some are assigned outside. This change adds comprehensive tests for those structs and verifies that the constant fields are preserved and the mutated fields have the correct value. The check for the constant fields is added in a new TestBootImageConfig test. The check for the mutated fields is added into TestSnapshotWithBootclasspathFragment_ImageName as that test checks an art bootclasspath_fragment in the following configurations: * source on its own * prebuilt on its own * source and prebuilt with source preferred * source and prebuilt with prebuilt It reveals a couple of interesting facts: * All the *installs fields are set to the same value irrespective of whether the source or prebuilt is preferred. The information is constructed solely from information already within the bootImageConfig/Variant and so can be moved within Once. * The licenseMetadataFile is incorrect when prebuilt is preferred. That is due to both the source and prebuilt modules setting it and the source module always wins as the source module depends on the prebuilt so always runs its GenerateAndroidBuildActions after it. Those issues will be cleaned up in following changes. Bug: 245956352 Test: m nothing Change-Id: If917cfbcb3b1c842a8682d51cc1ee1fed1c51add (cherry picked from commit 8eb4573b232accd19c9cd3b9d1b99572d4fe2c16) Merged-In: If917cfbcb3b1c842a8682d51cc1ee1fed1c51add --- android/makevars.go | 11 +- android/testing.go | 40 ++ java/Android.bp | 2 + java/dexpreopt_config_test.go | 30 + java/dexpreopt_config_testing.go | 768 +++++++++++++++++++++++++ java/testing.go | 1 + sdk/bootclasspath_fragment_sdk_test.go | 77 ++- 7 files changed, 912 insertions(+), 17 deletions(-) create mode 100644 java/dexpreopt_config_test.go create mode 100644 java/dexpreopt_config_testing.go diff --git a/android/makevars.go b/android/makevars.go index a74185a5c..5165a55e2 100644 --- a/android/makevars.go +++ b/android/makevars.go @@ -35,7 +35,7 @@ func androidMakeVarsProvider(ctx MakeVarsContext) { ctx.Strict("MIN_SUPPORTED_SDK_VERSION", ctx.Config().MinSupportedSdkVersion().String()) } -/////////////////////////////////////////////////////////////////////////////// +// ///////////////////////////////////////////////////////////////////////////// // BaseMakeVarsContext contains the common functions for other packages to use // to declare make variables @@ -173,13 +173,14 @@ type ModuleMakeVarsProvider interface { MakeVars(ctx MakeVarsModuleContext) } -/////////////////////////////////////////////////////////////////////////////// +// ///////////////////////////////////////////////////////////////////////////// func makeVarsSingletonFunc() Singleton { return &makeVarsSingleton{} } type makeVarsSingleton struct { + varsForTesting []makeVarsVariable installsForTesting []byte } @@ -320,7 +321,11 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) { ctx.Errorf(err.Error()) } - s.installsForTesting = installsBytes + // Only save state for tests when testing. + if ctx.Config().RunningInsideUnitTest() { + s.varsForTesting = vars + s.installsForTesting = installsBytes + } } func (s *makeVarsSingleton) writeVars(vars []makeVarsVariable) []byte { diff --git a/android/testing.go b/android/testing.go index b4429ca91..1b36c903a 100644 --- a/android/testing.go +++ b/android/testing.go @@ -667,6 +667,46 @@ func (ctx *TestContext) InstallMakeRulesForTesting(t *testing.T) []InstallMakeRu return parseMkRules(t, ctx.config, nodes) } +// MakeVarVariable provides access to make vars that will be written by the makeVarsSingleton +type MakeVarVariable interface { + // Name is the name of the variable. + Name() string + + // Value is the value of the variable. + Value() string +} + +func (v makeVarsVariable) Name() string { + return v.name +} + +func (v makeVarsVariable) Value() string { + return v.value +} + +// PrepareForTestAccessingMakeVars sets up the test so that MakeVarsForTesting will work. +var PrepareForTestAccessingMakeVars = GroupFixturePreparers( + PrepareForTestWithAndroidMk, + PrepareForTestWithMakevars, +) + +// MakeVarsForTesting returns a filtered list of MakeVarVariable objects that represent the +// variables that will be written out. +// +// It is necessary to use PrepareForTestAccessingMakeVars in tests that want to call this function. +// Along with any other preparers needed to add the make vars. +func (ctx *TestContext) MakeVarsForTesting(filter func(variable MakeVarVariable) bool) []MakeVarVariable { + vars := ctx.SingletonForTests("makevars").Singleton().(*makeVarsSingleton).varsForTesting + result := make([]MakeVarVariable, 0, len(vars)) + for _, v := range vars { + if filter(v) { + result = append(result, v) + } + } + + return result +} + func (ctx *TestContext) Config() Config { return ctx.config } diff --git a/java/Android.bp b/java/Android.bp index df0d1eb3d..d66e0953f 100644 --- a/java/Android.bp +++ b/java/Android.bp @@ -43,6 +43,7 @@ bootstrap_go_package { "dexpreopt_bootjars.go", "dexpreopt_check.go", "dexpreopt_config.go", + "dexpreopt_config_testing.go", "droiddoc.go", "droidstubs.go", "fuzz.go", @@ -85,6 +86,7 @@ bootstrap_go_package { "dex_test.go", "dexpreopt_test.go", "dexpreopt_bootjars_test.go", + "dexpreopt_config_test.go", "droiddoc_test.go", "droidstubs_test.go", "hiddenapi_singleton_test.go", diff --git a/java/dexpreopt_config_test.go b/java/dexpreopt_config_test.go new file mode 100644 index 000000000..eaa6a8c22 --- /dev/null +++ b/java/dexpreopt_config_test.go @@ -0,0 +1,30 @@ +// Copyright 2022 Google Inc. All rights reserved. +// +// 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 java + +import ( + "testing" + + "android/soong/android" +) + +func TestBootImageConfig(t *testing.T) { + result := android.GroupFixturePreparers( + PrepareForBootImageConfigTest, + ).RunTest(t) + + CheckArtBootImageConfig(t, result) + CheckFrameworkBootImageConfig(t, result) +} diff --git a/java/dexpreopt_config_testing.go b/java/dexpreopt_config_testing.go new file mode 100644 index 000000000..1c236d8af --- /dev/null +++ b/java/dexpreopt_config_testing.go @@ -0,0 +1,768 @@ +// Copyright 2022 Google Inc. All rights reserved. +// +// 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. + +// Testing support for dexpreopt config. +// +// The bootImageConfig/bootImageVariant structs returned by genBootImageConfigs are used in many +// places in the build and are currently mutated in a number of those locations. This provides +// comprehensive tests of the fields in those structs to ensure that they have been initialized +// correctly and where relevant, mutated correctly. +// +// This is used in TestBootImageConfig to verify that the + +package java + +import ( + "fmt" + "strings" + "testing" + + "android/soong/android" +) + +// PrepareForBootImageConfigTest is the minimal set of preparers that are needed to be able to use +// the Check*BootImageConfig methods define here. +var PrepareForBootImageConfigTest = android.GroupFixturePreparers( + android.PrepareForTestWithArchMutator, + android.PrepareForTestAccessingMakeVars, + FixtureConfigureBootJars("com.android.art:core1", "com.android.art:core2", "platform:framework"), +) + +// normalizedInstall represents a android.RuleBuilderInstall that has been normalized to remove +// test specific parts of the From path. +type normalizedInstall struct { + from string + to string +} + +// normalizeInstalls converts a slice of android.RuleBuilderInstall into a slice of +// normalizedInstall to allow them to be compared using android.AssertDeepEquals. +func normalizeInstalls(installs android.RuleBuilderInstalls) []normalizedInstall { + var normalized []normalizedInstall + for _, install := range installs { + normalized = append(normalized, normalizedInstall{ + from: install.From.RelativeToTop().String(), + to: install.To, + }) + } + return normalized +} + +// assertInstallsEqual normalized the android.RuleBuilderInstalls and compares against the expected +// normalizedInstalls. +func assertInstallsEqual(t *testing.T, message string, expected []normalizedInstall, actual android.RuleBuilderInstalls) { + t.Helper() + normalizedActual := normalizeInstalls(actual) + android.AssertDeepEquals(t, message, expected, normalizedActual) +} + +// expectedConfig encapsulates the expected properties that will be set in a bootImageConfig +// +// Each field in here is compared against the corresponding field in bootImageConfig. +type expectedConfig struct { + name string + stem string + dir string + symbolsDir string + installDirOnDevice string + installDirOnHost string + profileInstallPathInApex string + modules android.ConfiguredJarList + dexPaths []string + dexPathsDeps []string + zip string + variants []*expectedVariant + + // Mutated fields + profileInstalls []normalizedInstall + profileLicenseMetadataFile string +} + +// expectedVariant encapsulates the expected properties that will be set in a bootImageVariant +// +// Each field in here is compared against the corresponding field in bootImageVariant +// except for archType which is compared against the target.Arch.ArchType field in bootImageVariant. +type expectedVariant struct { + archType android.ArchType + dexLocations []string + dexLocationsDeps []string + imagePathOnHost string + imagePathOnDevice string + imagesDeps []string + primaryImages string + primaryImagesDeps []string + + // Mutated fields + installs []normalizedInstall + vdexInstalls []normalizedInstall + unstrippedInstalls []normalizedInstall + licenseMetadataFile string +} + +// CheckArtBootImageConfig checks the status of the fields of the bootImageConfig and +// bootImageVariant structures that are returned from artBootImageConfig. +// +// This is before any fields are mutated. +func CheckArtBootImageConfig(t *testing.T, result *android.TestResult) { + checkArtBootImageConfig(t, result, false, "") +} + +// 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) + return imageConfig +} + +// checkArtBootImageConfig checks the ART boot image. +// +// mutated is true if this is called after fields in the image have been mutated by the ART +// bootclasspath_fragment and false otherwise. +func checkArtBootImageConfig(t *testing.T, result *android.TestResult, mutated bool, expectedLicenseMetadataFile string) { + imageConfig := getArtImageConfig(result) + + expected := &expectedConfig{ + name: "art", + stem: "boot", + dir: "out/soong/test_device/dex_artjars", + symbolsDir: "out/soong/test_device/dex_artjars_unstripped", + installDirOnDevice: "system/framework", + installDirOnHost: "apex/art_boot_images/javalib", + profileInstallPathInApex: "etc/boot-image.prof", + modules: android.CreateTestConfiguredJarList([]string{"com.android.art:core1", "com.android.art:core2"}), + dexPaths: []string{"out/soong/test_device/dex_artjars_input/core1.jar", "out/soong/test_device/dex_artjars_input/core2.jar"}, + dexPathsDeps: []string{"out/soong/test_device/dex_artjars_input/core1.jar", "out/soong/test_device/dex_artjars_input/core2.jar"}, + zip: "out/soong/test_device/dex_artjars/art.zip", + variants: []*expectedVariant{ + { + archType: android.Arm64, + dexLocations: []string{"/apex/com.android.art/javalib/core1.jar", "/apex/com.android.art/javalib/core2.jar"}, + dexLocationsDeps: []string{"/apex/com.android.art/javalib/core1.jar", "/apex/com.android.art/javalib/core2.jar"}, + imagePathOnHost: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", + imagePathOnDevice: "/system/framework/arm64/boot.art", + imagesDeps: []string{ + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat", + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex", + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art", + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat", + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex", + }, + installs: []normalizedInstall{ + { + from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", + to: "/apex/art_boot_images/javalib/arm64/boot.art", + }, + { + from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat", + to: "/apex/art_boot_images/javalib/arm64/boot.oat", + }, + { + from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art", + to: "/apex/art_boot_images/javalib/arm64/boot-core2.art", + }, + { + from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat", + to: "/apex/art_boot_images/javalib/arm64/boot-core2.oat", + }, + }, + vdexInstalls: []normalizedInstall{ + { + from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex", + to: "/apex/art_boot_images/javalib/arm64/boot.vdex", + }, + { + from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex", + to: "/apex/art_boot_images/javalib/arm64/boot-core2.vdex", + }, + }, + unstrippedInstalls: []normalizedInstall{ + { + from: "out/soong/test_device/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm64/boot.oat", + to: "/apex/art_boot_images/javalib/arm64/boot.oat", + }, + { + from: "out/soong/test_device/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm64/boot-core2.oat", + to: "/apex/art_boot_images/javalib/arm64/boot-core2.oat", + }, + }, + licenseMetadataFile: expectedLicenseMetadataFile, + }, + { + archType: android.Arm, + dexLocations: []string{"/apex/com.android.art/javalib/core1.jar", "/apex/com.android.art/javalib/core2.jar"}, + dexLocationsDeps: []string{"/apex/com.android.art/javalib/core1.jar", "/apex/com.android.art/javalib/core2.jar"}, + imagePathOnHost: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", + imagePathOnDevice: "/system/framework/arm/boot.art", + imagesDeps: []string{ + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat", + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex", + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.art", + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.oat", + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.vdex", + }, + installs: []normalizedInstall{ + { + from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", + to: "/apex/art_boot_images/javalib/arm/boot.art", + }, + { + from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat", + to: "/apex/art_boot_images/javalib/arm/boot.oat", + }, + { + from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.art", + to: "/apex/art_boot_images/javalib/arm/boot-core2.art", + }, + { + from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.oat", + to: "/apex/art_boot_images/javalib/arm/boot-core2.oat", + }, + }, + vdexInstalls: []normalizedInstall{ + { + from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex", + to: "/apex/art_boot_images/javalib/arm/boot.vdex", + }, + { + from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.vdex", + to: "/apex/art_boot_images/javalib/arm/boot-core2.vdex", + }, + }, + unstrippedInstalls: []normalizedInstall{ + { + from: "out/soong/test_device/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm/boot.oat", + to: "/apex/art_boot_images/javalib/arm/boot.oat", + }, + { + from: "out/soong/test_device/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm/boot-core2.oat", + to: "/apex/art_boot_images/javalib/arm/boot-core2.oat", + }, + }, + licenseMetadataFile: expectedLicenseMetadataFile, + }, + { + archType: android.X86_64, + dexLocations: []string{"host/linux-x86/apex/com.android.art/javalib/core1.jar", "host/linux-x86/apex/com.android.art/javalib/core2.jar"}, + dexLocationsDeps: []string{"host/linux-x86/apex/com.android.art/javalib/core1.jar", "host/linux-x86/apex/com.android.art/javalib/core2.jar"}, + imagePathOnHost: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", + imagePathOnDevice: "/system/framework/x86_64/boot.art", + imagesDeps: []string{ + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat", + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex", + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art", + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat", + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex", + }, + installs: []normalizedInstall{ + { + from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", + to: "/apex/art_boot_images/javalib/x86_64/boot.art", + }, { + from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat", + to: "/apex/art_boot_images/javalib/x86_64/boot.oat", + }, + { + from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art", + to: "/apex/art_boot_images/javalib/x86_64/boot-core2.art", + }, { + from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat", + to: "/apex/art_boot_images/javalib/x86_64/boot-core2.oat", + }, + }, + vdexInstalls: []normalizedInstall{ + { + from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex", + to: "/apex/art_boot_images/javalib/x86_64/boot.vdex", + }, + { + from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex", + to: "/apex/art_boot_images/javalib/x86_64/boot-core2.vdex", + }, + }, + unstrippedInstalls: []normalizedInstall{ + { + from: "out/soong/test_device/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat", + to: "/apex/art_boot_images/javalib/x86_64/boot.oat", + }, + { + from: "out/soong/test_device/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat", + to: "/apex/art_boot_images/javalib/x86_64/boot-core2.oat", + }, + }, + licenseMetadataFile: expectedLicenseMetadataFile, + }, + { + archType: android.X86, + dexLocations: []string{"host/linux-x86/apex/com.android.art/javalib/core1.jar", "host/linux-x86/apex/com.android.art/javalib/core2.jar"}, + dexLocationsDeps: []string{"host/linux-x86/apex/com.android.art/javalib/core1.jar", "host/linux-x86/apex/com.android.art/javalib/core2.jar"}, + imagePathOnHost: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", + imagePathOnDevice: "/system/framework/x86/boot.art", + imagesDeps: []string{ + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat", + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex", + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art", + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat", + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex", + }, + installs: []normalizedInstall{ + { + from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", + to: "/apex/art_boot_images/javalib/x86/boot.art", + }, { + from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat", + to: "/apex/art_boot_images/javalib/x86/boot.oat", + }, + { + from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art", + to: "/apex/art_boot_images/javalib/x86/boot-core2.art", + }, { + from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat", + to: "/apex/art_boot_images/javalib/x86/boot-core2.oat", + }, + }, + vdexInstalls: []normalizedInstall{ + { + from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex", + to: "/apex/art_boot_images/javalib/x86/boot.vdex", + }, + { + from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex", + to: "/apex/art_boot_images/javalib/x86/boot-core2.vdex", + }, + }, + unstrippedInstalls: []normalizedInstall{ + { + from: "out/soong/test_device/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat", + to: "/apex/art_boot_images/javalib/x86/boot.oat", + }, + { + from: "out/soong/test_device/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat", + to: "/apex/art_boot_images/javalib/x86/boot-core2.oat", + }, + }, + licenseMetadataFile: expectedLicenseMetadataFile, + }, + }, + } + + checkBootImageConfig(t, imageConfig, mutated, expected) +} + +// getFrameworkImageConfig gets the framework bootImageConfig that was created during the test. +func getFrameworkImageConfig(result *android.TestResult) *bootImageConfig { + pathCtx := &android.TestPathContext{TestResult: result} + imageConfig := defaultBootImageConfig(pathCtx) + return imageConfig +} + +// CheckFrameworkBootImageConfig checks the status of the fields of the bootImageConfig and +// bootImageVariant structures that are returned from defaultBootImageConfig. +// +// This is before any fields are mutated. +func CheckFrameworkBootImageConfig(t *testing.T, result *android.TestResult) { + checkFrameworkBootImageConfig(t, result, false, "") +} + +// checkFrameworkBootImageConfig checks the framework boot image. +// +// mutated is true if this is called after fields in the image have been mutated by the +// platform_bootclasspath and false otherwise. +func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mutated bool, expectedLicenseMetadataFile string) { + imageConfig := getFrameworkImageConfig(result) + + expected := &expectedConfig{ + name: "boot", + stem: "boot", + dir: "out/soong/test_device/dex_bootjars", + symbolsDir: "out/soong/test_device/dex_bootjars_unstripped", + installDirOnDevice: "system/framework", + installDirOnHost: "system/framework", + profileInstallPathInApex: "", + modules: android.CreateTestConfiguredJarList([]string{"platform:framework"}), + dexPaths: []string{"out/soong/test_device/dex_bootjars_input/framework.jar"}, + dexPathsDeps: []string{"out/soong/test_device/dex_artjars_input/core1.jar", "out/soong/test_device/dex_artjars_input/core2.jar", "out/soong/test_device/dex_bootjars_input/framework.jar"}, + zip: "out/soong/test_device/dex_bootjars/boot.zip", + variants: []*expectedVariant{ + { + archType: android.Arm64, + dexLocations: []string{"/system/framework/framework.jar"}, + dexLocationsDeps: []string{ + "/apex/com.android.art/javalib/core1.jar", + "/apex/com.android.art/javalib/core2.jar", + "/system/framework/framework.jar", + }, + imagePathOnHost: "out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.art", + imagePathOnDevice: "/system/framework/arm64/boot-framework.art", + imagesDeps: []string{ + "out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.art", + "out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.oat", + "out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.vdex", + }, + primaryImages: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", + primaryImagesDeps: []string{ + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat", + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex", + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art", + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat", + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex", + }, + installs: []normalizedInstall{ + { + from: "out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.art", + to: "/system/framework/arm64/boot-framework.art", + }, + { + from: "out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.oat", + to: "/system/framework/arm64/boot-framework.oat", + }, + }, + vdexInstalls: []normalizedInstall{ + { + from: "out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.vdex", + to: "/system/framework/arm64/boot-framework.vdex", + }, + }, + unstrippedInstalls: []normalizedInstall{ + { + from: "out/soong/test_device/dex_bootjars_unstripped/android/system/framework/arm64/boot-framework.oat", + to: "/system/framework/arm64/boot-framework.oat", + }, + }, + licenseMetadataFile: expectedLicenseMetadataFile, + }, + { + archType: android.Arm, + dexLocations: []string{"/system/framework/framework.jar"}, + dexLocationsDeps: []string{ + "/apex/com.android.art/javalib/core1.jar", + "/apex/com.android.art/javalib/core2.jar", + "/system/framework/framework.jar", + }, + imagePathOnHost: "out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.art", + imagePathOnDevice: "/system/framework/arm/boot-framework.art", + imagesDeps: []string{ + "out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.art", + "out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.oat", + "out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.vdex", + }, + primaryImages: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", + primaryImagesDeps: []string{ + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat", + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex", + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.art", + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.oat", + "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.vdex", + }, + installs: []normalizedInstall{ + { + from: "out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.art", + to: "/system/framework/arm/boot-framework.art", + }, + { + from: "out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.oat", + to: "/system/framework/arm/boot-framework.oat", + }, + }, + vdexInstalls: []normalizedInstall{ + { + from: "out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.vdex", + to: "/system/framework/arm/boot-framework.vdex", + }, + }, + unstrippedInstalls: []normalizedInstall{ + { + from: "out/soong/test_device/dex_bootjars_unstripped/android/system/framework/arm/boot-framework.oat", + to: "/system/framework/arm/boot-framework.oat", + }, + }, + licenseMetadataFile: expectedLicenseMetadataFile, + }, + { + archType: android.X86_64, + dexLocations: []string{"host/linux-x86/system/framework/framework.jar"}, + dexLocationsDeps: []string{ + "host/linux-x86/apex/com.android.art/javalib/core1.jar", + "host/linux-x86/apex/com.android.art/javalib/core2.jar", + "host/linux-x86/system/framework/framework.jar", + }, + imagePathOnHost: "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art", + imagePathOnDevice: "/system/framework/x86_64/boot-framework.art", + imagesDeps: []string{ + "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art", + "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat", + "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex", + }, + primaryImages: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", + primaryImagesDeps: []string{ + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat", + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex", + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art", + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat", + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex", + }, + installs: []normalizedInstall{ + { + from: "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art", + to: "/system/framework/x86_64/boot-framework.art", + }, + { + from: "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat", + to: "/system/framework/x86_64/boot-framework.oat", + }, + }, + vdexInstalls: []normalizedInstall{ + { + from: "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex", + to: "/system/framework/x86_64/boot-framework.vdex", + }, + }, + unstrippedInstalls: []normalizedInstall{ + { + from: "out/soong/test_device/dex_bootjars_unstripped/linux_glibc/system/framework/x86_64/boot-framework.oat", + to: "/system/framework/x86_64/boot-framework.oat", + }, + }, + licenseMetadataFile: expectedLicenseMetadataFile, + }, + { + archType: android.X86, + dexLocations: []string{"host/linux-x86/system/framework/framework.jar"}, + dexLocationsDeps: []string{ + "host/linux-x86/apex/com.android.art/javalib/core1.jar", + "host/linux-x86/apex/com.android.art/javalib/core2.jar", + "host/linux-x86/system/framework/framework.jar", + }, + imagePathOnHost: "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art", + imagePathOnDevice: "/system/framework/x86/boot-framework.art", + imagesDeps: []string{ + "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art", + "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat", + "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex", + }, + primaryImages: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", + primaryImagesDeps: []string{ + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat", + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex", + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art", + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat", + "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex", + }, + installs: []normalizedInstall{ + { + from: "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art", + to: "/system/framework/x86/boot-framework.art", + }, + { + from: "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat", + to: "/system/framework/x86/boot-framework.oat", + }, + }, + vdexInstalls: []normalizedInstall{ + { + from: "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex", + to: "/system/framework/x86/boot-framework.vdex", + }, + }, + unstrippedInstalls: []normalizedInstall{ + { + from: "out/soong/test_device/dex_bootjars_unstripped/linux_glibc/system/framework/x86/boot-framework.oat", + to: "/system/framework/x86/boot-framework.oat", + }, + }, + licenseMetadataFile: expectedLicenseMetadataFile, + }, + }, + profileInstalls: []normalizedInstall{ + {from: "out/soong/test_device/dex_bootjars/boot.bprof", to: "/system/etc/boot-image.bprof"}, + {from: "out/soong/test_device/dex_bootjars/boot.prof", to: "/system/etc/boot-image.prof"}, + }, + profileLicenseMetadataFile: expectedLicenseMetadataFile, + } + + checkBootImageConfig(t, imageConfig, mutated, expected) +} + +// clearMutatedFields clears fields in the expectedConfig that correspond to fields in the +// bootImageConfig/bootImageVariant structs which are mutated outside the call to +// genBootImageConfigs. +// +// This allows the resulting expectedConfig struct to be compared against the values of those boot +// image structs immediately the call to genBootImageConfigs. If this is not called then the +// expectedConfig struct will expect the boot image structs to have been mutated by the ART +// bootclasspath_fragment and the platform_bootclasspath. +func clearMutatedFields(expected *expectedConfig) { + expected.profileInstalls = nil + expected.profileLicenseMetadataFile = "" + for _, variant := range expected.variants { + variant.installs = nil + variant.vdexInstalls = nil + variant.unstrippedInstalls = nil + variant.licenseMetadataFile = "" + } +} + +// checkBootImageConfig checks a boot image against the expected contents. +// +// If mutated is false then this will clear any mutated fields in the expected contents back to the +// zero value so that they will match the unmodified values in the boot image. +// +// It runs the checks in an image specific subtest of the current test. +func checkBootImageConfig(t *testing.T, imageConfig *bootImageConfig, mutated bool, expected *expectedConfig) { + if !mutated { + clearMutatedFields(expected) + } + + t.Run(imageConfig.name, func(t *testing.T) { + nestedCheckBootImageConfig(t, imageConfig, expected) + }) +} + +// nestedCheckBootImageConfig does the work of comparing the image against the expected values and +// is run in an image specific subtest. +func nestedCheckBootImageConfig(t *testing.T, imageConfig *bootImageConfig, expected *expectedConfig) { + android.AssertStringEquals(t, "name", expected.name, imageConfig.name) + android.AssertStringEquals(t, "stem", expected.stem, imageConfig.stem) + android.AssertPathRelativeToTopEquals(t, "dir", expected.dir, imageConfig.dir) + android.AssertPathRelativeToTopEquals(t, "symbolsDir", expected.symbolsDir, imageConfig.symbolsDir) + android.AssertStringEquals(t, "installDirOnDevice", expected.installDirOnDevice, imageConfig.installDirOnDevice) + android.AssertStringEquals(t, "installDirOnHost", expected.installDirOnHost, imageConfig.installDirOnHost) + 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()) + // dexPathsByModule is just a different representation of the other information in the config. + android.AssertPathRelativeToTopEquals(t, "zip", expected.zip, imageConfig.zip) + assertInstallsEqual(t, "profileInstalls", expected.profileInstalls, imageConfig.profileInstalls) + android.AssertStringEquals(t, "profileLicenseMetadataFile", expected.profileLicenseMetadataFile, imageConfig.profileLicenseMetadataFile.RelativeToTop().String()) + + android.AssertIntEquals(t, "variant count", 4, len(imageConfig.variants)) + for i, variant := range imageConfig.variants { + expectedVariant := expected.variants[i] + t.Run(variant.target.Arch.ArchType.String(), func(t *testing.T) { + android.AssertDeepEquals(t, "archType", expectedVariant.archType, variant.target.Arch.ArchType) + android.AssertDeepEquals(t, "dexLocations", expectedVariant.dexLocations, variant.dexLocations) + android.AssertDeepEquals(t, "dexLocationsDeps", expectedVariant.dexLocationsDeps, variant.dexLocationsDeps) + android.AssertPathRelativeToTopEquals(t, "imagePathOnHost", expectedVariant.imagePathOnHost, variant.imagePathOnHost) + android.AssertStringEquals(t, "imagePathOnDevice", expectedVariant.imagePathOnDevice, variant.imagePathOnDevice) + android.AssertPathsRelativeToTopEquals(t, "imagesDeps", expectedVariant.imagesDeps, variant.imagesDeps.Paths()) + android.AssertPathRelativeToTopEquals(t, "primaryImages", expectedVariant.primaryImages, variant.primaryImages) + android.AssertPathsRelativeToTopEquals(t, "primaryImagesDeps", expectedVariant.primaryImagesDeps, variant.primaryImagesDeps) + assertInstallsEqual(t, "installs", expectedVariant.installs, variant.installs) + assertInstallsEqual(t, "vdexInstalls", expectedVariant.vdexInstalls, variant.vdexInstalls) + assertInstallsEqual(t, "unstrippedInstalls", expectedVariant.unstrippedInstalls, variant.unstrippedInstalls) + android.AssertStringEquals(t, "licenseMetadataFile", expectedVariant.licenseMetadataFile, variant.licenseMetadataFile.RelativeToTop().String()) + }) + } +} + +// CheckMutatedArtBootImageConfig checks the mutated fields in the bootImageConfig/Variant for ART. +func CheckMutatedArtBootImageConfig(t *testing.T, result *android.TestResult, expectedLicenseMetadataFile string) { + checkArtBootImageConfig(t, result, true, expectedLicenseMetadataFile) + + // Check the dexpreopt make vars. Do it in here as it depends on the expected license metadata + // file at the moment and it + checkDexpreoptMakeVars(t, result, expectedLicenseMetadataFile) +} + +// CheckMutatedFrameworkBootImageConfig checks the mutated fields in the bootImageConfig/Variant for framework. +func CheckMutatedFrameworkBootImageConfig(t *testing.T, result *android.TestResult, expectedLicenseMetadataFile string) { + checkFrameworkBootImageConfig(t, result, true, expectedLicenseMetadataFile) +} + +// checkDexpreoptMakeVars checks the DEXPREOPT_ prefixed make vars produced by dexpreoptBootJars +// singleton. +func checkDexpreoptMakeVars(t *testing.T, result *android.TestResult, expectedLicenseMetadataFile string) { + vars := result.MakeVarsForTesting(func(variable android.MakeVarVariable) bool { + return strings.HasPrefix(variable.Name(), "DEXPREOPT_") + }) + + out := &strings.Builder{} + for _, v := range vars { + fmt.Fprintf(out, "%s=%s\n", v.Name(), android.StringRelativeToTop(result.Config, v.Value())) + } + format := ` +DEXPREOPT_BOOTCLASSPATH_DEX_FILES=out/soong/test_device/dex_artjars_input/core1.jar out/soong/test_device/dex_artjars_input/core2.jar out/soong/test_device/dex_bootjars_input/framework.jar +DEXPREOPT_BOOTCLASSPATH_DEX_LOCATIONS=/apex/com.android.art/javalib/core1.jar /apex/com.android.art/javalib/core2.jar /system/framework/framework.jar +DEXPREOPT_BOOT_JARS_MODULES=platform:framework +DEXPREOPT_GEN=out/host/linux-x86/bin/dexpreopt_gen +DEXPREOPT_IMAGE_BUILT_INSTALLED_art_arm=out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art:/apex/art_boot_images/javalib/arm/boot.art out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat:/apex/art_boot_images/javalib/arm/boot.oat out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.art:/apex/art_boot_images/javalib/arm/boot-core2.art out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.oat:/apex/art_boot_images/javalib/arm/boot-core2.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_art_arm64=out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art:/apex/art_boot_images/javalib/arm64/boot.art out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat:/apex/art_boot_images/javalib/arm64/boot.oat out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art:/apex/art_boot_images/javalib/arm64/boot-core2.art out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat:/apex/art_boot_images/javalib/arm64/boot-core2.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_art_host_x86=out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art:/apex/art_boot_images/javalib/x86/boot.art out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat:/apex/art_boot_images/javalib/x86/boot.oat out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art:/apex/art_boot_images/javalib/x86/boot-core2.art out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat:/apex/art_boot_images/javalib/x86/boot-core2.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_art_host_x86_64=out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art:/apex/art_boot_images/javalib/x86_64/boot.art out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat:/apex/art_boot_images/javalib/x86_64/boot.oat out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art:/apex/art_boot_images/javalib/x86_64/boot-core2.art out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat:/apex/art_boot_images/javalib/x86_64/boot-core2.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_arm=out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.art:/system/framework/arm/boot-framework.art out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.oat:/system/framework/arm/boot-framework.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_arm64=out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.art:/system/framework/arm64/boot-framework.art out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.oat:/system/framework/arm64/boot-framework.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_host_x86=out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art:/system/framework/x86/boot-framework.art out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat:/system/framework/x86/boot-framework.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_host_x86_64=out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art:/system/framework/x86_64/boot-framework.art out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat:/system/framework/x86_64/boot-framework.oat +DEXPREOPT_IMAGE_DEPS_art_arm=out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.art out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.oat out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.vdex +DEXPREOPT_IMAGE_DEPS_art_arm64=out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex +DEXPREOPT_IMAGE_DEPS_art_host_x86=out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex +DEXPREOPT_IMAGE_DEPS_art_host_x86_64=out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex +DEXPREOPT_IMAGE_DEPS_boot_arm=out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.art out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.oat out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.vdex +DEXPREOPT_IMAGE_DEPS_boot_arm64=out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.art out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.oat out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.vdex +DEXPREOPT_IMAGE_DEPS_boot_host_x86=out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex +DEXPREOPT_IMAGE_DEPS_boot_host_x86_64=out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex +DEXPREOPT_IMAGE_LICENSE_METADATA_art_arm=%[1]s +DEXPREOPT_IMAGE_LICENSE_METADATA_art_arm64=%[1]s +DEXPREOPT_IMAGE_LICENSE_METADATA_art_host_x86=%[1]s +DEXPREOPT_IMAGE_LICENSE_METADATA_art_host_x86_64=%[1]s +DEXPREOPT_IMAGE_LICENSE_METADATA_boot_arm=out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/meta_lic +DEXPREOPT_IMAGE_LICENSE_METADATA_boot_arm64=out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/meta_lic +DEXPREOPT_IMAGE_LICENSE_METADATA_boot_host_x86=out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/meta_lic +DEXPREOPT_IMAGE_LICENSE_METADATA_boot_host_x86_64=out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/meta_lic +DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICEart=/system/framework/boot.art +DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICEboot=/system/framework/boot.art:/system/framework/boot-framework.art +DEXPREOPT_IMAGE_LOCATIONS_ON_HOSTart=out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/boot.art +DEXPREOPT_IMAGE_LOCATIONS_ON_HOSTboot=out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/boot.art:out/soong/test_device/dex_bootjars/android/system/framework/boot-framework.art +DEXPREOPT_IMAGE_NAMES=art boot +DEXPREOPT_IMAGE_PROFILE_BUILT_INSTALLED=out/soong/test_device/dex_bootjars/boot.bprof:/system/etc/boot-image.bprof out/soong/test_device/dex_bootjars/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/test_device/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm/boot.oat:/apex/art_boot_images/javalib/arm/boot.oat out/soong/test_device/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/test_device/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm64/boot.oat:/apex/art_boot_images/javalib/arm64/boot.oat out/soong/test_device/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm64/boot-core2.oat:/apex/art_boot_images/javalib/arm64/boot-core2.oat +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_art_host_x86=out/soong/test_device/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat:/apex/art_boot_images/javalib/x86/boot.oat out/soong/test_device/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat:/apex/art_boot_images/javalib/x86/boot-core2.oat +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_art_host_x86_64=out/soong/test_device/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat:/apex/art_boot_images/javalib/x86_64/boot.oat out/soong/test_device/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat:/apex/art_boot_images/javalib/x86_64/boot-core2.oat +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_arm=out/soong/test_device/dex_bootjars_unstripped/android/system/framework/arm/boot-framework.oat:/system/framework/arm/boot-framework.oat +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_arm64=out/soong/test_device/dex_bootjars_unstripped/android/system/framework/arm64/boot-framework.oat:/system/framework/arm64/boot-framework.oat +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_host_x86=out/soong/test_device/dex_bootjars_unstripped/linux_glibc/system/framework/x86/boot-framework.oat:/system/framework/x86/boot-framework.oat +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_host_x86_64=out/soong/test_device/dex_bootjars_unstripped/linux_glibc/system/framework/x86_64/boot-framework.oat:/system/framework/x86_64/boot-framework.oat +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_art_arm=out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex:/apex/art_boot_images/javalib/arm/boot.vdex out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.vdex:/apex/art_boot_images/javalib/arm/boot-core2.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_art_arm64=out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex:/apex/art_boot_images/javalib/arm64/boot.vdex out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex:/apex/art_boot_images/javalib/arm64/boot-core2.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_art_host_x86=out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex:/apex/art_boot_images/javalib/x86/boot.vdex out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex:/apex/art_boot_images/javalib/x86/boot-core2.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_art_host_x86_64=out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex:/apex/art_boot_images/javalib/x86_64/boot.vdex out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex:/apex/art_boot_images/javalib/x86_64/boot-core2.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_arm=out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.vdex:/system/framework/arm/boot-framework.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_arm64=out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.vdex:/system/framework/arm64/boot-framework.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_host_x86=out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex:/system/framework/x86/boot-framework.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_host_x86_64=out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex:/system/framework/x86_64/boot-framework.vdex +DEXPREOPT_IMAGE_ZIP_art=out/soong/test_device/dex_artjars/art.zip +DEXPREOPT_IMAGE_ZIP_boot=out/soong/test_device/dex_bootjars/boot.zip +DEXPREOPT_IMAGE_art_arm=out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art +DEXPREOPT_IMAGE_art_arm64=out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art +DEXPREOPT_IMAGE_art_host_x86=out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art +DEXPREOPT_IMAGE_art_host_x86_64=out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art +DEXPREOPT_IMAGE_boot_arm=out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.art +DEXPREOPT_IMAGE_boot_arm64=out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.art +DEXPREOPT_IMAGE_boot_host_x86=out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art +DEXPREOPT_IMAGE_boot_host_x86_64=out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art +` + expected := strings.TrimSpace(fmt.Sprintf(format, expectedLicenseMetadataFile)) + actual := strings.TrimSpace(out.String()) + android.AssertStringEquals(t, "vars", expected, actual) +} diff --git a/java/testing.go b/java/testing.go index 1f411913b..49430ee05 100644 --- a/java/testing.go +++ b/java/testing.go @@ -393,6 +393,7 @@ func gatherRequiredDepsForTest() string { aidl: { export_include_dirs: ["framework/aidl"], }, + compile_dex: true, } android_app { diff --git a/sdk/bootclasspath_fragment_sdk_test.go b/sdk/bootclasspath_fragment_sdk_test.go index 4be0ace68..6faa0c5b9 100644 --- a/sdk/bootclasspath_fragment_sdk_test.go +++ b/sdk/bootclasspath_fragment_sdk_test.go @@ -17,6 +17,7 @@ package sdk import ( "fmt" "path/filepath" + "strings" "testing" "android/soong/android" @@ -80,7 +81,7 @@ func TestSnapshotWithBootclasspathFragment_ImageName(t *testing.T) { // Add a platform_bootclasspath that depends on the fragment. fixtureAddPlatformBootclasspathForBootclasspathFragment("com.android.art", "mybootclasspathfragment"), - java.FixtureConfigureBootJars("com.android.art:mybootlib"), + java.PrepareForBootImageConfigTest, android.FixtureWithRootAndroidBp(` sdk { name: "mysdk", @@ -99,7 +100,7 @@ func TestSnapshotWithBootclasspathFragment_ImageName(t *testing.T) { bootclasspath_fragment { name: "mybootclasspathfragment", image_name: "art", - contents: ["mybootlib"], + contents: ["core1", "core2"], apex_available: ["com.android.art"], hidden_api: { split_packages: ["*"], @@ -113,19 +114,32 @@ func TestSnapshotWithBootclasspathFragment_ImageName(t *testing.T) { } java_library { - name: "mybootlib", + name: "core1", srcs: ["Test.java"], system_modules: "none", sdk_version: "none", compile_dex: true, apex_available: ["com.android.art"], } - `), + + java_library { + name: "core2", + srcs: ["Test.java"], + system_modules: "none", + sdk_version: "none", + compile_dex: true, + apex_available: ["com.android.art"], + } +`), ).RunTest(t) // A preparer to update the test fixture used when processing an unpackage snapshot. preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("com.android.art", "mybootclasspathfragment") + // Check that source on its own configures the bootImageConfig correctly. + java.CheckMutatedArtBootImageConfig(t, result, "out/soong/.intermediates/mybootclasspathfragment/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", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -136,7 +150,10 @@ prebuilt_bootclasspath_fragment { visibility: ["//visibility:public"], apex_available: ["com.android.art"], image_name: "art", - contents: ["mybootlib"], + contents: [ + "core1", + "core2", + ], hidden_api: { annotation_flags: "hiddenapi/annotation-flags.csv", metadata: "hiddenapi/metadata.csv", @@ -148,11 +165,19 @@ prebuilt_bootclasspath_fragment { } java_import { - name: "mybootlib", + name: "core1", prefer: false, visibility: ["//visibility:public"], apex_available: ["com.android.art"], - jars: ["java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar"], + jars: ["java_boot_libs/snapshot/jars/are/invalid/core1.jar"], +} + +java_import { + name: "core2", + prefer: false, + visibility: ["//visibility:public"], + apex_available: ["com.android.art"], + jars: ["java_boot_libs/snapshot/jars/are/invalid/core2.jar"], } `), checkAllCopyRules(` @@ -162,31 +187,55 @@ java_import { .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/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar +.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 `), snapshotTestPreparer(checkSnapshotWithoutSource, preparerForSnapshot), // Check the behavior of the snapshot without the source. snapshotTestChecker(checkSnapshotWithoutSource, func(t *testing.T, result *android.TestResult) { - // Make sure that the boot jars package check rule includes the dex jar retrieved from the prebuilt apex. - checkBootJarsPackageCheckRule(t, result, "out/soong/.intermediates/prebuilts/apex/com.android.art.deapexer/android_common/deapexer/javalib/mybootlib.jar") + // Make sure that the boot jars package check rule includes the dex jars retrieved from the prebuilt apex. + checkBootJarsPackageCheckRule(t, result, + "out/soong/.intermediates/prebuilts/apex/com.android.art.deapexer/android_common/deapexer/javalib/core1.jar", + "out/soong/.intermediates/prebuilts/apex/com.android.art.deapexer/android_common/deapexer/javalib/core2.jar", + "out/soong/.intermediates/default/java/framework/android_common/aligned/framework.jar") + java.CheckMutatedArtBootImageConfig(t, result, "out/soong/.intermediates/snapshot/mybootclasspathfragment/android_common_com.android.art/meta_lic") + java.CheckMutatedFrameworkBootImageConfig(t, result, "out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/meta_lic") }), snapshotTestPreparer(checkSnapshotWithSourcePreferred, preparerForSnapshot), + + // 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.CheckMutatedFrameworkBootImageConfig(t, result, "out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/meta_lic") + }), + snapshotTestPreparer(checkSnapshotPreferredWithSource, preparerForSnapshot), + + // Check the behavior of the snapshot when it is preferred. + snapshotTestChecker(checkSnapshotPreferredWithSource, func(t *testing.T, result *android.TestResult) { + // TODO - the expectedLicenseMetadataFile passed here is incorrect as it is for the source module not the prebuilt module. + java.CheckMutatedArtBootImageConfig(t, result, "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/meta_lic") + java.CheckMutatedFrameworkBootImageConfig(t, result, "out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/meta_lic") + }), ) - // Make sure that the boot jars package check rule includes the dex jar created from the source. - checkBootJarsPackageCheckRule(t, result, "out/soong/.intermediates/mybootlib/android_common_apex10000/aligned/mybootlib.jar") + // Make sure that the boot jars package check rule includes the dex jars created from the source. + checkBootJarsPackageCheckRule(t, result, + "out/soong/.intermediates/core1/android_common_apex10000/aligned/core1.jar", + "out/soong/.intermediates/core2/android_common_apex10000/aligned/core2.jar", + "out/soong/.intermediates/default/java/framework/android_common/aligned/framework.jar") } // checkBootJarsPackageCheckRule checks that the supplied module is an input to the boot jars // package check rule. -func checkBootJarsPackageCheckRule(t *testing.T, result *android.TestResult, expectedModule string) { +func checkBootJarsPackageCheckRule(t *testing.T, result *android.TestResult, expectedModules ...string) { + t.Helper() platformBcp := result.ModuleForTests("platform-bootclasspath", "android_common") bootJarsCheckRule := platformBcp.Rule("boot_jars_package_check") command := bootJarsCheckRule.RuleParams.Command - expectedCommandArgs := " out/soong/host/linux-x86/bin/dexdump build/soong/scripts/check_boot_jars/package_allowed_list.txt " + expectedModule + " &&" + expectedCommandArgs := " build/soong/scripts/check_boot_jars/package_allowed_list.txt " + strings.Join(expectedModules, " ") + " &&" android.AssertStringDoesContain(t, "boot jars package check", command, expectedCommandArgs) } From 308fa1e56f0e9e4d6a1a56c1b6569cc24606c2fb Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 4 Oct 2022 20:01:04 +0100 Subject: [PATCH 086/172] Prevent bootImageVariant.licenseMetadataFile being set twice Previously, in a build containing source and prebuilt art bootclasspath_fragments, the bootImageVariant.licenseMetadataFile was set twice with the source always being set after the prebuilt and so winning. This change only sets bootImageVariant.licenseMetadataFile for the active module so it will use the prebuilt's license file if that is preferred. Bug: 245956352 Test: m nothing Change-Id: I948c7e5123169452f67c85ad98c4bbdb90a5d2de (cherry picked from commit 20d90e3e51ae85abb8c4133b19197201cae84ed1) Merged-In: I948c7e5123169452f67c85ad98c4bbdb90a5d2de --- java/dexpreopt_bootjars.go | 7 ++++++- sdk/bootclasspath_fragment_sdk_test.go | 3 +-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go index 323423d0a..2deb47252 100644 --- a/java/dexpreopt_bootjars.go +++ b/java/dexpreopt_bootjars.go @@ -809,10 +809,15 @@ func buildBootImageVariant(ctx android.ModuleContext, image *bootImageVariant, p rule.Build(image.name+"JarsDexpreopt_"+image.target.String(), "dexpreopt "+image.name+" jars "+arch.String()) // save output and installed files for makevars + // TODO - these are always the same and so should be initialized in genBootImageConfigs image.installs = rule.Installs() image.vdexInstalls = vdexInstalls image.unstrippedInstalls = unstrippedInstalls - image.licenseMetadataFile = android.OptionalPathForPath(ctx.LicenseMetadataFile()) + + // Only set the licenseMetadataFile from the active module. + if isActiveModule(ctx.Module()) { + image.licenseMetadataFile = android.OptionalPathForPath(ctx.LicenseMetadataFile()) + } return bootImageVariantOutputs{ image, diff --git a/sdk/bootclasspath_fragment_sdk_test.go b/sdk/bootclasspath_fragment_sdk_test.go index 6faa0c5b9..1b64130ce 100644 --- a/sdk/bootclasspath_fragment_sdk_test.go +++ b/sdk/bootclasspath_fragment_sdk_test.go @@ -215,8 +215,7 @@ java_import { // Check the behavior of the snapshot when it is preferred. snapshotTestChecker(checkSnapshotPreferredWithSource, func(t *testing.T, result *android.TestResult) { - // TODO - the expectedLicenseMetadataFile passed here is incorrect as it is for the source module not the prebuilt module. - java.CheckMutatedArtBootImageConfig(t, result, "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/meta_lic") + java.CheckMutatedArtBootImageConfig(t, result, "out/soong/.intermediates/snapshot/prebuilt_mybootclasspathfragment/android_common_com.android.art/meta_lic") java.CheckMutatedFrameworkBootImageConfig(t, result, "out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/meta_lic") }), ) From e1d7e7bda33f443d0a63ec6adbb721b7f63b700f Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 7 Oct 2022 12:21:14 +0100 Subject: [PATCH 087/172] Add TestPathContext Bug: 245956352 Test: m nothing Change-Id: I008c9379f4d9420b532513b33b4e295818cb9a0d Merged-In: I4997039003242b43e0e52ccf41729acb4ad11324 --- android/fixture.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/android/fixture.go b/android/fixture.go index 9cb26d69e..3a15ad3a5 100644 --- a/android/fixture.go +++ b/android/fixture.go @@ -630,6 +630,20 @@ type TestResult struct { NinjaDeps []string } +type TestPathContext struct { + *TestResult +} + +var _ PathContext = &TestPathContext{} + +func (t *TestPathContext) Config() Config { + return t.TestResult.Config +} + +func (t *TestPathContext) AddNinjaFileDeps(deps ...string) { + panic("unimplemented") +} + func createFixture(t *testing.T, buildDir string, preparers []*simpleFixturePreparer) Fixture { config := TestConfig(buildDir, nil, "", nil) ctx := NewTestContext(config) From 5961b2b0040bba1a7bf18870ab4a6bd3ac2b8bb1 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 6 Oct 2022 21:38:24 +0100 Subject: [PATCH 088/172] Skip TestBootImageConfig on non-Linux platforms Bug: 245956352 Test: m nothing Change-Id: I4c0bfd24febd308d8efa62da9603795a7e5ed222 (cherry picked from commit 3a56f5e0e0fdf366d34d661913bff708315bd951) Merged-In: I4c0bfd24febd308d8efa62da9603795a7e5ed222 --- java/dexpreopt_config_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/java/dexpreopt_config_test.go b/java/dexpreopt_config_test.go index eaa6a8c22..e64cb4846 100644 --- a/java/dexpreopt_config_test.go +++ b/java/dexpreopt_config_test.go @@ -15,12 +15,19 @@ package java import ( + "log" + "runtime" "testing" "android/soong/android" ) func TestBootImageConfig(t *testing.T) { + if runtime.GOOS != "linux" { + log.Printf("Skipping as boot image config test is only supported on linux not %s", runtime.GOOS) + return + } + result := android.GroupFixturePreparers( PrepareForBootImageConfigTest, ).RunTest(t) From a5319364ecc2559990744f0cf0d2f8ea289abfa1 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 7 Oct 2022 11:46:31 +0100 Subject: [PATCH 089/172] Properly skip TestBootImageConfig on non-Linux platforms Bug: 245956352 Test: m nothing Change-Id: I6402573b378eee77d802829ec5dfacf4c514d3b8 (cherry picked from commit 85d8bdc10e08d992fccee67b4708d728d5bc8705) Merged-In: I6402573b378eee77d802829ec5dfacf4c514d3b8 --- java/dexpreopt_config_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/java/dexpreopt_config_test.go b/java/dexpreopt_config_test.go index e64cb4846..b704d09d2 100644 --- a/java/dexpreopt_config_test.go +++ b/java/dexpreopt_config_test.go @@ -15,7 +15,6 @@ package java import ( - "log" "runtime" "testing" @@ -24,8 +23,7 @@ import ( func TestBootImageConfig(t *testing.T) { if runtime.GOOS != "linux" { - log.Printf("Skipping as boot image config test is only supported on linux not %s", runtime.GOOS) - return + t.Skipf("Skipping as boot image config test is only supported on linux not %s", runtime.GOOS) } result := android.GroupFixturePreparers( From dd5beebf4bb6225797495f5126cd52b758afa68c Mon Sep 17 00:00:00 2001 From: Dennis Shen Date: Mon, 17 Oct 2022 19:21:55 +0000 Subject: [PATCH 090/172] update and create bundle config pb python library update config.pb file to the source of truth: google3/third_party/java_src/android_appbundle/bundletool/schemas/proto/config.proto current config.pb is stale and needs update. Also, add a python library host soong module config_proto, so that it can be used by other python code. BUG: b/240288941 TETS: tested along with primary_train_build_worker that reuse BundleConfig.pb Change-Id: I426a5cb7ec42573ed2110494c50813abc0a96296 --- cmd/extract_apks/bundle_proto/Android.bp | 13 ++ cmd/extract_apks/bundle_proto/config.proto | 152 ++++++++++++++++++++- 2 files changed, 158 insertions(+), 7 deletions(-) create mode 100644 cmd/extract_apks/bundle_proto/Android.bp diff --git a/cmd/extract_apks/bundle_proto/Android.bp b/cmd/extract_apks/bundle_proto/Android.bp new file mode 100644 index 000000000..e56c0fb32 --- /dev/null +++ b/cmd/extract_apks/bundle_proto/Android.bp @@ -0,0 +1,13 @@ +package { + default_applicable_licenses: ["Android-Apache-2.0"], +} + +python_library_host { + name: "config_proto", + srcs: [ + "config.proto", + ], + proto: { + canonical_path_from_root: false, + }, +} diff --git a/cmd/extract_apks/bundle_proto/config.proto b/cmd/extract_apks/bundle_proto/config.proto index d6fac030e..946bd9af0 100644 --- a/cmd/extract_apks/bundle_proto/config.proto +++ b/cmd/extract_apks/bundle_proto/config.proto @@ -26,6 +26,9 @@ message BundleConfig { ASSET_ONLY = 2; } BundleType type = 8; + + // Configuration for locales. + Locales locales = 9; } message Bundletool { @@ -40,6 +43,48 @@ message Compression { // the name of the modules, and using forward slash ("/") as a name separator. // Examples: "res/raw/**", "assets/**/*.uncompressed", etc. repeated string uncompressed_glob = 1; + + enum AssetModuleCompression { + UNSPECIFIED = 0; + // Assets are left uncompressed in the generated asset module. + UNCOMPRESSED = 1; + // Assets are compressed in the generated asset module. + // This option can be overridden at a finer granularity by specifying + // files or folders to keep uncompressed in `uncompressed_glob`. + // This option should only be used if the app is able to handle compressed + // asset module content at runtime (some runtime APIs may misbehave). + COMPRESSED = 2; + } + + // Default compression strategy for install-time asset modules. + // If the compression strategy indicates to compress a file and the same file + // matches one of the `uncompressed_glob` values, the `uncompressed_glob` + // takes precedence (the file is left uncompressed in the generated APK). + // + // If unspecified, asset module content is left uncompressed in the + // generated asset modules. + // + // Note: this flag only configures the compression strategy for install-time + // asset modules; the content of on-demand and fast-follow asset modules is + // always kept uncompressed. + AssetModuleCompression install_time_asset_module_default_compression = 2; + + enum ApkCompressionAlgorithm { + // Default in the current version of bundletool is zlib deflate algorithm + // with compression level 9 for the application's resources and compression + // level 6 for other entries. + // + // This is a good trade-off between size of final APK and size of patches + // which are used to update the application from previous to next version. + DEFAULT_APK_COMPRESSION_ALGORITHM = 0; + + // 7zip implementation of deflate algorithm which gives smaller APK size + // but size of patches required to update the application are larger. + P7ZIP = 1; + } + + // Compression algorithm which is used to compress entries in final APKs. + ApkCompressionAlgorithm apk_compression_algorithm = 3; } // Resources to keep in the master split. @@ -55,12 +100,40 @@ message Optimizations { // This is for uncompressing native libraries on M+ devices (L+ devices on // instant apps). UncompressNativeLibraries uncompress_native_libraries = 2; - // This is for uncompressing dex files on P+ devices. + // This is for uncompressing dex files. UncompressDexFiles uncompress_dex_files = 3; // Configuration for the generation of standalone APKs. // If no StandaloneConfig is set, the configuration is inherited from // splits_config. StandaloneConfig standalone_config = 4; + + // Optimizations that are applied to resources. + ResourceOptimizations resource_optimizations = 5; + + // Configuration for archiving the app. + StoreArchive store_archive = 6; +} + +message ResourceOptimizations { + // Whether to use sparse encoding for resource tables. + // Resources in sparse resource table are accessed using a binary search tree. + // This decreases APK size at the cost of resource retrieval performance. + SparseEncoding sparse_encoding = 1; + + enum SparseEncoding { + // Previously 'ENFORCED'. This option is deprecated because of issues found + // in Android O up to Android Sv2 and causes segfaults in + // Resources#getIdentifier. + reserved 1; + reserved "ENFORCED"; + + // Disables sparse encoding. + UNSPECIFIED = 0; + // Generates special APKs for Android SDK +32 with sparse resource tables. + // Devices with Android SDK below 32 will still receive APKs with regular + // resource tables. + VARIANT_FOR_SDK_32 = 2; + } } message UncompressNativeLibraries { @@ -68,7 +141,39 @@ message UncompressNativeLibraries { } message UncompressDexFiles { + // A new variant with uncompressed dex will be generated. The sdk targeting + // of the variant is determined by 'uncompressed_dex_target_sdk'. bool enabled = 1; + + // If 'enabled' field is set, this will determine the sdk targeting of the + // generated variant. + UncompressedDexTargetSdk uncompressed_dex_target_sdk = 2; + + enum UncompressedDexTargetSdk { + // Q+ variant will be generated. + UNSPECIFIED = 0; + // S+ variant will be generated. + SDK_31 = 1; + } +} + +message StoreArchive { + // Archive is an app state that allows an official app store to reclaim device + // storage and disable app functionality temporarily until the user interacts + // with the app again. Upon interaction the latest available version of the + // app will be restored while leaving user data unaffected. + // Enabled by default. + bool enabled = 1; +} + +message Locales { + // Instructs bundletool to generate locale config and inject it into + // AndroidManifest.xml. A locale is marked as supported by the application if + // there is at least one resource value in this locale. Be very careful with + // this setting because if some of your libraries expose resources in some + // locales which are not actually supported by your application it will mark + // this locale as supported. Disabled by default. + bool inject_locale_config = 1; } // Optimization configuration used to generate Split APKs. @@ -82,8 +187,28 @@ message StandaloneConfig { repeated SplitDimension split_dimension = 1; // Whether 64 bit libraries should be stripped from Standalone APKs. bool strip_64_bit_libraries = 2; + // Dex merging strategy that should be applied to produce Standalone APKs. + DexMergingStrategy dex_merging_strategy = 3; + + enum DexMergingStrategy { + // Strategy that does dex merging for applications that have minimum SDK + // below 21 to ensure dex files from all modules are merged into one or + // mainDexList is applied when merging into one dex is not possible. For + // applications with minSdk >= 21 dex files from all modules are copied into + // standalone APK as is because Android supports multiple dex files natively + // starting from Android 5.0. + MERGE_IF_NEEDED = 0; + // Requires to copy dex files from all modules into standalone APK as is. + // If an application supports SDKs below 21 this strategy puts + // responsibility of providing dex files compatible with legacy multidex on + // application developers. + NEVER_MERGE = 1; + } } +// BEGIN-INTERNAL +// LINT.IfChange +// END-INTERNAL message SplitDimension { enum Value { UNSPECIFIED_VALUE = 0; @@ -92,8 +217,9 @@ message SplitDimension { LANGUAGE = 3; TEXTURE_COMPRESSION_FORMAT = 4; // BEGIN-INTERNAL - GRAPHICS_API = 5; + GRAPHICS_API = 5 [deprecated = true]; // END-INTERNAL + DEVICE_TIER = 6; } Value value = 1; @@ -105,11 +231,14 @@ message SplitDimension { // the targeting is encoded in the directory name (e.g: assets/foo#tcf_etc1) SuffixStripping suffix_stripping = 3; } +// BEGIN-INTERNAL +// LINT.ThenChange(//depot/google3/wireless/android/vending/developer/proto/storage/app/apk_bundle.proto) +// END-INTERNAL message SuffixStripping { // If set to 'true', indicates that the targeting suffix should be removed - // from assets paths for this dimension when splits (or asset slices) are - // generated. + // from assets paths for this dimension when splits (e.g: "asset packs") or + // standalone/universal APKs are generated. // This only applies to assets. // For example a folder with path "assets/level1_textures#tcf_etc1" // would be outputted to "assets/level1_textures". File contents are @@ -117,9 +246,9 @@ message SuffixStripping { bool enabled = 1; // The default suffix to be used for the cases where separate slices can't - // be generated for this dimension. In the case of standalone/universal APKs - // generation, stripping the suffix can lead to file name collisions. This - // default suffix defines the directories to retain. The others are + // be generated for this dimension - typically for standalone or universal + // APKs. + // This default suffix defines the directories to retain. The others are // discarded: standalone/universal APKs will contain only directories // targeted at this value for the dimension. // @@ -135,6 +264,15 @@ message SuffixStripping { message ApexConfig { // Configuration for processing of APKs embedded in an APEX image. repeated ApexEmbeddedApkConfig apex_embedded_apk_config = 1; + + // Explicit list of supported ABIs. + // Default: See ApexBundleValidator.REQUIRED_ONE_OF_ABI_SETS + repeated SupportedAbiSet supported_abi_set = 2; +} + +// Represents a set of ABIs which must be supported by a single APEX image. +message SupportedAbiSet { + repeated string abi = 1; } message ApexEmbeddedApkConfig { From 7829ec96b87dd74f88a8f7ed4eb4833c185bf3a4 Mon Sep 17 00:00:00 2001 From: Jon Bottarini Date: Wed, 19 Oct 2022 03:13:14 +0000 Subject: [PATCH 091/172] spelling/grammar fix Change-Id: I4522ec1c457c7d98adc2820faa457b2bb7cb517a --- fuzz/fuzz_common.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fuzz/fuzz_common.go b/fuzz/fuzz_common.go index 5e5769bf1..801176e3a 100644 --- a/fuzz/fuzz_common.go +++ b/fuzz/fuzz_common.go @@ -122,9 +122,9 @@ type FuzzConfig struct { // context from: // https://source.android.com/security/overview/updates-resources#context_types. Privilege_level PrivilegedLevel `json:"privilege_level,omitempty"` - // Can the fuzzed code isolated or can be called by multiple users/processes. + // Is the fuzzed code isolated or can it be called by multiple users/processes. Isolated *bool `json:"users_isolation,omitempty"` - // When code was relaeased or will be released. + // When code was released or will be released. Production_date string `json:"production_date,omitempty"` // Prevents critical service functionality like phone calls, bluetooth, etc. Critical *bool `json:"critical,omitempty"` @@ -134,7 +134,7 @@ type FuzzConfig struct { Fuzz_on_haiku_host *bool `json:"fuzz_on_haiku_host,omitempty"` // Component in Google's bug tracking system that bugs should be filed to. Componentid *int64 `json:"componentid,omitempty"` - // Hotlists in Google's bug tracking system that bugs should be marked with. + // Hotlist(s) in Google's bug tracking system that bugs should be marked with. Hotlists []string `json:"hotlists,omitempty"` // Specify whether this fuzz target was submitted by a researcher. Defaults // to false. From 6146d668fd4e63c5068b222ac8e854c2b1e6419a Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 30 Sep 2022 15:44:45 -0700 Subject: [PATCH 092/172] Removed unused GCC references Remove Toolchain.GccRoot, Toolchain.GccVersion, and Toolchain.GccTriple that were only used by an unused function. This removes most of the references to GCC, although there are still some left in the host toolchains. Test: No change to build.ninja for aosp_cf_x86_64_phone-userdebug or aosp_raven-userdebug Change-Id: I72b8af1f9aa83e6e15c9e00ed1e817b6cc3a031a Merged-In: I72b8af1f9aa83e6e15c9e00ed1e817b6cc3a031a (cherry picked from commit 4fa894d366533605063b28e10b7063e364a6ef92) --- cc/builder.go | 4 --- cc/config/arm64_device.go | 25 ++--------------- cc/config/arm_device.go | 45 ++++++++++-------------------- cc/config/darwin_host.go | 34 ---------------------- cc/config/toolchain.go | 5 ---- cc/config/x86_64_device.go | 24 +--------------- cc/config/x86_device.go | 21 -------------- cc/config/x86_linux_bionic_host.go | 21 ++++++-------- cc/config/x86_linux_host.go | 12 -------- cc/config/x86_windows_host.go | 16 ++--------- cc/makevars.go | 2 -- 11 files changed, 27 insertions(+), 182 deletions(-) diff --git a/cc/builder.go b/cc/builder.go index ea06839a9..c390a93ed 100644 --- a/cc/builder.go +++ b/cc/builder.go @@ -1151,7 +1151,3 @@ func transformArchiveRepack(ctx android.ModuleContext, inputFile android.Path, }, }) } - -func mingwCmd(toolchain config.Toolchain, cmd string) string { - return filepath.Join(toolchain.GccRoot(), "bin", toolchain.GccTriple()+"-"+cmd) -} diff --git a/cc/config/arm64_device.go b/cc/config/arm64_device.go index 66087e6f0..d7f96183a 100644 --- a/cc/config/arm64_device.go +++ b/cc/config/arm64_device.go @@ -74,7 +74,7 @@ var ( "-mcpu=kryo", }, "kryo385": []string{ - // Use cortex-a53 because kryo385 is not supported in GCC/clang. + // Use cortex-a53 because kryo385 is not supported in clang. "-mcpu=cortex-a53", }, "exynos-m1": []string{ @@ -86,16 +86,7 @@ var ( } ) -const ( - arm64GccVersion = "4.9" -) - func init() { - pctx.StaticVariable("arm64GccVersion", arm64GccVersion) - - pctx.SourcePathVariable("Arm64GccRoot", - "prebuilts/gcc/${HostPrebuiltTag}/aarch64/aarch64-linux-android-${arm64GccVersion}") - exportedVars.ExportStringListStaticVariable("Arm64Ldflags", arm64Ldflags) exportedVars.ExportStringListStaticVariable("Arm64Lldflags", arm64Lldflags) @@ -164,24 +155,12 @@ func (t *toolchainArm64) Name() string { return "arm64" } -func (t *toolchainArm64) GccRoot() string { - return "${config.Arm64GccRoot}" -} - -func (t *toolchainArm64) GccTriple() string { - return "aarch64-linux-android" -} - -func (t *toolchainArm64) GccVersion() string { - return arm64GccVersion -} - func (t *toolchainArm64) IncludeFlags() string { return "" } func (t *toolchainArm64) ClangTriple() string { - return t.GccTriple() + return "aarch64-linux-android" } func (t *toolchainArm64) Cflags() string { diff --git a/cc/config/arm_device.go b/cc/config/arm_device.go index d702c6145..b53a09782 100644 --- a/cc/config/arm_device.go +++ b/cc/config/arm_device.go @@ -79,7 +79,7 @@ var ( "cortex-a7": []string{ "-mcpu=cortex-a7", "-mfpu=neon-vfpv4", - // Fake an ARM compiler flag as these processors support LPAE which GCC/clang + // Fake an ARM compiler flag as these processors support LPAE which clang // don't advertise. // TODO This is a hack and we need to add it for each processor that supports LPAE until some // better solution comes around. See Bug 27340895 @@ -91,7 +91,7 @@ var ( "cortex-a15": []string{ "-mcpu=cortex-a15", "-mfpu=neon-vfpv4", - // Fake an ARM compiler flag as these processors support LPAE which GCC/clang + // Fake an ARM compiler flag as these processors support LPAE which clang // don't advertise. // TODO This is a hack and we need to add it for each processor that supports LPAE until some // better solution comes around. See Bug 27340895 @@ -100,7 +100,7 @@ var ( "cortex-a53": []string{ "-mcpu=cortex-a53", "-mfpu=neon-fp-armv8", - // Fake an ARM compiler flag as these processors support LPAE which GCC/clang + // Fake an ARM compiler flag as these processors support LPAE which clang // don't advertise. // TODO This is a hack and we need to add it for each processor that supports LPAE until some // better solution comes around. See Bug 27340895 @@ -109,7 +109,7 @@ var ( "cortex-a55": []string{ "-mcpu=cortex-a55", "-mfpu=neon-fp-armv8", - // Fake an ARM compiler flag as these processors support LPAE which GCC/clang + // Fake an ARM compiler flag as these processors support LPAE which clang // don't advertise. // TODO This is a hack and we need to add it for each processor that supports LPAE until some // better solution comes around. See Bug 27340895 @@ -118,7 +118,7 @@ var ( "cortex-a75": []string{ "-mcpu=cortex-a55", "-mfpu=neon-fp-armv8", - // Fake an ARM compiler flag as these processors support LPAE which GCC/clang + // Fake an ARM compiler flag as these processors support LPAE which clang // don't advertise. // TODO This is a hack and we need to add it for each processor that supports LPAE until some // better solution comes around. See Bug 27340895 @@ -127,7 +127,7 @@ var ( "cortex-a76": []string{ "-mcpu=cortex-a55", "-mfpu=neon-fp-armv8", - // Fake an ARM compiler flag as these processors support LPAE which GCC/clang + // Fake an ARM compiler flag as these processors support LPAE which clang // don't advertise. // TODO This is a hack and we need to add it for each processor that supports LPAE until some // better solution comes around. See Bug 27340895 @@ -136,7 +136,7 @@ var ( "krait": []string{ "-mcpu=krait", "-mfpu=neon-vfpv4", - // Fake an ARM compiler flag as these processors support LPAE which GCC/clang + // Fake an ARM compiler flag as these processors support LPAE which clang // don't advertise. // TODO This is a hack and we need to add it for each processor that supports LPAE until some // better solution comes around. See Bug 27340895 @@ -147,16 +147,16 @@ var ( // even though clang does. "-mcpu=cortex-a53", "-mfpu=neon-fp-armv8", - // Fake an ARM compiler flag as these processors support LPAE which GCC/clang + // Fake an ARM compiler flag as these processors support LPAE which clang // don't advertise. // TODO This is a hack and we need to add it for each processor that supports LPAE until some // better solution comes around. See Bug 27340895 "-D__ARM_FEATURE_LPAE=1", }, "kryo385": []string{ - // Use cortex-a53 because kryo385 is not supported in GCC/clang. + // Use cortex-a53 because kryo385 is not supported in clang. "-mcpu=cortex-a53", - // Fake an ARM compiler flag as these processors support LPAE which GCC/clang + // Fake an ARM compiler flag as these processors support LPAE which clang // don't advertise. // TODO This is a hack and we need to add it for each processor that supports LPAE until some // better solution comes around. See Bug 27340895 @@ -166,17 +166,12 @@ var ( ) const ( - name = "arm" - armGccVersion = "4.9" - gccTriple = "arm-linux-androideabi" - clangTriple = "armv7a-linux-androideabi" + name = "arm" + ndkTriple = "arm-linux-androideabi" + clangTriple = "armv7a-linux-androideabi" ) func init() { - pctx.StaticVariable("armGccVersion", armGccVersion) - - pctx.SourcePathVariable("ArmGccRoot", "prebuilts/gcc/${HostPrebuiltTag}/arm/arm-linux-androideabi-${armGccVersion}") - // Just exported. Not created as a Ninja static variable. exportedVars.ExportString("ArmClangTriple", clangTriple) @@ -255,18 +250,6 @@ func (t *toolchainArm) Name() string { return name } -func (t *toolchainArm) GccRoot() string { - return "${config.ArmGccRoot}" -} - -func (t *toolchainArm) GccTriple() string { - return gccTriple -} - -func (t *toolchainArm) GccVersion() string { - return armGccVersion -} - func (t *toolchainArm) IncludeFlags() string { return "" } @@ -278,7 +261,7 @@ func (t *toolchainArm) ClangTriple() string { func (t *toolchainArm) ndkTriple() string { // Use current NDK include path, while ClangTriple is changed. - return t.GccTriple() + return ndkTriple } func (t *toolchainArm) ToolchainCflags() string { diff --git a/cc/config/darwin_host.go b/cc/config/darwin_host.go index 5e3f7c7d6..1667ad7c1 100644 --- a/cc/config/darwin_host.go +++ b/cc/config/darwin_host.go @@ -75,10 +75,6 @@ var ( ) ) -const ( - darwinGccVersion = "4.2.1" -) - func init() { pctx.VariableFunc("macSdkRoot", func(ctx android.PackageVarContext) string { return getMacTools(ctx).sdkRoot @@ -100,12 +96,6 @@ func init() { return getMacTools(ctx).toolPath }) - pctx.StaticVariable("DarwinGccVersion", darwinGccVersion) - pctx.SourcePathVariable("DarwinGccRoot", - "prebuilts/gcc/${HostPrebuiltTag}/host/i686-apple-darwin-${DarwinGccVersion}") - - pctx.StaticVariable("DarwinGccTriple", "i686-apple-darwin11") - pctx.StaticVariable("DarwinCflags", strings.Join(darwinCflags, " ")) pctx.StaticVariable("DarwinLdflags", strings.Join(darwinLdflags, " ")) pctx.StaticVariable("DarwinLldflags", strings.Join(darwinLdflags, " ")) @@ -194,30 +184,6 @@ func (t *toolchainDarwinX86) Name() string { return "x86_64" } -func (t *toolchainDarwinArm) GccRoot() string { - panic("unimplemented") -} - -func (t *toolchainDarwinArm) GccTriple() string { - panic("unimplemented") -} - -func (t *toolchainDarwinArm) GccVersion() string { - panic("unimplemented") -} - -func (t *toolchainDarwinX86) GccRoot() string { - return "${config.DarwinGccRoot}" -} - -func (t *toolchainDarwinX86) GccTriple() string { - return "${config.DarwinGccTriple}" -} - -func (t *toolchainDarwinX86) GccVersion() string { - return darwinGccVersion -} - func (t *toolchainDarwin) IncludeFlags() string { return "" } diff --git a/cc/config/toolchain.go b/cc/config/toolchain.go index 7175fdc1a..e78e16a4b 100644 --- a/cc/config/toolchain.go +++ b/cc/config/toolchain.go @@ -72,11 +72,6 @@ func findToolchain(os android.OsType, arch android.Arch) (Toolchain, error) { type Toolchain interface { Name() string - GccRoot() string - GccTriple() string - // GccVersion should return a real value, not a ninja reference - GccVersion() string - IncludeFlags() string ClangTriple() string diff --git a/cc/config/x86_64_device.go b/cc/config/x86_64_device.go index aebda0b51..e2b0f062a 100644 --- a/cc/config/x86_64_device.go +++ b/cc/config/x86_64_device.go @@ -80,17 +80,7 @@ var ( } ) -const ( - x86_64GccVersion = "4.9" -) - func init() { - - pctx.StaticVariable("x86_64GccVersion", x86_64GccVersion) - - pctx.SourcePathVariable("X86_64GccRoot", - "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${x86_64GccVersion}") - exportedVars.ExportStringListStaticVariable("X86_64ToolchainCflags", []string{"-m64"}) exportedVars.ExportStringListStaticVariable("X86_64ToolchainLdflags", []string{"-m64"}) @@ -128,24 +118,12 @@ func (t *toolchainX86_64) Name() string { return "x86_64" } -func (t *toolchainX86_64) GccRoot() string { - return "${config.X86_64GccRoot}" -} - -func (t *toolchainX86_64) GccTriple() string { - return "x86_64-linux-android" -} - -func (t *toolchainX86_64) GccVersion() string { - return x86_64GccVersion -} - func (t *toolchainX86_64) IncludeFlags() string { return "" } func (t *toolchainX86_64) ClangTriple() string { - return t.GccTriple() + return "x86_64-linux-android" } func (t *toolchainX86_64) ToolchainLdflags() string { diff --git a/cc/config/x86_device.go b/cc/config/x86_device.go index 421b08354..3001ab405 100644 --- a/cc/config/x86_device.go +++ b/cc/config/x86_device.go @@ -88,16 +88,7 @@ var ( } ) -const ( - x86GccVersion = "4.9" -) - func init() { - pctx.StaticVariable("x86GccVersion", x86GccVersion) - - pctx.SourcePathVariable("X86GccRoot", - "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${x86GccVersion}") - exportedVars.ExportStringListStaticVariable("X86ToolchainCflags", []string{"-m32"}) exportedVars.ExportStringListStaticVariable("X86ToolchainLdflags", []string{"-m32"}) @@ -134,18 +125,6 @@ func (t *toolchainX86) Name() string { return "x86" } -func (t *toolchainX86) GccRoot() string { - return "${config.X86GccRoot}" -} - -func (t *toolchainX86) GccTriple() string { - return "x86_64-linux-android" -} - -func (t *toolchainX86) GccVersion() string { - return x86GccVersion -} - func (t *toolchainX86) IncludeFlags() string { return "" } diff --git a/cc/config/x86_linux_bionic_host.go b/cc/config/x86_linux_bionic_host.go index 976cc25be..96a53bff3 100644 --- a/cc/config/x86_linux_bionic_host.go +++ b/cc/config/x86_linux_bionic_host.go @@ -66,13 +66,20 @@ var ( "host_bionic_linker_script") ) +const ( + x86_64GccVersion = "4.9" +) + func init() { + pctx.StaticVariable("LinuxBionicCflags", strings.Join(linuxBionicCflags, " ")) pctx.StaticVariable("LinuxBionicLdflags", strings.Join(linuxBionicLdflags, " ")) pctx.StaticVariable("LinuxBionicLldflags", strings.Join(linuxBionicLdflags, " ")) // Use the device gcc toolchain for now - pctx.StaticVariable("LinuxBionicGccRoot", "${X86_64GccRoot}") + pctx.StaticVariable("LinuxBionicGccVersion", x86_64GccVersion) + pctx.SourcePathVariable("LinuxBionicGccRoot", + "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${LinuxBionicGccVersion}") } type toolchainLinuxBionic struct { @@ -84,18 +91,6 @@ func (t *toolchainLinuxBionic) Name() string { return "x86_64" } -func (t *toolchainLinuxBionic) GccRoot() string { - return "${config.LinuxBionicGccRoot}" -} - -func (t *toolchainLinuxBionic) GccTriple() string { - return "x86_64-linux-android" -} - -func (t *toolchainLinuxBionic) GccVersion() string { - return "4.9" -} - func (t *toolchainLinuxBionic) IncludeFlags() string { return "" } diff --git a/cc/config/x86_linux_host.go b/cc/config/x86_linux_host.go index 4e8fd7752..d928838ff 100644 --- a/cc/config/x86_linux_host.go +++ b/cc/config/x86_linux_host.go @@ -179,18 +179,6 @@ func (t *toolchainLinuxX8664) Name() string { return "x86_64" } -func (t *toolchainLinux) GccRoot() string { - return "${config.LinuxGccRoot}" -} - -func (t *toolchainLinux) GccTriple() string { - return "${config.LinuxGccTriple}" -} - -func (t *toolchainLinux) GccVersion() string { - return linuxGccVersion -} - func (t *toolchainLinux) IncludeFlags() string { return "" } diff --git a/cc/config/x86_windows_host.go b/cc/config/x86_windows_host.go index 2c8321100..565128037 100644 --- a/cc/config/x86_windows_host.go +++ b/cc/config/x86_windows_host.go @@ -173,24 +173,12 @@ func (t *toolchainWindowsX8664) Name() string { return "x86_64" } -func (t *toolchainWindows) GccRoot() string { - return "${config.WindowsGccRoot}" -} - -func (t *toolchainWindows) GccTriple() string { - return "${config.WindowsGccTriple}" -} - func (t *toolchainWindows) ToolchainCflags() string { - return "-B" + filepath.Join(t.GccRoot(), t.GccTriple(), "bin") + return "-B" + filepath.Join("${config.WindowsGccRoot}", "${config.WindowsGccTriple}", "bin") } func (t *toolchainWindows) ToolchainLdflags() string { - return "-B" + filepath.Join(t.GccRoot(), t.GccTriple(), "bin") -} - -func (t *toolchainWindows) GccVersion() string { - return windowsGccVersion + return "-B" + filepath.Join("${config.WindowsGccRoot}", "${config.WindowsGccTriple}", "bin") } func (t *toolchainWindows) IncludeFlags() string { diff --git a/cc/makevars.go b/cc/makevars.go index 6752f8cde..e4a9cf7ff 100644 --- a/cc/makevars.go +++ b/cc/makevars.go @@ -315,8 +315,6 @@ func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string, ctx.Strict(makePrefix+"LD", "${config.ClangBin}/lld") ctx.Strict(makePrefix+"NDK_TRIPLE", config.NDKTriple(toolchain)) ctx.Strict(makePrefix+"TOOLS_PREFIX", "${config.ClangBin}/llvm-") - // TODO: GCC version is obsolete now that GCC has been removed. - ctx.Strict(makePrefix+"GCC_VERSION", toolchain.GccVersion()) } if target.Os.Class == android.Host { From 93dd40bffa2e9c12f6e8782fa7432751ca66ddec Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 14 Jul 2022 18:10:34 -0700 Subject: [PATCH 093/172] Add riscv64-linux-android support Add barebones riscv64-linux-android support. This should be enough to add riscv64-specific entries to Android.bp files, but can't actually compile anything until there are riscv64 toolchains. Test: arch_test.go Change-Id: I0dcc7e797d9352dd38243be908a7f19004ff3db1 Merged-In: I0dcc7e797d9352dd38243be908a7f19004ff3db1 (cherry picked from commit f05b0d35d2fbe51be9961ce8ce8031f840295c68) --- android/arch.go | 11 +- android/arch_test.go | 1 + bazel/configurability.go | 14 +- bp2build/build_conversion_test.go | 5 + bp2build/cc_library_static_conversion_test.go | 20 +++ cc/config/Android.bp | 1 + cc/config/riscv64_device.go | 140 ++++++++++++++++++ rust/config/Android.bp | 1 + rust/config/riscv64_device.go | 91 ++++++++++++ 9 files changed, 274 insertions(+), 10 deletions(-) create mode 100644 cc/config/riscv64_device.go create mode 100644 rust/config/riscv64_device.go diff --git a/android/arch.go b/android/arch.go index 483e2dcc4..655b00832 100644 --- a/android/arch.go +++ b/android/arch.go @@ -146,10 +146,11 @@ const COMMON_VARIANT = "common" var ( archTypeList []ArchType - Arm = newArch("arm", "lib32") - Arm64 = newArch("arm64", "lib64") - X86 = newArch("x86", "lib32") - X86_64 = newArch("x86_64", "lib64") + Arm = newArch("arm", "lib32") + Arm64 = newArch("arm64", "lib64") + Riscv64 = newArch("riscv64", "lib64") + X86 = newArch("x86", "lib32") + X86_64 = newArch("x86_64", "lib64") Common = ArchType{ Name: COMMON_VARIANT, @@ -317,7 +318,7 @@ var ( Windows = newOsType("windows", Host, true, X86, X86_64) // Android is the OS for target devices that run all of Android, including the Linux kernel // and the Bionic libc runtime. - Android = newOsType("android", Device, false, Arm, Arm64, X86, X86_64) + Android = newOsType("android", Device, false, Arm, Arm64, Riscv64, X86, X86_64) // CommonOS is a pseudo OSType for a common OS variant, which is OsType agnostic and which // has dependencies on all the OS variants. diff --git a/android/arch_test.go b/android/arch_test.go index dd0b11515..8b328b6ac 100644 --- a/android/arch_test.go +++ b/android/arch_test.go @@ -495,6 +495,7 @@ func TestArchProperties(t *testing.T) { arm64: { a: ["arm64"], }, + riscv64: { a: ["riscv64"] }, x86: { a: ["x86"] }, x86_64: { a: ["x86_64"] }, }, diff --git a/bazel/configurability.go b/bazel/configurability.go index 7355ac7d3..e5c142917 100644 --- a/bazel/configurability.go +++ b/bazel/configurability.go @@ -21,10 +21,11 @@ import ( const ( // ArchType names in arch.go - archArm = "arm" - archArm64 = "arm64" - archX86 = "x86" - archX86_64 = "x86_64" + archArm = "arm" + archArm64 = "arm64" + archRiscv64 = "riscv64" + archX86 = "x86" + archX86_64 = "x86_64" // OsType names in arch.go osAndroid = "android" @@ -37,6 +38,7 @@ const ( // Targets in arch.go osArchAndroidArm = "android_arm" osArchAndroidArm64 = "android_arm64" + osArchAndroidRiscv64 = "android_riscv64" osArchAndroidX86 = "android_x86" osArchAndroidX86_64 = "android_x86_64" osArchDarwinArm64 = "darwin_arm64" @@ -75,6 +77,7 @@ var ( platformArchMap = map[string]string{ archArm: "//build/bazel/platforms/arch:arm", archArm64: "//build/bazel/platforms/arch:arm64", + archRiscv64: "//build/bazel/platforms/arch:riscv64", archX86: "//build/bazel/platforms/arch:x86", archX86_64: "//build/bazel/platforms/arch:x86_64", ConditionsDefaultConfigKey: ConditionsDefaultSelectKey, // The default condition of as arch select map. @@ -95,6 +98,7 @@ var ( platformOsArchMap = map[string]string{ osArchAndroidArm: "//build/bazel/platforms/os_arch:android_arm", osArchAndroidArm64: "//build/bazel/platforms/os_arch:android_arm64", + osArchAndroidRiscv64: "//build/bazel/platforms/os_arch:android_riscv64", osArchAndroidX86: "//build/bazel/platforms/os_arch:android_x86", osArchAndroidX86_64: "//build/bazel/platforms/os_arch:android_x86_64", osArchDarwinArm64: "//build/bazel/platforms/os_arch:darwin_arm64", @@ -116,7 +120,7 @@ var ( // TODO(cparsons): Source from arch.go; this task is nontrivial, as it currently results // in a cyclic dependency. osToArchMap = map[string][]string{ - osAndroid: {archArm, archArm64, archX86, archX86_64}, + osAndroid: {archArm, archArm64, archRiscv64, archX86, archX86_64}, osLinux: {archX86, archX86_64}, osLinuxMusl: {archX86, archX86_64}, osDarwin: {archArm64, archX86_64}, diff --git a/bp2build/build_conversion_test.go b/bp2build/build_conversion_test.go index 0f3ca79b5..7c83109e6 100644 --- a/bp2build/build_conversion_test.go +++ b/bp2build/build_conversion_test.go @@ -323,6 +323,7 @@ custom { x86_64: { arch_paths: ["x86_64.txt"] }, arm: { arch_paths: ["arm.txt"] }, arm64: { arch_paths: ["arm64.txt"] }, + riscv64: { arch_paths: ["riscv64.txt"] }, }, target: { linux: { arch_paths: ["linux.txt"] }, @@ -355,6 +356,10 @@ custom { "arm64.txt", "lib64.txt", ], + "//build/bazel/platforms/arch:riscv64": [ + "riscv64.txt", + "lib64.txt", + ], "//build/bazel/platforms/arch:x86": [ "x86.txt", "lib32.txt", diff --git a/bp2build/cc_library_static_conversion_test.go b/bp2build/cc_library_static_conversion_test.go index be10e866d..70c34c001 100644 --- a/bp2build/cc_library_static_conversion_test.go +++ b/bp2build/cc_library_static_conversion_test.go @@ -835,6 +835,10 @@ cc_library_static { "not-for-lib32.c", "for-lib64.c", ], + "//build/bazel/platforms/arch:riscv64": [ + "not-for-lib32.c", + "for-lib64.c", + ], "//build/bazel/platforms/arch:x86": [ "not-for-lib64.c", "for-lib32.c", @@ -866,6 +870,7 @@ func TestCcLibrarySTaticArchMultilibSrcsExcludeSrcs(t *testing.T) { "for-lib64.c": "", "not-for-arm.c": "", "not-for-arm64.c": "", + "not-for-riscv64.c": "", "not-for-x86.c": "", "not-for-x86_64.c": "", "not-for-lib32.c": "", @@ -880,6 +885,7 @@ cc_library_static { arch: { arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] }, arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] }, + riscv64: { srcs: ["for-riscv64.c"], exclude_srcs: ["not-for-riscv64.c"] }, x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] }, x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] }, }, @@ -895,6 +901,7 @@ cc_library_static { "//build/bazel/platforms/arch:arm": [ "not-for-arm64.c", "not-for-lib64.c", + "not-for-riscv64.c", "not-for-x86.c", "not-for-x86_64.c", "for-arm.c", @@ -903,15 +910,26 @@ cc_library_static { "//build/bazel/platforms/arch:arm64": [ "not-for-arm.c", "not-for-lib32.c", + "not-for-riscv64.c", "not-for-x86.c", "not-for-x86_64.c", "for-arm64.c", "for-lib64.c", ], + "//build/bazel/platforms/arch:riscv64": [ + "not-for-arm.c", + "not-for-arm64.c", + "not-for-lib32.c", + "not-for-x86.c", + "not-for-x86_64.c", + "for-riscv64.c", + "for-lib64.c", + ], "//build/bazel/platforms/arch:x86": [ "not-for-arm.c", "not-for-arm64.c", "not-for-lib64.c", + "not-for-riscv64.c", "not-for-x86_64.c", "for-x86.c", "for-lib32.c", @@ -920,6 +938,7 @@ cc_library_static { "not-for-arm.c", "not-for-arm64.c", "not-for-lib32.c", + "not-for-riscv64.c", "not-for-x86.c", "for-x86_64.c", "for-lib64.c", @@ -929,6 +948,7 @@ cc_library_static { "not-for-arm64.c", "not-for-lib32.c", "not-for-lib64.c", + "not-for-riscv64.c", "not-for-x86.c", "not-for-x86_64.c", ], diff --git a/cc/config/Android.bp b/cc/config/Android.bp index 1a21c1361..de163d9d3 100644 --- a/cc/config/Android.bp +++ b/cc/config/Android.bp @@ -21,6 +21,7 @@ bootstrap_go_package { "arm_device.go", "arm64_device.go", + "riscv64_device.go", "x86_device.go", "x86_64_device.go", diff --git a/cc/config/riscv64_device.go b/cc/config/riscv64_device.go new file mode 100644 index 000000000..d8918f164 --- /dev/null +++ b/cc/config/riscv64_device.go @@ -0,0 +1,140 @@ +// Copyright 2022 Google Inc. All rights reserved. +// +// 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 config + +import ( + "fmt" + "strings" + + "android/soong/android" +) + +var ( + riscv64Cflags = []string{ + // Help catch common 32/64-bit errors. + "-Werror=implicit-function-declaration", + } + + riscv64ArchVariantCflags = map[string][]string{} + + riscv64Ldflags = []string{ + "-Wl,--hash-style=gnu", + "-Wl,-z,separate-code", + } + + riscv64Lldflags = append(riscv64Ldflags, + "-Wl,-z,max-page-size=4096") + + riscv64Cppflags = []string{} + + riscv64CpuVariantCflags = map[string][]string{} +) + +const () + +func init() { + + exportedVars.ExportStringListStaticVariable("Riscv64Ldflags", riscv64Ldflags) + exportedVars.ExportStringListStaticVariable("Riscv64Lldflags", riscv64Lldflags) + + exportedVars.ExportStringListStaticVariable("Riscv64Cflags", riscv64Cflags) + exportedVars.ExportStringListStaticVariable("Riscv64Cppflags", riscv64Cppflags) + + exportedVars.ExportVariableReferenceDict("Riscv64ArchVariantCflags", riscv64ArchVariantCflagsVar) + exportedVars.ExportVariableReferenceDict("Riscv64CpuVariantCflags", riscv64CpuVariantCflagsVar) + exportedVars.ExportVariableReferenceDict("Riscv64CpuVariantLdflags", riscv64CpuVariantLdflags) +} + +var ( + riscv64ArchVariantCflagsVar = map[string]string{} + + riscv64CpuVariantCflagsVar = map[string]string{} + + riscv64CpuVariantLdflags = map[string]string{} +) + +type toolchainRiscv64 struct { + toolchainBionic + toolchain64Bit + + ldflags string + lldflags string + toolchainCflags string +} + +func (t *toolchainRiscv64) Name() string { + return "riscv64" +} + +func (t *toolchainRiscv64) IncludeFlags() string { + return "" +} + +func (t *toolchainRiscv64) ClangTriple() string { + return "riscv64-linux-android" +} + +func (t *toolchainRiscv64) Cflags() string { + return "${config.Riscv64Cflags}" +} + +func (t *toolchainRiscv64) Cppflags() string { + return "${config.Riscv64Cppflags}" +} + +func (t *toolchainRiscv64) Ldflags() string { + return t.ldflags +} + +func (t *toolchainRiscv64) Lldflags() string { + return t.lldflags +} + +func (t *toolchainRiscv64) ToolchainCflags() string { + return t.toolchainCflags +} + +func (toolchainRiscv64) LibclangRuntimeLibraryArch() string { + return "riscv64" +} + +func riscv64ToolchainFactory(arch android.Arch) Toolchain { + switch arch.ArchVariant { + case "": + default: + panic(fmt.Sprintf("Unknown Riscv64 architecture version: %q", arch.ArchVariant)) + } + + toolchainCflags := []string{riscv64ArchVariantCflagsVar[arch.ArchVariant]} + toolchainCflags = append(toolchainCflags, + variantOrDefault(riscv64CpuVariantCflagsVar, arch.CpuVariant)) + + extraLdflags := variantOrDefault(riscv64CpuVariantLdflags, arch.CpuVariant) + return &toolchainRiscv64{ + ldflags: strings.Join([]string{ + "${config.Riscv64Ldflags}", + extraLdflags, + }, " "), + lldflags: strings.Join([]string{ + "${config.Riscv64Lldflags}", + extraLdflags, + }, " "), + toolchainCflags: strings.Join(toolchainCflags, " "), + } +} + +func init() { + registerToolchainFactory(android.Android, android.Riscv64, riscv64ToolchainFactory) +} diff --git a/rust/config/Android.bp b/rust/config/Android.bp index 7757c79fc..e07d39b06 100644 --- a/rust/config/Android.bp +++ b/rust/config/Android.bp @@ -14,6 +14,7 @@ bootstrap_go_package { "arm64_device.go", "global.go", "lints.go", + "riscv64_device.go", "toolchain.go", "allowed_list.go", "darwin_host.go", diff --git a/rust/config/riscv64_device.go b/rust/config/riscv64_device.go new file mode 100644 index 000000000..3b41a10ad --- /dev/null +++ b/rust/config/riscv64_device.go @@ -0,0 +1,91 @@ +// Copyright 2022 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 config + +import ( + "strings" + + "android/soong/android" +) + +var ( + Riscv64RustFlags = []string{} + Riscv64ArchFeatureRustFlags = map[string][]string{"": {}} + Riscv64LinkFlags = []string{} + + Riscv64ArchVariantRustFlags = map[string][]string{} +) + +func init() { + registerToolchainFactory(android.Android, android.Riscv64, Riscv64ToolchainFactory) + + pctx.StaticVariable("Riscv64ToolchainRustFlags", strings.Join(Riscv64RustFlags, " ")) + pctx.StaticVariable("Riscv64ToolchainLinkFlags", strings.Join(Riscv64LinkFlags, " ")) + + for variant, rustFlags := range Riscv64ArchVariantRustFlags { + pctx.StaticVariable("Riscv64"+variant+"VariantRustFlags", + strings.Join(rustFlags, " ")) + } + +} + +type toolchainRiscv64 struct { + toolchain64Bit + toolchainRustFlags string +} + +func (t *toolchainRiscv64) RustTriple() string { + return "riscv64-linux-android" +} + +func (t *toolchainRiscv64) ToolchainLinkFlags() string { + // Prepend the lld flags from cc_config so we stay in sync with cc + return "${config.DeviceGlobalLinkFlags} ${cc_config.Riscv64Lldflags} ${config.Riscv64ToolchainLinkFlags}" +} + +func (t *toolchainRiscv64) ToolchainRustFlags() string { + return t.toolchainRustFlags +} + +func (t *toolchainRiscv64) RustFlags() string { + return "${config.Riscv64ToolchainRustFlags}" +} + +func (t *toolchainRiscv64) Supported() bool { + return true +} + +func (toolchainRiscv64) LibclangRuntimeLibraryArch() string { + return "riscv64" +} + +func Riscv64ToolchainFactory(arch android.Arch) Toolchain { + archVariant := arch.ArchVariant + + toolchainRustFlags := []string{ + "${config.Riscv64ToolchainRustFlags}", + "${config.Riscv64" + archVariant + "VariantRustFlags}", + } + + toolchainRustFlags = append(toolchainRustFlags, deviceGlobalRustFlags...) + + for _, feature := range arch.ArchFeatures { + toolchainRustFlags = append(toolchainRustFlags, Riscv64ArchFeatureRustFlags[feature]...) + } + + return &toolchainRiscv64{ + toolchainRustFlags: strings.Join(toolchainRustFlags, " "), + } +} From eb5e9fcc3ccab4161415a7c4e75aae4de33c311c Mon Sep 17 00:00:00 2001 From: Chen Guoyin Date: Wed, 12 Oct 2022 19:28:48 +0800 Subject: [PATCH 094/172] Add riscv64 support for apex prebuilt This add support for src field in bp file. Signed-off-by: Chen Guoyin Signed-off-by: Mao Han Change-Id: I9393696951db375d53436f9d5a9841b6a072cea3 Merged-In: I9393696951db375d53436f9d5a9841b6a072cea3 (cherry picked from commit 401f298e50cab8171f84e2ce04929a5fc1f20d97) --- apex/prebuilt.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apex/prebuilt.go b/apex/prebuilt.go index 172a2012d..609a9d297 100644 --- a/apex/prebuilt.go +++ b/apex/prebuilt.go @@ -500,6 +500,9 @@ type ApexFileProperties struct { Arm64 struct { Src *string `android:"path"` } + Riscv64 struct { + Src *string `android:"path"` + } X86 struct { Src *string `android:"path"` } @@ -527,6 +530,8 @@ func (p *ApexFileProperties) prebuiltApexSelector(ctx android.BaseModuleContext, src = String(p.Arch.Arm.Src) case android.Arm64: src = String(p.Arch.Arm64.Src) + case android.Riscv64: + src = String(p.Arch.Riscv64.Src) case android.X86: src = String(p.Arch.X86.Src) case android.X86_64: From de18343487ad1656610b61e02f8005aef340a8e6 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 3 Oct 2022 12:41:50 -0700 Subject: [PATCH 095/172] Fix panics when target arch is riscv64 Fix panics in api_level.go and apex.go when using riscv64 as the target arch. Bug: 250918230 Test: lunch aosp_riscv64-userdebug && m ALLOW_MISSING_DEPENDENCIES=true nothing Change-Id: I85c7685f3d14fa2dc7ffbcdea7f490feca304ef7 Merged-In: I85c7685f3d14fa2dc7ffbcdea7f490feca304ef7 (cherry picked from commit a2aaa2fdefa8496820a6e9910765b8f2de2020b2) --- apex/apex.go | 5 +++++ cc/api_level.go | 2 ++ java/app_set.go | 9 +++++---- rust/config/riscv64_device.go | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index 125177551..71efb9763 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -284,6 +284,9 @@ type apexArchBundleProperties struct { Arm64 struct { ApexNativeDependencies } + Riscv64 struct { + ApexNativeDependencies + } X86 struct { ApexNativeDependencies } @@ -784,6 +787,8 @@ func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) { depsList = append(depsList, a.archProperties.Arch.Arm.ApexNativeDependencies) case android.Arm64: depsList = append(depsList, a.archProperties.Arch.Arm64.ApexNativeDependencies) + case android.Riscv64: + depsList = append(depsList, a.archProperties.Arch.Riscv64.ApexNativeDependencies) case android.X86: depsList = append(depsList, a.archProperties.Arch.X86.ApexNativeDependencies) case android.X86_64: diff --git a/cc/api_level.go b/cc/api_level.go index fd145a9e2..8c2b2c2ac 100644 --- a/cc/api_level.go +++ b/cc/api_level.go @@ -28,6 +28,8 @@ func minApiForArch(ctx android.BaseModuleContext, return ctx.Config().MinSupportedSdkVersion() case android.Arm64, android.X86_64: return android.FirstLp64Version + case android.Riscv64: + return android.FutureApiLevel default: panic(fmt.Errorf("Unknown arch %q", arch)) } diff --git a/java/app_set.go b/java/app_set.go index 694b1670e..d99fadb34 100644 --- a/java/app_set.go +++ b/java/app_set.go @@ -90,10 +90,11 @@ func (as *AndroidAppSet) APKCertsFile() android.Path { } var TargetCpuAbi = map[string]string{ - "arm": "ARMEABI_V7A", - "arm64": "ARM64_V8A", - "x86": "X86", - "x86_64": "X86_64", + "arm": "ARMEABI_V7A", + "arm64": "ARM64_V8A", + "riscv64": "RISCV64", + "x86": "X86", + "x86_64": "X86_64", } func SupportedAbis(ctx android.ModuleContext) []string { diff --git a/rust/config/riscv64_device.go b/rust/config/riscv64_device.go index 3b41a10ad..d014dbf8b 100644 --- a/rust/config/riscv64_device.go +++ b/rust/config/riscv64_device.go @@ -25,7 +25,7 @@ var ( Riscv64ArchFeatureRustFlags = map[string][]string{"": {}} Riscv64LinkFlags = []string{} - Riscv64ArchVariantRustFlags = map[string][]string{} + Riscv64ArchVariantRustFlags = map[string][]string{"": {}} ) func init() { From 04e6dfbfaff7d477b974c2c8b6603c359804324e Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 2 Nov 2022 13:14:20 -0700 Subject: [PATCH 096/172] Add exclude_* properties to apex arch-specific properties The libcronet prebuilt JNI library doesn't exist for riscv64 yet. Add exclude_* properties to apex arch-specific properties so that the libcronet dependency can be excluded from the apex that contains when the arch is riscv64 until it exists for riscv64. Test: TestApexWithArch Change-Id: Ic395a077824f0f60b90178530fbfae8a96b3782f Merged-In: Ic395a077824f0f60b90178530fbfae8a96b3782f (cherry picked from commit 70572ed01e21fa8e2d37221b59ca914ead4fa93d) --- apex/apex.go | 87 ++++++++++++++++++++++++++++++++++------------- apex/apex_test.go | 16 +++++++++ 2 files changed, 79 insertions(+), 24 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index 71efb9763..e176388ae 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -222,7 +222,7 @@ type ApexNativeDependencies struct { // List of JNI libraries that are embedded inside this APEX. Jni_libs []string - // List of rust dyn libraries + // List of rust dyn libraries that are embedded inside this APEX. Rust_dyn_libs []string // List of native executables that are embedded inside this APEX. @@ -233,6 +233,41 @@ type ApexNativeDependencies struct { // List of filesystem images that are embedded inside this APEX bundle. Filesystems []string + + // List of native libraries to exclude from this APEX. + Exclude_native_shared_libs []string + + // List of JNI libraries to exclude from this APEX. + Exclude_jni_libs []string + + // List of rust dyn libraries to exclude from this APEX. + Exclude_rust_dyn_libs []string + + // List of native executables to exclude from this APEX. + Exclude_binaries []string + + // List of native tests to exclude from this APEX. + Exclude_tests []string + + // List of filesystem images to exclude from this APEX bundle. + Exclude_filesystems []string +} + +// Merge combines another ApexNativeDependencies into this one +func (a *ApexNativeDependencies) Merge(b ApexNativeDependencies) { + a.Native_shared_libs = append(a.Native_shared_libs, b.Native_shared_libs...) + a.Jni_libs = append(a.Jni_libs, b.Jni_libs...) + a.Rust_dyn_libs = append(a.Rust_dyn_libs, b.Rust_dyn_libs...) + a.Binaries = append(a.Binaries, b.Binaries...) + a.Tests = append(a.Tests, b.Tests...) + a.Filesystems = append(a.Filesystems, b.Filesystems...) + + a.Exclude_native_shared_libs = append(a.Exclude_native_shared_libs, b.Exclude_native_shared_libs...) + a.Exclude_jni_libs = append(a.Exclude_jni_libs, b.Exclude_jni_libs...) + a.Exclude_rust_dyn_libs = append(a.Exclude_rust_dyn_libs, b.Exclude_rust_dyn_libs...) + a.Exclude_binaries = append(a.Exclude_binaries, b.Exclude_binaries...) + a.Exclude_tests = append(a.Exclude_tests, b.Exclude_tests...) + a.Exclude_filesystems = append(a.Exclude_filesystems, b.Exclude_filesystems...) } type apexMultilibProperties struct { @@ -671,12 +706,18 @@ func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeM // Use *FarVariation* to be able to depend on modules having conflicting variations with // this module. This is required since arch variant of an APEX bundle is 'common' but it is // 'arm' or 'arm64' for native shared libs. - ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...) - ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...) - ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...) - ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...) - ctx.AddFarVariationDependencies(rustLibVariations, sharedLibTag, nativeModules.Rust_dyn_libs...) - ctx.AddFarVariationDependencies(target.Variations(), fsTag, nativeModules.Filesystems...) + ctx.AddFarVariationDependencies(binVariations, executableTag, + android.RemoveListFromList(nativeModules.Binaries, nativeModules.Exclude_binaries)...) + ctx.AddFarVariationDependencies(binVariations, testTag, + android.RemoveListFromList(nativeModules.Tests, nativeModules.Exclude_tests)...) + ctx.AddFarVariationDependencies(libVariations, jniLibTag, + android.RemoveListFromList(nativeModules.Jni_libs, nativeModules.Exclude_jni_libs)...) + ctx.AddFarVariationDependencies(libVariations, sharedLibTag, + android.RemoveListFromList(nativeModules.Native_shared_libs, nativeModules.Exclude_native_shared_libs)...) + ctx.AddFarVariationDependencies(rustLibVariations, sharedLibTag, + android.RemoveListFromList(nativeModules.Rust_dyn_libs, nativeModules.Exclude_rust_dyn_libs)...) + ctx.AddFarVariationDependencies(target.Variations(), fsTag, + android.RemoveListFromList(nativeModules.Filesystems, nativeModules.Exclude_filesystems)...) } func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) { @@ -744,12 +785,12 @@ func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) { continue } - var depsList []ApexNativeDependencies + var deps ApexNativeDependencies // Add native modules targeting both ABIs. When multilib.* is omitted for // native_shared_libs/jni_libs/tests, it implies multilib.both - depsList = append(depsList, a.properties.Multilib.Both) - depsList = append(depsList, ApexNativeDependencies{ + deps.Merge(a.properties.Multilib.Both) + deps.Merge(ApexNativeDependencies{ Native_shared_libs: a.properties.Native_shared_libs, Tests: a.properties.Tests, Jni_libs: a.properties.Jni_libs, @@ -760,8 +801,8 @@ func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) { // binaries, it implies multilib.first isPrimaryAbi := i == 0 if isPrimaryAbi { - depsList = append(depsList, a.properties.Multilib.First) - depsList = append(depsList, ApexNativeDependencies{ + deps.Merge(a.properties.Multilib.First) + deps.Merge(ApexNativeDependencies{ Native_shared_libs: nil, Tests: nil, Jni_libs: nil, @@ -772,34 +813,32 @@ func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) { // Add native modules targeting either 32-bit or 64-bit ABI switch target.Arch.ArchType.Multilib { case "lib32": - depsList = append(depsList, a.properties.Multilib.Lib32) - depsList = append(depsList, a.properties.Multilib.Prefer32) + deps.Merge(a.properties.Multilib.Lib32) + deps.Merge(a.properties.Multilib.Prefer32) case "lib64": - depsList = append(depsList, a.properties.Multilib.Lib64) + deps.Merge(a.properties.Multilib.Lib64) if !has32BitTarget { - depsList = append(depsList, a.properties.Multilib.Prefer32) + deps.Merge(a.properties.Multilib.Prefer32) } } // Add native modules targeting a specific arch variant switch target.Arch.ArchType { case android.Arm: - depsList = append(depsList, a.archProperties.Arch.Arm.ApexNativeDependencies) + deps.Merge(a.archProperties.Arch.Arm.ApexNativeDependencies) case android.Arm64: - depsList = append(depsList, a.archProperties.Arch.Arm64.ApexNativeDependencies) + deps.Merge(a.archProperties.Arch.Arm64.ApexNativeDependencies) case android.Riscv64: - depsList = append(depsList, a.archProperties.Arch.Riscv64.ApexNativeDependencies) + deps.Merge(a.archProperties.Arch.Riscv64.ApexNativeDependencies) case android.X86: - depsList = append(depsList, a.archProperties.Arch.X86.ApexNativeDependencies) + deps.Merge(a.archProperties.Arch.X86.ApexNativeDependencies) case android.X86_64: - depsList = append(depsList, a.archProperties.Arch.X86_64.ApexNativeDependencies) + deps.Merge(a.archProperties.Arch.X86_64.ApexNativeDependencies) default: panic(fmt.Errorf("unsupported arch %v\n", ctx.Arch().ArchType)) } - for _, d := range depsList { - addDependenciesForNativeModules(ctx, d, target, imageVariation) - } + addDependenciesForNativeModules(ctx, deps, target, imageVariation) ctx.AddFarVariationDependencies([]blueprint.Variation{ {Mutator: "os", Variation: target.OsVariation()}, {Mutator: "arch", Variation: target.ArchVariation()}, diff --git a/apex/apex_test.go b/apex/apex_test.go index 96e2f4c6c..510e3501c 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -4296,12 +4296,15 @@ func TestApexWithArch(t *testing.T) { name: "myapex", key: "myapex.key", updatable: false, + native_shared_libs: ["mylib.generic"], arch: { arm64: { native_shared_libs: ["mylib.arm64"], + exclude_native_shared_libs: ["mylib.generic"], }, x86_64: { native_shared_libs: ["mylib.x64"], + exclude_native_shared_libs: ["mylib.generic"], }, } } @@ -4312,6 +4315,18 @@ func TestApexWithArch(t *testing.T) { private_key: "testkey.pem", } + cc_library { + name: "mylib.generic", + srcs: ["mylib.cpp"], + system_shared_libs: [], + stl: "none", + // TODO: remove //apex_available:platform + apex_available: [ + "//apex_available:platform", + "myapex", + ], + } + cc_library { name: "mylib.arm64", srcs: ["mylib.cpp"], @@ -4342,6 +4357,7 @@ func TestApexWithArch(t *testing.T) { // Ensure that apex variant is created for the direct dep ensureListContains(t, ctx.ModuleVariantsForTests("mylib.arm64"), "android_arm64_armv8-a_shared_apex10000") + ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib.generic"), "android_arm64_armv8-a_shared_apex10000") ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib.x64"), "android_arm64_armv8-a_shared_apex10000") // Ensure that both direct and indirect deps are copied into apex From 58ffdf8b88a7a12995f4b287b3b4b4a5f063f582 Mon Sep 17 00:00:00 2001 From: Nikita Ioffe Date: Mon, 24 Oct 2022 17:24:38 +0100 Subject: [PATCH 097/172] Add support for per-arch configuration in apex_defaults Bug: 243512044 Test: m Change-Id: Icd63e8c11b6f65c5b425e4d89b016d400cac72c5 Merged-In: Icd63e8c11b6f65c5b425e4d89b016d400cac72c5 (cherry picked from commit e58f527dfc0adc3c31bed163a0b8bc0effa5e29e) --- apex/apex.go | 1 + 1 file changed, 1 insertion(+) diff --git a/apex/apex.go b/apex/apex.go index e176388ae..d5e2a3db6 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -2493,6 +2493,7 @@ func DefaultsFactory(props ...interface{}) android.Module { module.AddProperties( &apexBundleProperties{}, &apexTargetBundleProperties{}, + &apexArchBundleProperties{}, &overridableProperties{}, ) From 97e2e4a942a45821ac61a5e29deb0ed0950c4769 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 8 Nov 2022 12:21:15 +0000 Subject: [PATCH 098/172] Allow namespace config to be tested properly Previously, the NewTextContext created a context that always called NewNameResolver with a export filter that always returned true. This change fixes that by: 1. Changing NewNameResolver to take a Config parameter instead of a filter parameter and pushing the code to create the filter from the Config from newNameResolver() in cmd/soong_build/main.go into the NewNameResolver function. 2. Extracting a newTestContextForFixture that does not create a NameResolver or set it on the context. That avoids creating a NameResolver before the test has prepared the config. 3. Modify the fixture to create and set the NameResolver in the Context after the config has been prepared by the test. 4. Added test to verify that it all works. Bug: 234825639 Test: m nothing Change-Id: Ie4b13f18093dc01a0ab65a9ecfd143585d843b55 (cherry picked from commit 3f7bf9fa0ddb4c8da9996464e1472b46d53d6ad8) Merged-In: Ie4b13f18093dc01a0ab65a9ecfd143585d843b55 --- android/fixture.go | 12 +++++++++++- android/namespace.go | 22 +++++++++++++++++++++- android/namespace_test.go | 30 ++++++++++++++++++++++++++++++ android/testing.go | 22 ++++++++++++---------- cmd/soong_build/main.go | 14 +------------- 5 files changed, 75 insertions(+), 25 deletions(-) diff --git a/android/fixture.go b/android/fixture.go index 3a15ad3a5..d082fc9e0 100644 --- a/android/fixture.go +++ b/android/fixture.go @@ -646,7 +646,7 @@ func (t *TestPathContext) AddNinjaFileDeps(deps ...string) { func createFixture(t *testing.T, buildDir string, preparers []*simpleFixturePreparer) Fixture { config := TestConfig(buildDir, nil, "", nil) - ctx := NewTestContext(config) + ctx := newTestContextForFixture(config) fixture := &fixture{ preparers: preparers, t: t, @@ -778,6 +778,16 @@ func (f *fixture) RunTest() *TestResult { } } + // Create and set the Context's NameInterface. It needs to be created here as it depends on the + // configuration that has been prepared for this fixture. + resolver := NewNameResolver(ctx.config) + + // Set the NameInterface in the main Context. + ctx.SetNameInterface(resolver) + + // Set the NameResolver in the TestContext. + ctx.NameResolver = resolver + ctx.Register() var ninjaDeps []string extraNinjaDeps, errs := ctx.ParseBlueprintsFiles("ignored") diff --git a/android/namespace.go b/android/namespace.go index fc7bc290f..1f821ff84 100644 --- a/android/namespace.go +++ b/android/namespace.go @@ -91,7 +91,27 @@ type NameResolver struct { namespaceExportFilter func(*Namespace) bool } -func NewNameResolver(namespaceExportFilter func(*Namespace) bool) *NameResolver { +// NameResolverConfig provides the subset of the Config interface needed by the +// NewNameResolver function. +type NameResolverConfig interface { + // ExportedNamespaces is the list of namespaces that Soong must export to + // make. + ExportedNamespaces() []string +} + +func NewNameResolver(config NameResolverConfig) *NameResolver { + namespacePathsToExport := make(map[string]bool) + + for _, namespaceName := range config.ExportedNamespaces() { + namespacePathsToExport[namespaceName] = true + } + + namespacePathsToExport["."] = true // always export the root namespace + + namespaceExportFilter := func(namespace *Namespace) bool { + return namespacePathsToExport[namespace.Path] + } + r := &NameResolver{ namespacesByDir: sync.Map{}, namespaceExportFilter: namespaceExportFilter, diff --git a/android/namespace_test.go b/android/namespace_test.go index ea399da06..f76bda31e 100644 --- a/android/namespace_test.go +++ b/android/namespace_test.go @@ -621,6 +621,36 @@ func TestRename(t *testing.T) { // setupTest will report any errors } +func TestNamespace_Exports(t *testing.T) { + result := GroupFixturePreparers( + prepareForTestWithNamespace, + FixtureModifyProductVariables(func(variables FixtureProductVariables) { + variables.NamespacesToExport = []string{"dir1"} + }), + dirBpToPreparer(map[string]string{ + "dir1": ` + soong_namespace { + } + test_module { + name: "a", + } + `, + "dir2": ` + soong_namespace { + } + test_module { + name: "b", + } + `, + }), + ).RunTest(t) + + aModule := result.Module("a", "") + AssertBoolEquals(t, "a exported", true, aModule.ExportedToMake()) + bModule := result.Module("b", "") + AssertBoolEquals(t, "b not exported", false, bModule.ExportedToMake()) +} + // some utils to support the tests func mockFiles(bps map[string]string) (files map[string][]byte) { diff --git a/android/testing.go b/android/testing.go index 1b36c903a..f5210d185 100644 --- a/android/testing.go +++ b/android/testing.go @@ -30,19 +30,11 @@ import ( "github.com/google/blueprint/proptools" ) -func NewTestContext(config Config) *TestContext { - namespaceExportFilter := func(namespace *Namespace) bool { - return true - } - - nameResolver := NewNameResolver(namespaceExportFilter) +func newTestContextForFixture(config Config) *TestContext { ctx := &TestContext{ - Context: &Context{blueprint.NewContext(), config}, - NameResolver: nameResolver, + Context: &Context{blueprint.NewContext(), config}, } - ctx.SetNameInterface(nameResolver) - ctx.postDeps = append(ctx.postDeps, registerPathDepsMutator) ctx.SetFs(ctx.config.fs) @@ -53,6 +45,16 @@ func NewTestContext(config Config) *TestContext { return ctx } +func NewTestContext(config Config) *TestContext { + ctx := newTestContextForFixture(config) + + nameResolver := NewNameResolver(config) + ctx.NameResolver = nameResolver + ctx.SetNameInterface(nameResolver) + + return ctx +} + var PrepareForTestWithArchMutator = GroupFixturePreparers( // Configure architecture targets in the fixture config. FixtureModifyConfig(modifyTestConfigToSupportArchMutator), diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go index 3f8105c88..7c500b76c 100644 --- a/cmd/soong_build/main.go +++ b/cmd/soong_build/main.go @@ -97,19 +97,7 @@ func init() { } func newNameResolver(config android.Config) *android.NameResolver { - namespacePathsToExport := make(map[string]bool) - - for _, namespaceName := range config.ExportedNamespaces() { - namespacePathsToExport[namespaceName] = true - } - - namespacePathsToExport["."] = true // always export the root namespace - - exportFilter := func(namespace *android.Namespace) bool { - return namespacePathsToExport[namespace.Path] - } - - return android.NewNameResolver(exportFilter) + return android.NewNameResolver(config) } func newContext(configuration android.Config) *android.Context { From 85db4a67ba928fef7cb16a6f840411555a3a3c16 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 6 Jul 2021 22:36:33 +0100 Subject: [PATCH 099/172] Switch the namespace tests to fully use test fixtures Indented the bp contents to make it easier to differentiate between them and the directory in which they belong. Bug: 181070625 Test: m nothing Change-Id: Iae7495fb7c88769dc688006a41f4d21f57cf03b8 (cherry picked from commit 0fc6d32c8270ef0940db36aefe3e1a2d35daa3c7) Merged-In: Iae7495fb7c88769dc688006a41f4d21f57cf03b8 --- android/fixture.go | 12 + android/namespace_test.go | 900 ++++++++++++++++++-------------------- 2 files changed, 443 insertions(+), 469 deletions(-) diff --git a/android/fixture.go b/android/fixture.go index 3a15ad3a5..f33e7189d 100644 --- a/android/fixture.go +++ b/android/fixture.go @@ -588,6 +588,18 @@ func FixtureExpectsAllErrorsToMatchAPattern(patterns []string) FixtureErrorHandl }) } +// FixtureExpectsOneErrorPattern returns an error handler that will cause the test to fail +// if there is more than one error or the error does not match the pattern. +// +// If the test fails this handler will call `result.FailNow()` which will exit the goroutine within +// which the test is being run which means that the RunTest() method will not return. +func FixtureExpectsOneErrorPattern(pattern string) FixtureErrorHandler { + return FixtureCustomErrorHandler(func(t *testing.T, result *TestResult) { + t.Helper() + CheckErrorsAgainstExpectations(t, result.Errs, []string{pattern}) + }) +} + // FixtureCustomErrorHandler creates a custom error handler func FixtureCustomErrorHandler(function func(t *testing.T, result *TestResult)) FixtureErrorHandler { return simpleErrorHandler{ diff --git a/android/namespace_test.go b/android/namespace_test.go index ea399da06..87d13206b 100644 --- a/android/namespace_test.go +++ b/android/namespace_test.go @@ -15,7 +15,6 @@ package android import ( - "errors" "path/filepath" "reflect" "testing" @@ -24,577 +23,555 @@ import ( ) func TestDependingOnModuleInSameNamespace(t *testing.T) { - ctx := setupTest(t, - map[string]string{ + result := GroupFixturePreparers( + prepareForTestWithNamespace, + dirBpToPreparer(map[string]string{ "dir1": ` - soong_namespace { - } - test_module { - name: "a", - } - test_module { - name: "b", - deps: ["a"], - } + soong_namespace { + } + test_module { + name: "a", + } + test_module { + name: "b", + deps: ["a"], + } `, - }, - ) + }), + ).RunTest(t) - a := getModule(ctx, "a") - b := getModule(ctx, "b") - if !dependsOn(ctx, b, a) { + a := getModule(result, "a") + b := getModule(result, "b") + if !dependsOn(result, b, a) { t.Errorf("module b does not depend on module a in the same namespace") } } func TestDependingOnModuleInRootNamespace(t *testing.T) { - ctx := setupTest(t, - map[string]string{ + result := GroupFixturePreparers( + prepareForTestWithNamespace, + dirBpToPreparer(map[string]string{ ".": ` - test_module { - name: "b", - deps: ["a"], - } - test_module { - name: "a", - } + test_module { + name: "b", + deps: ["a"], + } + test_module { + name: "a", + } `, - }, - ) + }), + ).RunTest(t) - a := getModule(ctx, "a") - b := getModule(ctx, "b") - if !dependsOn(ctx, b, a) { + a := getModule(result, "a") + b := getModule(result, "b") + if !dependsOn(result, b, a) { t.Errorf("module b in root namespace does not depend on module a in the root namespace") } } func TestImplicitlyImportRootNamespace(t *testing.T) { - _ = setupTest(t, - map[string]string{ + GroupFixturePreparers( + prepareForTestWithNamespace, + dirBpToPreparer(map[string]string{ ".": ` - test_module { - name: "a", - } + test_module { + name: "a", + } `, "dir1": ` - soong_namespace { - } - test_module { - name: "b", - deps: ["a"], - } + soong_namespace { + } + test_module { + name: "b", + deps: ["a"], + } `, - }, - ) + }), + ).RunTest(t) - // setupTest will report any errors + // RunTest will report any errors } func TestDependingOnBlueprintModuleInRootNamespace(t *testing.T) { - _ = setupTest(t, - map[string]string{ + GroupFixturePreparers( + prepareForTestWithNamespace, + dirBpToPreparer(map[string]string{ ".": ` - blueprint_test_module { - name: "a", - } + blueprint_test_module { + name: "a", + } `, "dir1": ` - soong_namespace { - } - blueprint_test_module { - name: "b", - deps: ["a"], - } + soong_namespace { + } + blueprint_test_module { + name: "b", + deps: ["a"], + } `, - }, - ) + }), + ).RunTest(t) - // setupTest will report any errors + // RunTest will report any errors } func TestDependingOnModuleInImportedNamespace(t *testing.T) { - ctx := setupTest(t, - map[string]string{ + result := GroupFixturePreparers( + prepareForTestWithNamespace, + dirBpToPreparer(map[string]string{ "dir1": ` - soong_namespace { - } - test_module { - name: "a", - } + soong_namespace { + } + test_module { + name: "a", + } `, "dir2": ` - soong_namespace { - imports: ["dir1"], - } - test_module { - name: "b", - deps: ["a"], - } + soong_namespace { + imports: ["dir1"], + } + test_module { + name: "b", + deps: ["a"], + } `, - }, - ) + }), + ).RunTest(t) - a := getModule(ctx, "a") - b := getModule(ctx, "b") - if !dependsOn(ctx, b, a) { + a := getModule(result, "a") + b := getModule(result, "b") + if !dependsOn(result, b, a) { t.Errorf("module b does not depend on module a in the same namespace") } } func TestDependingOnModuleInNonImportedNamespace(t *testing.T) { - _, errs := setupTestExpectErrs(t, - map[string]string{ + GroupFixturePreparers( + prepareForTestWithNamespace, + dirBpToPreparer(map[string]string{ "dir1": ` - soong_namespace { - } - test_module { - name: "a", - } + soong_namespace { + } + test_module { + name: "a", + } `, "dir2": ` - soong_namespace { - } - test_module { - name: "a", - } + soong_namespace { + } + test_module { + name: "a", + } `, "dir3": ` - soong_namespace { - } - test_module { - name: "b", - deps: ["a"], - } + soong_namespace { + } + test_module { + name: "b", + deps: ["a"], + } `, - }, - ) - - expectedErrors := []error{ - errors.New( - `dir3/Android.bp:4:4: "b" depends on undefined module "a" + }), + ). + ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(`\Qdir3/Android.bp:4:5: "b" depends on undefined module "a" Module "b" is defined in namespace "dir3" which can read these 2 namespaces: ["dir3" "."] -Module "a" can be found in these namespaces: ["dir1" "dir2"]`), - } - - if len(errs) != 1 || errs[0].Error() != expectedErrors[0].Error() { - t.Errorf("Incorrect errors. Expected:\n%v\n, got:\n%v\n", expectedErrors, errs) - } +Module "a" can be found in these namespaces: ["dir1" "dir2"]\E`)). + RunTest(t) } func TestDependingOnModuleByFullyQualifiedReference(t *testing.T) { - ctx := setupTest(t, - map[string]string{ + result := GroupFixturePreparers( + prepareForTestWithNamespace, + dirBpToPreparer(map[string]string{ "dir1": ` - soong_namespace { - } - test_module { - name: "a", - } + soong_namespace { + } + test_module { + name: "a", + } `, "dir2": ` - soong_namespace { - } - test_module { - name: "b", - deps: ["//dir1:a"], - } + soong_namespace { + } + test_module { + name: "b", + deps: ["//dir1:a"], + } `, - }, - ) - a := getModule(ctx, "a") - b := getModule(ctx, "b") - if !dependsOn(ctx, b, a) { + }), + ).RunTest(t) + + a := getModule(result, "a") + b := getModule(result, "b") + if !dependsOn(result, b, a) { t.Errorf("module b does not depend on module a") } } func TestSameNameInTwoNamespaces(t *testing.T) { - ctx := setupTest(t, - map[string]string{ + result := GroupFixturePreparers( + prepareForTestWithNamespace, + dirBpToPreparer(map[string]string{ "dir1": ` - soong_namespace { - } - test_module { - name: "a", - id: "1", - } - test_module { - name: "b", - deps: ["a"], - id: "2", - } + soong_namespace { + } + test_module { + name: "a", + id: "1", + } + test_module { + name: "b", + deps: ["a"], + id: "2", + } `, "dir2": ` - soong_namespace { - } - test_module { - name: "a", - id:"3", - } - test_module { - name: "b", - deps: ["a"], - id:"4", - } + soong_namespace { + } + test_module { + name: "a", + id:"3", + } + test_module { + name: "b", + deps: ["a"], + id:"4", + } `, - }, - ) + }), + ).RunTest(t) - one := findModuleById(ctx, "1") - two := findModuleById(ctx, "2") - three := findModuleById(ctx, "3") - four := findModuleById(ctx, "4") - if !dependsOn(ctx, two, one) { + one := findModuleById(result, "1") + two := findModuleById(result, "2") + three := findModuleById(result, "3") + four := findModuleById(result, "4") + if !dependsOn(result, two, one) { t.Fatalf("Module 2 does not depend on module 1 in its namespace") } - if dependsOn(ctx, two, three) { + if dependsOn(result, two, three) { t.Fatalf("Module 2 depends on module 3 in another namespace") } - if !dependsOn(ctx, four, three) { + if !dependsOn(result, four, three) { t.Fatalf("Module 4 does not depend on module 3 in its namespace") } - if dependsOn(ctx, four, one) { + if dependsOn(result, four, one) { t.Fatalf("Module 4 depends on module 1 in another namespace") } } func TestSearchOrder(t *testing.T) { - ctx := setupTest(t, - map[string]string{ + result := GroupFixturePreparers( + prepareForTestWithNamespace, + dirBpToPreparer(map[string]string{ "dir1": ` - soong_namespace { - } - test_module { - name: "a", - id: "1", - } + soong_namespace { + } + test_module { + name: "a", + id: "1", + } `, "dir2": ` - soong_namespace { - } - test_module { - name: "a", - id:"2", - } - test_module { - name: "b", - id:"3", - } + soong_namespace { + } + test_module { + name: "a", + id:"2", + } + test_module { + name: "b", + id:"3", + } `, "dir3": ` - soong_namespace { - } - test_module { - name: "a", - id:"4", - } - test_module { - name: "b", - id:"5", - } - test_module { - name: "c", - id:"6", - } + soong_namespace { + } + test_module { + name: "a", + id:"4", + } + test_module { + name: "b", + id:"5", + } + test_module { + name: "c", + id:"6", + } `, ".": ` - test_module { - name: "a", - id: "7", - } - test_module { - name: "b", - id: "8", - } - test_module { - name: "c", - id: "9", - } - test_module { - name: "d", - id: "10", - } + test_module { + name: "a", + id: "7", + } + test_module { + name: "b", + id: "8", + } + test_module { + name: "c", + id: "9", + } + test_module { + name: "d", + id: "10", + } `, "dir4": ` - soong_namespace { - imports: ["dir1", "dir2", "dir3"] - } - test_module { - name: "test_me", - id:"0", - deps: ["a", "b", "c", "d"], - } + soong_namespace { + imports: ["dir1", "dir2", "dir3"] + } + test_module { + name: "test_me", + id:"0", + deps: ["a", "b", "c", "d"], + } `, - }, - ) + }), + ).RunTest(t) - testMe := findModuleById(ctx, "0") - if !dependsOn(ctx, testMe, findModuleById(ctx, "1")) { + testMe := findModuleById(result, "0") + if !dependsOn(result, testMe, findModuleById(result, "1")) { t.Errorf("test_me doesn't depend on id 1") } - if !dependsOn(ctx, testMe, findModuleById(ctx, "3")) { + if !dependsOn(result, testMe, findModuleById(result, "3")) { t.Errorf("test_me doesn't depend on id 3") } - if !dependsOn(ctx, testMe, findModuleById(ctx, "6")) { + if !dependsOn(result, testMe, findModuleById(result, "6")) { t.Errorf("test_me doesn't depend on id 6") } - if !dependsOn(ctx, testMe, findModuleById(ctx, "10")) { + if !dependsOn(result, testMe, findModuleById(result, "10")) { t.Errorf("test_me doesn't depend on id 10") } - if numDeps(ctx, testMe) != 4 { - t.Errorf("num dependencies of test_me = %v, not 4\n", numDeps(ctx, testMe)) + if numDeps(result, testMe) != 4 { + t.Errorf("num dependencies of test_me = %v, not 4\n", numDeps(result, testMe)) } } func TestTwoNamespacesCanImportEachOther(t *testing.T) { - _ = setupTest(t, - map[string]string{ + GroupFixturePreparers( + prepareForTestWithNamespace, + dirBpToPreparer(map[string]string{ "dir1": ` - soong_namespace { - imports: ["dir2"] - } - test_module { - name: "a", - } - test_module { - name: "c", - deps: ["b"], - } + soong_namespace { + imports: ["dir2"] + } + test_module { + name: "a", + } + test_module { + name: "c", + deps: ["b"], + } `, "dir2": ` - soong_namespace { - imports: ["dir1"], - } - test_module { - name: "b", - deps: ["a"], - } + soong_namespace { + imports: ["dir1"], + } + test_module { + name: "b", + deps: ["a"], + } `, - }, - ) + }), + ).RunTest(t) - // setupTest will report any errors + // RunTest will report any errors } func TestImportingNonexistentNamespace(t *testing.T) { - _, errs := setupTestExpectErrs(t, - map[string]string{ + GroupFixturePreparers( + prepareForTestWithNamespace, + dirBpToPreparer(map[string]string{ "dir1": ` - soong_namespace { - imports: ["a_nonexistent_namespace"] - } - test_module { - name: "a", - deps: ["a_nonexistent_module"] - } + soong_namespace { + imports: ["a_nonexistent_namespace"] + } + test_module { + name: "a", + deps: ["a_nonexistent_module"] + } `, - }, - ) - - // should complain about the missing namespace and not complain about the unresolvable dependency - expectedErrors := []error{ - errors.New(`dir1/Android.bp:2:4: module "soong_namespace": namespace a_nonexistent_namespace does not exist`), - } - if len(errs) != 1 || errs[0].Error() != expectedErrors[0].Error() { - t.Errorf("Incorrect errors. Expected:\n%v\n, got:\n%v\n", expectedErrors, errs) - } + }), + ). + // should complain about the missing namespace and not complain about the unresolvable dependency + ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(`\Qdir1/Android.bp:2:5: module "soong_namespace": namespace a_nonexistent_namespace does not exist\E`)). + RunTest(t) } func TestNamespacesDontInheritParentNamespaces(t *testing.T) { - _, errs := setupTestExpectErrs(t, - map[string]string{ + GroupFixturePreparers( + prepareForTestWithNamespace, + dirBpToPreparer(map[string]string{ "dir1": ` - soong_namespace { - } - test_module { - name: "a", - } + soong_namespace { + } + test_module { + name: "a", + } `, "dir1/subdir1": ` - soong_namespace { - } - test_module { - name: "b", - deps: ["a"], - } + soong_namespace { + } + test_module { + name: "b", + deps: ["a"], + } `, - }, - ) - - expectedErrors := []error{ - errors.New(`dir1/subdir1/Android.bp:4:4: "b" depends on undefined module "a" + }), + ). + ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(`\Qdir1/subdir1/Android.bp:4:5: "b" depends on undefined module "a" Module "b" is defined in namespace "dir1/subdir1" which can read these 2 namespaces: ["dir1/subdir1" "."] -Module "a" can be found in these namespaces: ["dir1"]`), - } - if len(errs) != 1 || errs[0].Error() != expectedErrors[0].Error() { - t.Errorf("Incorrect errors. Expected:\n%v\n, got:\n%v\n", expectedErrors, errs) - } +Module "a" can be found in these namespaces: ["dir1"]\E`)). + RunTest(t) } func TestModulesDoReceiveParentNamespace(t *testing.T) { - _ = setupTest(t, - map[string]string{ + GroupFixturePreparers( + prepareForTestWithNamespace, + dirBpToPreparer(map[string]string{ "dir1": ` - soong_namespace { - } - test_module { - name: "a", - } + soong_namespace { + } + test_module { + name: "a", + } `, "dir1/subdir": ` - test_module { - name: "b", - deps: ["a"], - } + test_module { + name: "b", + deps: ["a"], + } `, - }, - ) + }), + ).RunTest(t) - // setupTest will report any errors + // RunTest will report any errors } func TestNamespaceImportsNotTransitive(t *testing.T) { - _, errs := setupTestExpectErrs(t, - map[string]string{ + GroupFixturePreparers( + prepareForTestWithNamespace, + dirBpToPreparer(map[string]string{ "dir1": ` - soong_namespace { - } - test_module { - name: "a", - } + soong_namespace { + } + test_module { + name: "a", + } `, "dir2": ` - soong_namespace { - imports: ["dir1"], - } - test_module { - name: "b", - deps: ["a"], - } + soong_namespace { + imports: ["dir1"], + } + test_module { + name: "b", + deps: ["a"], + } `, "dir3": ` - soong_namespace { - imports: ["dir2"], - } - test_module { - name: "c", - deps: ["a"], - } + soong_namespace { + imports: ["dir2"], + } + test_module { + name: "c", + deps: ["a"], + } `, - }, - ) - - expectedErrors := []error{ - errors.New(`dir3/Android.bp:5:4: "c" depends on undefined module "a" + }), + ). + ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(`\Qdir3/Android.bp:5:5: "c" depends on undefined module "a" Module "c" is defined in namespace "dir3" which can read these 3 namespaces: ["dir3" "dir2" "."] -Module "a" can be found in these namespaces: ["dir1"]`), - } - if len(errs) != 1 || errs[0].Error() != expectedErrors[0].Error() { - t.Errorf("Incorrect errors. Expected:\n%v\n, got:\n%v\n", expectedErrors, errs) - } +Module "a" can be found in these namespaces: ["dir1"]\E`)). + RunTest(t) } func TestTwoNamepacesInSameDir(t *testing.T) { - _, errs := setupTestExpectErrs(t, - map[string]string{ + GroupFixturePreparers( + prepareForTestWithNamespace, + dirBpToPreparer(map[string]string{ "dir1": ` - soong_namespace { - } - soong_namespace { - } + soong_namespace { + } + soong_namespace { + } `, - }, - ) - - expectedErrors := []error{ - errors.New(`dir1/Android.bp:4:4: namespace dir1 already exists`), - } - if len(errs) != 1 || errs[0].Error() != expectedErrors[0].Error() { - t.Errorf("Incorrect errors. Expected:\n%v\n, got:\n%v\n", expectedErrors, errs) - } + }), + ). + ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(`\Qdir1/Android.bp:4:5: namespace dir1 already exists\E`)). + RunTest(t) } func TestNamespaceNotAtTopOfFile(t *testing.T) { - _, errs := setupTestExpectErrs(t, - map[string]string{ + GroupFixturePreparers( + prepareForTestWithNamespace, + dirBpToPreparer(map[string]string{ "dir1": ` - test_module { - name: "a" - } - soong_namespace { - } + test_module { + name: "a" + } + soong_namespace { + } `, - }, - ) - - expectedErrors := []error{ - errors.New(`dir1/Android.bp:5:4: a namespace must be the first module in the file`), - } - if len(errs) != 1 || errs[0].Error() != expectedErrors[0].Error() { - t.Errorf("Incorrect errors. Expected:\n%v\n, got:\n%v\n", expectedErrors, errs) - } + }), + ). + ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(`\Qdir1/Android.bp:5:5: a namespace must be the first module in the file\E`)). + RunTest(t) } func TestTwoModulesWithSameNameInSameNamespace(t *testing.T) { - _, errs := setupTestExpectErrs(t, - map[string]string{ + GroupFixturePreparers( + prepareForTestWithNamespace, + dirBpToPreparer(map[string]string{ "dir1": ` - soong_namespace { - } - test_module { - name: "a" - } - test_module { - name: "a" - } + soong_namespace { + } + test_module { + name: "a" + } + test_module { + name: "a" + } `, - }, - ) - - expectedErrors := []error{ - errors.New(`dir1/Android.bp:7:4: module "a" already defined - dir1/Android.bp:4:4 <-- previous definition here`), - } - if len(errs) != 1 || errs[0].Error() != expectedErrors[0].Error() { - t.Errorf("Incorrect errors. Expected:\n%v\n, got:\n%v\n", expectedErrors, errs) - } + }), + ). + ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(`\Qdir1/Android.bp:7:5: module "a" already defined + dir1/Android.bp:4:5 <-- previous definition here\E`)). + RunTest(t) } func TestDeclaringNamespaceInNonAndroidBpFile(t *testing.T) { - _, errs := setupTestFromFiles(t, - map[string][]byte{ - "Android.bp": []byte(` + GroupFixturePreparers( + prepareForTestWithNamespace, + FixtureWithRootAndroidBp(` build = ["include.bp"] - `), - "include.bp": []byte(` + `), + FixtureAddTextFile("include.bp", ` soong_namespace { } - `), - }, - ) - - expectedErrors := []error{ - errors.New(`include.bp:2:5: A namespace may only be declared in a file named Android.bp`), - } - - if len(errs) != 1 || errs[0].Error() != expectedErrors[0].Error() { - t.Errorf("Incorrect errors. Expected:\n%v\n, got:\n%v\n", expectedErrors, errs) - } + `), + ). + ExtendWithErrorHandler(FixtureExpectsOneErrorPattern( + `\Qinclude.bp:2:5: A namespace may only be declared in a file named Android.bp\E`, + )). + RunTest(t) } // so that the generated .ninja file will have consistent names func TestConsistentNamespaceNames(t *testing.T) { - ctx := setupTest(t, - map[string]string{ + result := GroupFixturePreparers( + prepareForTestWithNamespace, + dirBpToPreparer(map[string]string{ "dir1": "soong_namespace{}", "dir2": "soong_namespace{}", "dir3": "soong_namespace{}", - }) + }), + ).RunTest(t) - ns1, _ := ctx.NameResolver.namespaceAt("dir1") - ns2, _ := ctx.NameResolver.namespaceAt("dir2") - ns3, _ := ctx.NameResolver.namespaceAt("dir3") + ns1, _ := result.NameResolver.namespaceAt("dir1") + ns2, _ := result.NameResolver.namespaceAt("dir2") + ns3, _ := result.NameResolver.namespaceAt("dir3") actualIds := []string{ns1.id, ns2.id, ns3.id} expectedIds := []string{"1", "2", "3"} if !reflect.DeepEqual(actualIds, expectedIds) { @@ -604,103 +581,88 @@ func TestConsistentNamespaceNames(t *testing.T) { // so that the generated .ninja file will have consistent names func TestRename(t *testing.T) { - _ = setupTest(t, - map[string]string{ + GroupFixturePreparers( + prepareForTestWithNamespace, + dirBpToPreparer(map[string]string{ "dir1": ` - soong_namespace { - } - test_module { - name: "a", - deps: ["c"], - } - test_module { - name: "b", - rename: "c", - } - `}) - // setupTest will report any errors + soong_namespace { + } + test_module { + name: "a", + deps: ["c"], + } + test_module { + name: "b", + rename: "c", + } + `, + }), + ).RunTest(t) + + // RunTest will report any errors } // some utils to support the tests -func mockFiles(bps map[string]string) (files map[string][]byte) { - files = make(map[string][]byte, len(bps)) +var prepareForTestWithNamespace = GroupFixturePreparers( + FixtureRegisterWithContext(registerNamespaceBuildComponents), + FixtureRegisterWithContext(func(ctx RegistrationContext) { + ctx.PreArchMutators(RegisterNamespaceMutator) + }), + FixtureModifyContext(func(ctx *TestContext) { + ctx.RegisterModuleType("test_module", newTestModule) + ctx.Context.RegisterModuleType("blueprint_test_module", newBlueprintTestModule) + ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) { + ctx.BottomUp("rename", renameMutator) + }) + }), +) + +// dirBpToPreparer takes a map from directory to the contents of the Android.bp file and produces a +// FixturePreparer. +func dirBpToPreparer(bps map[string]string) FixturePreparer { + files := make(MockFS, len(bps)) files["Android.bp"] = []byte("") for dir, text := range bps { files[filepath.Join(dir, "Android.bp")] = []byte(text) } - return files + return files.AddToFixture() } -func setupTestFromFiles(t *testing.T, bps MockFS) (ctx *TestContext, errs []error) { - result := GroupFixturePreparers( - FixtureModifyContext(func(ctx *TestContext) { - ctx.RegisterModuleType("test_module", newTestModule) - ctx.Context.RegisterModuleType("blueprint_test_module", newBlueprintTestModule) - ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) { - ctx.BottomUp("rename", renameMutator) - }) - }), - PrepareForTestWithNamespace, - bps.AddToFixture(), - ). - // Ignore errors for now so tests can check them later. - ExtendWithErrorHandler(FixtureIgnoreErrors). - RunTest(t) - - return result.TestContext, result.Errs -} - -func setupTestExpectErrs(t *testing.T, bps map[string]string) (ctx *TestContext, errs []error) { - files := make(map[string][]byte, len(bps)) - files["Android.bp"] = []byte("") - for dir, text := range bps { - files[filepath.Join(dir, "Android.bp")] = []byte(text) - } - return setupTestFromFiles(t, files) -} - -func setupTest(t *testing.T, bps map[string]string) (ctx *TestContext) { - t.Helper() - ctx, errs := setupTestExpectErrs(t, bps) - FailIfErrored(t, errs) - return ctx -} - -func dependsOn(ctx *TestContext, module TestingModule, possibleDependency TestingModule) bool { +func dependsOn(result *TestResult, module TestingModule, possibleDependency TestingModule) bool { depends := false visit := func(dependency blueprint.Module) { if dependency == possibleDependency.module { depends = true } } - ctx.VisitDirectDeps(module.module, visit) + result.VisitDirectDeps(module.module, visit) return depends } -func numDeps(ctx *TestContext, module TestingModule) int { +func numDeps(result *TestResult, module TestingModule) int { count := 0 visit := func(dependency blueprint.Module) { count++ } - ctx.VisitDirectDeps(module.module, visit) + result.VisitDirectDeps(module.module, visit) return count } -func getModule(ctx *TestContext, moduleName string) TestingModule { - return ctx.ModuleForTests(moduleName, "") +func getModule(result *TestResult, moduleName string) TestingModule { + return result.ModuleForTests(moduleName, "") } -func findModuleById(ctx *TestContext, id string) (module TestingModule) { +func findModuleById(result *TestResult, id string) (module TestingModule) { visit := func(candidate blueprint.Module) { testModule, ok := candidate.(*testModule) if ok { if testModule.properties.Id == id { - module = newTestingModule(ctx.config, testModule) + module = newTestingModule(result.config, testModule) } } } - ctx.VisitAllModules(visit) + result.VisitAllModules(visit) return module } @@ -747,7 +709,7 @@ type blueprintTestModule struct { } } -func (b *blueprintTestModule) DynamicDependencies(ctx blueprint.DynamicDependerModuleContext) []string { +func (b *blueprintTestModule) DynamicDependencies(_ blueprint.DynamicDependerModuleContext) []string { return b.properties.Deps } From c21336e7cd011ccb3bbe0f855f4a4471ffcca5c2 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Mon, 14 Nov 2022 17:35:50 +0000 Subject: [PATCH 100/172] Remove support for unused env vars from sdk snapshot generation The following environment variables are no longer used when generating sdk snapshots: * SOONG_SDK_SNAPSHOT_PREFER - we can control the modules that are preferred at build time now. * SOONG_SDK_SNAPSHOT_USE_SOURCE_CONFIG_VAR - this is done as a post-processing step by the mainline_module_sdks.sh script to avoid having to regenerate the ninja files for every module. * SOONG_SDK_SNAPSHOT_VERSION - support for this was removed a long time ago but was still referenced from dumpvars.go. Bug: 259095197 Test: m nothing # Searched for uses of these variables but could not find any # outside the build. Change-Id: Id2b32b29ff6f09faffea43292f549ba13acd956d (cherry picked from commit 82d75ade2a7dd0dbcd483c46e833ce697a443a34) Merged-In: Id2b32b29ff6f09faffea43292f549ba13acd956d --- sdk/sdk_test.go | 54 -------------------------------------------- sdk/update.go | 54 +------------------------------------------- ui/build/dumpvars.go | 3 --- 3 files changed, 1 insertion(+), 110 deletions(-) diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go index 2f9aee9da..108a664ea 100644 --- a/sdk/sdk_test.go +++ b/sdk/sdk_test.go @@ -409,60 +409,6 @@ java_import { ) }) - t.Run("SOONG_SDK_SNAPSHOT_PREFER=true", func(t *testing.T) { - result := android.GroupFixturePreparers( - preparer, - android.FixtureMergeEnv(map[string]string{ - "SOONG_SDK_SNAPSHOT_PREFER": "true", - }), - ).RunTest(t) - - checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-current.zip") - - CheckSnapshot(t, result, "mysdk", "", - checkAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_import { - name: "myjavalib", - prefer: true, - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - jars: ["java/myjavalib.jar"], -} - `), - ) - }) - - t.Run("SOONG_SDK_SNAPSHOT_USE_SOURCE_CONFIG_VAR=module:build_from_source", func(t *testing.T) { - result := android.GroupFixturePreparers( - preparer, - android.FixtureMergeEnv(map[string]string{ - "SOONG_SDK_SNAPSHOT_USE_SOURCE_CONFIG_VAR": "module:build_from_source", - }), - ).RunTest(t) - - checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-current.zip") - - CheckSnapshot(t, result, "mysdk", "", - checkAndroidBpContents(` -// This is auto-generated. DO NOT EDIT. - -java_import { - name: "myjavalib", - prefer: false, - use_source_config_var: { - config_namespace: "module", - var_name: "build_from_source", - }, - visibility: ["//visibility:public"], - apex_available: ["//apex_available:platform"], - jars: ["java/myjavalib.jar"], -} - `), - ) - }) - t.Run("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE=S", func(t *testing.T) { result := android.GroupFixturePreparers( prepareForSdkTestWithJava, diff --git a/sdk/update.go b/sdk/update.go index 92a13fa7f..baa203302 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -34,41 +34,6 @@ import ( // Environment variables that affect the generated snapshot // ======================================================== // -// SOONG_SDK_SNAPSHOT_PREFER -// By default every module in the generated snapshot has prefer: false. Building it -// with SOONG_SDK_SNAPSHOT_PREFER=true will force them to use prefer: true. -// -// SOONG_SDK_SNAPSHOT_USE_SOURCE_CONFIG_VAR -// If set this specifies the Soong config var that can be used to control whether the prebuilt -// modules from the generated snapshot or the original source modules. Values must be a colon -// separated pair of strings, the first of which is the Soong config namespace, and the second -// is the name of the variable within that namespace. -// -// The config namespace and var name are used to set the `use_source_config_var` property. That -// in turn will cause the generated prebuilts to use the soong config variable to select whether -// source or the prebuilt is used. -// e.g. If an sdk snapshot is built using: -// m SOONG_SDK_SNAPSHOT_USE_SOURCE_CONFIG_VAR=acme:build_from_source sdkextensions-sdk -// Then the resulting snapshot will include: -// use_source_config_var: { -// config_namespace: "acme", -// var_name: "build_from_source", -// } -// -// Assuming that the config variable is defined in .mk using something like: -// $(call add_soong_config_namespace,acme) -// $(call add_soong_config_var_value,acme,build_from_source,true) -// -// Then when the snapshot is unpacked in the repository it will have the following behavior: -// m droid - will use the sdkextensions-sdk prebuilts if present. Otherwise, it will use the -// sources. -// m SOONG_CONFIG_acme_build_from_source=true droid - will use the sdkextensions-sdk -// sources, if present. Otherwise, it will use the prebuilts. -// -// This is a temporary mechanism to control the prefer flags and will be removed once a more -// maintainable solution has been implemented. -// TODO(b/174997203): Remove when no longer necessary. -// // SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE // This allows the target build release (i.e. the release version of the build within which // the snapshot will be used) of the snapshot to be specified. If unspecified then it defaults @@ -2019,29 +1984,12 @@ func (s *sdk) createMemberSnapshot(ctx *memberContext, member *sdkMember, bpModu // Do not add the prefer property if the member snapshot module is a source module type. moduleCtx := ctx.sdkMemberContext - config := moduleCtx.Config() if !memberType.UsesSourceModuleTypeInSnapshot() { - // Set the prefer based on the environment variable. This is a temporary work around to allow a - // snapshot to be created that sets prefer: true. - // TODO(b/174997203): Remove once the ability to select the modules to prefer can be done - // dynamically at build time not at snapshot generation time. - prefer := config.IsEnvTrue("SOONG_SDK_SNAPSHOT_PREFER") - // Set prefer. Setting this to false is not strictly required as that is the default but it does // provide a convenient hook to post-process the generated Android.bp file, e.g. in tests to // check the behavior when a prebuilt is preferred. It also makes it explicit what the default // behavior is for the module. - bpModule.insertAfter("name", "prefer", prefer) - - configVar := config.Getenv("SOONG_SDK_SNAPSHOT_USE_SOURCE_CONFIG_VAR") - if configVar != "" { - parts := strings.Split(configVar, ":") - cfp := android.ConfigVarProperties{ - Config_namespace: proptools.StringPtr(parts[0]), - Var_name: proptools.StringPtr(parts[1]), - } - bpModule.insertAfter("prefer", "use_source_config_var", cfp) - } + bpModule.insertAfter("name", "prefer", false) } variants := selectApexVariantsWhereAvailable(ctx, member.variants) diff --git a/ui/build/dumpvars.go b/ui/build/dumpvars.go index 285f1569b..45bfe5dfa 100644 --- a/ui/build/dumpvars.go +++ b/ui/build/dumpvars.go @@ -162,10 +162,7 @@ var BannerVars = []string{ "OUT_DIR", "AUX_OS_VARIANT_LIST", "PRODUCT_SOONG_NAMESPACES", - "SOONG_SDK_SNAPSHOT_PREFER", "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE", - "SOONG_SDK_SNAPSHOT_USE_SOURCE_CONFIG_VAR", - "SOONG_SDK_SNAPSHOT_VERSION", } func Banner(make_vars map[string]string) string { From dfa78b5e9045c8488eff9f64e6406820423db9c3 Mon Sep 17 00:00:00 2001 From: Alfred Piccioni Date: Wed, 30 Nov 2022 10:57:46 +0100 Subject: [PATCH 101/172] Removing references to arm7 emulator targets. Test: Makefiles no longer exist. Bug: 258197384 Change-Id: Id7ba8957dee12259379c4852aed9cc7640a28a9a --- mk2rbc/android_products_test.go | 1 - mk2rbc/test/android_products.mk.test | 1 - 2 files changed, 2 deletions(-) diff --git a/mk2rbc/android_products_test.go b/mk2rbc/android_products_test.go index f8c930aeb..5f55f6a90 100644 --- a/mk2rbc/android_products_test.go +++ b/mk2rbc/android_products_test.go @@ -29,7 +29,6 @@ func TestProductsMakefile(t *testing.T) { } expectedProducts := map[string]string{ "aosp_cf_x86_tv": abspath("vsoc_x86/tv/device.mk"), - "aosp_tv_arm": abspath("aosp_tv_arm.mk"), "aosp_tv_arm64": abspath("aosp_tv_arm64.mk"), } if !reflect.DeepEqual(actualProducts, expectedProducts) { diff --git a/mk2rbc/test/android_products.mk.test b/mk2rbc/test/android_products.mk.test index a2220edac..400ec3598 100644 --- a/mk2rbc/test/android_products.mk.test +++ b/mk2rbc/test/android_products.mk.test @@ -1,4 +1,3 @@ PRODUCT_MAKEFILES := \ - $(LOCAL_DIR)/aosp_tv_arm.mk \ $(LOCAL_DIR)/aosp_tv_arm64.mk \ aosp_cf_x86_tv:$(LOCAL_DIR)/vsoc_x86/tv/device.mk \ No newline at end of file From 004fbef8f5109e8f08fa5144ec0d9aba14ef8340 Mon Sep 17 00:00:00 2001 From: Sahana Rao Date: Fri, 2 Dec 2022 17:00:22 +0000 Subject: [PATCH 102/172] Add option to override defaultManifestVersion Add an option to override defaultManifestVersion using environment variable. The environment variable will be used to override the apex version locally when developing a desert release feature in mainline-prod branch. Overriding the apex version in mainline-prod branch allows us to install apex built in mainline-prod branch to device running code from git_master which has a higher apex version than mainline-prod branch. Bug: b/233608815 Bug: b/196860838 Test: presubmit Test: go test -v ./build/soong/apex/ Change-Id: I8ac2aae2b6b29da7f09db6edb893e0a0f0691e51 Merged-In: I8ac2aae2b6b29da7f09db6edb893e0a0f0691e51 --- apex/apex_test.go | 35 +++++++++++++++++++++++++++++++++++ apex/builder.go | 6 +++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/apex/apex_test.go b/apex/apex_test.go index 510e3501c..83adeca6d 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -4097,6 +4097,41 @@ func TestApexName(t *testing.T) { ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") } +func TestOverrideApexManifestDefaultVersion(t *testing.T) { + ctx := testApex(t, ` + apex { + name: "myapex", + key: "myapex.key", + apex_name: "com.android.myapex", + native_shared_libs: ["mylib"], + updatable: false, + } + + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + + cc_library { + name: "mylib", + srcs: ["mylib.cpp"], + system_shared_libs: [], + stl: "none", + apex_available: [ + "//apex_available:platform", + "myapex", + ], + } + `, android.FixtureMergeEnv(map[string]string{ + "OVERRIDE_APEX_MANIFEST_DEFAULT_VERSION": "1234", + })) + + module := ctx.ModuleForTests("myapex", "android_common_com.android.myapex_image") + apexManifestRule := module.Rule("apexManifestRule") + ensureContains(t, apexManifestRule.Args["default_version"], "1234") +} + func TestNonTestApex(t *testing.T) { ctx := testApex(t, ` apex { diff --git a/apex/builder.go b/apex/builder.go index 6fb2bb0c4..0c1f3ba89 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -236,6 +236,10 @@ func (a *apexBundle) buildManifest(ctx android.ModuleContext, provideNativeLibs, } manifestJsonFullOut := android.PathForModuleOut(ctx, "apex_manifest_full.json") + defaultVersion := defaultManifestVersion + if override := ctx.Config().Getenv("OVERRIDE_APEX_MANIFEST_DEFAULT_VERSION"); override != "" { + defaultVersion = override + } ctx.Build(pctx, android.BuildParams{ Rule: apexManifestRule, Input: src, @@ -243,7 +247,7 @@ func (a *apexBundle) buildManifest(ctx android.ModuleContext, provideNativeLibs, Args: map[string]string{ "provideNativeLibs": strings.Join(provideNativeLibs, " "), "requireNativeLibs": strings.Join(requireNativeLibs, " "), - "default_version": defaultManifestVersion, + "default_version": defaultVersion, "opt": strings.Join(optCommands, " "), }, }) From 138b6c5aadaf641c3d05da1970ac7c7e56ce0c03 Mon Sep 17 00:00:00 2001 From: Vinh Tran Date: Mon, 28 Nov 2022 11:15:23 -0500 Subject: [PATCH 103/172] Add bp2build conversion to reference to fdo_profile targets The fdo_profile targets are handcrafted in ag/20469925. Bp2build creates fdo_profile attribute on cc_library_shared and references to the fdo_profile target if the profile exists. This works under assumption that all afdo profiles have an associated Bazel fdo_profile target declared in the same folder/package. As noted in b/253540178, this won't work when we check in the BUILD files (which is likely 6+ months away) because some profiles might only exist internally but not in AOSP. We will implement a long-term solution once we figure out all the requirements we need to support afdo both in Soong and Bazel. Bug: 253540178 Test: go tests Change-Id: Iebd5dd7a76583b4b2bf0d9ee56d58f247d313a54 --- bp2build/cc_library_conversion_test.go | 64 ++++++++++++++++++++++++++ cc/bp2build.go | 40 ++++++++++++++++ cc/library.go | 6 +++ 3 files changed, 110 insertions(+) diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go index a1e83d8c9..4ccd4e071 100644 --- a/bp2build/cc_library_conversion_test.go +++ b/bp2build/cc_library_conversion_test.go @@ -3603,6 +3603,70 @@ cc_library_static { }) } +func TestCcLibraryWithAfdoEnabled(t *testing.T) { + bp := ` +cc_library { + name: "foo", + afdo: true, + include_build_directory: false, +}` + + // TODO(b/260714900): Add test case for arch-specific afdo profile + testCases := []struct { + description string + filesystem map[string]string + expectedBazelTargets []string + }{ + { + description: "cc_library with afdo enabled and existing profile", + filesystem: map[string]string{"vendor/google_data/pgo_profile/sampling/foo.afdo": ""}, + expectedBazelTargets: []string{ + MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}), + MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ + "fdo_profile": `"//vendor/google_data/pgo_profile/sampling:foo"`, + }), + }, + }, + { + description: "cc_library with afdo enabled and existing profile in AOSP", + filesystem: map[string]string{"toolchain/pgo-profiles/sampling/foo.afdo": ""}, + expectedBazelTargets: []string{ + MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}), + MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ + "fdo_profile": `"//toolchain/pgo-profiles/sampling:foo"`, + }), + }, + }, + { + description: "cc_library with afdo enabled but profile filename doesn't match with module name", + filesystem: map[string]string{"toolchain/pgo-profiles/sampling/bar.afdo": ""}, + expectedBazelTargets: []string{ + MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}), + MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{}), + }, + }, + { + description: "cc_library with afdo enabled but profile doesn't exist", + expectedBazelTargets: []string{ + MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}), + MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{}), + }, + }, + } + for _, testCase := range testCases { + t.Run(testCase.description, func(t *testing.T) { + runCcLibraryTestCase(t, Bp2buildTestCase{ + ExpectedBazelTargets: testCase.expectedBazelTargets, + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Description: testCase.description, + Blueprint: binaryReplacer.Replace(bp), + Filesystem: testCase.filesystem, + }) + }) + } +} + func TestCcLibraryHeaderAbiChecker(t *testing.T) { runCcLibraryTestCase(t, Bp2buildTestCase{ Description: "cc_library with header abi checker", diff --git a/cc/bp2build.go b/cc/bp2build.go index 6caa85422..d258ca0dd 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -393,6 +393,8 @@ type compilerAttributes struct { features bazel.StringListAttribute suffix bazel.StringAttribute + + fdoProfile bazel.LabelAttribute } type filterOutFn func(string) bool @@ -777,6 +779,13 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) (&compilerAttrs).srcs.Add(&convertedLSrcs.srcName) (&compilerAttrs).cSrcs.Add(&convertedLSrcs.cSrcName) + if module.afdo != nil && module.afdo.Properties.Afdo { + fdoProfileDep := bp2buildFdoProfile(ctx, module) + if fdoProfileDep != nil { + (&compilerAttrs).fdoProfile.SetValue(*fdoProfileDep) + } + } + if !compilerAttrs.syspropSrcs.IsEmpty() { (&linkerAttrs).wholeArchiveDeps.Add(bp2buildCcSysprop(ctx, module.Name(), module.Properties.Min_sdk_version, compilerAttrs.syspropSrcs)) } @@ -793,6 +802,37 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) } } +type fdoProfileAttributes struct { + Absolute_path_profile string +} + +func bp2buildFdoProfile( + ctx android.Bp2buildMutatorContext, + m *Module, +) *bazel.Label { + for _, project := range globalAfdoProfileProjects { + // We handcraft a BUILD file with fdo_profile targets that use the existing profiles in the project + // This implementation is assuming that every afdo profile in globalAfdoProfileProjects already has + // an associated fdo_profile target declared in the same package. + // TODO(b/260714900): Handle arch-specific afdo profiles (e.g. `-arm<64>.afdo`) + path := android.ExistentPathForSource(ctx, project, m.Name()+".afdo") + if path.Valid() { + // FIXME: Some profiles only exist internally and are not released to AOSP. + // When generated BUILD files are checked in, we'll run into merge conflict. + // The cc_library_shared target in AOSP won't have reference to an fdo_profile target because + // the profile doesn't exist. Internally, the same cc_library_shared target will + // have reference to the fdo_profile. + // For more context, see b/258682955#comment2 + fdoProfileLabel := "//" + strings.TrimSuffix(project, "/") + ":" + m.Name() + return &bazel.Label{ + Label: fdoProfileLabel, + } + } + } + + return nil +} + func bp2buildCcAidlLibrary( ctx android.Bp2buildMutatorContext, m *Module, diff --git a/cc/library.go b/cc/library.go index d1d19452f..a501124b8 100644 --- a/cc/library.go +++ b/cc/library.go @@ -414,6 +414,8 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) { Strip: stripAttrsFromLinkerAttrs(&linkerAttrs), Features: baseAttributes.features, bazelCcHeaderAbiCheckerAttributes: bp2buildParseAbiCheckerProps(ctx, m), + + Fdo_profile: compilerAttrs.fdoProfile, } if compilerAttrs.stubsSymbolFile != nil && len(compilerAttrs.stubsVersions.Value) > 0 { @@ -2904,6 +2906,8 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo Suffix: compilerAttrs.suffix, bazelCcHeaderAbiCheckerAttributes: bp2buildParseAbiCheckerProps(ctx, module), + + Fdo_profile: compilerAttrs.fdoProfile, } if compilerAttrs.stubsSymbolFile != nil && len(compilerAttrs.stubsVersions.Value) > 0 { hasStubs := true @@ -2994,6 +2998,8 @@ type bazelCcLibrarySharedAttributes struct { Suffix bazel.StringAttribute bazelCcHeaderAbiCheckerAttributes + + Fdo_profile bazel.LabelAttribute } type bazelCcStubSuiteAttributes struct { From 1ef296886ff0932d00edd0241babfbe021b591a4 Mon Sep 17 00:00:00 2001 From: Vinh Tran Date: Fri, 9 Dec 2022 12:03:52 -0500 Subject: [PATCH 104/172] Add check for handcrafted BUILD file in bp2build ag/20469925 added a handcrafted BUILD file (allowlisted in ag/20597986) to internal master. ag/c/platform/build/soong/+/20583593/12/cc/bp2build.go#818 generates references to the targets in the BUILD file. However in tm-dev, the BUILD file doesn't exist while the .afdo files do. One solution is to cherry-pick the BUILD file to tm-dev. However, tm-dev doesn't have vendor/google/build/soong/bp2build_allowlist.go to check in the BUILD file in bp2build. This CL adds a check that the BUILD file exists to avoid the failure as in https://android-build.googleplex.com/builds/pending/P45724500/aosp_cf_x86_64_phone-userdebug/latest/view/logs/build_error.log in tm-qpr-dev-plus-aosp branch. Bug: 253540178 Test: go test Change-Id: I47fb853015ca230afe3cefe1d37728bf714624be --- bp2build/cc_library_conversion_test.go | 25 ++++++++++++++++--- cc/bp2build.go | 34 ++++++++++++++------------ 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go index 1ffdc0e8b..416e1298d 100644 --- a/bp2build/cc_library_conversion_test.go +++ b/bp2build/cc_library_conversion_test.go @@ -3619,7 +3619,10 @@ cc_library { }{ { description: "cc_library with afdo enabled and existing profile", - filesystem: map[string]string{"vendor/google_data/pgo_profile/sampling/foo.afdo": ""}, + filesystem: map[string]string{ + "vendor/google_data/pgo_profile/sampling/BUILD": "", + "vendor/google_data/pgo_profile/sampling/foo.afdo": "", + }, expectedBazelTargets: []string{ MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ @@ -3629,7 +3632,10 @@ cc_library { }, { description: "cc_library with afdo enabled and existing profile in AOSP", - filesystem: map[string]string{"toolchain/pgo-profiles/sampling/foo.afdo": ""}, + filesystem: map[string]string{ + "toolchain/pgo-profiles/sampling/BUILD": "", + "toolchain/pgo-profiles/sampling/foo.afdo": "", + }, expectedBazelTargets: []string{ MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ @@ -3639,7 +3645,10 @@ cc_library { }, { description: "cc_library with afdo enabled but profile filename doesn't match with module name", - filesystem: map[string]string{"toolchain/pgo-profiles/sampling/bar.afdo": ""}, + filesystem: map[string]string{ + "toolchain/pgo-profiles/sampling/BUILD": "", + "toolchain/pgo-profiles/sampling/bar.afdo": "", + }, expectedBazelTargets: []string{ MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{}), @@ -3652,6 +3661,16 @@ cc_library { MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{}), }, }, + { + description: "cc_library with afdo enabled and existing profile but BUILD file doesn't exist", + filesystem: map[string]string{ + "vendor/google_data/pgo_profile/sampling/foo.afdo": "", + }, + expectedBazelTargets: []string{ + MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}), + MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{}), + }, + }, } for _, testCase := range testCases { t.Run(testCase.description, func(t *testing.T) { diff --git a/cc/bp2build.go b/cc/bp2build.go index 598e35001..3cd0b1a3f 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -811,21 +811,25 @@ func bp2buildFdoProfile( m *Module, ) *bazel.Label { for _, project := range globalAfdoProfileProjects { - // We handcraft a BUILD file with fdo_profile targets that use the existing profiles in the project - // This implementation is assuming that every afdo profile in globalAfdoProfileProjects already has - // an associated fdo_profile target declared in the same package. - // TODO(b/260714900): Handle arch-specific afdo profiles (e.g. `-arm<64>.afdo`) - path := android.ExistentPathForSource(ctx, project, m.Name()+".afdo") - if path.Valid() { - // FIXME: Some profiles only exist internally and are not released to AOSP. - // When generated BUILD files are checked in, we'll run into merge conflict. - // The cc_library_shared target in AOSP won't have reference to an fdo_profile target because - // the profile doesn't exist. Internally, the same cc_library_shared target will - // have reference to the fdo_profile. - // For more context, see b/258682955#comment2 - fdoProfileLabel := "//" + strings.TrimSuffix(project, "/") + ":" + m.Name() - return &bazel.Label{ - Label: fdoProfileLabel, + // Ensure handcrafted BUILD file exists in the project + BUILDPath := android.ExistentPathForSource(ctx, project, "BUILD") + if BUILDPath.Valid() { + // We handcraft a BUILD file with fdo_profile targets that use the existing profiles in the project + // This implementation is assuming that every afdo profile in globalAfdoProfileProjects already has + // an associated fdo_profile target declared in the same package. + // TODO(b/260714900): Handle arch-specific afdo profiles (e.g. `-arm<64>.afdo`) + path := android.ExistentPathForSource(ctx, project, m.Name()+".afdo") + if path.Valid() { + // FIXME: Some profiles only exist internally and are not released to AOSP. + // When generated BUILD files are checked in, we'll run into merge conflict. + // The cc_library_shared target in AOSP won't have reference to an fdo_profile target because + // the profile doesn't exist. Internally, the same cc_library_shared target will + // have reference to the fdo_profile. + // For more context, see b/258682955#comment2 + fdoProfileLabel := "//" + strings.TrimSuffix(project, "/") + ":" + m.Name() + return &bazel.Label{ + Label: fdoProfileLabel, + } } } } From 9d00f2a4c5f77492f23da427f3147d7121380ccd Mon Sep 17 00:00:00 2001 From: Vinh Tran Date: Fri, 9 Dec 2022 17:47:03 -0500 Subject: [PATCH 105/172] Change out path to android_target-opt in bazel integration tests ag/c/platform/build/bazel/+/20584767/15/common.bazelrc#116 defaulted our build to opt compilation mode which affects bazel's output path. This change fixes the tests to reflect that. Test: ./tests/apex_comparison_tests.sh Test: ./tests/bp2build_bazel_test.sh Bug: 253540178 Change-Id: Idc42a2c3173800db0d6155ef3d74e33c15d220d0 --- tests/apex_comparison_tests.sh | 8 ++++---- tests/bp2build_bazel_test.sh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/apex_comparison_tests.sh b/tests/apex_comparison_tests.sh index bfcf42d86..d57942989 100755 --- a/tests/apex_comparison_tests.sh +++ b/tests/apex_comparison_tests.sh @@ -68,10 +68,10 @@ call_bazel build --config=bp2build --config=ci --config=android \ //system/timezone/apex:com.android.tzdata \ //build/bazel/examples/apex/minimal:build.bazel.examples.apex.minimal.apex -# Build debugfs separately, as it's not a dep of apexer, but needs to be an explicit arg. +# # Build debugfs separately, as it's not a dep of apexer, but needs to be an explicit arg. call_bazel build --config=bp2build --config=linux_x86_64 //external/e2fsprogs/debugfs //system/apex/tools:deapexer -DEBUGFS_PATH="$BAZEL_OUT/linux_x86_64-fastbuild/bin/external/e2fsprogs/debugfs/debugfs" -DEAPEXER="$BAZEL_OUT/linux_x86_64-fastbuild/bin/system/apex/tools/deapexer --debugfs_path=$DEBUGFS_PATH" +DEBUGFS_PATH="$BAZEL_OUT/linux_x86_64-opt/bin/external/e2fsprogs/debugfs/debugfs" +DEAPEXER="$BAZEL_OUT/linux_x86_64-opt/bin/system/apex/tools/deapexer --debugfs_path=$DEBUGFS_PATH" ####### # Tests @@ -83,7 +83,7 @@ function compare_deapexer_list() { # Compare the outputs of `deapexer list`, which lists the contents of the apex filesystem image. local SOONG_APEX="$SOONG_OUTPUT_DIR/$APEX" - local BAZEL_APEX="$BAZEL_OUT/android_target-fastbuild/bin/$APEX_DIR/$APEX" + local BAZEL_APEX="$BAZEL_OUT/android_target-opt/bin/$APEX_DIR/$APEX" local SOONG_LIST="$OUTPUT_DIR/soong.list" local BAZEL_LIST="$OUTPUT_DIR/bazel.list" diff --git a/tests/bp2build_bazel_test.sh b/tests/bp2build_bazel_test.sh index 679ac557c..101bb2bc4 100755 --- a/tests/bp2build_bazel_test.sh +++ b/tests/bp2build_bazel_test.sh @@ -148,7 +148,7 @@ EOF # NOTE: We don't actually use the extra BUILD file for anything here run_bazel build --config=android --package_path=out/soong/workspace //foo/... - local the_answer_file="bazel-out/android_target-fastbuild/bin/foo/convertible_soong_module/the_answer.txt" + local the_answer_file="bazel-out/android_target-opt/bin/foo/convertible_soong_module/the_answer.txt" if [[ ! -f "${the_answer_file}" ]]; then fail "Expected '${the_answer_file}' to be generated, but was missing" fi From c8e4a79ecacd11384b1e65a58fa95f99e87f5c76 Mon Sep 17 00:00:00 2001 From: Alan Viverette Date: Thu, 11 Aug 2022 10:59:12 -0400 Subject: [PATCH 106/172] Add support for prepending text from a file Bug: b/241826272 Bug: b/258279262 Test: ./update_prebuilts.py -x Change-Id: I47146fc8a4f9120891ee28d15b006448d66aaff7 (cherry picked from commit a1fb0d98dad224e82ad2377ed8b9705259022e98) --- cmd/pom2bp/pom2bp.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cmd/pom2bp/pom2bp.go b/cmd/pom2bp/pom2bp.go index e0638b8ed..0e8ad05a9 100644 --- a/cmd/pom2bp/pom2bp.go +++ b/cmd/pom2bp/pom2bp.go @@ -828,6 +828,7 @@ Usage: %s [--rewrite =] [--exclude ] [--extra-static-lib var regen string var pom2build bool + var prepend string flag.Var(&excludes, "exclude", "Exclude module") flag.Var(&extraStaticLibs, "extra-static-libs", "Extra static dependencies needed when depending on a module") @@ -844,6 +845,7 @@ Usage: %s [--rewrite =] [--exclude ] [--extra-static-lib flag.BoolVar(&jetifier, "jetifier", false, "Sets jetifier: true on all modules") flag.StringVar(®en, "regen", "", "Rewrite specified file") flag.BoolVar(&pom2build, "pom2build", false, "If true, will generate a Bazel BUILD file *instead* of a .bp file") + flag.StringVar(&prepend, "prepend", "", "Path to a file containing text to insert at the beginning of the generated build file") flag.Parse() if regen != "" { @@ -975,6 +977,15 @@ Usage: %s [--rewrite =] [--exclude ] [--extra-static-lib fmt.Fprintln(buf, commentString, "pom2bp", strings.Join(proptools.ShellEscapeList(os.Args[1:]), " ")) } + if prepend != "" { + contents, err := ioutil.ReadFile(prepend) + if err != nil { + fmt.Fprintln(os.Stderr, "Error reading", prepend, err) + os.Exit(1) + } + fmt.Fprintln(buf, string(contents)) + } + depsTemplate := bpDepsTemplate template := bpTemplate if pom2build { From 3df1467912317a2b627de9b4c4f9f560d6a4211d Mon Sep 17 00:00:00 2001 From: Brett Chabot Date: Wed, 12 Oct 2022 12:12:02 -0700 Subject: [PATCH 107/172] Add support for pom with packaging=apk to pom2bp. Bug: b/258279262 Bug: 251825866 Test: ./prebuilts/misc/common/androidx-test/update-from-gmaven.py Change-Id: I7811898d9801bb733f3b43c55308f6741778a378 Test: None (cherry picked from commit 688e6960fa1f3ee887c0f8159d6b0af50453028a) --- cmd/pom2bp/pom2bp.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/cmd/pom2bp/pom2bp.go b/cmd/pom2bp/pom2bp.go index e0638b8ed..0d741dd32 100644 --- a/cmd/pom2bp/pom2bp.go +++ b/cmd/pom2bp/pom2bp.go @@ -207,6 +207,10 @@ func (p Pom) IsJar() bool { return p.Packaging == "jar" } +func (p Pom) IsApk() bool { + return p.Packaging == "apk" +} + func (p Pom) IsHostModule() bool { return hostModuleNames.IsHostModule(p.GroupId, p.ArtifactId) } @@ -244,6 +248,8 @@ func (p Pom) BazelTargetType() string { func (p Pom) ImportModuleType() string { if p.IsAar() { return "android_library_import" + } else if p.IsApk() { + return "android_app_import" } else if p.IsHostOnly() { return "java_import_host" } else { @@ -254,6 +260,8 @@ func (p Pom) ImportModuleType() string { func (p Pom) BazelImportTargetType() string { if p.IsAar() { return "aar_import" + } else if p.IsApk() { + return "apk_import" } else { return "java_import" } @@ -262,6 +270,8 @@ func (p Pom) BazelImportTargetType() string { func (p Pom) ImportProperty() string { if p.IsAar() { return "aars" + } else if p.IsApk() { + return "apk" } else { return "jars" } @@ -270,6 +280,8 @@ func (p Pom) ImportProperty() string { func (p Pom) BazelImportProperty() string { if p.IsAar() { return "aar" + } else if p.IsApk() { + return "apk" } else { return "jars" } @@ -493,8 +505,12 @@ func (p *Pom) ExtractMinSdkVersion() error { var bpTemplate = template.Must(template.New("bp").Parse(` {{.ImportModuleType}} { name: "{{.BpName}}", + {{- if .IsApk}} + {{.ImportProperty}}: "{{.ArtifactFile}}", + {{- else}} {{.ImportProperty}}: ["{{.ArtifactFile}}"], sdk_version: "{{.SdkVersion}}", + {{- end}} {{- if .Jetifier}} jetifier: true, {{- end}} @@ -535,8 +551,14 @@ var bpTemplate = template.Must(template.New("bp").Parse(` ], {{- end}} {{- else if not .IsHostOnly}} + {{- if not .IsApk}} min_sdk_version: "{{.DefaultMinSdkVersion}}", {{- end}} + {{- end}} + {{- if .IsApk}} + presigned: true + {{- end}} + } `)) @@ -984,7 +1006,7 @@ Usage: %s [--rewrite =] [--exclude ] [--extra-static-lib for _, pom := range poms { var err error - if staticDeps { + if staticDeps && !pom.IsApk() { err = depsTemplate.Execute(buf, pom) } else { err = template.Execute(buf, pom) From 38c5baba25402fd3c52324a2f963c1461509fa44 Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Fri, 21 Oct 2022 21:52:13 +0000 Subject: [PATCH 108/172] Do not register missing deps This is a fix to aosp/2260763 and skips the existence check corectly. Previously, it would not throw an exception during Soong analysis, but would add the path to a `MissingDeps` object. The ninja graph generated using this would throw an exception during ninja execution. We should not do this check for `cc_api_library`. The prebuilt library.so is missing in the build graph of the inner tree (expected), but it will be present when the orchestrator creates the combined multi-tree ninja graph. Test: rm -rf out && multitree_build vendor/vendorimage (I did not clean out/ in aosp/2260763, and therefore did not catch this earlier) Test: go test ./cc Change-Id: I68d245acae3bfb777bfc8a72fb7cd4909cb0a289 Merged-In: I68d245acae3bfb777bfc8a72fb7cd4909cb0a289 --- android/paths.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/android/paths.go b/android/paths.go index c3ef7548a..6163762a5 100644 --- a/android/paths.go +++ b/android/paths.go @@ -1137,6 +1137,21 @@ func PathForSource(ctx PathContext, pathComponents ...string) SourcePath { return path } +// MaybeExistentPathForSource joins the provided path components and validates that the result +// neither escapes the source dir nor is in the out dir. +// It does not validate whether the path exists. +func MaybeExistentPathForSource(ctx PathContext, pathComponents ...string) SourcePath { + path, err := pathForSource(ctx, pathComponents...) + if err != nil { + reportPathError(ctx, err) + } + + if pathtools.IsGlob(path.String()) { + ReportPathErrorf(ctx, "path may not contain a glob: %s", path.String()) + } + return path +} + // ExistentPathForSource returns an OptionalPath with the SourcePath, rooted from SrcDir, *not* // rooted from the module's local source directory, if the path exists, or an empty OptionalPath if // it doesn't exist. Dependencies are added so that the ninja file will be regenerated if the state From 24756d7d9411db9fe588293998a305020728dbdd Mon Sep 17 00:00:00 2001 From: Jihoon Kang Date: Tue, 15 Nov 2022 19:06:14 +0000 Subject: [PATCH 109/172] Create java_api_contribution and java_api_library module Context - Droidstubs module is currently responsible not only for java api stubs generation, but also for checking api equality and compatibility. - Generating stubs with incomplete api text file that does not list entire api surface is done through metalava implicitly adding unlisted methods from java source files to the stubs in droidstubs module. - These factors make java stubs generation harder to debug, thus introduce `java_api_contribution` and `java_api_library` modules to make java api stubs and jar generation more explicit in Android.bp level and eventually easier to debug. Implementation - `java_api_contribution` module is included in api domains' directory and lists api text file directory to be added to the api surface - `java_api_library` collects all api text file that forms the api surface and creates stubs invoking metalava. Generated java stub files are converted into `.srcjar`, and eventually `.jar` file which is the complete api surface. Test: m Change-Id: I86f097cc8592334a5eaa900cec12764c5fcc09e7 Merged-In: I86f097cc8592334a5eaa900cec12764c5fcc09e7 --- java/java.go | 219 +++++++++++++++++++++++++++++++++++++++++----- java/java_test.go | 105 ++++++++++++++++++++++ 2 files changed, 303 insertions(+), 21 deletions(-) diff --git a/java/java.go b/java/java.go index e46712349..d8c30340e 100644 --- a/java/java.go +++ b/java/java.go @@ -24,6 +24,7 @@ import ( "strings" "android/soong/bazel" + "android/soong/remoteexec" "github.com/google/blueprint" "github.com/google/blueprint/proptools" @@ -58,6 +59,8 @@ func registerJavaBuildComponents(ctx android.RegistrationContext) { ctx.RegisterModuleType("java_device_for_host", DeviceForHostFactory) ctx.RegisterModuleType("java_host_for_device", HostForDeviceFactory) ctx.RegisterModuleType("dex_import", DexImportFactory) + ctx.RegisterModuleType("java_api_library", ApiLibraryFactory) + ctx.RegisterModuleType("java_api_contribution", ApiContributionFactory) // This mutator registers dependencies on dex2oat for modules that should be // dexpreopted. This is done late when the final variants have been @@ -1444,6 +1447,182 @@ func BinaryHostFactory() android.Module { return module } +type JavaApiContribution struct { + android.ModuleBase + android.DefaultableModuleBase + + properties struct { + // name of the API surface + Api_surface *string + + // relative path to the API signature text file + Api_file *string `android:"path"` + } +} + +func ApiContributionFactory() android.Module { + module := &JavaApiContribution{} + android.InitAndroidModule(module) + android.InitDefaultableModule(module) + module.AddProperties(&module.properties) + return module +} + +type JavaApiImportInfo struct { + ApiFile android.Path +} + +var JavaApiImportProvider = blueprint.NewProvider(JavaApiImportInfo{}) + +func (ap *JavaApiContribution) GenerateAndroidBuildActions(ctx android.ModuleContext) { + apiFile := android.PathForModuleSrc(ctx, String(ap.properties.Api_file)) + ctx.SetProvider(JavaApiImportProvider, JavaApiImportInfo{ + ApiFile: apiFile, + }) +} + +type ApiLibrary struct { + android.ModuleBase + android.DefaultableModuleBase + + properties JavaApiLibraryProperties + + stubsSrcJar android.WritablePath + stubsJar android.WritablePath +} + +type JavaApiLibraryProperties struct { + // name of the API surface + Api_surface *string + + // list of API provider modules that consists this API surface + Api_providers []string + + // List of flags to be passed to the javac compiler to generate jar file + Javacflags []string +} + +func ApiLibraryFactory() android.Module { + module := &ApiLibrary{} + android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) + android.InitDefaultableModule(module) + module.AddProperties(&module.properties) + return module +} + +func (al *ApiLibrary) ApiSurface() *string { + return al.properties.Api_surface +} + +func (al *ApiLibrary) StubsJar() android.Path { + return al.stubsJar +} + +func metalavaStubCmd(ctx android.ModuleContext, rule *android.RuleBuilder, + srcs android.Paths, homeDir android.WritablePath) *android.RuleBuilderCommand { + rule.Command().Text("rm -rf").Flag(homeDir.String()) + rule.Command().Text("mkdir -p").Flag(homeDir.String()) + + cmd := rule.Command() + cmd.FlagWithArg("ANDROID_PREFS_ROOT=", homeDir.String()) + + if metalavaUseRbe(ctx) { + rule.Remoteable(android.RemoteRuleSupports{RBE: true}) + execStrategy := ctx.Config().GetenvWithDefault("RBE_METALAVA_EXEC_STRATEGY", remoteexec.LocalExecStrategy) + labels := map[string]string{"type": "tool", "name": "metalava"} + + pool := ctx.Config().GetenvWithDefault("RBE_METALAVA_POOL", "java16") + rule.Rewrapper(&remoteexec.REParams{ + Labels: labels, + ExecStrategy: execStrategy, + ToolchainInputs: []string{config.JavaCmd(ctx).String()}, + Platform: map[string]string{remoteexec.PoolKey: pool}, + }) + } + + cmd.BuiltTool("metalava").ImplicitTool(ctx.Config().HostJavaToolPath(ctx, "metalava.jar")). + Flag(config.JavacVmFlags). + Flag("-J--add-opens=java.base/java.util=ALL-UNNAMED"). + FlagWithArg("-encoding ", "UTF-8"). + FlagWithInputList("--source-files ", srcs, " ") + + cmd.Flag("--no-banner"). + Flag("--color"). + Flag("--quiet"). + Flag("--format=v2"). + FlagWithArg("--repeat-errors-max ", "10"). + FlagWithArg("--hide ", "UnresolvedImport"). + FlagWithArg("--hide ", "InvalidNullabilityOverride"). + FlagWithArg("--hide ", "ChangedDefault") + + return cmd +} + +func (al *ApiLibrary) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.OptionalPath) { + if stubsDir.Valid() { + cmd.FlagWithArg("--stubs ", stubsDir.String()) + } +} + +var javaApiProviderTag = dependencyTag{name: "java-api-provider"} + +func (al *ApiLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { + apiProviders := al.properties.Api_providers + for _, apiProviderName := range apiProviders { + ctx.AddDependency(ctx.Module(), javaApiProviderTag, apiProviderName) + } +} + +func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { + + rule := android.NewRuleBuilder(pctx, ctx) + + rule.Sbox(android.PathForModuleOut(ctx, "metalava"), + android.PathForModuleOut(ctx, "metalava.sbox.textproto")). + SandboxInputs() + + var stubsDir android.OptionalPath + stubsDir = android.OptionalPathForPath(android.PathForModuleOut(ctx, "metalava", "stubsDir")) + rule.Command().Text("rm -rf").Text(stubsDir.String()) + rule.Command().Text("mkdir -p").Text(stubsDir.String()) + + homeDir := android.PathForModuleOut(ctx, "metalava", "home") + + apiProviders := al.properties.Api_providers + srcFiles := make([]android.Path, len(apiProviders)) + for i, apiProviderName := range apiProviders { + apiProvider := ctx.GetDirectDepWithTag(apiProviderName, javaApiProviderTag) + if apiProvider == nil { + panic(fmt.Errorf("Java API provider module %s not found, called from %s", apiProviderName, al.Name())) + } + provider := ctx.OtherModuleProvider(apiProvider, JavaApiImportProvider).(JavaApiImportInfo) + srcFiles[i] = android.PathForModuleSrc(ctx, provider.ApiFile.String()) + } + + cmd := metalavaStubCmd(ctx, rule, srcFiles, homeDir) + + al.stubsFlags(ctx, cmd, stubsDir) + + al.stubsSrcJar = android.PathForModuleOut(ctx, "metalava", ctx.ModuleName()+"-"+"stubs.srcjar") + rule.Command(). + BuiltTool("soong_zip"). + Flag("-write_if_changed"). + Flag("-jar"). + FlagWithOutput("-o ", al.stubsSrcJar). + FlagWithArg("-C ", stubsDir.String()). + FlagWithArg("-D ", stubsDir.String()) + + rule.Build("metalava", "metalava merged") + + al.stubsJar = android.PathForModuleOut(ctx, ctx.ModuleName(), "android.jar") + + var flags javaBuilderFlags + flags.javacFlags = strings.Join(al.properties.Javacflags, " ") + + TransformJavaToClasses(ctx, al.stubsJar, 0, android.Paths{}, + android.Paths{al.stubsSrcJar}, flags, android.Paths{}) +} + // // Java prebuilts // @@ -2017,9 +2196,7 @@ func DexImportFactory() android.Module { return module } -// // Defaults -// type Defaults struct { android.ModuleBase android.DefaultsModuleBase @@ -2034,29 +2211,29 @@ type Defaults struct { // // Example: // -// java_defaults { -// name: "example_defaults", -// srcs: ["common/**/*.java"], -// javacflags: ["-Xlint:all"], -// aaptflags: ["--auto-add-overlay"], -// } +// java_defaults { +// name: "example_defaults", +// srcs: ["common/**/*.java"], +// javacflags: ["-Xlint:all"], +// aaptflags: ["--auto-add-overlay"], +// } // -// java_library { -// name: "example", -// defaults: ["example_defaults"], -// srcs: ["example/**/*.java"], -// } +// java_library { +// name: "example", +// defaults: ["example_defaults"], +// srcs: ["example/**/*.java"], +// } // // is functionally identical to: // -// java_library { -// name: "example", -// srcs: [ -// "common/**/*.java", -// "example/**/*.java", -// ], -// javacflags: ["-Xlint:all"], -// } +// java_library { +// name: "example", +// srcs: [ +// "common/**/*.java", +// "example/**/*.java", +// ], +// javacflags: ["-Xlint:all"], +// } func DefaultsFactory() android.Module { module := &Defaults{} diff --git a/java/java_test.go b/java/java_test.go index af889ccd4..60e1210b2 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -1667,3 +1667,108 @@ func TestDataDeviceBinsBuildsDeviceBinary(t *testing.T) { }) } } + +func TestJavaApiLibraryAndProviderLink(t *testing.T) { + provider_bp_a := ` + java_api_contribution { + name: "foo1", + api_file: "foo1.txt", + } + ` + provider_bp_b := `java_api_contribution { + name: "foo2", + api_file: "foo2.txt", + } + ` + ctx, _ := testJavaWithFS(t, ` + java_api_library { + name: "bar1", + api_surface: "public", + api_providers: ["foo1"], + } + + java_api_library { + name: "bar2", + api_surface: "system", + api_providers: ["foo1", "foo2"], + } + `, + map[string][]byte{ + "a/Android.bp": []byte(provider_bp_a), + "b/Android.bp": []byte(provider_bp_b), + }) + + testcases := []struct { + moduleName string + sourceTextFileDirs []string + }{ + { + moduleName: "bar1", + sourceTextFileDirs: []string{"a/foo1.txt"}, + }, + { + moduleName: "bar2", + sourceTextFileDirs: []string{"a/foo1.txt", "b/foo2.txt"}, + }, + } + for _, c := range testcases { + m := ctx.ModuleForTests(c.moduleName, "android_common") + manifest := m.Output("metalava.sbox.textproto") + sboxProto := android.RuleBuilderSboxProtoForTests(t, manifest) + manifestCommand := sboxProto.Commands[0].GetCommand() + sourceFilesFlag := "--source-files " + strings.Join(c.sourceTextFileDirs, " ") + android.AssertStringDoesContain(t, "source text files not present", manifestCommand, sourceFilesFlag) + } +} + +func TestJavaApiLibraryJarGeneration(t *testing.T) { + provider_bp_a := ` + java_api_contribution { + name: "foo1", + api_file: "foo1.txt", + } + ` + provider_bp_b := `java_api_contribution { + name: "foo2", + api_file: "foo2.txt", + } + ` + ctx, _ := testJavaWithFS(t, ` + java_api_library { + name: "bar1", + api_surface: "public", + api_providers: ["foo1"], + } + + java_api_library { + name: "bar2", + api_surface: "system", + api_providers: ["foo1", "foo2"], + } + `, + map[string][]byte{ + "a/Android.bp": []byte(provider_bp_a), + "b/Android.bp": []byte(provider_bp_b), + }) + + testcases := []struct { + moduleName string + outputJarName string + }{ + { + moduleName: "bar1", + outputJarName: "bar1/android.jar", + }, + { + moduleName: "bar2", + outputJarName: "bar2/android.jar", + }, + } + for _, c := range testcases { + m := ctx.ModuleForTests(c.moduleName, "android_common") + outputs := fmt.Sprint(m.AllOutputs()) + if !strings.Contains(outputs, c.outputJarName) { + t.Errorf("Module output does not contain expected jar %s", c.outputJarName) + } + } +} From 2913b4b626e949d3802ba26adf2e2932bd35ca62 Mon Sep 17 00:00:00 2001 From: Jihoon Kang Date: Thu, 17 Nov 2022 23:47:43 +0000 Subject: [PATCH 110/172] Update java_api_library prop name Context - Update java_api_library module's prop name from api_providers to api_contributions to adjust to module rename - Update variables name correspondingly to enhance readability Test: m Change-Id: I93b941a572e04bed6084109d151ba83a82715651 Merged-In: I93b941a572e04bed6084109d151ba83a82715651 --- java/java.go | 27 +++++++++++---------------- java/java_test.go | 8 ++++---- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/java/java.go b/java/java.go index d8c30340e..8d68ce5de 100644 --- a/java/java.go +++ b/java/java.go @@ -1495,8 +1495,8 @@ type JavaApiLibraryProperties struct { // name of the API surface Api_surface *string - // list of API provider modules that consists this API surface - Api_providers []string + // list of Java API contribution modules that consists this API surface + Api_contributions []string // List of flags to be passed to the javac compiler to generate jar file Javacflags []string @@ -1564,12 +1564,12 @@ func (al *ApiLibrary) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBui } } -var javaApiProviderTag = dependencyTag{name: "java-api-provider"} +var javaApiContributionTag = dependencyTag{name: "java-api-contribution"} func (al *ApiLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { - apiProviders := al.properties.Api_providers - for _, apiProviderName := range apiProviders { - ctx.AddDependency(ctx.Module(), javaApiProviderTag, apiProviderName) + apiContributions := al.properties.Api_contributions + for _, apiContributionName := range apiContributions { + ctx.AddDependency(ctx.Module(), javaApiContributionTag, apiContributionName) } } @@ -1588,16 +1588,11 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { homeDir := android.PathForModuleOut(ctx, "metalava", "home") - apiProviders := al.properties.Api_providers - srcFiles := make([]android.Path, len(apiProviders)) - for i, apiProviderName := range apiProviders { - apiProvider := ctx.GetDirectDepWithTag(apiProviderName, javaApiProviderTag) - if apiProvider == nil { - panic(fmt.Errorf("Java API provider module %s not found, called from %s", apiProviderName, al.Name())) - } - provider := ctx.OtherModuleProvider(apiProvider, JavaApiImportProvider).(JavaApiImportInfo) - srcFiles[i] = android.PathForModuleSrc(ctx, provider.ApiFile.String()) - } + var srcFiles []android.Path + ctx.VisitDirectDepsWithTag(javaApiContributionTag, func(dep android.Module) { + provider := ctx.OtherModuleProvider(dep, JavaApiImportProvider).(JavaApiImportInfo) + srcFiles = append(srcFiles, android.PathForModuleSrc(ctx, provider.ApiFile.String())) + }) cmd := metalavaStubCmd(ctx, rule, srcFiles, homeDir) diff --git a/java/java_test.go b/java/java_test.go index 60e1210b2..d437a1723 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -1684,13 +1684,13 @@ func TestJavaApiLibraryAndProviderLink(t *testing.T) { java_api_library { name: "bar1", api_surface: "public", - api_providers: ["foo1"], + api_contributions: ["foo1"], } java_api_library { name: "bar2", api_surface: "system", - api_providers: ["foo1", "foo2"], + api_contributions: ["foo1", "foo2"], } `, map[string][]byte{ @@ -1737,13 +1737,13 @@ func TestJavaApiLibraryJarGeneration(t *testing.T) { java_api_library { name: "bar1", api_surface: "public", - api_providers: ["foo1"], + api_contributions: ["foo1"], } java_api_library { name: "bar2", api_surface: "system", - api_providers: ["foo1", "foo2"], + api_contributions: ["foo1", "foo2"], } `, map[string][]byte{ From ea04aad416a23a527c79f999fbecb58512bf97a6 Mon Sep 17 00:00:00 2001 From: Jihoon Kang Date: Tue, 29 Nov 2022 23:10:10 +0000 Subject: [PATCH 111/172] Add phony rule for java_api_library module type Context - Create phony rule for java_api_library module with its artifact (*.jar) as dependency - Fix source directory base mislinkage issue for input text files passed from java_api_contributions modules Test: m Change-Id: I055332fd5bc7ef0d03e7b311b0efa93f4454102f Merged-In: I055332fd5bc7ef0d03e7b311b0efa93f4454102f --- java/java.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/java/java.go b/java/java.go index 8d68ce5de..4e1837922 100644 --- a/java/java.go +++ b/java/java.go @@ -1591,7 +1591,7 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { var srcFiles []android.Path ctx.VisitDirectDepsWithTag(javaApiContributionTag, func(dep android.Module) { provider := ctx.OtherModuleProvider(dep, JavaApiImportProvider).(JavaApiImportInfo) - srcFiles = append(srcFiles, android.PathForModuleSrc(ctx, provider.ApiFile.String())) + srcFiles = append(srcFiles, android.PathForSource(ctx, provider.ApiFile.String())) }) cmd := metalavaStubCmd(ctx, rule, srcFiles, homeDir) @@ -1616,6 +1616,8 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { TransformJavaToClasses(ctx, al.stubsJar, 0, android.Paths{}, android.Paths{al.stubsSrcJar}, flags, android.Paths{}) + + ctx.Phony(ctx.ModuleName(), al.stubsJar) } // From 09ff3deef5ef2f70299eab805c28576616e4e8ec Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Thu, 1 Dec 2022 21:43:06 +0000 Subject: [PATCH 112/172] Add an api_files property in java_api_library java_api_contribution is useful to java_api_library when the api files are not colocated. If they are colocated (e.g. in Multi-tree assembled api_surfaces directory), it is useful to refer to them directly without nedding to create a java_api_contribution module. Test: In build/soong, go test ./java Change-Id: I5b4e557068a1e5c71a80c76452030e72ec83a696 Merged-In: I5b4e557068a1e5c71a80c76452030e72ec83a696 --- java/java.go | 13 +++++++++++++ java/java_test.go | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/java/java.go b/java/java.go index 4e1837922..7a1f53231 100644 --- a/java/java.go +++ b/java/java.go @@ -1496,8 +1496,14 @@ type JavaApiLibraryProperties struct { Api_surface *string // list of Java API contribution modules that consists this API surface + // This is a list of Soong modules Api_contributions []string + // list of api.txt files relative to this directory that contribute to the + // API surface. + // This is a list of relative paths + Api_files []string + // List of flags to be passed to the javac compiler to generate jar file Javacflags []string } @@ -1594,6 +1600,13 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { srcFiles = append(srcFiles, android.PathForSource(ctx, provider.ApiFile.String())) }) + // Add the api_files inputs + for _, api := range al.properties.Api_files { + // Use MaybeExistentPathForSource since the api file might not exist during analysis. + // This will be provided by the orchestrator in the combined execution. + srcFiles = append(srcFiles, android.MaybeExistentPathForSource(ctx, ctx.ModuleDir(), api)) + } + cmd := metalavaStubCmd(ctx, rule, srcFiles, homeDir) al.stubsFlags(ctx, cmd, stubsDir) diff --git a/java/java_test.go b/java/java_test.go index d437a1723..2378a6cbe 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -1691,6 +1691,7 @@ func TestJavaApiLibraryAndProviderLink(t *testing.T) { name: "bar2", api_surface: "system", api_contributions: ["foo1", "foo2"], + api_files: ["api1/current.txt", "api2/current.txt"] } `, map[string][]byte{ @@ -1708,7 +1709,7 @@ func TestJavaApiLibraryAndProviderLink(t *testing.T) { }, { moduleName: "bar2", - sourceTextFileDirs: []string{"a/foo1.txt", "b/foo2.txt"}, + sourceTextFileDirs: []string{"a/foo1.txt", "b/foo2.txt", "api1/current.txt", "api2/current.txt"}, }, } for _, c := range testcases { From fc9623bb28f08ab05513b9ea8919deb1740462a8 Mon Sep 17 00:00:00 2001 From: Jihoon Kang Date: Thu, 22 Dec 2022 21:26:06 +0000 Subject: [PATCH 113/172] Set Java version for java_api_library module Currently, stubs are compiled with Java version 1.8. To align with this, set the java version passed to javac invocation as 1.8 for java_api_library module. Helper function is used to sync the java version of droiddoc module and java_api_library module. Test: m Change-Id: I103b94aed9747a2f2dd65d13de0ae9c0f33db5c0 Merged-In: I103b94aed9747a2f2dd65d13de0ae9c0f33db5c0 --- java/droiddoc.go | 2 +- java/java.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/java/droiddoc.go b/java/droiddoc.go index c1182652f..0c8908e24 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -591,7 +591,7 @@ func (d *Droiddoc) doclavaDocsFlags(ctx android.ModuleContext, cmd *android.Rule // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9 // sources, droiddoc will get sources produced by metalava which will have already stripped out the // 1.9 language features. - cmd.FlagWithArg("-source ", "1.8"). + cmd.FlagWithArg("-source ", getStubsJavaVersion().String()). Flag("-J-Xmx1600m"). Flag("-J-XX:-OmitStackTraceInFastThrow"). Flag("-XDignore.symbol.file"). diff --git a/java/java.go b/java/java.go index 7a1f53231..5a3a2e0a3 100644 --- a/java/java.go +++ b/java/java.go @@ -503,6 +503,11 @@ func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext an } } +// Java version for stubs generation +func getStubsJavaVersion() javaVersion { + return JAVA_VERSION_8 +} + type javaVersion int const ( @@ -1625,6 +1630,7 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { al.stubsJar = android.PathForModuleOut(ctx, ctx.ModuleName(), "android.jar") var flags javaBuilderFlags + flags.javaVersion = getStubsJavaVersion() flags.javacFlags = strings.Join(al.properties.Javacflags, " ") TransformJavaToClasses(ctx, al.stubsJar, 0, android.Paths{}, From 5d647d0376ad75239e91a7d8f401dca63539e4ac Mon Sep 17 00:00:00 2001 From: Harshit Mahajan Date: Mon, 9 Jan 2023 20:45:55 +0000 Subject: [PATCH 114/172] [Cherry picked from I86e0bf684a5083221dae53907d9f548a0390b673] Move target sdk version enforcement check Enforce target sdk version flag could only be used by `android_app`, moving the check into a common function `generateAndroidBuildActions`. This would ensure that the `enforce_target_sdk_version` flag can also be set by `android_test` and `android_test_helper_app`. Bug: b/227460469 Test: m nothing Change-Id: I86e0bf684a5083221dae53907d9f548a0390b673 --- java/app.go | 9 +++--- java/app_test.go | 72 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 76 insertions(+), 5 deletions(-) diff --git a/java/app.go b/java/app.go index 04db0d4d8..4c7f0172e 100755 --- a/java/app.go +++ b/java/app.go @@ -315,10 +315,6 @@ func (a *AndroidApp) checkAppSdkVersions(ctx android.ModuleContext) { } } - if Bool(a.appProperties.Enforce_default_target_sdk_version) { - a.SetEnforceDefaultTargetSdkVersion(true) - } - a.checkPlatformAPI(ctx) a.checkSdkVersions(ctx) } @@ -620,6 +616,11 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { a.aapt.noticeFile = android.OptionalPathForPath(noticeAssetPath) } + // For apps targeting latest target_sdk_version + if Bool(a.appProperties.Enforce_default_target_sdk_version) { + a.SetEnforceDefaultTargetSdkVersion(true) + } + // Process all building blocks, from AAPT to certificates. a.aaptBuildActions(ctx) diff --git a/java/app_test.go b/java/app_test.go index 83b47bdc9..53676be37 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -3166,7 +3166,7 @@ func TestEnforceDefaultAppTargetSdkVersionFlag(t *testing.T) { updatable: true, }, { - name: "[SDK finalised] Enforce Target SDK Version: Android.bp has current targetSdkVersion", + name: "Enforce Target SDK Version: Android.bp has current targetSdkVersion", enforceDefaultTargetSdkVersion: true, platform_sdk_final: false, targetSdkVersionInBp: "current", @@ -3222,6 +3222,76 @@ func TestEnforceDefaultAppTargetSdkVersionFlag(t *testing.T) { } } +func TestEnforceDefaultAppTargetSdkVersionFlagForTests(t *testing.T) { + platform_sdk_codename := "Tiramisu" + platform_sdk_version := 33 + testCases := []struct { + name string + enforceDefaultTargetSdkVersion bool + expectedError string + platform_sdk_final bool + targetSdkVersionInBp string + targetSdkVersionExpected string + }{ + { + name: "Not enforcing Target SDK Version: Android.bp has older targetSdkVersion", + enforceDefaultTargetSdkVersion: false, + targetSdkVersionInBp: "29", + targetSdkVersionExpected: "29", + }, + { + name: "[SDK finalised] Enforce Target SDK Version: Android.bp has current targetSdkVersion", + enforceDefaultTargetSdkVersion: true, + platform_sdk_final: true, + targetSdkVersionInBp: "current", + targetSdkVersionExpected: "33", + }, + { + name: "Enforce Target SDK Version: Android.bp has current targetSdkVersion", + enforceDefaultTargetSdkVersion: true, + platform_sdk_final: false, + targetSdkVersionInBp: "current", + targetSdkVersionExpected: "10000", + }, + } + for _, testCase := range testCases { + errExpected := testCase.expectedError != "" + bp := fmt.Sprintf(` + android_test { + name: "foo", + enforce_default_target_sdk_version: %t, + min_sdk_version: "29", + target_sdk_version: "%v", + } + `, testCase.enforceDefaultTargetSdkVersion, testCase.targetSdkVersionInBp) + + fixture := android.GroupFixturePreparers( + PrepareForTestWithJavaDefaultModules, + android.PrepareForTestWithAllowMissingDependencies, + android.PrepareForTestWithAndroidMk, + android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + // explicitly set following platform variables to make the test deterministic + variables.Platform_sdk_final = &testCase.platform_sdk_final + variables.Platform_sdk_version = &platform_sdk_version + variables.Platform_sdk_codename = &platform_sdk_codename + variables.Unbundled_build_apps = []string{"sampleModule"} + }), + ) + + errorHandler := android.FixtureExpectsNoErrors + if errExpected { + errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(testCase.expectedError) + } + result := fixture.ExtendWithErrorHandler(errorHandler).RunTestWithBp(t, bp) + + if !errExpected { + foo := result.ModuleForTests("foo", "android_common") + manifestFixerArgs := foo.Output("manifest_fixer/AndroidManifest.xml").Args["args"] + android.AssertStringDoesContain(t, testCase.name, manifestFixerArgs, "--targetSdkVersion "+testCase.targetSdkVersionExpected) + } + } +} + func TestAppMissingCertificateAllowMissingDependencies(t *testing.T) { result := android.GroupFixturePreparers( PrepareForTestWithJavaDefaultModules, From c895c7b3ee4f1c9f11201370476b7c4442c114a9 Mon Sep 17 00:00:00 2001 From: zhidou Date: Fri, 27 Jan 2023 20:57:40 +0000 Subject: [PATCH 115/172] DO NOT MERGE: Make min_sdk overridable in override_apex It makes sense to make min_sdk overridable because the override_apex is a variant of the original apex, and this variant might be created/introduced in the newer Android release compared with the base apex. Despite the fact that the source of the variant apex is the same as the original one, the variant may not support the older version, like Go modules, trimmed modules. If we consider the variant as a "new" module, then it makes sense to have a new min_sdk to make it only available for the newer Android released version only. Will make change in AOSP separately. Bug: 266945903 Test: Build locally, and check if the override works Change-Id: I816ed020f51dae37666a0c7612dc9c11afd63b83 --- apex/apex.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index d5e2a3db6..132b2b29f 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -120,10 +120,6 @@ type apexBundleProperties struct { // List of filesystem images that are embedded inside this APEX bundle. Filesystems []string - // The minimum SDK version that this APEX must support at minimum. This is usually set to - // the SDK version that the APEX was first introduced. - Min_sdk_version *string - // Whether this APEX is considered updatable or not. When set to true, this will enforce // additional rules for making sure that the APEX is truly updatable. To be updatable, // min_sdk_version should be set as well. This will also disable the size optimizations like @@ -386,6 +382,10 @@ type overridableProperties struct { // conditions, e.g., target device needs to support APEX compression, are also fulfilled. // Default: false. Compressible *bool + + // The minimum SDK version that this APEX must support at minimum. This is usually set to + // the SDK version that the APEX was first introduced. + Min_sdk_version *string } type apexBundle struct { @@ -2550,14 +2550,14 @@ func (a *apexBundle) minSdkVersionValue(ctx android.EarlyModuleContext) string { // min_sdk_version value is lower than the one to override with. overrideMinSdkValue := ctx.DeviceConfig().ApexGlobalMinSdkVersionOverride() overrideApiLevel := minSdkVersionFromValue(ctx, overrideMinSdkValue) - originalMinApiLevel := minSdkVersionFromValue(ctx, proptools.String(a.properties.Min_sdk_version)) - isMinSdkSet := a.properties.Min_sdk_version != nil + originalMinApiLevel := minSdkVersionFromValue(ctx, proptools.String(a.overridableProperties.Min_sdk_version)) + isMinSdkSet := a.overridableProperties.Min_sdk_version != nil isOverrideValueHigher := overrideApiLevel.CompareTo(originalMinApiLevel) > 0 if overrideMinSdkValue != "" && isMinSdkSet && isOverrideValueHigher { return overrideMinSdkValue } - return proptools.String(a.properties.Min_sdk_version) + return proptools.String(a.overridableProperties.Min_sdk_version) } // Returns apex's min_sdk_version SdkSpec, honoring overrides @@ -3255,8 +3255,8 @@ func (a *apexBundle) ConvertWithBp2build(ctx android.TopDownMutatorContext) { // TODO(b/219503907) this would need to be set to a.MinSdkVersionValue(ctx) but // given it's coming via config, we probably don't want to put it in here. var minSdkVersion *string - if a.properties.Min_sdk_version != nil { - minSdkVersion = a.properties.Min_sdk_version + if a.overridableProperties.Min_sdk_version != nil { + minSdkVersion = a.overridableProperties.Min_sdk_version } var keyLabelAttribute bazel.LabelAttribute From fdf043a7b109250447f7c89bbeb29a1726a4d602 Mon Sep 17 00:00:00 2001 From: Cory Barker Date: Fri, 3 Feb 2023 00:20:52 +0000 Subject: [PATCH 116/172] Fix Soong code, remove dead code, and clean up code for Java fuzz Test: built fuzz targets locally and tested them with Jazzer Change-Id: I3ff487ba4e34289e0f53f2077463f524f4bf4f11 --- java/androidmk.go | 10 ++- java/fuzz.go | 206 +++++++++++++--------------------------------- java/fuzz_test.go | 10 +-- java/java.go | 1 - 4 files changed, 71 insertions(+), 156 deletions(-) diff --git a/java/androidmk.go b/java/androidmk.go index a4dac80d4..d90e6df6b 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -133,13 +133,19 @@ func (library *Library) AndroidMkEntries() []android.AndroidMkEntries { return entriesList } -func (j *JavaFuzzLibrary) AndroidMkEntries() []android.AndroidMkEntries { +func (j *JavaFuzzTest) AndroidMkEntries() []android.AndroidMkEntries { entriesList := j.Library.AndroidMkEntries() entries := &entriesList[0] entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", "null-suite") - androidMkWriteTestData(j.jniFilePaths, entries) androidMkWriteTestData(android.Paths{j.implementationJarFile}, entries) + androidMkWriteTestData(j.jniFilePaths, entries) + if j.fuzzPackagedModule.Corpus != nil { + androidMkWriteTestData(j.fuzzPackagedModule.Corpus, entries) + } + if j.fuzzPackagedModule.Dictionary != nil { + androidMkWriteTestData(android.Paths{j.fuzzPackagedModule.Dictionary}, entries) + } }) return entriesList } diff --git a/java/fuzz.go b/java/fuzz.go index 1d6b91346..2b9e22b8e 100644 --- a/java/fuzz.go +++ b/java/fuzz.go @@ -19,12 +19,12 @@ import ( "sort" "strings" - "github.com/google/blueprint" - "github.com/google/blueprint/proptools" - "android/soong/android" "android/soong/cc" "android/soong/fuzz" + + "github.com/google/blueprint" + "github.com/google/blueprint/proptools" ) const ( @@ -32,63 +32,63 @@ const ( targetString = "target" ) -type jniProperties struct { - // list of jni libs - Jni_libs []string - - // sanitization - Sanitizers []string -} - func init() { RegisterJavaFuzzBuildComponents(android.InitRegistrationContext) } func RegisterJavaFuzzBuildComponents(ctx android.RegistrationContext) { ctx.RegisterModuleType("java_fuzz", JavaFuzzFactory) - ctx.RegisterModuleType("java_fuzz_host", JavaFuzzHostFactory) - ctx.RegisterSingletonType("java_fuzz_host_packaging", javaFuzzHostPackagingFactory) - ctx.RegisterSingletonType("java_fuzz_device_packaging", javaFuzzDevicePackagingFactory) + ctx.RegisterSingletonType("java_fuzz_packaging", javaFuzzPackagingFactory) } -type JavaFuzzLibrary struct { - Library +type JavaFuzzTest struct { + Test fuzzPackagedModule fuzz.FuzzPackagedModule - jniProperties jniProperties jniFilePaths android.Paths } -// IsSanitizerEnabledForJni implemented to make JavaFuzzLibrary implement -// cc.JniSanitizeable. It returns a bool for whether a cc dependency should be -// sanitized for the given sanitizer or not. -func (j *JavaFuzzLibrary) IsSanitizerEnabledForJni(ctx android.BaseModuleContext, sanitizerName string) bool { - // TODO: once b/231370928 is resolved, please uncomment the loop - // for _, s := range j.jniProperties.Sanitizers { - // if sanitizerName == s { - // return true - // } - // } - return false +// java_fuzz builds and links sources into a `.jar` file for the device. +// This generates .class files in a jar which can then be instrumented before +// fuzzing in Android Runtime (ART: Android OS on emulator or device) +func JavaFuzzFactory() android.Module { + module := &JavaFuzzTest{} + + module.addHostAndDeviceProperties() + module.AddProperties(&module.testProperties) + module.AddProperties(&module.fuzzPackagedModule.FuzzProperties) + + module.Module.properties.Installable = proptools.BoolPtr(true) + module.Module.dexpreopter.isTest = true + module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) + + android.AddLoadHook(module, func(ctx android.LoadHookContext) { + disableLinuxBionic := struct { + Target struct { + Linux_bionic struct { + Enabled *bool + } + } + }{} + disableLinuxBionic.Target.Linux_bionic.Enabled = proptools.BoolPtr(false) + ctx.AppendProperties(&disableLinuxBionic) + }) + + InitJavaModuleMultiTargets(module, android.HostAndDeviceSupported) + return module } -func (j *JavaFuzzLibrary) DepsMutator(mctx android.BottomUpMutatorContext) { - if len(j.jniProperties.Jni_libs) > 0 { - if j.fuzzPackagedModule.FuzzProperties.Fuzz_config == nil { - config := &fuzz.FuzzConfig{} - j.fuzzPackagedModule.FuzzProperties.Fuzz_config = config - } - // this will be used by the ingestion pipeline to determine the version - // of jazzer to add to the fuzzer package - j.fuzzPackagedModule.FuzzProperties.Fuzz_config.IsJni = proptools.BoolPtr(true) - for _, target := range mctx.MultiTargets() { +func (j *JavaFuzzTest) DepsMutator(ctx android.BottomUpMutatorContext) { + if len(j.testProperties.Jni_libs) > 0 { + for _, target := range ctx.MultiTargets() { sharedLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"}) - mctx.AddFarVariationDependencies(sharedLibVariations, cc.JniFuzzLibTag, j.jniProperties.Jni_libs...) + ctx.AddFarVariationDependencies(sharedLibVariations, jniLibTag, j.testProperties.Jni_libs...) } } - j.Library.DepsMutator(mctx) + + j.deps(ctx) } -func (j *JavaFuzzLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { +func (j *JavaFuzzTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { if j.fuzzPackagedModule.FuzzProperties.Corpus != nil { j.fuzzPackagedModule.Corpus = android.PathsForModuleSrc(ctx, j.fuzzPackagedModule.FuzzProperties.Corpus) } @@ -105,21 +105,15 @@ func (j *JavaFuzzLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) } _, sharedDeps := cc.CollectAllSharedDependencies(ctx) - for _, dep := range sharedDeps { sharedLibInfo := ctx.OtherModuleProvider(dep, cc.SharedLibraryInfoProvider).(cc.SharedLibraryInfo) if sharedLibInfo.SharedLibrary != nil { - // The .class jars are output in slightly different locations - // relative to the jni libs. Therefore, for consistency across - // host and device fuzzers of jni lib location, we save it in a - // native_libs directory. - var relPath string + arch := "lib" if sharedLibInfo.Target.Arch.ArchType.Multilib == "lib64" { - relPath = filepath.Join("lib64", sharedLibInfo.SharedLibrary.Base()) - } else { - relPath = filepath.Join("lib", sharedLibInfo.SharedLibrary.Base()) + arch = "lib64" } - libPath := android.PathForModuleOut(ctx, relPath) + + libPath := android.PathForModuleOut(ctx, filepath.Join(arch, sharedLibInfo.SharedLibrary.Base())) ctx.Build(pctx, android.BuildParams{ Rule: android.Cp, Input: sharedLibInfo.SharedLibrary, @@ -129,104 +123,35 @@ func (j *JavaFuzzLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) } else { ctx.PropertyErrorf("jni_libs", "%q of type %q is not supported", dep.Name(), ctx.OtherModuleType(dep)) } + } - j.Library.GenerateAndroidBuildActions(ctx) + j.Test.GenerateAndroidBuildActions(ctx) } -// java_fuzz_host builds and links sources into a `.jar` file for the host. -// -// By default, a java_fuzz produces a `.jar` file containing `.class` files. -// This jar is not suitable for installing on a device. -func JavaFuzzHostFactory() android.Module { - module := &JavaFuzzLibrary{} - module.addHostProperties() - module.AddProperties(&module.jniProperties) - module.Module.properties.Installable = proptools.BoolPtr(true) - module.AddProperties(&module.fuzzPackagedModule.FuzzProperties) - - // java_fuzz packaging rules collide when both linux_glibc and linux_bionic are enabled, disable the linux_bionic variants. - android.AddLoadHook(module, func(ctx android.LoadHookContext) { - disableLinuxBionic := struct { - Target struct { - Linux_bionic struct { - Enabled *bool - } - } - }{} - disableLinuxBionic.Target.Linux_bionic.Enabled = proptools.BoolPtr(false) - ctx.AppendProperties(&disableLinuxBionic) - }) - - InitJavaModuleMultiTargets(module, android.HostSupportedNoCross) - return module -} - -// java_fuzz builds and links sources into a `.jar` file for the device. -// This generates .class files in a jar which can then be instrumented before -// fuzzing in Android Runtime (ART: Android OS on emulator or device) -func JavaFuzzFactory() android.Module { - module := &JavaFuzzLibrary{} - module.addHostAndDeviceProperties() - module.AddProperties(&module.jniProperties) - module.Module.properties.Installable = proptools.BoolPtr(true) - module.AddProperties(&module.fuzzPackagedModule.FuzzProperties) - module.Module.dexpreopter.isTest = true - module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) - InitJavaModuleMultiTargets(module, android.DeviceSupported) - return module -} - -// Responsible for generating rules that package host fuzz targets into -// a zip file. -type javaFuzzHostPackager struct { +type javaFuzzPackager struct { fuzz.FuzzPackager } -// Responsible for generating rules that package device fuzz targets into -// a zip file. -type javaFuzzDevicePackager struct { - fuzz.FuzzPackager +func javaFuzzPackagingFactory() android.Singleton { + return &javaFuzzPackager{} } -func javaFuzzHostPackagingFactory() android.Singleton { - return &javaFuzzHostPackager{} -} - -func javaFuzzDevicePackagingFactory() android.Singleton { - return &javaFuzzDevicePackager{} -} - -func (s *javaFuzzHostPackager) GenerateBuildActions(ctx android.SingletonContext) { - generateBuildActions(&s.FuzzPackager, hostString, ctx) -} - -func (s *javaFuzzDevicePackager) GenerateBuildActions(ctx android.SingletonContext) { - generateBuildActions(&s.FuzzPackager, targetString, ctx) -} - -func generateBuildActions(s *fuzz.FuzzPackager, hostOrTargetString string, ctx android.SingletonContext) { +func (s *javaFuzzPackager) GenerateBuildActions(ctx android.SingletonContext) { // Map between each architecture + host/device combination. archDirs := make(map[fuzz.ArchOs][]fuzz.FileToZip) - // List of individual fuzz targets. s.FuzzTargets = make(map[string]bool) - ctx.VisitAllModules(func(module android.Module) { // Discard non-fuzz targets. - javaFuzzModule, ok := module.(*JavaFuzzLibrary) + javaFuzzModule, ok := module.(*JavaFuzzTest) if !ok { return } - if hostOrTargetString == hostString { - if !javaFuzzModule.Host() { - return - } - } else if hostOrTargetString == targetString { - if javaFuzzModule.Host() || javaFuzzModule.Target().HostCross { - return - } + hostOrTargetString := "target" + if javaFuzzModule.Host() { + hostOrTargetString = "host" } fuzzModuleValidator := fuzz.FuzzModule{ @@ -246,7 +171,7 @@ func generateBuildActions(s *fuzz.FuzzPackager, hostOrTargetString string, ctx a var files []fuzz.FileToZip builder := android.NewRuleBuilder(pctx, ctx) - // Package the artifacts (data, corpus, config and dictionary into a zipfile. + // Package the artifacts (data, corpus, config and dictionary) into a zipfile. files = s.PackageArtifacts(ctx, module, javaFuzzModule.fuzzPackagedModule, archDir, builder) // Add .jar @@ -261,27 +186,14 @@ func generateBuildActions(s *fuzz.FuzzPackager, hostOrTargetString string, ctx a if !ok { return } - }) s.CreateFuzzPackage(ctx, archDirs, fuzz.Java, pctx) } -func (s *javaFuzzHostPackager) MakeVars(ctx android.MakeVarsContext) { +func (s *javaFuzzPackager) MakeVars(ctx android.MakeVarsContext) { packages := s.Packages.Strings() sort.Strings(packages) - - ctx.Strict("SOONG_JAVA_FUZZ_HOST_PACKAGING_ARCH_MODULES", strings.Join(packages, " ")) - + ctx.Strict("SOONG_JAVA_FUZZ_PACKAGING_ARCH_MODULES", strings.Join(packages, " ")) // Preallocate the slice of fuzz targets to minimize memory allocations. - s.PreallocateSlice(ctx, "ALL_JAVA_FUZZ_HOST_TARGETS") -} - -func (s *javaFuzzDevicePackager) MakeVars(ctx android.MakeVarsContext) { - packages := s.Packages.Strings() - sort.Strings(packages) - - ctx.Strict("SOONG_JAVA_FUZZ_DEVICE_PACKAGING_ARCH_MODULES", strings.Join(packages, " ")) - - // Preallocate the slice of fuzz targets to minimize memory allocations. - s.PreallocateSlice(ctx, "ALL_JAVA_FUZZ_DEVICE_TARGETS") + s.PreallocateSlice(ctx, "ALL_JAVA_FUZZ_TARGETS") } diff --git a/java/fuzz_test.go b/java/fuzz_test.go index 186c3aa95..dd1e96b3e 100644 --- a/java/fuzz_test.go +++ b/java/fuzz_test.go @@ -31,17 +31,15 @@ var prepForJavaFuzzTest = android.GroupFixturePreparers( func TestJavaFuzz(t *testing.T) { result := prepForJavaFuzzTest.RunTestWithBp(t, ` - java_fuzz_host { + java_fuzz { name: "foo", srcs: ["a.java"], + host_supported: true, + device_supported: false, libs: ["bar"], static_libs: ["baz"], jni_libs: [ "libjni", - ], - sanitizers: [ - "address", - "fuzzer", ], } @@ -84,7 +82,7 @@ func TestJavaFuzz(t *testing.T) { } ctx := result.TestContext - foo := ctx.ModuleForTests("foo", osCommonTarget).Module().(*JavaFuzzLibrary) + foo := ctx.ModuleForTests("foo", osCommonTarget).Module().(*JavaFuzzTest) expected := "lib64/libjni.so" if runtime.GOOS == "darwin" { diff --git a/java/java.go b/java/java.go index 659f98a7c..42a196e55 100644 --- a/java/java.go +++ b/java/java.go @@ -1144,7 +1144,6 @@ func (j *TestHost) DepsMutator(ctx android.BottomUpMutatorContext) { } j.addDataDeviceBinsDeps(ctx) - j.deps(ctx) } From 470fcbf29c18e305ea37855e94e0c431cb152545 Mon Sep 17 00:00:00 2001 From: Srilakshmi Singaraju Date: Thu, 23 Feb 2023 23:57:26 +0000 Subject: [PATCH 117/172] DO NOT MERGE Update the module versions in udc-dev Bug: 258850762 Ignore-AOSP-First: Version bump only needed on udc-dev branch not on git_master Change-Id: I88d5a6dc1b46cae1358ca215a20354cf02784d94 --- android/updatable_modules.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/updatable_modules.go b/android/updatable_modules.go index 1548170f9..6d0eeb716 100644 --- a/android/updatable_modules.go +++ b/android/updatable_modules.go @@ -33,4 +33,4 @@ package android // * AOSP - xx9990000 // * x-mainline-prod - xx9990000 // * master - 990090000 -const DefaultUpdatableModuleVersion = "990090000" +const DefaultUpdatableModuleVersion = "340090000" From 2bb9c554b1945addf2796af189a198f8e58d56e1 Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Thu, 11 Aug 2022 11:59:04 -0700 Subject: [PATCH 118/172] Add lint test property Some libraries are only used for tests, but are not test module types. These modules get warnings about @VisibleForTesting usages when they really shouldn't. Expose a test flag that module authors can use to make lint treat a module as test code. Bug: 235339747 Test: Manually tested applying it to SystemUI-tests Change-Id: I1356749a669dc80a7725605d7159da27c9a211b4 (cherry picked from commit d57e8b2c2a55359c86def86a06dfdc7f7678d3c3) Merged-In: I1356749a669dc80a7725605d7159da27c9a211b4 --- java/app.go | 4 ++-- java/java.go | 4 ++-- java/lint.go | 8 ++++++-- java/robolectric.go | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/java/app.go b/java/app.go index 4c7f0172e..c3a33ff8d 100755 --- a/java/app.go +++ b/java/app.go @@ -1086,7 +1086,7 @@ func AndroidTestFactory() android.Module { module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true) module.appProperties.AlwaysPackageNativeLibs = true module.Module.dexpreopter.isTest = true - module.Module.linter.test = true + module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) module.addHostAndDeviceProperties() module.AddProperties( @@ -1138,7 +1138,7 @@ func AndroidTestHelperAppFactory() android.Module { module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true) module.appProperties.AlwaysPackageNativeLibs = true module.Module.dexpreopter.isTest = true - module.Module.linter.test = true + module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) module.addHostAndDeviceProperties() module.AddProperties( diff --git a/java/java.go b/java/java.go index 5a3a2e0a3..a07565ce5 100644 --- a/java/java.go +++ b/java/java.go @@ -1251,7 +1251,7 @@ func TestFactory() android.Module { module.Module.properties.Installable = proptools.BoolPtr(true) module.Module.dexpreopter.isTest = true - module.Module.linter.test = true + module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) android.InitSdkAwareModule(module) InitJavaModule(module, android.HostAndDeviceSupported) @@ -1267,7 +1267,7 @@ func TestHelperLibraryFactory() android.Module { module.Module.properties.Installable = proptools.BoolPtr(true) module.Module.dexpreopter.isTest = true - module.Module.linter.test = true + module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) InitJavaModule(module, android.HostAndDeviceSupported) return module diff --git a/java/lint.go b/java/lint.go index 426a2af25..fdc9dbd99 100644 --- a/java/lint.go +++ b/java/lint.go @@ -60,6 +60,11 @@ type LintProperties struct { // If true, baselining updatability lint checks (e.g. NewApi) is prohibited. Defaults to false. Strict_updatability_linting *bool + + // Treat the code in this module as test code for @VisibleForTesting enforcement. + // This will be true by default for test module types, false otherwise. + // If soong gets support for testonly, this flag should be replaced with that. + Test *bool } } @@ -73,7 +78,6 @@ type linter struct { classpath android.Paths classes android.Path extraLintCheckJars android.Paths - test bool library bool minSdkVersion android.ApiLevel targetSdkVersion android.ApiLevel @@ -228,7 +232,7 @@ func (l *linter) writeLintProjectXML(ctx android.ModuleContext, rule *android.Ru if l.library { cmd.Flag("--library") } - if l.test { + if proptools.BoolDefault(l.properties.Lint.Test, false) { cmd.Flag("--test") } if l.manifest != nil { diff --git a/java/robolectric.go b/java/robolectric.go index 80be04612..999da6fca 100644 --- a/java/robolectric.go +++ b/java/robolectric.go @@ -354,7 +354,7 @@ func RobolectricTestFactory() android.Module { &module.testProperties) module.Module.dexpreopter.isTest = true - module.Module.linter.test = true + module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) module.testProperties.Test_suites = []string{"robolectric-tests"} From 85c207ed43af473d86024f4836876d47c1176e46 Mon Sep 17 00:00:00 2001 From: Helen Qin Date: Wed, 1 Mar 2023 19:31:36 +0000 Subject: [PATCH 119/172] Revert "Update clang version to clang-r487747" Revert submission 2446165-update-clang-r487747 Reason for revert: DroidMonitor-triggered revert due to breakage bug b/271252582 and b/271243811 Reverted changes: /q/submissionid:2446165-update-clang-r487747 Bug: 271252582 Bug: 271243811 Change-Id: I3b5c44982d268b5c6c3db39e7af4d7aa7c6dfbf7 (cherry picked from commit 9ede2803752681713244f8800c86381e9a35c501) Merged-In: I3b5c44982d268b5c6c3db39e7af4d7aa7c6dfbf7 --- android/config.go | 5 ----- cc/config/global.go | 9 ++------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/android/config.go b/android/config.go index 78da32036..bb3cc97ab 100644 --- a/android/config.go +++ b/android/config.go @@ -1359,11 +1359,6 @@ func (c *deviceConfig) NativeCoverageEnabledForPath(path string) bool { } } if coverage && len(c.config.productVariables.NativeCoverageExcludePaths) > 0 { - // Workaround coverage boot failure. - // http://b/269981180 - if strings.HasPrefix(path, "external/protobuf") { - coverage = false - } if HasAnyPrefix(path, c.config.productVariables.NativeCoverageExcludePaths) { coverage = false } diff --git a/cc/config/global.go b/cc/config/global.go index d65f88351..05dc77354 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -192,10 +192,6 @@ var ( } noOverrideGlobalCflags = []string{ - // Workaround for boot loop caused by stack protector. - // http://b/267839238 - "-mllvm -disable-check-noreturn-call", - "-Werror=bool-operation", "-Werror=implicit-int-float-conversion", "-Werror=int-in-bool-context", @@ -257,7 +253,6 @@ var ( "-Wno-bitwise-instead-of-logical", "-Wno-misleading-indentation", "-Wno-array-parameter", - "-Wno-gnu-offsetof-extensions", } // Extra cflags for external third-party projects to disable warnings that @@ -310,8 +305,8 @@ var ( // prebuilts/clang default settings. ClangDefaultBase = "prebuilts/clang/host" - ClangDefaultVersion = "clang-r487747" - ClangDefaultShortVersion = "17" + ClangDefaultVersion = "clang-r475365b" + ClangDefaultShortVersion = "16.0.2" // Directories with warnings from Android.bp files. WarningAllowedProjects = []string{ From 76889ce00a058e8ed2fa9dc5273f65af97e43444 Mon Sep 17 00:00:00 2001 From: Zi Wang Date: Mon, 6 Mar 2023 22:54:40 -0800 Subject: [PATCH 120/172] Incorporate Bazel-built fingerprint file into mixed builds Test: m and TH Bug: 268337233 Ignore-AOSP-First: merge conflict resolutions Change-Id: Ib2f7fa35b2d94972869e8e85be47b288ff875408 --- android/allowlists/allowlists.go | 7 ++++++- java/sdk.go | 9 +++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go index af24beaac..63495bc99 100644 --- a/android/allowlists/allowlists.go +++ b/android/allowlists/allowlists.go @@ -695,6 +695,9 @@ var ( "non-updatable-system-current.txt", "non-updatable-module-lib-current.txt", "non-updatable-system-server-current.txt", + + // for api_fingerprint.txt generation + "api_fingerprint", } Bp2buildModuleTypeAlwaysConvertList = []string{ @@ -1436,7 +1439,9 @@ var ( // which will soon be added to the prod allowlist. // It is implicit that all modules in ProdMixedBuildsEnabledList will // also be built - do not add them to this list. - StagingMixedBuildsEnabledList = []string{} + StagingMixedBuildsEnabledList = []string{ + "api_fingerprint", + } // These should be the libs that are included by the apexes in the ProdMixedBuildsEnabledList ProdDclaMixedBuildsEnabledList = []string{} diff --git a/java/sdk.go b/java/sdk.go index 10ae3f6e8..855e5598a 100644 --- a/java/sdk.go +++ b/java/sdk.go @@ -384,10 +384,7 @@ func createAPIFingerprint(ctx android.SingletonContext) { } else if ctx.Config().FrameworksBaseDirExists(ctx) && !ctx.Config().AlwaysUsePrebuiltSdks() { cmd.Text("cat") apiTxtFileModules := []string{ - "frameworks-base-api-current.txt", - "frameworks-base-api-system-current.txt", - "frameworks-base-api-module-lib-current.txt", - "frameworks-base-api-system-server-current.txt", + "api_fingerprint", } count := 0 ctx.VisitAllModules(func(module android.Module) { @@ -398,10 +395,10 @@ func createAPIFingerprint(ctx android.SingletonContext) { } }) if count != len(apiTxtFileModules) { - ctx.Errorf("Could not find all the expected API modules %v, found %d\n", apiTxtFileModules, count) + ctx.Errorf("Could not find expected API module %v, found %d\n", apiTxtFileModules, count) return } - cmd.Text("| md5sum | cut -d' ' -f1 >"). + cmd.Text(">"). Output(out) } else { // Unbundled build From c398be808e6da8b76b7e8efb92f49ba555fd6117 Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Fri, 10 Mar 2023 11:22:10 -0800 Subject: [PATCH 121/172] Promote NewApi to an error again Now that issues have been baselined. Bug: 268261262 Test: Presubmits Change-Id: I3a1591d650fc46f67426d0f64162d261a24aa6eb --- java/lint.go | 7 +------ java/lint_test.go | 3 +-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/java/lint.go b/java/lint.go index 58b43dfdb..8a8d9d147 100644 --- a/java/lint.go +++ b/java/lint.go @@ -314,12 +314,7 @@ func (l *linter) writeLintProjectXML(ctx android.ModuleContext, rule *android.Ru cmd.FlagWithInput("@", android.PathForSource(ctx, "build/soong/java/lint_defaults.txt")) - if l.compileSdkKind == android.SdkPublic { - cmd.FlagForEachArg("--error_check ", l.extraMainlineLintErrors) - } else { - // TODO(b/268261262): Remove this branch. We're demoting NewApi to a warning due to pre-existing issues that need to be fixed. - cmd.FlagForEachArg("--warning_check ", l.extraMainlineLintErrors) - } + cmd.FlagForEachArg("--error_check ", l.extraMainlineLintErrors) cmd.FlagForEachArg("--disable_check ", l.properties.Lint.Disabled_checks) cmd.FlagForEachArg("--warning_check ", l.properties.Lint.Warning_checks) cmd.FlagForEachArg("--error_check ", l.properties.Lint.Error_checks) diff --git a/java/lint_test.go b/java/lint_test.go index ec901aa70..5f6418d99 100644 --- a/java/lint_test.go +++ b/java/lint_test.go @@ -113,8 +113,7 @@ func TestJavaLintUsesCorrectBpConfig(t *testing.T) { t.Error("did not use the correct file for baseline") } - if !strings.Contains(*sboxProto.Commands[0].Command, "--warning_check NewApi") { - // TODO(b/268261262): Change this to check for --error_check + if !strings.Contains(*sboxProto.Commands[0].Command, "--error_check NewApi") { t.Error("should check NewApi warnings") } From dfe8dca36984794fa0192f52e91360698c9cc1fc Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Mon, 6 Mar 2023 11:43:02 +0000 Subject: [PATCH 122/172] Add filegroup_test.go to sources I don't think it was running before. Test: yes Change-Id: Ia3bf53ddcc1ddefd7a236122256594ba764ee8e5 (cherry picked from https://android-review.googlesource.com/q/commit:7a444cec60ec4e70d6c8581ef45c7f0c3c1927f5) Merged-In: Ia3bf53ddcc1ddefd7a236122256594ba764ee8e5 --- android/Android.bp | 1 + 1 file changed, 1 insertion(+) diff --git a/android/Android.bp b/android/Android.bp index 65332b2d8..c0a35accd 100644 --- a/android/Android.bp +++ b/android/Android.bp @@ -106,6 +106,7 @@ bootstrap_go_package { "depset_test.go", "deptag_test.go", "expand_test.go", + "filegroup_test.go", "fixture_test.go", "gen_notice_test.go", "license_kind_test.go", From ac7ec5400483d79287c8c9b940fb4b36b8140e5e Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Mon, 6 Mar 2023 11:26:17 +0000 Subject: [PATCH 123/172] Add filegroup_defaults module Allows specifying shared filegroup attributes in a central place. Test: filegroup_test.go Change-Id: I82feac37ae6998313a0004f8af58f3decf7a514e (cherry picked from https://android-review.googlesource.com/q/commit:7d6dd8bb3324e81b5c4afc80b062baad2fed1770) Merged-In: I82feac37ae6998313a0004f8af58f3decf7a514e --- android/filegroup.go | 25 +++++++++++++++++++++++-- android/filegroup_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 android/filegroup_test.go diff --git a/android/filegroup.go b/android/filegroup.go index 50356d1c3..a2e69efa4 100644 --- a/android/filegroup.go +++ b/android/filegroup.go @@ -23,13 +23,18 @@ import ( ) func init() { - RegisterModuleType("filegroup", FileGroupFactory) + RegisterFilegroupBuildComponents(InitRegistrationContext) } var PrepareForTestWithFilegroup = FixtureRegisterWithContext(func(ctx RegistrationContext) { - ctx.RegisterModuleType("filegroup", FileGroupFactory) + RegisterFilegroupBuildComponents(ctx) }) +func RegisterFilegroupBuildComponents(ctx RegistrationContext) { + ctx.RegisterModuleType("filegroup", FileGroupFactory) + ctx.RegisterModuleType("filegroup_defaults", FileGroupDefaultsFactory) +} + // IsFilegroup checks that a module is a filegroup type func IsFilegroup(ctx bazel.OtherModuleContext, m blueprint.Module) bool { return ctx.OtherModuleType(m) == "filegroup" @@ -97,6 +102,7 @@ type fileGroupProperties struct { type fileGroup struct { ModuleBase BazelModuleBase + DefaultableModuleBase properties fileGroupProperties srcs Paths } @@ -111,6 +117,7 @@ func FileGroupFactory() Module { module.AddProperties(&module.properties) InitAndroidModule(module) InitBazelModule(module) + InitDefaultableModule(module) return module } @@ -161,3 +168,17 @@ func (fg *fileGroup) MakeVars(ctx MakeVarsModuleContext) { ctx.StrictRaw(makeVar, strings.Join(fg.srcs.Strings(), " ")) } } + +// Defaults +type FileGroupDefaults struct { + ModuleBase + DefaultsModuleBase +} + +func FileGroupDefaultsFactory() Module { + module := &FileGroupDefaults{} + module.AddProperties(&fileGroupProperties{}) + InitDefaultsModule(module) + + return module +} diff --git a/android/filegroup_test.go b/android/filegroup_test.go new file mode 100644 index 000000000..670037d56 --- /dev/null +++ b/android/filegroup_test.go @@ -0,0 +1,26 @@ +package android + +import ( + "testing" +) + +func TestFilegroupDefaults(t *testing.T) { + bp := FixtureAddTextFile("p/Android.bp", ` + filegroup_defaults { + name: "defaults", + visibility: ["//x"], + } + filegroup { + name: "foo", + defaults: ["defaults"], + visibility: ["//y"], + } + `) + result := GroupFixturePreparers( + PrepareForTestWithFilegroup, + PrepareForTestWithDefaults, + PrepareForTestWithVisibility, + bp).RunTest(t) + rules := effectiveVisibilityRules(result.Config, qualifiedModuleName{pkg: "p", name: "foo"}) + AssertDeepEquals(t, "visibility", []string{"//x", "//y"}, rules.Strings()) +} From 2eb349a79ba93d991a35a5df83555b5eae6010a0 Mon Sep 17 00:00:00 2001 From: Yuyang Huang Date: Wed, 15 Mar 2023 02:35:55 +0000 Subject: [PATCH 124/172] Revert "Promote NewApi to an error again" This reverts commit c398be808e6da8b76b7e8efb92f49ba555fd6117. Reason for revert: Broken the build b/273624365 Change-Id: I87bb4ca7c561cfbc6643501f60b4c00a53201908 --- java/lint.go | 7 ++++++- java/lint_test.go | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/java/lint.go b/java/lint.go index 8a8d9d147..58b43dfdb 100644 --- a/java/lint.go +++ b/java/lint.go @@ -314,7 +314,12 @@ func (l *linter) writeLintProjectXML(ctx android.ModuleContext, rule *android.Ru cmd.FlagWithInput("@", android.PathForSource(ctx, "build/soong/java/lint_defaults.txt")) - cmd.FlagForEachArg("--error_check ", l.extraMainlineLintErrors) + if l.compileSdkKind == android.SdkPublic { + cmd.FlagForEachArg("--error_check ", l.extraMainlineLintErrors) + } else { + // TODO(b/268261262): Remove this branch. We're demoting NewApi to a warning due to pre-existing issues that need to be fixed. + cmd.FlagForEachArg("--warning_check ", l.extraMainlineLintErrors) + } cmd.FlagForEachArg("--disable_check ", l.properties.Lint.Disabled_checks) cmd.FlagForEachArg("--warning_check ", l.properties.Lint.Warning_checks) cmd.FlagForEachArg("--error_check ", l.properties.Lint.Error_checks) diff --git a/java/lint_test.go b/java/lint_test.go index 5f6418d99..ec901aa70 100644 --- a/java/lint_test.go +++ b/java/lint_test.go @@ -113,7 +113,8 @@ func TestJavaLintUsesCorrectBpConfig(t *testing.T) { t.Error("did not use the correct file for baseline") } - if !strings.Contains(*sboxProto.Commands[0].Command, "--error_check NewApi") { + if !strings.Contains(*sboxProto.Commands[0].Command, "--warning_check NewApi") { + // TODO(b/268261262): Change this to check for --error_check t.Error("should check NewApi warnings") } From 15fc2294389d8d1d8f6c2247a57425d299033d9c Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Fri, 13 May 2022 16:01:35 +0200 Subject: [PATCH 125/172] =?UTF-8?q?Make=20=E2=80=98rustfmt.toml=E2=80=99?= =?UTF-8?q?=20available=20for=20other=20modules?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We need the config file to ensure consistent output when running tests. Bug: 237977382 Test: manual (cherry picked from https://android-review.googlesource.com/q/commit:4e86b5e07acd44b04f47e2dcbf3918859d66ccb0) Merged-In: Ib19d4b739305a5cbed94a40908d76dbbeec67fe5 Change-Id: Ib19d4b739305a5cbed94a40908d76dbbeec67fe5 --- scripts/Android.bp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/Android.bp b/scripts/Android.bp index a37d2597b..814bd5753 100644 --- a/scripts/Android.bp +++ b/scripts/Android.bp @@ -203,3 +203,9 @@ sh_binary_host { name: "list_image", src: "list_image.sh", } + +filegroup { + name: "rustfmt.toml", + srcs: ["rustfmt.toml"], + visibility: ["//visibility:public"], +} From d1c6e334a046c5dfbd7e49fa4c829c21784e9a1a Mon Sep 17 00:00:00 2001 From: Alex Buynytskyy Date: Tue, 4 Apr 2023 19:52:34 +0000 Subject: [PATCH 126/172] UpsideDownCake is now 34 Ignore-AOSP-First: UpsideDownCake Finalization Bug: 275409981 Test: build Change-Id: I70da9e094781c49ce3fa905e202fa0114696aa77 --- android/api_levels.go | 1 + java/droidstubs.go | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/android/api_levels.go b/android/api_levels.go index 7214ccbb6..137fd9dad 100644 --- a/android/api_levels.go +++ b/android/api_levels.go @@ -431,6 +431,7 @@ func getApiLevelsMapReleasedVersions() map[string]int { "S": 31, "S-V2": 32, "Tiramisu": 33, + "UpsideDownCake": 34, } } diff --git a/java/droidstubs.go b/java/droidstubs.go index 8a521aabb..f26315b9f 100644 --- a/java/droidstubs.go +++ b/java/droidstubs.go @@ -394,7 +394,8 @@ func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *a } if apiVersions != nil { cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion().String()) - cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename()) + // STOPSHIP: RESTORE THIS LOGIC WHEN DECLARING "REL" BUILD + // cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename()) cmd.FlagWithInput("--apply-api-levels ", apiVersions) } } From e9184d757e6c0b0021feb4697025040c568e3d4e Mon Sep 17 00:00:00 2001 From: Alex Buynytskyy Date: Fri, 21 Apr 2023 18:32:14 +0000 Subject: [PATCH 127/172] UpsideDownCake/34 is now REL Ignore-AOSP-First: UpsideDownCake Finalization Bug: 275409981 Test: build Change-Id: Iaa3054f3449a5bf6887c24937646d22c79c4af1e Merged-In: Iaa3054f3449a5bf6887c24937646d22c79c4af1e --- java/droidstubs.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/java/droidstubs.go b/java/droidstubs.go index f26315b9f..8a521aabb 100644 --- a/java/droidstubs.go +++ b/java/droidstubs.go @@ -394,8 +394,7 @@ func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *a } if apiVersions != nil { cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion().String()) - // STOPSHIP: RESTORE THIS LOGIC WHEN DECLARING "REL" BUILD - // cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename()) + cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename()) cmd.FlagWithInput("--apply-api-levels ", apiVersions) } } From a2f41c7695e937e2b7f4933f6696a71777a6b517 Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Thu, 20 Apr 2023 14:07:29 -0700 Subject: [PATCH 128/172] Enable -funique-internal-linkage-names when afdo=true We used to enable unique names only when a profile is available. But A profile generated for a binary without unique names doesn't work well when building a binary with unique names. To avoid a chicken-and-egg problem, this CL enables the flag when afdo=true, whether a profile exists or not. Bug: 241523910 Test: build (cherry picked from https://android-review.googlesource.com/q/commit:01c4456ce21ec3aa6693c083d77c0bfe1e7cccdc) Merged-In: I74d834510d81d2db76e34d0488c74a60e1fcecd5 Change-Id: I74d834510d81d2db76e34d0488c74a60e1fcecd5 --- cc/afdo.go | 72 ++++++++++++++++++++++++++----------------- cc/afdo_test.go | 82 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 29 deletions(-) diff --git a/cc/afdo.go b/cc/afdo.go index be4f50adb..49f69873c 100644 --- a/cc/afdo.go +++ b/cc/afdo.go @@ -34,7 +34,7 @@ var ( var afdoProfileProjectsConfigKey = android.NewOnceKey("AfdoProfileProjects") -const afdoCFlagsFormat = "-funique-internal-linkage-names -fprofile-sample-accurate -fprofile-sample-use=%s" +const afdoCFlagsFormat = "-fprofile-sample-accurate -fprofile-sample-use=%s" func recordMissingAfdoProfileFile(ctx android.BaseModuleContext, missing string) { getNamedMapForConfig(ctx.Config(), modulesMissingProfileFileKey).Store(missing, true) @@ -66,10 +66,24 @@ func (afdo *afdo) props() []interface{} { // afdoEnabled returns true for binaries and shared libraries // that set afdo prop to True and there is a profile available func (afdo *afdo) afdoEnabled() bool { - return afdo != nil && afdo.Properties.Afdo && afdo.Properties.FdoProfilePath != nil + return afdo != nil && afdo.Properties.Afdo } func (afdo *afdo) flags(ctx ModuleContext, flags Flags) Flags { + if afdo.Properties.Afdo { + // We use `-funique-internal-linkage-names` to associate profiles to the right internal + // functions. This option should be used before generating a profile. Because a profile + // generated for a binary without unique names doesn't work well building a binary with + // unique names (they have different internal function names). + // To avoid a chicken-and-egg problem, we enable `-funique-internal-linkage-names` when + // `afdo=true`, whether a profile exists or not. + // The profile can take effect in three steps: + // 1. Add `afdo: true` in Android.bp, and build the binary. + // 2. Collect an AutoFDO profile for the binary. + // 3. Make the profile searchable by the build system. So it's used the next time the binary + // is built. + flags.Local.CFlags = append([]string{"-funique-internal-linkage-names"}, flags.Local.CFlags...) + } if path := afdo.Properties.FdoProfilePath; path != nil { // The flags are prepended to allow overriding. profileUseFlag := fmt.Sprintf(afdoCFlagsFormat, *path) @@ -129,42 +143,41 @@ var _ FdoProfileMutatorInterface = (*Module)(nil) // Propagate afdo requirements down from binaries and shared libraries func afdoDepsMutator(mctx android.TopDownMutatorContext) { if m, ok := mctx.Module().(*Module); ok && m.afdo.afdoEnabled() { - if path := m.afdo.Properties.FdoProfilePath; path != nil { - mctx.WalkDeps(func(dep android.Module, parent android.Module) bool { - tag := mctx.OtherModuleDependencyTag(dep) - libTag, isLibTag := tag.(libraryDependencyTag) + path := m.afdo.Properties.FdoProfilePath + mctx.WalkDeps(func(dep android.Module, parent android.Module) bool { + tag := mctx.OtherModuleDependencyTag(dep) + libTag, isLibTag := tag.(libraryDependencyTag) - // Do not recurse down non-static dependencies - if isLibTag { - if !libTag.static() { - return false - } - } else { - if tag != objDepTag && tag != reuseObjTag { - return false - } + // Do not recurse down non-static dependencies + if isLibTag { + if !libTag.static() { + return false } - - if dep, ok := dep.(*Module); ok { - dep.afdo.Properties.AfdoRDeps = append( - dep.afdo.Properties.AfdoRDeps, - afdoRdep{ - VariationName: proptools.StringPtr(encodeTarget(m.Name())), - ProfilePath: path, - }, - ) + } else { + if tag != objDepTag && tag != reuseObjTag { + return false } + } - return true - }) - } + if dep, ok := dep.(*Module); ok { + dep.afdo.Properties.AfdoRDeps = append( + dep.afdo.Properties.AfdoRDeps, + afdoRdep{ + VariationName: proptools.StringPtr(encodeTarget(m.Name())), + ProfilePath: path, + }, + ) + } + + return true + }) } } // Create afdo variants for modules that need them func afdoMutator(mctx android.BottomUpMutatorContext) { if m, ok := mctx.Module().(*Module); ok && m.afdo != nil { - if !m.static() && m.afdo.Properties.Afdo && m.afdo.Properties.FdoProfilePath != nil { + if !m.static() && m.afdo.Properties.Afdo { mctx.SetDependencyVariation(encodeTarget(m.Name())) return } @@ -182,7 +195,7 @@ func afdoMutator(mctx android.BottomUpMutatorContext) { // \ ^ // ----------------------| // We only need to create one variant per unique rdep - if variantNameToProfilePath[variantName] == nil { + if _, exists := variantNameToProfilePath[variantName]; !exists { variationNames = append(variationNames, variantName) variantNameToProfilePath[variantName] = afdoRDep.ProfilePath } @@ -197,6 +210,7 @@ func afdoMutator(mctx android.BottomUpMutatorContext) { variation := modules[i].(*Module) variation.Properties.PreventInstall = true variation.Properties.HideFromMake = true + variation.afdo.Properties.Afdo = true variation.afdo.Properties.FdoProfilePath = variantNameToProfilePath[name] } } diff --git a/cc/afdo_test.go b/cc/afdo_test.go index 1c20bfc8c..b250ad1a1 100644 --- a/cc/afdo_test.go +++ b/cc/afdo_test.go @@ -379,3 +379,85 @@ func TestMultipleAfdoRDeps(t *testing.T) { t.Errorf("libFoo missing dependency on non-afdo variant of libBar") } } + +func TestAfdoDepsWithoutProfile(t *testing.T) { + t.Parallel() + bp := ` + cc_library_shared { + name: "libTest", + srcs: ["test.c"], + static_libs: ["libFoo"], + afdo: true, + } + + cc_library_static { + name: "libFoo", + srcs: ["foo.c"], + static_libs: ["libBar"], + } + + cc_library_static { + name: "libBar", + srcs: ["bar.c"], + } + ` + + result := android.GroupFixturePreparers( + PrepareForTestWithFdoProfile, + prepareForCcTest, + ).RunTestWithBp(t, bp) + + // Even without a profile path, the afdo enabled libraries should be built with + // -funique-internal-linkage-names. + expectedCFlag := "-funique-internal-linkage-names" + + libTest := result.ModuleForTests("libTest", "android_arm64_armv8-a_shared") + libFooAfdoVariant := result.ModuleForTests("libFoo", "android_arm64_armv8-a_static_afdo-libTest") + libBarAfdoVariant := result.ModuleForTests("libBar", "android_arm64_armv8-a_static_afdo-libTest") + + // Check cFlags of afdo-enabled module and the afdo-variant of its static deps + cFlags := libTest.Rule("cc").Args["cFlags"] + if !strings.Contains(cFlags, expectedCFlag) { + t.Errorf("Expected 'libTest' to enable afdo, but did not find %q in cflags %q", expectedCFlag, cFlags) + } + + cFlags = libFooAfdoVariant.Rule("cc").Args["cFlags"] + if !strings.Contains(cFlags, expectedCFlag) { + t.Errorf("Expected 'libFooAfdoVariant' to enable afdo, but did not find %q in cflags %q", expectedCFlag, cFlags) + } + + cFlags = libBarAfdoVariant.Rule("cc").Args["cFlags"] + if !strings.Contains(cFlags, expectedCFlag) { + t.Errorf("Expected 'libBarAfdoVariant' to enable afdo, but did not find %q in cflags %q", expectedCFlag, cFlags) + } + // Check dependency edge from afdo-enabled module to static deps + if !hasDirectDep(result, libTest.Module(), libFooAfdoVariant.Module()) { + t.Errorf("libTest missing dependency on afdo variant of libFoo") + } + + if !hasDirectDep(result, libFooAfdoVariant.Module(), libBarAfdoVariant.Module()) { + t.Errorf("libTest missing dependency on afdo variant of libBar") + } + + // Verify non-afdo variant exists and doesn't contain afdo + libFoo := result.ModuleForTests("libFoo", "android_arm64_armv8-a_static") + libBar := result.ModuleForTests("libBar", "android_arm64_armv8-a_static") + + cFlags = libFoo.Rule("cc").Args["cFlags"] + if strings.Contains(cFlags, expectedCFlag) { + t.Errorf("Expected 'libFoo' to not enable afdo, but found %q in cflags %q", expectedCFlag, cFlags) + } + cFlags = libBar.Rule("cc").Args["cFlags"] + if strings.Contains(cFlags, expectedCFlag) { + t.Errorf("Expected 'libBar' to not enable afdo, but found %q in cflags %q", expectedCFlag, cFlags) + } + + // Check dependency edges of static deps + if hasDirectDep(result, libTest.Module(), libFoo.Module()) { + t.Errorf("libTest should not depend on non-afdo variant of libFoo") + } + + if !hasDirectDep(result, libFoo.Module(), libBar.Module()) { + t.Errorf("libFoo missing dependency on non-afdo variant of libBar") + } +} From 054897952213f87d40a901ed8546ce6375c93347 Mon Sep 17 00:00:00 2001 From: Inseob Kim Date: Thu, 20 Apr 2023 10:16:14 +0900 Subject: [PATCH 129/172] Remove deps from Soong intermediate to symbols These should be handled by Makefile dependency (LOCAL_REQUIRED_MODULES). Bug: 278832320 Test: build and see symbol files (cherry picked from https://android-review.googlesource.com/q/commit:5bedfee4484a8786ccd761212057f8aac9a02eb7) Merged-In: I80ad9d8e7e8384e2ae3537cc681bc1d1b327d04c Change-Id: I80ad9d8e7e8384e2ae3537cc681bc1d1b327d04c --- apex/apex_test.go | 15 ++++++++++++--- apex/builder.go | 11 +---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/apex/apex_test.go b/apex/apex_test.go index 4e063cb73..440afec97 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -5716,6 +5716,7 @@ func TestPrebuiltSkipsSymbols(t *testing.T) { // Source module apex { name: "myapex", + binaries: ["foo"], key: "myapex.key", updatable: false, } @@ -5731,11 +5732,19 @@ func TestPrebuiltSkipsSymbols(t *testing.T) { set: "myapex.apks", `+preferProperty+` } + + cc_binary { + name: "foo", + srcs: ["mylib.cpp"], + system_shared_libs: [], + stl: "none", + apex_available: [ "myapex" ], + } `) // Symbol files are installed by installing entries under ${OUT}/apex/{apex name} - android.AssertStringListContainsEquals(t, "Implicits", - ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule").Implicits.Strings(), - "out/soong/target/product/test_device/apex/myapex/apex_manifest.pb", + android.AssertStringListContainsEquals(t, "Installs", + ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().FilesToInstall().Strings(), + filepath.Join(ctx.Config().SoongOutDir(), "target/product/test_device/apex/myapex/bin/foo"), tc.installSymbolFiles) }) } diff --git a/apex/builder.go b/apex/builder.go index 2f8a4ec09..3c7671b00 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -517,9 +517,6 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { } } implicitInputs = append(implicitInputs, fi.builtFile) - if installSymbolFiles { - implicitInputs = append(implicitInputs, installedPath) - } // Create additional symlinks pointing the file inside the APEX (if any). Note that // this is independent from the symlink optimization. @@ -527,8 +524,7 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { symlinkDest := imageDir.Join(ctx, symlinkPath).String() copyCommands = append(copyCommands, "ln -sfn "+filepath.Base(destPath)+" "+symlinkDest) if installSymbolFiles { - installedSymlink := ctx.InstallSymlink(apexDir.Join(ctx, filepath.Dir(symlinkPath)), filepath.Base(symlinkPath), installedPath) - implicitInputs = append(implicitInputs, installedSymlink) + ctx.InstallSymlink(apexDir.Join(ctx, filepath.Dir(symlinkPath)), filepath.Base(symlinkPath), installedPath) } } @@ -553,11 +549,6 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { installMapSet[installMapPath.String()+":"+fi.installDir+"/"+fi.builtFile.Base()] = true } implicitInputs = append(implicitInputs, a.manifestPbOut) - if installSymbolFiles { - installedManifest := ctx.InstallFile(apexDir, "apex_manifest.pb", a.manifestPbOut) - installedKey := ctx.InstallFile(apexDir, "apex_pubkey", a.publicKeyFile) - implicitInputs = append(implicitInputs, installedManifest, installedKey) - } if len(installMapSet) > 0 { var installs []string From 2b6b7af8f4c760860331352fedd10029b3a79928 Mon Sep 17 00:00:00 2001 From: Justin Yun Date: Tue, 11 Apr 2023 18:20:07 +0900 Subject: [PATCH 130/172] Include license information for vendor and host snapshots In addition to the license text files, include license kinds information to json file. Also, use the original paths of license text files that are copied to NOTICE_FILES directory. This will be used when generating snapshots from the snapshot build. Bug: 271539873 Test: m vendor-snapshot Merged-In: I0c0427bb66f2c1fca322d5554aa66220a3b62fb3 Change-Id: I0c0427bb66f2c1fca322d5554aa66220a3b62fb3 (cherry picked from commit 1db9748805147a69792b2a1a556689253c5b82f6) --- cc/util.go | 11 ----------- cc/vendor_snapshot.go | 19 ++++++++----------- etc/prebuilt_etc.go | 27 ++++++++------------------- snapshot/host_snapshot.go | 18 +++++++++++------- snapshot/snapshot.go | 28 ++++++++++++++++++++++++++-- snapshot/snapshot_base.go | 15 +++++++++++++++ snapshot/util.go | 16 ++++++++++++---- 7 files changed, 80 insertions(+), 54 deletions(-) diff --git a/cc/util.go b/cc/util.go index aa0f6b5d6..6d8ac435f 100644 --- a/cc/util.go +++ b/cc/util.go @@ -100,17 +100,6 @@ func makeSymlinkCmd(linkDirOnDevice string, linkName string, target string) stri "ln -sf " + target + " " + filepath.Join(dir, linkName) } -func combineNoticesRule(ctx android.SingletonContext, paths android.Paths, out string) android.OutputPath { - outPath := android.PathForOutput(ctx, out) - ctx.Build(pctx, android.BuildParams{ - Rule: android.Cat, - Inputs: paths, - Output: outPath, - Description: "combine notices for " + out, - }) - return outPath -} - // Dump a map to a list file as: // // {key1} {value1} diff --git a/cc/vendor_snapshot.go b/cc/vendor_snapshot.go index aed37753a..e6e566025 100644 --- a/cc/vendor_snapshot.go +++ b/cc/vendor_snapshot.go @@ -160,7 +160,7 @@ type snapshotJsonFlags struct { MinSdkVersion string `json:",omitempty"` } -var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) android.Paths { +var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) snapshot.SnapshotPaths { /* Vendor snapshot zipped artifacts directory structure for cc modules: {SNAPSHOT_ARCH}/ @@ -195,10 +195,10 @@ var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotS */ var snapshotOutputs android.Paths + var snapshotNotices android.Paths includeDir := filepath.Join(snapshotArchDir, "include") configsDir := filepath.Join(snapshotArchDir, "configs") - noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES") installedNotices := make(map[string]bool) installedConfigs := make(map[string]bool) @@ -228,7 +228,7 @@ var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotS prop := snapshotJsonFlags{} // Common properties among snapshots. - prop.ModuleName = ctx.ModuleName(m) + prop.InitBaseSnapshotPropsWithName(m, ctx.ModuleName(m)) if supportsVndkExt(s.Image) && m.IsVndkExt() { // vndk exts are installed to /vendor/lib(64)?/vndk(-sp)? if m.IsVndkSp() { @@ -406,13 +406,10 @@ var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotS headers = append(headers, m.SnapshotHeaders()...) } - if len(m.EffectiveLicenseFiles()) > 0 { - noticeName := ctx.ModuleName(m) + ".txt" - noticeOut := filepath.Join(noticeDir, noticeName) - // skip already copied notice file - if !installedNotices[noticeOut] { - installedNotices[noticeOut] = true - snapshotOutputs = append(snapshotOutputs, combineNoticesRule(ctx, m.EffectiveLicenseFiles(), noticeOut)) + for _, notice := range m.EffectiveLicenseFiles() { + if _, ok := installedNotices[notice.String()]; !ok { + installedNotices[notice.String()] = true + snapshotNotices = append(snapshotNotices, notice) } } }) @@ -422,7 +419,7 @@ var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotS snapshotOutputs = append(snapshotOutputs, copyFile(ctx, header, filepath.Join(includeDir, header.String()), s.Fake)) } - return snapshotOutputs + return snapshot.SnapshotPaths{OutputFiles: snapshotOutputs, NoticeFiles: snapshotNotices} } func init() { diff --git a/etc/prebuilt_etc.go b/etc/prebuilt_etc.go index dcd7fdcb9..6817dcef0 100644 --- a/etc/prebuilt_etc.go +++ b/etc/prebuilt_etc.go @@ -617,7 +617,7 @@ func isSnapshotAware(ctx android.SingletonContext, m *PrebuiltEtc, image snapsho return true } -func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) android.Paths { +func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) snapshot.SnapshotPaths { /* Snapshot zipped artifacts directory structure for etc modules: {SNAPSHOT_ARCH}/ @@ -631,7 +631,7 @@ func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.Singleto (notice files) */ var snapshotOutputs android.Paths - noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES") + var snapshotNotices android.Paths installedNotices := make(map[string]bool) ctx.VisitAllModules(func(module android.Module) { @@ -651,7 +651,7 @@ func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.Singleto prop := snapshot.SnapshotJsonFlags{} propOut := snapshotLibOut + ".json" - prop.ModuleName = m.BaseModuleName() + prop.InitBaseSnapshotProps(m) if m.subdirProperties.Relative_install_path != nil { prop.RelativeInstallPath = *m.subdirProperties.Relative_install_path } @@ -667,27 +667,16 @@ func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.Singleto } snapshotOutputs = append(snapshotOutputs, snapshot.WriteStringToFileRule(ctx, string(j), propOut)) - if len(m.EffectiveLicenseFiles()) > 0 { - noticeName := ctx.ModuleName(m) + ".txt" - noticeOut := filepath.Join(noticeDir, noticeName) - // skip already copied notice file - if !installedNotices[noticeOut] { - installedNotices[noticeOut] = true - - noticeOutPath := android.PathForOutput(ctx, noticeOut) - ctx.Build(pctx, android.BuildParams{ - Rule: android.Cat, - Inputs: m.EffectiveLicenseFiles(), - Output: noticeOutPath, - Description: "combine notices for " + noticeOut, - }) - snapshotOutputs = append(snapshotOutputs, noticeOutPath) + for _, notice := range m.EffectiveLicenseFiles() { + if _, ok := installedNotices[notice.String()]; !ok { + installedNotices[notice.String()] = true + snapshotNotices = append(snapshotNotices, notice) } } }) - return snapshotOutputs + return snapshot.SnapshotPaths{OutputFiles: snapshotOutputs, NoticeFiles: snapshotNotices} } // For Bazel / bp2build diff --git a/snapshot/host_snapshot.go b/snapshot/host_snapshot.go index 9793218a3..edcc16348 100644 --- a/snapshot/host_snapshot.go +++ b/snapshot/host_snapshot.go @@ -96,6 +96,7 @@ func (f *hostSnapshot) CreateMetaData(ctx android.ModuleContext, fileName string var jsonData []SnapshotJsonFlags var metaPaths android.Paths + installedNotices := make(map[string]bool) metaZipFile := android.PathForModuleOut(ctx, fileName).OutputPath // Create JSON file based on the direct dependencies @@ -104,12 +105,14 @@ func (f *hostSnapshot) CreateMetaData(ctx android.ModuleContext, fileName string if desc != nil { jsonData = append(jsonData, *desc) } - if len(dep.EffectiveLicenseFiles()) > 0 { - noticeFile := android.PathForModuleOut(ctx, "NOTICE_FILES", dep.Name()+".txt").OutputPath - android.CatFileRule(ctx, dep.EffectiveLicenseFiles(), noticeFile) - metaPaths = append(metaPaths, noticeFile) + for _, notice := range dep.EffectiveLicenseFiles() { + if _, ok := installedNotices[notice.String()]; !ok { + installedNotices[notice.String()] = true + noticeOut := android.PathForModuleOut(ctx, "NOTICE_FILES", notice.String()).OutputPath + CopyFileToOutputPathRule(pctx, ctx, notice, noticeOut) + metaPaths = append(metaPaths, noticeOut) + } } - }) // Sort notice paths and json data for repeatble build sort.Slice(jsonData, func(i, j int) bool { @@ -220,8 +223,7 @@ func hostJsonDesc(m android.Module) *SnapshotJsonFlags { } if path.Valid() && path.String() != "" { - return &SnapshotJsonFlags{ - ModuleName: m.Name(), + props := &SnapshotJsonFlags{ ModuleStemName: moduleStem, Filename: path.String(), Required: append(m.HostRequiredModuleNames(), m.RequiredModuleNames()...), @@ -229,6 +231,8 @@ func hostJsonDesc(m android.Module) *SnapshotJsonFlags { RustProcMacro: procMacro, CrateName: crateName, } + props.InitBaseSnapshotProps(m) + return props } return nil } diff --git a/snapshot/snapshot.go b/snapshot/snapshot.go index 206ecc947..c95a53774 100644 --- a/snapshot/snapshot.go +++ b/snapshot/snapshot.go @@ -26,6 +26,10 @@ import ( var pctx = android.NewPackageContext("android/soong/snapshot") +func init() { + pctx.Import("android/soong/android") +} + type SnapshotSingleton struct { // Name, e.g., "vendor", "recovery", "ramdisk". name string @@ -48,8 +52,18 @@ type SnapshotSingleton struct { Fake bool } +// The output files to be included in the snapshot. +type SnapshotPaths struct { + // All files to be included in the snapshot + OutputFiles android.Paths + + // Notice files of the snapshot output files + NoticeFiles android.Paths +} + // Interface of function to capture snapshot from each module -type GenerateSnapshotAction func(snapshot SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) android.Paths +// Returns snapshot ouputs and notice files. +type GenerateSnapshotAction func(snapshot SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) SnapshotPaths var snapshotActionList []GenerateSnapshotAction @@ -74,9 +88,19 @@ func (c *SnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) { snapshotDir = filepath.Join("fake", snapshotDir) } snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch()) + noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES") + installedNotices := make(map[string]bool) for _, f := range snapshotActionList { - snapshotOutputs = append(snapshotOutputs, f(*c, ctx, snapshotArchDir)...) + snapshotPaths := f(*c, ctx, snapshotArchDir) + snapshotOutputs = append(snapshotOutputs, snapshotPaths.OutputFiles...) + for _, notice := range snapshotPaths.NoticeFiles { + if _, ok := installedNotices[notice.String()]; !ok { + installedNotices[notice.String()] = true + snapshotOutputs = append(snapshotOutputs, CopyFileRule( + pctx, ctx, notice, filepath.Join(noticeDir, notice.String()))) + } + } } // All artifacts are ready. Sort them to normalize ninja and then zip. diff --git a/snapshot/snapshot_base.go b/snapshot/snapshot_base.go index 809ca3d11..fb4ee0c83 100644 --- a/snapshot/snapshot_base.go +++ b/snapshot/snapshot_base.go @@ -120,4 +120,19 @@ type SnapshotJsonFlags struct { // dependencies Required []string `json:",omitempty"` Overrides []string `json:",omitempty"` + + // license information + LicenseKinds []string `json:",omitempty"` + LicenseTexts []string `json:",omitempty"` +} + +func (prop *SnapshotJsonFlags) InitBaseSnapshotPropsWithName(m android.Module, name string) { + prop.ModuleName = name + + prop.LicenseKinds = m.EffectiveLicenseKinds() + prop.LicenseTexts = m.EffectiveLicenseFiles().Strings() +} + +func (prop *SnapshotJsonFlags) InitBaseSnapshotProps(m android.Module) { + prop.InitBaseSnapshotPropsWithName(m, m.Name()) } diff --git a/snapshot/util.go b/snapshot/util.go index 806ac90fa..c87c508e6 100644 --- a/snapshot/util.go +++ b/snapshot/util.go @@ -21,17 +21,25 @@ func WriteStringToFileRule(ctx android.SingletonContext, content, out string) an return outPath } -func CopyFileRule(pctx android.PackageContext, ctx android.SingletonContext, path android.Path, out string) android.OutputPath { - outPath := android.PathForOutput(ctx, out) +type buildContext interface { + Build(pctx android.PackageContext, params android.BuildParams) +} + +func CopyFileToOutputPathRule(pctx android.PackageContext, ctx buildContext, path android.Path, outPath android.OutputPath) { ctx.Build(pctx, android.BuildParams{ Rule: android.Cp, Input: path, Output: outPath, - Description: "copy " + path.String() + " -> " + out, + Description: "copy " + path.String() + " -> " + outPath.String(), Args: map[string]string{ - "cpFlags": "-f -L", + "cpFlags": "-L", }, }) +} + +func CopyFileRule(pctx android.PackageContext, ctx android.SingletonContext, path android.Path, out string) android.OutputPath { + outPath := android.PathForOutput(ctx, out) + CopyFileToOutputPathRule(pctx, ctx, path, outPath) return outPath } From ec0e5a3e9706c8dfbe645d5ed37826f59bae4d89 Mon Sep 17 00:00:00 2001 From: Alexei Nicoara Date: Thu, 27 Apr 2023 09:12:44 +0000 Subject: [PATCH 131/172] DO NOT MERGE: Changing the udc-dev version to 345990000 The udc-dev version is now lower than the prebuilts b/278817494. Increasing it so it's higher than prebuilts but still low enough, b/231691162 suggested initially to use xx5990000 for x-dev. I've checked tm-dev and the latest prebuilt was 3318, so 3459 prefix should be enough for udc-dev. Change-Id: Idc85a121825aea754b258b306660ca71c6b1fdd9 BUG: 278817494 Ignore-AOSP-First: This change is needed in udc-dev only --- android/updatable_modules.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/updatable_modules.go b/android/updatable_modules.go index 6d0eeb716..1de73c4f8 100644 --- a/android/updatable_modules.go +++ b/android/updatable_modules.go @@ -29,8 +29,8 @@ package android // based on the branch such that the builds from testing and development // branches will have a version higher than the prebuilts. // Versions per branch: -// * x-dev - xx0090000 (where xx is the branch SDK level) +// * x-dev - xx5990000 (where xx is the branch SDK level) // * AOSP - xx9990000 // * x-mainline-prod - xx9990000 // * master - 990090000 -const DefaultUpdatableModuleVersion = "340090000" +const DefaultUpdatableModuleVersion = "345990000" From c9ef91211e49e1e9d00749ec204f0f38d0c7b26d Mon Sep 17 00:00:00 2001 From: Justin Yun Date: Wed, 19 Apr 2023 19:26:30 +0900 Subject: [PATCH 132/172] Add license visibility to prebuilt vsdk libbpf_minimal can be included as a prebuilt vsdk library. This must include the license_kinds of libbpf_minimal-license from soong. Add the visibility for the prebuilts. Bug: 271539873 Test: build against vsdk Merged-In: Ib1c3e7705e7f234b2b54c2180642d6134c6131ea Change-Id: Ib1c3e7705e7f234b2b54c2180642d6134c6131ea (cherry picked from commit 3b23ac0025570f850e31958e47d477fbdcf21afa) --- licenses/Android.bp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/licenses/Android.bp b/licenses/Android.bp index 7267cf374..dee72ed42 100644 --- a/licenses/Android.bp +++ b/licenses/Android.bp @@ -923,7 +923,10 @@ license_kind { license_kind { name: "SPDX-license-identifier-Linux-syscall-note", // expanding visibility requires approval from an OSPO lawyer or pcounsel - visibility: ["//external/libbpf:__subpackages__"], + visibility: [ + "//external/libbpf:__subpackages__", + "//prebuilts/vsdk:__subpackages__", + ], conditions: ["permissive"], url: "https://spdx.org/licenses/Linux-syscall-note.html", } From 09ddb3a73e14823d51d8227ecaf1997fa010bc14 Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Wed, 19 Oct 2022 01:29:18 -0400 Subject: [PATCH 133/172] Restrict plugins to an existing allowlist Adds a singleton to do validation that can be disabled via a BUILD_BROKEN_PLUGIN_VALIDATION flag. Validation process: For all go modules that are a plugin for soong_build: * if path is in build/soong, allow * if path is in vendor, outside of google paths, allow * if path is in hardware, outside of google paths, allow * if name is in allowlist of current plugins, allow We extend the plugin the list for internal modules via vendor/google/build/soong/internal_plugins.json Ignore-AOSP-First: Requires an internal only change to not break when submitted Test: CI Change-Id: I264a89b3636043330711d6c996c0360b61f51d92 --- android/Android.bp | 1 + android/config.go | 4 ++ android/plugin.go | 139 ++++++++++++++++++++++++++++++++++++++++ android/variable.go | 1 + tests/bootstrap_test.sh | 24 +++---- 5 files changed, 157 insertions(+), 12 deletions(-) create mode 100644 android/plugin.go diff --git a/android/Android.bp b/android/Android.bp index 118087db7..94d2c04f6 100644 --- a/android/Android.bp +++ b/android/Android.bp @@ -77,6 +77,7 @@ bootstrap_go_package { "path_properties.go", "paths.go", "phony.go", + "plugin.go", "prebuilt.go", "prebuilt_build_tool.go", "proto.go", diff --git a/android/config.go b/android/config.go index 7141e54c3..e0cf173f0 100644 --- a/android/config.go +++ b/android/config.go @@ -1819,6 +1819,10 @@ func (c *deviceConfig) ShippingApiLevel() ApiLevel { return uncheckedFinalApiLevel(apiLevel) } +func (c *deviceConfig) BuildBrokenPluginValidation() []string { + return c.config.productVariables.BuildBrokenPluginValidation +} + func (c *deviceConfig) BuildBrokenClangAsFlags() bool { return c.config.productVariables.BuildBrokenClangAsFlags } diff --git a/android/plugin.go b/android/plugin.go new file mode 100644 index 000000000..5be3d3ad8 --- /dev/null +++ b/android/plugin.go @@ -0,0 +1,139 @@ +// Copyright 2022 Google Inc. All rights reserved. +// +// 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 android + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "os" + "strings" + + "github.com/google/blueprint" +) + +func init() { + RegisterPluginSingletonBuildComponents(InitRegistrationContext) +} + +func RegisterPluginSingletonBuildComponents(ctx RegistrationContext) { + ctx.RegisterSingletonType("plugins", pluginSingletonFactory) +} + +// pluginSingleton is a singleton to handle allowlisting of the final Android-.mk file +// output. +func pluginSingletonFactory() Singleton { + return &pluginSingleton{} +} + +type pluginSingleton struct{} + +var allowedPluginsByName = map[string]bool{ + "aidl-soong-rules": true, + "arm_compute_library_nn_driver": true, + "cuttlefish-soong-rules": true, + "gki-soong-rules": true, + "hidl-soong-rules": true, + "kernel-config-soong-rules": true, + "soong-angle-codegen": true, + "soong-api": true, + "soong-art": true, + "soong-ca-certificates": true, + "soong-clang": true, + "soong-clang-prebuilts": true, + "soong-csuite": true, + "soong-fluoride": true, + "soong-fs_config": true, + "soong-icu": true, + "soong-java-config-error_prone": true, + "soong-libchrome": true, + "soong-llvm": true, + "soong-robolectric": true, + "soong-rust-prebuilts": true, + "soong-selinux": true, + "soong-wayland-protocol-codegen": true, + "treble_report_app": true, + "treble_report_local": true, + "treble_report_module": true, + "vintf-compatibility-matrix-soong-rules": true, + "xsdc-soong-rules": true, +} + +const ( + internalPluginsPath = "vendor/google/build/soong/internal_plugins.json" +) + +type pluginProvider interface { + IsPluginFor(string) bool +} + +func maybeAddInternalPluginsToAllowlist(ctx SingletonContext) { + if path := ExistentPathForSource(ctx, internalPluginsPath); path.Valid() { + ctx.AddNinjaFileDeps(path.String()) + absPath := absolutePath(path.String()) + var moreAllowed map[string]bool + data, err := ioutil.ReadFile(absPath) + if err != nil { + ctx.Errorf("Failed to open internal plugins path %q %q", internalPluginsPath, err) + } + if err := json.Unmarshal(data, &moreAllowed); err != nil { + fmt.Fprintf(os.Stderr, "Internal plugins file %q did not parse correctly: %q", data, err) + } + for k, v := range moreAllowed { + allowedPluginsByName[k] = v + } + } +} + +func (p *pluginSingleton) GenerateBuildActions(ctx SingletonContext) { + for _, p := range ctx.DeviceConfig().BuildBrokenPluginValidation() { + allowedPluginsByName[p] = true + } + maybeAddInternalPluginsToAllowlist(ctx) + + disallowedPlugins := map[string]bool{} + ctx.VisitAllModulesBlueprint(func(module blueprint.Module) { + if ctx.ModuleType(module) != "bootstrap_go_package" { + return + } + + p, ok := module.(pluginProvider) + if !ok || !p.IsPluginFor("soong_build") { + return + } + + name := ctx.ModuleName(module) + if _, ok := allowedPluginsByName[name]; ok { + return + } + + dir := ctx.ModuleDir(module) + + // allow use of plugins within Soong to not allowlist everything + if strings.HasPrefix(dir, "build/soong") { + return + } + + // allow third party users outside of external to create new plugins, i.e. non-google paths + // under vendor or hardware + if !strings.HasPrefix(dir, "external/") && IsThirdPartyPath(dir) { + return + } + disallowedPlugins[name] = true + }) + if len(disallowedPlugins) > 0 { + ctx.Errorf("New plugins are not supported; however %q were found. Please reach out to the build team or use BUILD_BROKEN_PLUGIN_VALIDATION (see Changes.md for more info).", SortedStringKeys(disallowedPlugins)) + } +} diff --git a/android/variable.go b/android/variable.go index 249d53b07..b5d966668 100644 --- a/android/variable.go +++ b/android/variable.go @@ -437,6 +437,7 @@ type productVariables struct { ShippingApiLevel *string `json:",omitempty"` + BuildBrokenPluginValidation []string `json:",omitempty"` BuildBrokenClangAsFlags bool `json:",omitempty"` BuildBrokenClangCFlags bool `json:",omitempty"` BuildBrokenClangProperty bool `json:",omitempty"` diff --git a/tests/bootstrap_test.sh b/tests/bootstrap_test.sh index fda5ca086..c5a6336a8 100755 --- a/tests/bootstrap_test.sh +++ b/tests/bootstrap_test.sh @@ -207,8 +207,8 @@ EOF function test_soong_build_rerun_iff_environment_changes() { setup - mkdir -p cherry - cat > cherry/Android.bp <<'EOF' + mkdir -p build/soong/cherry + cat > build/soong/cherry/Android.bp <<'EOF' bootstrap_go_package { name: "cherry", pkgPath: "android/soong/cherry", @@ -224,7 +224,7 @@ bootstrap_go_package { } EOF - cat > cherry/cherry.go <<'EOF' + cat > build/soong/cherry/cherry.go <<'EOF' package cherry import ( @@ -317,8 +317,8 @@ function test_add_file_to_soong_build() { run_soong local -r mtime1=$(stat -c "%y" out/soong/build.ninja) - mkdir -p a - cat > a/Android.bp <<'EOF' + mkdir -p vendor/foo/picard + cat > vendor/foo/picard/Android.bp <<'EOF' bootstrap_go_package { name: "picard-soong-rules", pkgPath: "android/soong/picard", @@ -334,7 +334,7 @@ bootstrap_go_package { } EOF - cat > a/picard.go <<'EOF' + cat > vendor/foo/picard/picard.go <<'EOF' package picard import ( @@ -390,11 +390,11 @@ EOF function test_glob_during_bootstrapping() { setup - mkdir -p a - cat > a/Android.bp <<'EOF' + mkdir -p build/soong/picard + cat > build/soong/picard/Android.bp <<'EOF' build=["foo*.bp"] EOF - cat > a/fooa.bp <<'EOF' + cat > build/soong/picard/fooa.bp <<'EOF' bootstrap_go_package { name: "picard-soong-rules", pkgPath: "android/soong/picard", @@ -410,7 +410,7 @@ bootstrap_go_package { } EOF - cat > a/picard.go <<'EOF' + cat > build/soong/picard/picard.go <<'EOF' package picard import ( @@ -459,7 +459,7 @@ EOF grep -q "Make it so" out/soong/build.ninja || fail "Original action not present" - cat > a/foob.bp <<'EOF' + cat > build/soong/picard/foob.bp <<'EOF' bootstrap_go_package { name: "worf-soong-rules", pkgPath: "android/soong/worf", @@ -476,7 +476,7 @@ bootstrap_go_package { } EOF - cat > a/worf.go <<'EOF' + cat > build/soong/picard/worf.go <<'EOF' package worf import "android/soong/picard" From e6979a102cf2807adba465b05454ee0b3a4463ae Mon Sep 17 00:00:00 2001 From: Juan Yescas Date: Fri, 7 Apr 2023 10:35:35 -0700 Subject: [PATCH 134/172] 16k: Align shared libraries and executables to 4k by default The default ELF segment alignment will be 4096. This alignment can be overriden by setting the desired alignment in PRODUCT_MAX_PAGE_SIZE_SUPPORTED flag. The alignment has to be a multiple of the configured kernel page size. Test: Built changes for Pixel 4a, 6 and checked alignment. Bug: 276963698 Bug: 276801883 (cherry picked from https://android-review.googlesource.com/q/commit:05d4d901146d96634ad0ff3a9982c9c87c394f18) Merged-In: Icb380041a5b27da1fa0d86b302e1e7cde9a236d7 Change-Id: Icb380041a5b27da1fa0d86b302e1e7cde9a236d7 --- android/config.go | 7 +++++++ android/variable.go | 2 ++ cc/config/arm64_device.go | 11 ++++++++--- cc/config/arm_device.go | 7 ++++++- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/android/config.go b/android/config.go index 032172d6e..9920fe41b 100644 --- a/android/config.go +++ b/android/config.go @@ -174,6 +174,13 @@ func (c Config) RunningInsideUnitTest() bool { return c.config.TestProductVariables != nil } +// MaxPageSizeSupported returns the max page size supported by the device. This +// value will define the ELF segment alignment for binaries (executables and +// shared libraries). +func (c Config) MaxPageSizeSupported() string { + return String(c.config.productVariables.DeviceMaxPageSizeSupported) +} + // A DeviceConfig object represents the configuration for a particular device // being built. For now there will only be one of these, but in the future there // may be multiple devices being built. diff --git a/android/variable.go b/android/variable.go index 249d53b07..d7152b367 100644 --- a/android/variable.go +++ b/android/variable.go @@ -218,6 +218,7 @@ type productVariables struct { DeviceVndkVersion *string `json:",omitempty"` DeviceCurrentApiLevelForVendorModules *string `json:",omitempty"` DeviceSystemSdkVersions []string `json:",omitempty"` + DeviceMaxPageSizeSupported *string `json:",omitempty"` RecoverySnapshotVersion *string `json:",omitempty"` @@ -505,6 +506,7 @@ func (v *productVariables) SetDefaultConfig() { DeviceSecondaryArchVariant: stringPtr("armv8-a"), DeviceSecondaryCpuVariant: stringPtr("generic"), DeviceSecondaryAbi: []string{"armeabi-v7a", "armeabi"}, + DeviceMaxPageSizeSupported: stringPtr("4096"), AAPTConfig: []string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"}, AAPTPreferredConfig: stringPtr("xhdpi"), diff --git a/cc/config/arm64_device.go b/cc/config/arm64_device.go index 28f368205..ca2e05fc3 100644 --- a/cc/config/arm64_device.go +++ b/cc/config/arm64_device.go @@ -53,8 +53,7 @@ var ( "-Wl,-z,separate-code", } - arm64Lldflags = append(arm64Ldflags, - "-Wl,-z,max-page-size=4096") + arm64Lldflags = arm64Ldflags arm64Cppflags = []string{} @@ -93,7 +92,13 @@ var ( func init() { exportedVars.ExportStringListStaticVariable("Arm64Ldflags", arm64Ldflags) - exportedVars.ExportStringListStaticVariable("Arm64Lldflags", arm64Lldflags) + + exportedVars.ExportStringList("Arm64Lldflags", arm64Lldflags) + pctx.VariableFunc("Arm64Lldflags", func(ctx android.PackageVarContext) string { + maxPageSizeFlag := "-Wl,-z,max-page-size=" + ctx.Config().MaxPageSizeSupported() + flags := append(arm64Lldflags, maxPageSizeFlag) + return strings.Join(flags, " ") + }) exportedVars.ExportStringListStaticVariable("Arm64Cflags", arm64Cflags) exportedVars.ExportStringListStaticVariable("Arm64Cppflags", arm64Cppflags) diff --git a/cc/config/arm_device.go b/cc/config/arm_device.go index 070455021..dec2b4552 100644 --- a/cc/config/arm_device.go +++ b/cc/config/arm_device.go @@ -185,7 +185,12 @@ func init() { exportedVars.ExportString("ArmClangTriple", clangTriple) exportedVars.ExportStringListStaticVariable("ArmLdflags", armLdflags) - exportedVars.ExportStringListStaticVariable("ArmLldflags", armLldflags) + exportedVars.ExportStringList("ArmLldflags", armLldflags) + pctx.VariableFunc("ArmLldflags", func(ctx android.PackageVarContext) string { + maxPageSizeFlag := "-Wl,-z,max-page-size=" + ctx.Config().MaxPageSizeSupported() + flags := append(armLldflags, maxPageSizeFlag) + return strings.Join(flags, " ") + }) exportedVars.ExportStringListStaticVariable("ArmFixCortexA8LdFlags", armFixCortexA8LdFlags) exportedVars.ExportStringListStaticVariable("ArmNoFixCortexA8LdFlags", armNoFixCortexA8LdFlags) From f902b8af82f4f131b55c9c4aacf50bf6d4ebc1bf Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Thu, 27 Apr 2023 16:08:26 +0000 Subject: [PATCH 135/172] target_sdk_version replacement should respect REL branches Currently, target_sdk_version of MTS tests were being set to 10000 even in release branches. This should only happen in active branches. Test: Unit test Test: aapt2 on CtsContentTestCases in udc-dev and verified targetSdkVersion is 34 Bug: 279507428 Change-Id: Ib79318febc0f6e771b3679c0281a97357930ec56 Merged-In: Ib79318febc0f6e771b3679c0281a97357930ec56 (cherry picked from commit fb6a1ee68bd7b17d1a8632082de88504dddc3540) --- java/android_manifest.go | 4 +++- java/app_test.go | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/java/android_manifest.go b/java/android_manifest.go index dbcf09830..f2ebfa6a2 100644 --- a/java/android_manifest.go +++ b/java/android_manifest.go @@ -63,9 +63,11 @@ func targetSdkVersionForManifestFixer(ctx android.ModuleContext, params Manifest // 2. The module is run as part of MTS, and should be testable on stable branches // Do not return 10000 if we are enforcing default targetSdkVersion and sdk has been finalised func shouldReturnFinalOrFutureInt(ctx android.ModuleContext, targetSdkVersionLevel android.ApiLevel, enforceDefaultTargetSdkVersion bool) bool { - if enforceDefaultTargetSdkVersion && ctx.Config().PlatformSdkFinal() { + // If this is a REL branch, do not return 10000 + if ctx.Config().PlatformSdkFinal() { return false } + // If this a module targeting an unreleased SDK (MTS or unbundled builds), return 10000 return targetSdkVersionLevel.IsPreview() && (ctx.Config().UnbundledBuildApps() || includedInMts(ctx.Module())) } diff --git a/java/app_test.go b/java/app_test.go index 561be684e..7e97b0fb1 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -3034,11 +3034,13 @@ func TestExportedProguardFlagFiles(t *testing.T) { func TestTargetSdkVersionManifestFixer(t *testing.T) { platform_sdk_codename := "Tiramisu" + platform_sdk_version := 33 testCases := []struct { name string targetSdkVersionInBp string targetSdkVersionExpected string unbundledBuild bool + platformSdkFinal bool }{ { name: "Non-Unbundled build: Android.bp has targetSdkVersion", @@ -3075,6 +3077,12 @@ func TestTargetSdkVersionManifestFixer(t *testing.T) { targetSdkVersionExpected: "10000", unbundledBuild: true, }, + { + name: "Bundled build in REL branches", + targetSdkVersionExpected: "33", + unbundledBuild: false, + platformSdkFinal: true, + }, } for _, testCase := range testCases { targetSdkVersionTemplate := "" @@ -3091,8 +3099,12 @@ func TestTargetSdkVersionManifestFixer(t *testing.T) { fixture := android.GroupFixturePreparers( prepareForJavaTest, android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + if testCase.platformSdkFinal { + variables.Platform_sdk_final = proptools.BoolPtr(true) + } // explicitly set platform_sdk_codename to make the test deterministic variables.Platform_sdk_codename = &platform_sdk_codename + variables.Platform_sdk_version = &platform_sdk_version variables.Platform_version_active_codenames = []string{platform_sdk_codename} // create a non-empty list if unbundledBuild==true if testCase.unbundledBuild { From bda0ca753e0ecb152441b6e722570d1052107301 Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Fri, 28 Apr 2023 12:32:27 -0700 Subject: [PATCH 136/172] Use api_levels_released_versions from starlark Instead of exporting it to soong_injection. Ignore-AOSP-First: Needed to resolve merge conflict Bug: 279095899 Test: m nothing Change-Id: I7b93af233b7450848a475512b5f5682ece773c09 --- android/api_levels.go | 100 +++++++++++++++++------------------- android/sdk.go | 3 ++ bp2build/conversion.go | 7 ++- bp2build/conversion_test.go | 4 -- java/java.go | 5 +- sdk/update.go | 4 ++ 6 files changed, 62 insertions(+), 61 deletions(-) diff --git a/android/api_levels.go b/android/api_levels.go index 137fd9dad..fa919fda7 100644 --- a/android/api_levels.go +++ b/android/api_levels.go @@ -15,12 +15,10 @@ package android import ( + "android/soong/starlark_import" "encoding/json" "fmt" "strconv" - - "android/soong/bazel" - "android/soong/starlark_fmt" ) func init() { @@ -288,13 +286,17 @@ var LastWithoutModuleLibCoreSystemModules = uncheckedFinalApiLevel(31) // ReplaceFinalizedCodenames returns the API level number associated with that API level // if the `raw` input is the codename of an API level has been finalized. // If the input is *not* a finalized codename, the input is returned unmodified. -func ReplaceFinalizedCodenames(config Config, raw string) string { - num, ok := getFinalCodenamesMap(config)[raw] +func ReplaceFinalizedCodenames(config Config, raw string) (string, error) { + finalCodenamesMap, err := getFinalCodenamesMap(config) + if err != nil { + return raw, err + } + num, ok := finalCodenamesMap[raw] if !ok { - return raw + return raw, nil } - return strconv.Itoa(num) + return strconv.Itoa(num), nil } // ApiLevelFrom converts the given string `raw` to an ApiLevel. @@ -344,7 +346,11 @@ func ApiLevelFromUserWithConfig(config Config, raw string) (ApiLevel, error) { } } - canonical, ok := getApiLevelsMapReleasedVersions()[raw] + apiLevelsReleasedVersions, err := getApiLevelsMapReleasedVersions() + if err != nil { + return NoneApiLevel, err + } + canonical, ok := apiLevelsReleasedVersions[raw] if !ok { asInt, err := strconv.Atoi(raw) if err != nil { @@ -410,38 +416,21 @@ func GetApiLevelsJson(ctx PathContext) WritablePath { return PathForOutput(ctx, "api_levels.json") } -func getApiLevelsMapReleasedVersions() map[string]int { - return map[string]int{ - "G": 9, - "I": 14, - "J": 16, - "J-MR1": 17, - "J-MR2": 18, - "K": 19, - "L": 21, - "L-MR1": 22, - "M": 23, - "N": 24, - "N-MR1": 25, - "O": 26, - "O-MR1": 27, - "P": 28, - "Q": 29, - "R": 30, - "S": 31, - "S-V2": 32, - "Tiramisu": 33, - "UpsideDownCake": 34, - } +func getApiLevelsMapReleasedVersions() (map[string]int, error) { + return starlark_import.GetStarlarkValue[map[string]int]("api_levels_released_versions") } var finalCodenamesMapKey = NewOnceKey("FinalCodenamesMap") -func getFinalCodenamesMap(config Config) map[string]int { +func getFinalCodenamesMap(config Config) (map[string]int, error) { + type resultStruct struct { + result map[string]int + err error + } // This logic is replicated in starlark, if changing logic here update starlark code too // https://cs.android.com/android/platform/superproject/+/master:build/bazel/rules/common/api.bzl;l=30;drc=231c7e8c8038fd478a79eb68aa5b9f5c64e0e061 - return config.Once(finalCodenamesMapKey, func() interface{} { - apiLevelsMap := getApiLevelsMapReleasedVersions() + result := config.Once(finalCodenamesMapKey, func() interface{} { + apiLevelsMap, err := getApiLevelsMapReleasedVersions() // TODO: Differentiate "current" and "future". // The code base calls it FutureApiLevel, but the spelling is "current", @@ -454,41 +443,44 @@ func getFinalCodenamesMap(config Config) map[string]int { // added in S, both of these are usable when building for "current" when // neither R nor S are final, but the S APIs stop being available in a // final R build. - if Bool(config.productVariables.Platform_sdk_final) { + if err == nil && Bool(config.productVariables.Platform_sdk_final) { apiLevelsMap["current"] = config.PlatformSdkVersion().FinalOrFutureInt() } - return apiLevelsMap - }).(map[string]int) + return resultStruct{apiLevelsMap, err} + }).(resultStruct) + return result.result, result.err } var apiLevelsMapKey = NewOnceKey("ApiLevelsMap") // ApiLevelsMap has entries for preview API levels -func GetApiLevelsMap(config Config) map[string]int { +func GetApiLevelsMap(config Config) (map[string]int, error) { + type resultStruct struct { + result map[string]int + err error + } // This logic is replicated in starlark, if changing logic here update starlark code too // https://cs.android.com/android/platform/superproject/+/master:build/bazel/rules/common/api.bzl;l=23;drc=231c7e8c8038fd478a79eb68aa5b9f5c64e0e061 - return config.Once(apiLevelsMapKey, func() interface{} { - apiLevelsMap := getApiLevelsMapReleasedVersions() - for i, codename := range config.PlatformVersionAllPreviewCodenames() { - apiLevelsMap[codename] = previewAPILevelBase + i + result := config.Once(apiLevelsMapKey, func() interface{} { + apiLevelsMap, err := getApiLevelsMapReleasedVersions() + if err == nil { + for i, codename := range config.PlatformVersionAllPreviewCodenames() { + apiLevelsMap[codename] = previewAPILevelBase + i + } } - return apiLevelsMap - }).(map[string]int) + return resultStruct{apiLevelsMap, err} + }).(resultStruct) + return result.result, result.err } func (a *apiLevelsSingleton) GenerateBuildActions(ctx SingletonContext) { - apiLevelsMap := GetApiLevelsMap(ctx.Config()) + apiLevelsMap, err := GetApiLevelsMap(ctx.Config()) + if err != nil { + ctx.Errorf("%s\n", err) + return + } apiLevelsJson := GetApiLevelsJson(ctx) createApiLevelsJson(ctx, apiLevelsJson, apiLevelsMap) } - -func StarlarkApiLevelConfigs(config Config) string { - return fmt.Sprintf(bazel.GeneratedBazelFileWarning+` -_api_levels_released_versions = %s - -api_levels_released_versions = _api_levels_released_versions -`, starlark_fmt.PrintStringIntDict(getApiLevelsMapReleasedVersions(), 0), - ) -} diff --git a/android/sdk.go b/android/sdk.go index 63e0bbeec..6b598ab9e 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -830,6 +830,9 @@ type SdkMemberContext interface { // IsTargetBuildBeforeTiramisu return true if the target build release for which this snapshot is // being generated is before Tiramisu, i.e. S. IsTargetBuildBeforeTiramisu() bool + + // ModuleErrorf reports an error at the line number of the module type in the module definition. + ModuleErrorf(fmt string, args ...interface{}) } // ExportedComponentsInfo contains information about the components that this module exports to an diff --git a/bp2build/conversion.go b/bp2build/conversion.go index 608fcd879..f5983323c 100644 --- a/bp2build/conversion.go +++ b/bp2build/conversion.go @@ -59,14 +59,17 @@ func soongInjectionFiles(cfg android.Config, metrics CodegenMetrics) ([]BazelFil files = append(files, newFile("product_config", "arch_configuration.bzl", android.StarlarkArchConfigurations())) - apiLevelsContent, err := json.Marshal(android.GetApiLevelsMap(cfg)) + apiLevelsMap, err := android.GetApiLevelsMap(cfg) + if err != nil { + return nil, err + } + apiLevelsContent, err := json.Marshal(apiLevelsMap) if err != nil { return nil, err } files = append(files, newFile("api_levels", GeneratedBuildFileName, `exports_files(["api_levels.json"])`)) // TODO(b/269691302) value of apiLevelsContent is product variable dependent and should be avoided for soong injection files = append(files, newFile("api_levels", "api_levels.json", string(apiLevelsContent))) - files = append(files, newFile("api_levels", "api_levels.bzl", android.StarlarkApiLevelConfigs(cfg))) files = append(files, newFile("api_levels", "platform_versions.bzl", platformVersionContents(cfg))) files = append(files, newFile("allowlists", GeneratedBuildFileName, "")) diff --git a/bp2build/conversion_test.go b/bp2build/conversion_test.go index 2f5dc3cb7..379f83bd8 100644 --- a/bp2build/conversion_test.go +++ b/bp2build/conversion_test.go @@ -157,10 +157,6 @@ func TestCreateBazelFiles_Bp2Build_CreatesDefaultFiles(t *testing.T) { dir: "api_levels", basename: "api_levels.json", }, - { - dir: "api_levels", - basename: "api_levels.bzl", - }, { dir: "api_levels", basename: "platform_versions.bzl", diff --git a/java/java.go b/java/java.go index 26fb3a784..e859cb4e1 100644 --- a/java/java.go +++ b/java/java.go @@ -815,7 +815,10 @@ func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberCo // If the min_sdk_version was set then add the canonical representation of the API level to the // snapshot. if j.deviceProperties.Min_sdk_version != nil { - canonical := android.ReplaceFinalizedCodenames(ctx.SdkModuleContext().Config(), j.minSdkVersion.String()) + canonical, err := android.ReplaceFinalizedCodenames(ctx.SdkModuleContext().Config(), j.minSdkVersion.String()) + if err != nil { + ctx.ModuleErrorf("%s", err) + } p.MinSdkVersion = proptools.StringPtr(canonical) } diff --git a/sdk/update.go b/sdk/update.go index d98ab683d..d3c59b0e4 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -1963,6 +1963,10 @@ type memberContext struct { requiredTraits android.SdkMemberTraitSet } +func (m *memberContext) ModuleErrorf(fmt string, args ...interface{}) { + m.sdkMemberContext.ModuleErrorf(fmt, args...) +} + func (m *memberContext) SdkModuleContext() android.ModuleContext { return m.sdkMemberContext } From 88086621d16359e1f1925f417dc66e6daca39dac Mon Sep 17 00:00:00 2001 From: Hang Lu Date: Fri, 17 Mar 2023 13:17:22 +0800 Subject: [PATCH 137/172] Enable HWASan for multiple modules in one place(Soong) Environment variables HWASAN_INCLUDE_PATHS and PRODUCT_HWASAN_INCLUDE_PATHS can be used to enable HWASan for multiple modules, by just adding the module directory to the env variable. Bug: b/271948407 Test: Set specific module directory to above env variable and check the assembly codes of output elf files after building, finding hwasan related symbols inside. Merged-In: Ic49b515830c4469ca5fa94f547b26c0fb602fc54 Change-Id: Ic49b515830c4469ca5fa94f547b26c0fb602fc54 (cherry picked from commit a98aab98c45aa7245cd235b8822de35aa6eb4fd6) --- android/config.go | 7 +++++++ android/variable.go | 2 ++ cc/sanitize.go | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/android/config.go b/android/config.go index 9920fe41b..980460a7b 100644 --- a/android/config.go +++ b/android/config.go @@ -1564,6 +1564,13 @@ func (c *config) MemtagHeapSyncEnabledForPath(path string) bool { return HasAnyPrefix(path, c.productVariables.MemtagHeapSyncIncludePaths) && !c.MemtagHeapDisabledForPath(path) } +func (c *config) HWASanEnabledForPath(path string) bool { + if len(c.productVariables.HWASanIncludePaths) == 0 { + return false + } + return HasAnyPrefix(path, c.productVariables.HWASanIncludePaths) +} + func (c *config) VendorConfig(name string) VendorConfig { return soongconfig.Config(c.productVariables.VendorVars[name]) } diff --git a/android/variable.go b/android/variable.go index d7152b367..496f523b2 100644 --- a/android/variable.go +++ b/android/variable.go @@ -307,6 +307,8 @@ type productVariables struct { MemtagHeapAsyncIncludePaths []string `json:",omitempty"` MemtagHeapSyncIncludePaths []string `json:",omitempty"` + HWASanIncludePaths []string `json:",omitempty"` + VendorPath *string `json:",omitempty"` OdmPath *string `json:",omitempty"` ProductPath *string `json:",omitempty"` diff --git a/cc/sanitize.go b/cc/sanitize.go index 45d7fab4f..7fddc1b83 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -593,6 +593,12 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) { } } + // Enable HWASan for all components in the include paths (for Aarch64 only) + if s.Hwaddress == nil && ctx.Config().HWASanEnabledForPath(ctx.ModuleDir()) && + ctx.Arch().ArchType == android.Arm64 && ctx.toolchain().Bionic() { + s.Hwaddress = proptools.BoolPtr(true) + } + // Enable CFI for non-host components in the include paths if s.Cfi == nil && ctx.Config().CFIEnabledForPath(ctx.ModuleDir()) && !ctx.Host() { s.Cfi = proptools.BoolPtr(true) From 38dfc1d7c159b60f2520c5eba7288855a2df9150 Mon Sep 17 00:00:00 2001 From: Justin Yun Date: Tue, 2 May 2023 14:56:38 +0900 Subject: [PATCH 138/172] VSDK: use relative install path when generating snapshots Without respecting the relative install path, the snapshot install path may collide when they use the same stem name. To avoid this, respect the relative install path when generating the snapshots. Bug: 279652606 Test: RECOVERY_SNAPSHOT_VERSION=current m recovery-snapshot Merged-In: Ic70a5855aeb2a6eda397b4dd06113dddb6ef70f4 Change-Id: Ic70a5855aeb2a6eda397b4dd06113dddb6ef70f4 (cherry picked from commit 17d0ee2160e79cc5b30d7b779bc595712125d23b) --- cc/vendor_snapshot.go | 4 +-- cc/vendor_snapshot_test.go | 66 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/cc/vendor_snapshot.go b/cc/vendor_snapshot.go index e6e566025..51f23c57e 100644 --- a/cc/vendor_snapshot.go +++ b/cc/vendor_snapshot.go @@ -324,13 +324,13 @@ var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotS } } } - snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, stem) + snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, m.RelativeInstallPath(), stem) ret = append(ret, copyFile(ctx, libPath, snapshotLibOut, fake)) } else { stem = ctx.ModuleName(m) } - propOut = filepath.Join(snapshotArchDir, targetArch, libType, stem+".json") + propOut = filepath.Join(snapshotArchDir, targetArch, libType, m.RelativeInstallPath(), stem+".json") } else if m.Binary() { // binary flags prop.Symlinks = m.Symlinks() diff --git a/cc/vendor_snapshot_test.go b/cc/vendor_snapshot_test.go index 619500e1d..5b69a10be 100644 --- a/cc/vendor_snapshot_test.go +++ b/cc/vendor_snapshot_test.go @@ -1657,3 +1657,69 @@ func TestRecoverySnapshotDirected(t *testing.T) { } } } + +func TestSnapshotInRelativeInstallPath(t *testing.T) { + bp := ` + cc_library { + name: "libvendor_available", + vendor_available: true, + nocrt: true, + } + + cc_library { + name: "libvendor_available_var", + vendor_available: true, + stem: "libvendor_available", + relative_install_path: "var", + nocrt: true, + } +` + + config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) + config.TestProductVariables.DeviceVndkVersion = StringPtr("current") + config.TestProductVariables.Platform_vndk_version = StringPtr("29") + ctx := testCcWithConfig(t, config) + + // Check Vendor snapshot output. + + snapshotDir := "vendor-snapshot" + snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64") + snapshotSingleton := ctx.SingletonForTests("vendor-snapshot") + + var jsonFiles []string + + for _, arch := range [][]string{ + []string{"arm64", "armv8-a"}, + []string{"arm", "armv7-a-neon"}, + } { + archType := arch[0] + archVariant := arch[1] + archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) + + // For shared libraries, only non-VNDK vendor_available modules are captured + sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant) + sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") + sharedDirVar := filepath.Join(sharedDir, "var") + CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant) + CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available_var", "libvendor_available.so", sharedDirVar, sharedVariant) + jsonFiles = append(jsonFiles, + filepath.Join(sharedDir, "libvendor_available.so.json"), + filepath.Join(sharedDirVar, "libvendor_available.so.json")) + } + + for _, jsonFile := range jsonFiles { + // verify all json files exist + if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { + t.Errorf("%q expected but not found", jsonFile) + } + } + + // fake snapshot should have all outputs in the normal snapshot. + fakeSnapshotSingleton := ctx.SingletonForTests("vendor-fake-snapshot") + for _, output := range snapshotSingleton.AllOutputs() { + fakeOutput := strings.Replace(output, "/vendor-snapshot/", "/fake/vendor-snapshot/", 1) + if fakeSnapshotSingleton.MaybeOutput(fakeOutput).Rule == nil { + t.Errorf("%q expected but not found", fakeOutput) + } + } +} From 1240f28d09b861f1245c9f54e388a425252e60b5 Mon Sep 17 00:00:00 2001 From: Alexei Nicoara Date: Wed, 3 May 2023 16:43:37 +0000 Subject: [PATCH 139/172] Revert "DO NOT MERGE: Changing the udc-dev version to 345990000" This reverts commit ec0e5a3e9706c8dfbe645d5ed37826f59bae4d89. Reason for revert: b/280553936 Change-Id: Iad9079f026f46da35f36723937db9bf5771580d1 --- android/updatable_modules.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/updatable_modules.go b/android/updatable_modules.go index 1de73c4f8..6d0eeb716 100644 --- a/android/updatable_modules.go +++ b/android/updatable_modules.go @@ -29,8 +29,8 @@ package android // based on the branch such that the builds from testing and development // branches will have a version higher than the prebuilts. // Versions per branch: -// * x-dev - xx5990000 (where xx is the branch SDK level) +// * x-dev - xx0090000 (where xx is the branch SDK level) // * AOSP - xx9990000 // * x-mainline-prod - xx9990000 // * master - 990090000 -const DefaultUpdatableModuleVersion = "345990000" +const DefaultUpdatableModuleVersion = "340090000" From c21c1e4dbf56cf8a3fb95bdd6a71132dbb23d25a Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Mon, 8 May 2023 13:54:50 +0900 Subject: [PATCH 140/172] Mark LLNDK prebuilts as LLNDK so that Vendor APEXes don't embed the LLNDK prebuilts (which are just stubs of LLNDK libraries). Bug: 280697209 Bug: 277403349 Test: m nothing (soong test) Merged-In: I9e6c123e73fa0ab56d8494a01652ee32a9b6a6cd Change-Id: I9e6c123e73fa0ab56d8494a01652ee32a9b6a6cd (cherry picked from commit e3f0281b8897da1fe23b2f4f3a05f1dc87bcc902) --- apex/apex_test.go | 168 ++++++++++++++++++++++++++++++++++++++++++++++ cc/vndk.go | 7 +- 2 files changed, 174 insertions(+), 1 deletion(-) diff --git a/apex/apex_test.go b/apex/apex_test.go index 440afec97..5a96b8e7b 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -4102,6 +4102,174 @@ func TestVndkApexShouldNotProvideNativeLibs(t *testing.T) { }) } +func TestVendorApexWithVndkPrebuilts(t *testing.T) { + ctx := testApex(t, "", + android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + variables.DeviceVndkVersion = proptools.StringPtr("27") + }), + android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { + cc.RegisterVendorSnapshotModules(ctx) + }), + withFiles(map[string][]byte{ + "vendor/foo/Android.bp": []byte(` + apex { + name: "myapex", + binaries: ["foo"], + key: "myapex.key", + min_sdk_version: "27", + vendor: true, + } + + cc_binary { + name: "foo", + vendor: true, + srcs: ["abc.cpp"], + shared_libs: [ + "libllndk", + "libvndk", + ], + nocrt: true, + system_shared_libs: [], + min_sdk_version: "27", + } + + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + `), + // Simulate VNDK prebuilts with vendor_snapshot + "prebuilts/vndk/Android.bp": []byte(` + vndk_prebuilt_shared { + name: "libllndk", + version: "27", + vendor_available: true, + product_available: true, + target_arch: "arm64", + arch: { + arm64: { + srcs: ["libllndk.so"], + }, + }, + } + + vndk_prebuilt_shared { + name: "libvndk", + version: "27", + vendor_available: true, + product_available: true, + target_arch: "arm64", + arch: { + arm64: { + srcs: ["libvndk.so"], + }, + }, + vndk: { + enabled: true, + }, + min_sdk_version: "27", + } + + vndk_prebuilt_shared { + name: "libc++", + version: "27", + target_arch: "arm64", + vendor_available: true, + product_available: true, + vndk: { + enabled: true, + support_system_process: true, + }, + arch: { + arm64: { + srcs: ["libc++.so"], + }, + }, + min_sdk_version: "apex_inherit", + } + + vendor_snapshot { + name: "vendor_snapshot", + version: "27", + arch: { + arm64: { + vndk_libs: [ + "libc++", + "libllndk", + "libvndk", + ], + static_libs: [ + "libc++demangle", + "libclang_rt.builtins", + "libunwind", + ], + }, + } + } + + vendor_snapshot_static { + name: "libclang_rt.builtins", + version: "27", + target_arch: "arm64", + vendor: true, + arch: { + arm64: { + src: "libclang_rt.builtins-aarch64-android.a", + }, + }, + } + + vendor_snapshot_static { + name: "libc++demangle", + version: "27", + target_arch: "arm64", + compile_multilib: "64", + vendor: true, + arch: { + arm64: { + src: "libc++demangle.a", + }, + }, + min_sdk_version: "apex_inherit", + } + + vendor_snapshot_static { + name: "libunwind", + version: "27", + target_arch: "arm64", + compile_multilib: "64", + vendor: true, + arch: { + arm64: { + src: "libunwind.a", + }, + }, + min_sdk_version: "apex_inherit", + } + `), + })) + + // Should embed the prebuilt VNDK libraries in the apex + ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ + "bin/foo", + "prebuilts/vndk/libc++.so:lib64/libc++.so", + "prebuilts/vndk/libvndk.so:lib64/libvndk.so", + }) + + // Should link foo with prebuilt libraries (shared/static) + ldRule := ctx.ModuleForTests("foo", "android_vendor.27_arm64_armv8-a_myapex").Rule("ld") + android.AssertStringDoesContain(t, "should link to prebuilt llndk", ldRule.Args["libFlags"], "prebuilts/vndk/libllndk.so") + android.AssertStringDoesContain(t, "should link to prebuilt vndk", ldRule.Args["libFlags"], "prebuilts/vndk/libvndk.so") + android.AssertStringDoesContain(t, "should link to prebuilt libc++demangle", ldRule.Args["libFlags"], "prebuilts/vndk/libc++demangle.a") + android.AssertStringDoesContain(t, "should link to prebuilt libunwind", ldRule.Args["libFlags"], "prebuilts/vndk/libunwind.a") + + // Should declare the LLNDK library as a "required" external dependency + manifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") + requireNativeLibs := names(manifestRule.Args["requireNativeLibs"]) + ensureListContains(t, requireNativeLibs, "libllndk.so") +} + func TestDependenciesInApexManifest(t *testing.T) { ctx := testApex(t, ` apex { diff --git a/cc/vndk.go b/cc/vndk.go index 30bfdd89f..9b70004c5 100644 --- a/cc/vndk.go +++ b/cc/vndk.go @@ -241,7 +241,7 @@ var ( func vndkModuleLister(predicate func(*Module) bool) moduleListerFunc { return func(ctx android.SingletonContext) (moduleNames, fileNames []string) { ctx.VisitAllModules(func(m android.Module) { - if c, ok := m.(*Module); ok && predicate(c) { + if c, ok := m.(*Module); ok && predicate(c) && !c.IsVndkPrebuiltLibrary() { filename, err := getVndkFileName(c) if err != nil { ctx.ModuleErrorf(m, "%s", err) @@ -402,6 +402,11 @@ func VndkMutator(mctx android.BottomUpMutatorContext) { m.VendorProperties.IsVNDKPrivate = Bool(prebuiltLib.Properties.Llndk.Private) } + if m.IsVndkPrebuiltLibrary() && !m.IsVndk() { + m.VendorProperties.IsLLNDK = true + // TODO(b/280697209): copy "llndk.private" flag to vndk_prebuilt_shared + } + if (isLib && lib.buildShared()) || (isPrebuiltLib && prebuiltLib.buildShared()) { if m.vndkdep != nil && m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() { processVndkLibrary(mctx, m) From 6bd266b3ec571d02d062e0d1d896123a434bc1d8 Mon Sep 17 00:00:00 2001 From: Justin Yun Date: Mon, 8 May 2023 21:06:59 +0900 Subject: [PATCH 141/172] APEX can use any Prebuilt libraries Vendor snapshot libraries generated from prebuilt libraries set "apex_inherit" to their min_sdk_version property to allow them to be used by vendor APEXes. Bug: 277403349 Test: m vendor-snapshot Merged-In: Idd9e5f8e94b3fa2adf47a04507bf0c50c59edfb7 Change-Id: Idd9e5f8e94b3fa2adf47a04507bf0c50c59edfb7 (cherry picked from commit 3cc7846b5887c130ba5ccb5a8f77d8a1a7358ab2) --- cc/vendor_snapshot.go | 6 +++++- cc/vendor_snapshot_test.go | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cc/vendor_snapshot.go b/cc/vendor_snapshot.go index e6e566025..22bf3bf91 100644 --- a/cc/vendor_snapshot.go +++ b/cc/vendor_snapshot.go @@ -250,7 +250,11 @@ var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotS for _, path := range m.VintfFragments() { prop.VintfFragments = append(prop.VintfFragments, filepath.Join("configs", path.Base())) } - prop.MinSdkVersion = m.MinSdkVersion() + if m.IsPrebuilt() { + prop.MinSdkVersion = "apex_inherit" + } else { + prop.MinSdkVersion = m.MinSdkVersion() + } // install config files. ignores any duplicates. for _, path := range append(m.InitRc(), m.VintfFragments()...) { diff --git a/cc/vendor_snapshot_test.go b/cc/vendor_snapshot_test.go index 619500e1d..aa9963301 100644 --- a/cc/vendor_snapshot_test.go +++ b/cc/vendor_snapshot_test.go @@ -23,6 +23,17 @@ import ( "testing" ) +func checkJsonContents(t *testing.T, ctx android.TestingSingleton, jsonPath string, key string, value string) { + jsonOut := ctx.MaybeOutput(jsonPath) + if jsonOut.Rule == nil { + t.Errorf("%q expected but not found", jsonPath) + return + } + if !strings.Contains(jsonOut.Args["content"], fmt.Sprintf("%q:%q", key, value)) { + t.Errorf("%q must include %q:%q but it only has %v", jsonPath, key, value, jsonOut.Args["content"]) + } +} + func TestVendorSnapshotCapture(t *testing.T) { bp := ` cc_library { @@ -52,6 +63,7 @@ func TestVendorSnapshotCapture(t *testing.T) { name: "libvendor_available", vendor_available: true, nocrt: true, + min_sdk_version: "29", } cc_library_headers { @@ -155,6 +167,9 @@ func TestVendorSnapshotCapture(t *testing.T) { filepath.Join(staticDir, "libvendor_available.a.json"), filepath.Join(staticDir, "libvendor_available.cfi.a.json")) + checkJsonContents(t, snapshotSingleton, filepath.Join(staticDir, "libb.a.json"), "MinSdkVersion", "apex_inherit") + checkJsonContents(t, snapshotSingleton, filepath.Join(staticDir, "libvendor_available.a.json"), "MinSdkVersion", "29") + // For binary executables, all vendor:true and vendor_available modules are captured. if archType == "arm64" { binaryVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant) From 1d99986d30518b711d6716fc26fa380881647023 Mon Sep 17 00:00:00 2001 From: Jiakai Zhang Date: Mon, 8 May 2023 16:28:38 +0000 Subject: [PATCH 142/172] Generate boot image profiles even if dexpreopt is disabled. Bug: 280440941 Test: - 1. Patch ag/22302622 to disable dexpreopt. 2. See boot image profiles still generated. (cherry picked from https://android-review.googlesource.com/q/commit:bc698cd28aa2ee17af208bfd56f003347116ddb0) Merged-In: I5f7f746ca1d4da660fe0c40115e6c71750dfdccc Change-Id: I1bf05ade53fa83f3dba46f28a8f9246ba1fdf664 --- apex/apex.go | 2 +- apex/bootclasspath_fragment_test.go | 20 ++++++++++++++++++++ dexpreopt/config.go | 9 +++++++++ dexpreopt/testing.go | 7 +++++++ java/bootclasspath_fragment.go | 13 ++++++++----- java/dexpreopt_bootjars.go | 9 +++++---- java/platform_bootclasspath.go | 13 +++++++------ sdk/java_sdk_test.go | 2 ++ 8 files changed, 59 insertions(+), 16 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index 4fda5058f..d2c535c5e 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -2670,7 +2670,7 @@ func apexBootclasspathFragmentFiles(ctx android.ModuleContext, module blueprint. } pathInApex := bootclasspathFragmentInfo.ProfileInstallPathInApex() - if pathInApex != "" && !java.SkipDexpreoptBootJars(ctx) { + if pathInApex != "" { pathOnHost := bootclasspathFragmentInfo.ProfilePathOnHost() tempPath := android.PathForModuleOut(ctx, "boot_image_profile", pathInApex) diff --git a/apex/bootclasspath_fragment_test.go b/apex/bootclasspath_fragment_test.go index 2ddfd0305..4a661d4ea 100644 --- a/apex/bootclasspath_fragment_test.go +++ b/apex/bootclasspath_fragment_test.go @@ -497,6 +497,26 @@ func TestBootclasspathFragmentInArtApex(t *testing.T) { }) }) + 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, diff --git a/dexpreopt/config.go b/dexpreopt/config.go index 609a29c2d..0cc3bd63b 100644 --- a/dexpreopt/config.go +++ b/dexpreopt/config.go @@ -475,7 +475,16 @@ func RegisterToolDeps(ctx android.BottomUpMutatorContext) { ctx.AddFarVariationDependencies(v, Dex2oatDepTag, dex2oatBin) } +func IsDex2oatNeeded(ctx android.PathContext) bool { + global := GetGlobalConfig(ctx) + return !global.DisablePreopt || !global.DisablePreoptBootImages +} + func dex2oatPathFromDep(ctx android.ModuleContext) android.Path { + if !IsDex2oatNeeded(ctx) { + return nil + } + dex2oatBin := dex2oatModuleName(ctx.Config()) // Find the right dex2oat module, trying to follow PrebuiltDepTag from source diff --git a/dexpreopt/testing.go b/dexpreopt/testing.go index 47ae494e3..b3dd3cca2 100644 --- a/dexpreopt/testing.go +++ b/dexpreopt/testing.go @@ -174,3 +174,10 @@ func FixtureDisableGenerateProfile(disable bool) android.FixturePreparer { dexpreoptConfig.DisableGenerateProfile = disable }) } + +// FixtureDisableDexpreoptBootImages sets the DisablePreoptBootImages property in the global config. +func FixtureDisableDexpreoptBootImages(disable bool) android.FixturePreparer { + return FixtureModifyGlobalConfig(func(_ android.PathContext, dexpreoptConfig *GlobalConfig) { + dexpreoptConfig.DisablePreoptBootImages = disable + }) +} diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index f69256347..6ccf5a331 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -506,7 +506,7 @@ func (b *BootclasspathFragmentModule) DepsMutator(ctx android.BottomUpMutatorCon } } - if SkipDexpreoptBootJars(ctx) { + if !dexpreopt.IsDex2oatNeeded(ctx) { return } @@ -901,10 +901,6 @@ func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleC // produceBootImageFiles builds the boot image files from the source if it is required. func (b *BootclasspathFragmentModule) produceBootImageFiles(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageOutputs { - if SkipDexpreoptBootJars(ctx) { - return bootImageOutputs{} - } - // Only generate the boot image if the configuration does not skip it. return b.generateBootImageBuildActions(ctx, imageConfig) } @@ -929,6 +925,13 @@ func (b *BootclasspathFragmentModule) generateBootImageBuildActions(ctx android. // Build a profile for the image config and then use that to build the boot image. profile := bootImageProfileRule(ctx, imageConfig) + // If dexpreopt of boot image jars should be skipped, generate only a profile. + if SkipDexpreoptBootJars(ctx) { + return bootImageOutputs{ + profile: profile, + } + } + // Build boot image files for the host variants. buildBootImageVariantsForBuildOs(ctx, imageConfig, profile) diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go index f4827ea3a..a0364d28b 100644 --- a/java/dexpreopt_bootjars.go +++ b/java/dexpreopt_bootjars.go @@ -500,9 +500,6 @@ func (d *dexpreoptBootJars) GenerateAndroidBuildActions(ctx android.ModuleContex // Generate build rules for boot images. func (d *dexpreoptBootJars) GenerateSingletonBuildActions(ctx android.SingletonContext) { - if SkipDexpreoptBootJars(ctx) { - return - } if dexpreopt.GetCachedGlobalSoongConfig(ctx) == nil { // No module has enabled dexpreopting, so we assume there will be no boot image to make. return @@ -1002,7 +999,7 @@ func writeGlobalConfigForMake(ctx android.SingletonContext, path android.Writabl // (make/core/dex_preopt_libart.mk) to generate install rules that copy boot image files to the // correct output directories. func (d *dexpreoptBootJars) MakeVars(ctx android.MakeVarsContext) { - if d.dexpreoptConfigForMake != nil { + if d.dexpreoptConfigForMake != nil && !SkipDexpreoptBootJars(ctx) { ctx.Strict("DEX_PREOPT_CONFIG_FOR_MAKE", d.dexpreoptConfigForMake.String()) ctx.Strict("DEX_PREOPT_SOONG_CONFIG_FOR_MAKE", android.PathForOutput(ctx, "dexpreopt_soong.config").String()) } @@ -1014,6 +1011,10 @@ func (d *dexpreoptBootJars) MakeVars(ctx android.MakeVarsContext) { ctx.Strict("DEXPREOPT_IMAGE_PROFILE_LICENSE_METADATA", image.profileLicenseMetadataFile.String()) } + if SkipDexpreoptBootJars(ctx) { + return + } + global := dexpreopt.GetGlobalConfig(ctx) dexPaths, dexLocations := bcpForDexpreopt(ctx, global.PreoptWithUpdatableBcp) ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_FILES", strings.Join(dexPaths.Strings(), " ")) diff --git a/java/platform_bootclasspath.go b/java/platform_bootclasspath.go index 0ea360979..d5779f75b 100644 --- a/java/platform_bootclasspath.go +++ b/java/platform_bootclasspath.go @@ -103,7 +103,7 @@ func (b *platformBootclasspathModule) OutputFiles(tag string) (android.Paths, er func (b *platformBootclasspathModule) DepsMutator(ctx android.BottomUpMutatorContext) { b.hiddenAPIDepsMutator(ctx) - if SkipDexpreoptBootJars(ctx) { + if !dexpreopt.IsDex2oatNeeded(ctx) { return } @@ -187,11 +187,6 @@ func (b *platformBootclasspathModule) GenerateAndroidBuildActions(ctx android.Mo bootDexJarByModule := b.generateHiddenAPIBuildActions(ctx, b.configuredModules, b.fragments) buildRuleForBootJarsPackageCheck(ctx, bootDexJarByModule) - // Nothing to do if skipping the dexpreopt of boot image jars. - if SkipDexpreoptBootJars(ctx) { - return - } - b.generateBootImageBuildActions(ctx, platformModules, apexModules) } @@ -429,6 +424,12 @@ func (b *platformBootclasspathModule) generateBootImage(ctx android.ModuleContex // Build a profile for the image config and then use that to build the boot image. profile := bootImageProfileRule(ctx, imageConfig) + // If dexpreopt of boot image jars should be skipped, generate only a profile. + global := dexpreopt.GetGlobalConfig(ctx) + if global.DisablePreoptBootImages { + return + } + // Build boot image files for the android variants. androidBootImageFiles := buildBootImageVariantsForAndroidOs(ctx, imageConfig, profile) diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go index 3a2ecc00c..6159ea9c2 100644 --- a/sdk/java_sdk_test.go +++ b/sdk/java_sdk_test.go @@ -19,12 +19,14 @@ import ( "testing" "android/soong/android" + "android/soong/dexpreopt" "android/soong/java" ) var prepareForSdkTestWithJava = android.GroupFixturePreparers( java.PrepareForTestWithJavaBuildComponents, PrepareForTestWithSdkBuildComponents, + dexpreopt.PrepareForTestWithFakeDex2oatd, // Ensure that all source paths are provided. This helps ensure that the snapshot generation is // consistent and all files referenced from the snapshot's Android.bp file have actually been From 1b2f306db8a87782389ac7fc1d0ecd28e6ea45fa Mon Sep 17 00:00:00 2001 From: Jiakai Zhang Date: Mon, 8 May 2023 16:28:38 +0000 Subject: [PATCH 143/172] Generate app profiles even if dexpreopt is disabled. Bug: 280440941 Test: - 1. Patch ag/22302622 to disable dexpreopt. 2. lunch aosp_cf_x86_64_phone-userdebug && m 3. See app profiles still generated. Test: - 1. Patch ag/20592051 to enable profile for service-art. 2. banchan com.android.art x86_64 && m 3. See the profile for service-art generated. (cherry picked from https://android-review.googlesource.com/q/commit:cf61e3c59133227894ac7d72091b48451a3e6761) Merged-In: I6090b4b74cedb6d129fcbeef58d075c8ccdcc4e2 Change-Id: I4e721b475b84a2f667bbccc030a8947078f26bb0 --- android/testing.go | 21 +++++++++++++++------ dexpreopt/dexpreopt.go | 8 ++++++++ dexpreopt/testing.go | 7 +++++++ java/dex_test.go | 10 +++++----- java/dexpreopt.go | 12 +++--------- java/dexpreopt_test.go | 25 +++++++++++++++++++++++++ 6 files changed, 63 insertions(+), 20 deletions(-) diff --git a/android/testing.go b/android/testing.go index fc39a9c7a..2a9c6584e 100644 --- a/android/testing.go +++ b/android/testing.go @@ -813,6 +813,20 @@ func normalizePathRelativeToTop(path Path) Path { return path.RelativeToTop() } +func allOutputs(p BuildParams) []string { + outputs := append(WritablePaths(nil), p.Outputs...) + outputs = append(outputs, p.ImplicitOutputs...) + if p.Output != nil { + outputs = append(outputs, p.Output) + } + return outputs.Strings() +} + +// AllOutputs returns all 'BuildParams.Output's and 'BuildParams.Outputs's in their full path string forms. +func (p TestingBuildParams) AllOutputs() []string { + return allOutputs(p.BuildParams) +} + // baseTestingComponent provides functionality common to both TestingModule and TestingSingleton. type baseTestingComponent struct { config Config @@ -954,12 +968,7 @@ func (b baseTestingComponent) buildParamsFromOutput(file string) TestingBuildPar func (b baseTestingComponent) allOutputs() []string { var outputFullPaths []string for _, p := range b.provider.BuildParamsForTests() { - outputs := append(WritablePaths(nil), p.Outputs...) - outputs = append(outputs, p.ImplicitOutputs...) - if p.Output != nil { - outputs = append(outputs, p.Output) - } - outputFullPaths = append(outputFullPaths, outputs.Strings()...) + outputFullPaths = append(outputFullPaths, allOutputs(p)...) } return outputFullPaths } diff --git a/dexpreopt/dexpreopt.go b/dexpreopt/dexpreopt.go index a590c72a5..2b38793ff 100644 --- a/dexpreopt/dexpreopt.go +++ b/dexpreopt/dexpreopt.go @@ -100,11 +100,19 @@ func GenerateDexpreoptRule(ctx android.BuilderContext, globalSoong *GlobalSoongC return rule, nil } +// If dexpreopt is applicable to the module, returns whether dexpreopt is disabled. Otherwise, the +// behavior is undefined. +// When it returns true, dexpreopt artifacts will not be generated, but profile will still be +// generated if profile-guided compilation is requested. func dexpreoptDisabled(ctx android.PathContext, global *GlobalConfig, module *ModuleConfig) bool { if ctx.Config().UnbundledBuild() { return true } + if global.DisablePreopt { + return true + } + if contains(global.DisablePreoptModules, module.Name) { return true } diff --git a/dexpreopt/testing.go b/dexpreopt/testing.go index b3dd3cca2..6ed0736f7 100644 --- a/dexpreopt/testing.go +++ b/dexpreopt/testing.go @@ -181,3 +181,10 @@ func FixtureDisableDexpreoptBootImages(disable bool) android.FixturePreparer { dexpreoptConfig.DisablePreoptBootImages = disable }) } + +// FixtureDisableDexpreopt sets the DisablePreopt property in the global config. +func FixtureDisableDexpreopt(disable bool) android.FixturePreparer { + return FixtureModifyGlobalConfig(func(_ android.PathContext, dexpreoptConfig *GlobalConfig) { + dexpreoptConfig.DisablePreopt = disable + }) +} diff --git a/java/dex_test.go b/java/dex_test.go index 97fc3d0dd..2ba3831f4 100644 --- a/java/dex_test.go +++ b/java/dex_test.go @@ -23,7 +23,7 @@ import ( ) func TestR8(t *testing.T) { - result := PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd.RunTestWithBp(t, ` + result := PrepareForTestWithJavaDefaultModules.RunTestWithBp(t, ` android_app { name: "app", srcs: ["foo.java"], @@ -191,7 +191,7 @@ func TestR8TransitiveDeps(t *testing.T) { for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { - fixturePreparer := PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd + fixturePreparer := PrepareForTestWithJavaDefaultModules if tc.unbundled { fixturePreparer = android.GroupFixturePreparers( fixturePreparer, @@ -258,7 +258,7 @@ func TestR8TransitiveDeps(t *testing.T) { } func TestR8Flags(t *testing.T) { - result := PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd.RunTestWithBp(t, ` + result := PrepareForTestWithJavaDefaultModules.RunTestWithBp(t, ` android_app { name: "app", srcs: ["foo.java"], @@ -287,7 +287,7 @@ func TestR8Flags(t *testing.T) { } func TestD8(t *testing.T) { - result := PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd.RunTestWithBp(t, ` + result := PrepareForTestWithJavaDefaultModules.RunTestWithBp(t, ` java_library { name: "foo", srcs: ["foo.java"], @@ -328,7 +328,7 @@ func TestD8(t *testing.T) { } func TestProguardFlagsInheritance(t *testing.T) { - result := PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd.RunTestWithBp(t, ` + result := PrepareForTestWithJavaDefaultModules.RunTestWithBp(t, ` android_app { name: "app", static_libs: [ diff --git a/java/dexpreopt.go b/java/dexpreopt.go index 0ffedf6c4..a96b31281 100644 --- a/java/dexpreopt.go +++ b/java/dexpreopt.go @@ -180,6 +180,8 @@ func moduleName(ctx android.BaseModuleContext) string { return android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()) } +// Returns whether dexpreopt is applicable to the module. +// When it returns true, neither profile nor dexpreopt artifacts will be generated. func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext) bool { if !ctx.Device() { return true @@ -205,14 +207,6 @@ func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext) bool { global := dexpreopt.GetGlobalConfig(ctx) - if global.DisablePreopt { - return true - } - - if inList(moduleName(ctx), global.DisablePreoptModules) { - return true - } - isApexSystemServerJar := global.AllApexSystemServerJars(ctx).ContainsJar(moduleName(ctx)) if isApexVariant(ctx) { // Don't preopt APEX variant module unless the module is an APEX system server jar. @@ -232,7 +226,7 @@ func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext) bool { } func dexpreoptToolDepsMutator(ctx android.BottomUpMutatorContext) { - if d, ok := ctx.Module().(DexpreopterInterface); !ok || d.dexpreoptDisabled(ctx) { + if d, ok := ctx.Module().(DexpreopterInterface); !ok || d.dexpreoptDisabled(ctx) || !dexpreopt.IsDex2oatNeeded(ctx) { return } dexpreopt.RegisterToolDeps(ctx) diff --git a/java/dexpreopt_test.go b/java/dexpreopt_test.go index 3d2c5c3a1..f91ac5cc3 100644 --- a/java/dexpreopt_test.go +++ b/java/dexpreopt_test.go @@ -438,3 +438,28 @@ func TestAndroidMkEntriesForApex(t *testing.T) { android.AssertIntEquals(t, "entries count", 0, len(entriesList)) } + +func TestGenerateProfileEvenIfDexpreoptIsDisabled(t *testing.T) { + preparers := android.GroupFixturePreparers( + PrepareForTestWithJavaDefaultModules, + PrepareForTestWithFakeApexMutator, + dexpreopt.FixtureDisableDexpreopt(true), + ) + + result := preparers.RunTestWithBp(t, ` + java_library { + name: "foo", + installable: true, + dex_preopt: { + profile: "art-profile", + }, + srcs: ["a.java"], + }`) + + ctx := result.TestContext + dexpreopt := ctx.ModuleForTests("foo", "android_common").MaybeRule("dexpreopt") + + expected := []string{"out/soong/.intermediates/foo/android_common/dexpreopt/profile.prof"} + + android.AssertArrayString(t, "outputs", expected, dexpreopt.AllOutputs()) +} From e3a5103cba2ea1647f98b7230ea156c559835570 Mon Sep 17 00:00:00 2001 From: Yi Kong Date: Thu, 11 May 2023 16:52:11 +0100 Subject: [PATCH 144/172] Update clang version to clang-r487747c Test: presubmit Bug: 279955553 Change-Id: Ibe3b5e81f7850560b340c89a1f83d5ebdf4fc25f Merged-In: Ibe3b5e81f7850560b340c89a1f83d5ebdf4fc25f (cherry picked from commit 1c223017351e0a8d3fe490d78f4a8252ee914bf9) --- cc/config/global.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cc/config/global.go b/cc/config/global.go index a2d5cf439..3df739e7f 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -311,7 +311,7 @@ var ( // prebuilts/clang default settings. ClangDefaultBase = "prebuilts/clang/host" - ClangDefaultVersion = "clang-r487747" + ClangDefaultVersion = "clang-r487747c" ClangDefaultShortVersion = "17" // Directories with warnings from Android.bp files. From bc9256b53168eddd5fc0be4e94dd74c7293dd2ae Mon Sep 17 00:00:00 2001 From: Jeongik Cha Date: Wed, 19 Apr 2023 23:25:41 +0900 Subject: [PATCH 145/172] Get rid of DeviceName() from path related to dexpreopt As-is, dexpreopt config and bootjar is in the dir including DeviceName(). It causes unnecessary dexpreopt invocation when target is changed repeatly. To avoid it, rename dir to common name. Bug: 278833696 Test: m (cherry picked from https://android-review.googlesource.com/q/commit:4753b39ccaaf573910e6b7a4200e9ca03ec8d96d) Merged-In: I2818d9ae09e6c22ca6989cc8efdb70b470ec502c Change-Id: I2818d9ae09e6c22ca6989cc8efdb70b470ec502c --- apex/bootclasspath_fragment_test.go | 30 +- java/dexpreopt_bootjars.go | 4 +- java/dexpreopt_bootjars_test.go | 4 +- java/dexpreopt_config.go | 11 +- java/dexpreopt_config_testing.go | 572 ++++++++++++++-------------- 5 files changed, 313 insertions(+), 308 deletions(-) diff --git a/apex/bootclasspath_fragment_test.go b/apex/bootclasspath_fragment_test.go index 4a661d4ea..3e55ccc11 100644 --- a/apex/bootclasspath_fragment_test.go +++ b/apex/bootclasspath_fragment_test.go @@ -116,18 +116,18 @@ func TestBootclasspathFragments(t *testing.T) { // 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", ` -test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art -test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat -test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex -test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.art -test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.oat -test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.vdex -test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art -test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat -test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex -test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.art -test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.oat -test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.vdex +dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art +dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat +dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex +dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.art +dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.oat +dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.vdex +dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art +dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat +dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex +dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.art +dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.oat +dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.vdex `) } @@ -784,7 +784,7 @@ func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) { checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo") // Check that the right deapexer module was chosen for a boot image. - param := module.Output("out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art") + param := module.Output("out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art") android.AssertStringDoesContain(t, "didn't find the expected deapexer in the input path", param.Input.String(), "/com.android.art.deapexer") }) @@ -802,7 +802,7 @@ func checkCopiesToPredefinedLocationForArt(t *testing.T, config android.Config, bootJarLocations := []string{} for _, output := range module.AllOutputs() { output = android.StringRelativeToTop(config, output) - if strings.HasPrefix(output, "out/soong/test_device/dex_artjars_input/") { + if strings.HasPrefix(output, "out/soong/dexpreopt_arm64/dex_artjars_input/") { bootJarLocations = append(bootJarLocations, output) } } @@ -810,7 +810,7 @@ func checkCopiesToPredefinedLocationForArt(t *testing.T, config android.Config, sort.Strings(bootJarLocations) expected := []string{} for _, m := range modules { - expected = append(expected, fmt.Sprintf("out/soong/test_device/dex_artjars_input/%s.jar", m)) + expected = append(expected, fmt.Sprintf("out/soong/dexpreopt_arm64/dex_artjars_input/%s.jar", m)) } sort.Strings(expected) diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go index a0364d28b..8e79674fb 100644 --- a/java/dexpreopt_bootjars.go +++ b/java/dexpreopt_bootjars.go @@ -504,8 +504,8 @@ func (d *dexpreoptBootJars) GenerateSingletonBuildActions(ctx android.SingletonC // No module has enabled dexpreopting, so we assume there will be no boot image to make. return } - - d.dexpreoptConfigForMake = android.PathForOutput(ctx, ctx.Config().DeviceName(), "dexpreopt.config") + archType := ctx.Config().Targets[android.Android][0].Arch.ArchType + d.dexpreoptConfigForMake = android.PathForOutput(ctx, toDexpreoptDirName(archType), "dexpreopt.config") writeGlobalConfigForMake(ctx, d.dexpreoptConfigForMake) global := dexpreopt.GetGlobalConfig(ctx) diff --git a/java/dexpreopt_bootjars_test.go b/java/dexpreopt_bootjars_test.go index bc7a55eb9..908380813 100644 --- a/java/dexpreopt_bootjars_test.go +++ b/java/dexpreopt_bootjars_test.go @@ -58,11 +58,11 @@ func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOu rule := platformBootclasspath.Output(ruleFile) for i := range expectedInputs { - expectedInputs[i] = filepath.Join("out/soong/test_device", expectedInputs[i]) + expectedInputs[i] = filepath.Join("out/soong/dexpreopt_arm64", expectedInputs[i]) } for i := range expectedOutputs { - expectedOutputs[i] = filepath.Join("out/soong/test_device", expectedOutputs[i]) + expectedOutputs[i] = filepath.Join("out/soong/dexpreopt_arm64", expectedOutputs[i]) } inputs := rule.Implicits.Strings() diff --git a/java/dexpreopt_config.go b/java/dexpreopt_config.go index 8c62c332a..8f732cf56 100644 --- a/java/dexpreopt_config.go +++ b/java/dexpreopt_config.go @@ -108,7 +108,8 @@ 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) - deviceDir := android.PathForOutput(ctx, ctx.Config().DeviceName()) + archType := ctx.Config().Targets[android.Android][0].Arch.ArchType + deviceDir := android.PathForOutput(ctx, toDexpreoptDirName(archType)) configs := genBootImageConfigRaw(ctx) @@ -220,8 +221,8 @@ var updatableBootConfigKey = android.NewOnceKey("apexBootConfig") func GetApexBootConfig(ctx android.PathContext) apexBootConfig { return ctx.Config().Once(updatableBootConfigKey, func() interface{} { apexBootJars := dexpreopt.GetGlobalConfig(ctx).ApexBootJars - - dir := android.PathForOutput(ctx, ctx.Config().DeviceName(), "apex_bootjars") + archType := ctx.Config().Targets[android.Android][0].Arch.ArchType + dir := android.PathForOutput(ctx, toDexpreoptDirName(archType), "apex_bootjars") dexPaths := apexBootJars.BuildPaths(ctx, dir) dexPathsByModuleName := apexBootJars.BuildPathsByModule(ctx, dir) @@ -261,3 +262,7 @@ func init() { 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() +} diff --git a/java/dexpreopt_config_testing.go b/java/dexpreopt_config_testing.go index 86dd32988..6b98ca58c 100644 --- a/java/dexpreopt_config_testing.go +++ b/java/dexpreopt_config_testing.go @@ -207,65 +207,65 @@ func checkArtBootImageConfig(t *testing.T, result *android.TestResult, mutated b expected := &expectedConfig{ name: "art", stem: "boot", - dir: "out/soong/test_device/dex_artjars", - symbolsDir: "out/soong/test_device/dex_artjars_unstripped", + dir: "out/soong/dexpreopt_arm64/dex_artjars", + symbolsDir: "out/soong/dexpreopt_arm64/dex_artjars_unstripped", installDirOnDevice: "system/framework", installDirOnHost: "apex/art_boot_images/javalib", profileInstallPathInApex: "etc/boot-image.prof", modules: android.CreateTestConfiguredJarList([]string{"com.android.art:core1", "com.android.art:core2"}), - dexPaths: []string{"out/soong/test_device/dex_artjars_input/core1.jar", "out/soong/test_device/dex_artjars_input/core2.jar"}, - dexPathsDeps: []string{"out/soong/test_device/dex_artjars_input/core1.jar", "out/soong/test_device/dex_artjars_input/core2.jar"}, - zip: "out/soong/test_device/dex_artjars/art.zip", + dexPaths: []string{"out/soong/dexpreopt_arm64/dex_artjars_input/core1.jar", "out/soong/dexpreopt_arm64/dex_artjars_input/core2.jar"}, + dexPathsDeps: []string{"out/soong/dexpreopt_arm64/dex_artjars_input/core1.jar", "out/soong/dexpreopt_arm64/dex_artjars_input/core2.jar"}, + zip: "out/soong/dexpreopt_arm64/dex_artjars/art.zip", variants: []*expectedVariant{ { archType: android.Arm64, dexLocations: []string{"/apex/com.android.art/javalib/core1.jar", "/apex/com.android.art/javalib/core2.jar"}, dexLocationsDeps: []string{"/apex/com.android.art/javalib/core1.jar", "/apex/com.android.art/javalib/core2.jar"}, - imagePathOnHost: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", + imagePathOnHost: "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", imagePathOnDevice: "/system/framework/arm64/boot.art", imagesDeps: []string{ - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex", }, installs: []normalizedInstall{ { - from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", + from: "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", to: "/apex/art_boot_images/javalib/arm64/boot.art", }, { - from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat", + from: "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat", to: "/apex/art_boot_images/javalib/arm64/boot.oat", }, { - from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art", + from: "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art", to: "/apex/art_boot_images/javalib/arm64/boot-core2.art", }, { - from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat", + from: "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat", to: "/apex/art_boot_images/javalib/arm64/boot-core2.oat", }, }, vdexInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex", + from: "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex", to: "/apex/art_boot_images/javalib/arm64/boot.vdex", }, { - from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex", + from: "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex", to: "/apex/art_boot_images/javalib/arm64/boot-core2.vdex", }, }, unstrippedInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm64/boot.oat", + from: "out/soong/dexpreopt_arm64/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm64/boot.oat", to: "/apex/art_boot_images/javalib/arm64/boot.oat", }, { - from: "out/soong/test_device/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm64/boot-core2.oat", + from: "out/soong/dexpreopt_arm64/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm64/boot-core2.oat", to: "/apex/art_boot_images/javalib/arm64/boot-core2.oat", }, }, @@ -275,51 +275,51 @@ func checkArtBootImageConfig(t *testing.T, result *android.TestResult, mutated b archType: android.Arm, dexLocations: []string{"/apex/com.android.art/javalib/core1.jar", "/apex/com.android.art/javalib/core2.jar"}, dexLocationsDeps: []string{"/apex/com.android.art/javalib/core1.jar", "/apex/com.android.art/javalib/core2.jar"}, - imagePathOnHost: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", + imagePathOnHost: "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", imagePathOnDevice: "/system/framework/arm/boot.art", imagesDeps: []string{ - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.art", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.oat", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.vdex", }, installs: []normalizedInstall{ { - from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", + from: "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", to: "/apex/art_boot_images/javalib/arm/boot.art", }, { - from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat", + from: "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat", to: "/apex/art_boot_images/javalib/arm/boot.oat", }, { - from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.art", + from: "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.art", to: "/apex/art_boot_images/javalib/arm/boot-core2.art", }, { - from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.oat", + from: "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.oat", to: "/apex/art_boot_images/javalib/arm/boot-core2.oat", }, }, vdexInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex", + from: "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex", to: "/apex/art_boot_images/javalib/arm/boot.vdex", }, { - from: "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.vdex", + from: "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.vdex", to: "/apex/art_boot_images/javalib/arm/boot-core2.vdex", }, }, unstrippedInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm/boot.oat", + from: "out/soong/dexpreopt_arm64/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm/boot.oat", to: "/apex/art_boot_images/javalib/arm/boot.oat", }, { - from: "out/soong/test_device/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm/boot-core2.oat", + from: "out/soong/dexpreopt_arm64/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm/boot-core2.oat", to: "/apex/art_boot_images/javalib/arm/boot-core2.oat", }, }, @@ -329,49 +329,49 @@ func checkArtBootImageConfig(t *testing.T, result *android.TestResult, mutated b archType: android.X86_64, dexLocations: []string{"host/linux-x86/apex/com.android.art/javalib/core1.jar", "host/linux-x86/apex/com.android.art/javalib/core2.jar"}, dexLocationsDeps: []string{"host/linux-x86/apex/com.android.art/javalib/core1.jar", "host/linux-x86/apex/com.android.art/javalib/core2.jar"}, - imagePathOnHost: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", + imagePathOnHost: "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", imagePathOnDevice: "/system/framework/x86_64/boot.art", imagesDeps: []string{ - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex", }, installs: []normalizedInstall{ { - from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", + from: "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", to: "/apex/art_boot_images/javalib/x86_64/boot.art", }, { - from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat", + from: "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat", to: "/apex/art_boot_images/javalib/x86_64/boot.oat", }, { - from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art", + from: "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art", to: "/apex/art_boot_images/javalib/x86_64/boot-core2.art", }, { - from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat", + from: "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat", to: "/apex/art_boot_images/javalib/x86_64/boot-core2.oat", }, }, vdexInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex", + from: "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex", to: "/apex/art_boot_images/javalib/x86_64/boot.vdex", }, { - from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex", + from: "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex", to: "/apex/art_boot_images/javalib/x86_64/boot-core2.vdex", }, }, unstrippedInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat", + from: "out/soong/dexpreopt_arm64/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat", to: "/apex/art_boot_images/javalib/x86_64/boot.oat", }, { - from: "out/soong/test_device/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat", + from: "out/soong/dexpreopt_arm64/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat", to: "/apex/art_boot_images/javalib/x86_64/boot-core2.oat", }, }, @@ -381,49 +381,49 @@ func checkArtBootImageConfig(t *testing.T, result *android.TestResult, mutated b archType: android.X86, dexLocations: []string{"host/linux-x86/apex/com.android.art/javalib/core1.jar", "host/linux-x86/apex/com.android.art/javalib/core2.jar"}, dexLocationsDeps: []string{"host/linux-x86/apex/com.android.art/javalib/core1.jar", "host/linux-x86/apex/com.android.art/javalib/core2.jar"}, - imagePathOnHost: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", + imagePathOnHost: "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", imagePathOnDevice: "/system/framework/x86/boot.art", imagesDeps: []string{ - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex", }, installs: []normalizedInstall{ { - from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", + from: "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", to: "/apex/art_boot_images/javalib/x86/boot.art", }, { - from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat", + from: "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat", to: "/apex/art_boot_images/javalib/x86/boot.oat", }, { - from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art", + from: "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art", to: "/apex/art_boot_images/javalib/x86/boot-core2.art", }, { - from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat", + from: "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat", to: "/apex/art_boot_images/javalib/x86/boot-core2.oat", }, }, vdexInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex", + from: "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex", to: "/apex/art_boot_images/javalib/x86/boot.vdex", }, { - from: "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex", + from: "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex", to: "/apex/art_boot_images/javalib/x86/boot-core2.vdex", }, }, unstrippedInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat", + from: "out/soong/dexpreopt_arm64/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat", to: "/apex/art_boot_images/javalib/x86/boot.oat", }, { - from: "out/soong/test_device/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat", + from: "out/soong/dexpreopt_arm64/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat", to: "/apex/art_boot_images/javalib/x86/boot-core2.oat", }, }, @@ -460,15 +460,15 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut expected := &expectedConfig{ name: "boot", stem: "boot", - dir: "out/soong/test_device/dex_bootjars", - symbolsDir: "out/soong/test_device/dex_bootjars_unstripped", + dir: "out/soong/dexpreopt_arm64/dex_bootjars", + symbolsDir: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped", installDirOnDevice: "system/framework", installDirOnHost: "system/framework", profileInstallPathInApex: "", modules: android.CreateTestConfiguredJarList([]string{"platform:framework"}), - dexPaths: []string{"out/soong/test_device/dex_bootjars_input/framework.jar"}, - dexPathsDeps: []string{"out/soong/test_device/dex_artjars_input/core1.jar", "out/soong/test_device/dex_artjars_input/core2.jar", "out/soong/test_device/dex_bootjars_input/framework.jar"}, - zip: "out/soong/test_device/dex_bootjars/boot.zip", + dexPaths: []string{"out/soong/dexpreopt_arm64/dex_bootjars_input/framework.jar"}, + dexPathsDeps: []string{"out/soong/dexpreopt_arm64/dex_artjars_input/core1.jar", "out/soong/dexpreopt_arm64/dex_artjars_input/core2.jar", "out/soong/dexpreopt_arm64/dex_bootjars_input/framework.jar"}, + zip: "out/soong/dexpreopt_arm64/dex_bootjars/boot.zip", variants: []*expectedVariant{ { archType: android.Arm64, @@ -478,41 +478,41 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut "/apex/com.android.art/javalib/core2.jar", "/system/framework/framework.jar", }, - imagePathOnHost: "out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.art", + imagePathOnHost: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art", imagePathOnDevice: "/system/framework/arm64/boot-framework.art", imagesDeps: []string{ - "out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.art", - "out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.oat", - "out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.vdex", }, - baseImages: []string{"out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art"}, + baseImages: []string{"out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art"}, baseImagesDeps: []string{ - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex", }, installs: []normalizedInstall{ { - from: "out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.art", + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art", to: "/system/framework/arm64/boot-framework.art", }, { - from: "out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.oat", + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.oat", to: "/system/framework/arm64/boot-framework.oat", }, }, vdexInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.vdex", + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.vdex", to: "/system/framework/arm64/boot-framework.vdex", }, }, unstrippedInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_bootjars_unstripped/android/system/framework/arm64/boot-framework.oat", + from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-framework.oat", to: "/system/framework/arm64/boot-framework.oat", }, }, @@ -526,41 +526,41 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut "/apex/com.android.art/javalib/core2.jar", "/system/framework/framework.jar", }, - imagePathOnHost: "out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.art", + imagePathOnHost: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art", imagePathOnDevice: "/system/framework/arm/boot-framework.art", imagesDeps: []string{ - "out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.art", - "out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.oat", - "out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.vdex", }, - baseImages: []string{"out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art"}, + baseImages: []string{"out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art"}, baseImagesDeps: []string{ - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.art", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.oat", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.vdex", }, installs: []normalizedInstall{ { - from: "out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.art", + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art", to: "/system/framework/arm/boot-framework.art", }, { - from: "out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.oat", + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.oat", to: "/system/framework/arm/boot-framework.oat", }, }, vdexInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.vdex", + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.vdex", to: "/system/framework/arm/boot-framework.vdex", }, }, unstrippedInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_bootjars_unstripped/android/system/framework/arm/boot-framework.oat", + from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm/boot-framework.oat", to: "/system/framework/arm/boot-framework.oat", }, }, @@ -574,41 +574,41 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut "host/linux-x86/apex/com.android.art/javalib/core2.jar", "host/linux-x86/system/framework/framework.jar", }, - imagePathOnHost: "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art", + imagePathOnHost: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art", imagePathOnDevice: "/system/framework/x86_64/boot-framework.art", imagesDeps: []string{ - "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art", - "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat", - "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex", }, - baseImages: []string{"out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art"}, + baseImages: []string{"out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art"}, baseImagesDeps: []string{ - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex", }, installs: []normalizedInstall{ { - from: "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art", + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art", to: "/system/framework/x86_64/boot-framework.art", }, { - from: "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat", + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat", to: "/system/framework/x86_64/boot-framework.oat", }, }, vdexInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex", + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex", to: "/system/framework/x86_64/boot-framework.vdex", }, }, unstrippedInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_bootjars_unstripped/linux_glibc/system/framework/x86_64/boot-framework.oat", + from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86_64/boot-framework.oat", to: "/system/framework/x86_64/boot-framework.oat", }, }, @@ -622,41 +622,41 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut "host/linux-x86/apex/com.android.art/javalib/core2.jar", "host/linux-x86/system/framework/framework.jar", }, - imagePathOnHost: "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art", + imagePathOnHost: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art", imagePathOnDevice: "/system/framework/x86/boot-framework.art", imagesDeps: []string{ - "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art", - "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat", - "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex", }, - baseImages: []string{"out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art"}, + baseImages: []string{"out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art"}, baseImagesDeps: []string{ - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex", }, installs: []normalizedInstall{ { - from: "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art", + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art", to: "/system/framework/x86/boot-framework.art", }, { - from: "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat", + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat", to: "/system/framework/x86/boot-framework.oat", }, }, vdexInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex", + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex", to: "/system/framework/x86/boot-framework.vdex", }, }, unstrippedInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_bootjars_unstripped/linux_glibc/system/framework/x86/boot-framework.oat", + from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86/boot-framework.oat", to: "/system/framework/x86/boot-framework.oat", }, }, @@ -664,8 +664,8 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut }, }, profileInstalls: []normalizedInstall{ - {from: "out/soong/test_device/dex_bootjars/boot.bprof", to: "/system/etc/boot-image.bprof"}, - {from: "out/soong/test_device/dex_bootjars/boot.prof", to: "/system/etc/boot-image.prof"}, + {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"}, }, profileLicenseMetadataFile: expectedLicenseMetadataFile, } @@ -691,8 +691,8 @@ func CheckMainlineBootImageConfig(t *testing.T, result *android.TestResult) { expected := &expectedConfig{ name: "mainline", stem: "boot", - dir: "out/soong/test_device/dex_mainlinejars", - symbolsDir: "out/soong/test_device/dex_mainlinejars_unstripped", + dir: "out/soong/dexpreopt_arm64/dex_mainlinejars", + symbolsDir: "out/soong/dexpreopt_arm64/dex_mainlinejars_unstripped", installDirOnDevice: "system/framework", installDirOnHost: "system/framework", profileInstallPathInApex: "", @@ -701,17 +701,17 @@ func CheckMainlineBootImageConfig(t *testing.T, result *android.TestResult) { "com.android.bar:framework-bar", }), dexPaths: []string{ - "out/soong/test_device/dex_mainlinejars_input/framework-foo.jar", - "out/soong/test_device/dex_mainlinejars_input/framework-bar.jar", + "out/soong/dexpreopt_arm64/dex_mainlinejars_input/framework-foo.jar", + "out/soong/dexpreopt_arm64/dex_mainlinejars_input/framework-bar.jar", }, dexPathsDeps: []string{ - "out/soong/test_device/dex_artjars_input/core1.jar", - "out/soong/test_device/dex_artjars_input/core2.jar", - "out/soong/test_device/dex_bootjars_input/framework.jar", - "out/soong/test_device/dex_mainlinejars_input/framework-foo.jar", - "out/soong/test_device/dex_mainlinejars_input/framework-bar.jar", + "out/soong/dexpreopt_arm64/dex_artjars_input/core1.jar", + "out/soong/dexpreopt_arm64/dex_artjars_input/core2.jar", + "out/soong/dexpreopt_arm64/dex_bootjars_input/framework.jar", + "out/soong/dexpreopt_arm64/dex_mainlinejars_input/framework-foo.jar", + "out/soong/dexpreopt_arm64/dex_mainlinejars_input/framework-bar.jar", }, - zip: "out/soong/test_device/dex_mainlinejars/mainline.zip", + zip: "out/soong/dexpreopt_arm64/dex_mainlinejars/mainline.zip", variants: []*expectedVariant{ { archType: android.Arm64, @@ -726,47 +726,47 @@ func CheckMainlineBootImageConfig(t *testing.T, result *android.TestResult) { "/apex/com.android.foo/javalib/framework-foo.jar", "/apex/com.android.bar/javalib/framework-bar.jar", }, - imagePathOnHost: "out/soong/test_device/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.art", + imagePathOnHost: "out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.art", imagePathOnDevice: "/system/framework/arm64/boot-framework-foo.art", imagesDeps: []string{ - "out/soong/test_device/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.art", - "out/soong/test_device/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.oat", - "out/soong/test_device/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.vdex", + "out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.art", + "out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.oat", + "out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.vdex", }, baseImages: []string{ - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", - "out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.art", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art", }, baseImagesDeps: []string{ - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex", - "out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.art", - "out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.oat", - "out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.vdex", }, installs: []normalizedInstall{ { - from: "out/soong/test_device/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.art", + from: "out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.art", to: "/system/framework/arm64/boot-framework-foo.art", }, { - from: "out/soong/test_device/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.oat", + from: "out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.oat", to: "/system/framework/arm64/boot-framework-foo.oat", }, }, vdexInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.vdex", + from: "out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.vdex", to: "/system/framework/arm64/boot-framework-foo.vdex", }, }, unstrippedInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_mainlinejars_unstripped/android/system/framework/arm64/boot-framework-foo.oat", + from: "out/soong/dexpreopt_arm64/dex_mainlinejars_unstripped/android/system/framework/arm64/boot-framework-foo.oat", to: "/system/framework/arm64/boot-framework-foo.oat", }, }, @@ -785,47 +785,47 @@ func CheckMainlineBootImageConfig(t *testing.T, result *android.TestResult) { "/apex/com.android.foo/javalib/framework-foo.jar", "/apex/com.android.bar/javalib/framework-bar.jar", }, - imagePathOnHost: "out/soong/test_device/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.art", + imagePathOnHost: "out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.art", imagePathOnDevice: "/system/framework/arm/boot-framework-foo.art", imagesDeps: []string{ - "out/soong/test_device/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.art", - "out/soong/test_device/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.oat", - "out/soong/test_device/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.vdex", + "out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.art", + "out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.oat", + "out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.vdex", }, baseImages: []string{ - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", - "out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.art", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art", }, baseImagesDeps: []string{ - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.art", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.oat", - "out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.vdex", - "out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.art", - "out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.oat", - "out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.vdex", }, installs: []normalizedInstall{ { - from: "out/soong/test_device/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.art", + from: "out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.art", to: "/system/framework/arm/boot-framework-foo.art", }, { - from: "out/soong/test_device/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.oat", + from: "out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.oat", to: "/system/framework/arm/boot-framework-foo.oat", }, }, vdexInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.vdex", + from: "out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.vdex", to: "/system/framework/arm/boot-framework-foo.vdex", }, }, unstrippedInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_mainlinejars_unstripped/android/system/framework/arm/boot-framework-foo.oat", + from: "out/soong/dexpreopt_arm64/dex_mainlinejars_unstripped/android/system/framework/arm/boot-framework-foo.oat", to: "/system/framework/arm/boot-framework-foo.oat", }, }, @@ -844,47 +844,47 @@ func CheckMainlineBootImageConfig(t *testing.T, result *android.TestResult) { "host/linux-x86/apex/com.android.foo/javalib/framework-foo.jar", "host/linux-x86/apex/com.android.bar/javalib/framework-bar.jar", }, - imagePathOnHost: "out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.art", + imagePathOnHost: "out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.art", imagePathOnDevice: "/system/framework/x86_64/boot-framework-foo.art", imagesDeps: []string{ - "out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.art", - "out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.oat", - "out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.vdex", + "out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.art", + "out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.oat", + "out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.vdex", }, baseImages: []string{ - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", - "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art", }, baseImagesDeps: []string{ - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex", - "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art", - "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat", - "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex", }, installs: []normalizedInstall{ { - from: "out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.art", + from: "out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.art", to: "/system/framework/x86_64/boot-framework-foo.art", }, { - from: "out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.oat", + from: "out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.oat", to: "/system/framework/x86_64/boot-framework-foo.oat", }, }, vdexInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.vdex", + from: "out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.vdex", to: "/system/framework/x86_64/boot-framework-foo.vdex", }, }, unstrippedInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_mainlinejars_unstripped/linux_glibc/system/framework/x86_64/boot-framework-foo.oat", + from: "out/soong/dexpreopt_arm64/dex_mainlinejars_unstripped/linux_glibc/system/framework/x86_64/boot-framework-foo.oat", to: "/system/framework/x86_64/boot-framework-foo.oat", }, }, @@ -903,47 +903,47 @@ func CheckMainlineBootImageConfig(t *testing.T, result *android.TestResult) { "host/linux-x86/apex/com.android.foo/javalib/framework-foo.jar", "host/linux-x86/apex/com.android.bar/javalib/framework-bar.jar", }, - imagePathOnHost: "out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.art", + imagePathOnHost: "out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.art", imagePathOnDevice: "/system/framework/x86/boot-framework-foo.art", imagesDeps: []string{ - "out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.art", - "out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.oat", - "out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.vdex", + "out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.art", + "out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.oat", + "out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.vdex", }, baseImages: []string{ - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", - "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art", }, baseImagesDeps: []string{ - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat", - "out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex", - "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art", - "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat", - "out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex", }, installs: []normalizedInstall{ { - from: "out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.art", + from: "out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.art", to: "/system/framework/x86/boot-framework-foo.art", }, { - from: "out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.oat", + from: "out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.oat", to: "/system/framework/x86/boot-framework-foo.oat", }, }, vdexInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.vdex", + from: "out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.vdex", to: "/system/framework/x86/boot-framework-foo.vdex", }, }, unstrippedInstalls: []normalizedInstall{ { - from: "out/soong/test_device/dex_mainlinejars_unstripped/linux_glibc/system/framework/x86/boot-framework-foo.oat", + from: "out/soong/dexpreopt_arm64/dex_mainlinejars_unstripped/linux_glibc/system/framework/x86/boot-framework-foo.oat", to: "/system/framework/x86/boot-framework-foo.oat", }, }, @@ -1056,34 +1056,34 @@ func checkDexpreoptMakeVars(t *testing.T, result *android.TestResult, expectedLi fmt.Fprintf(out, "%s=%s\n", v.Name(), android.StringRelativeToTop(result.Config, v.Value())) } format := ` -DEXPREOPT_BOOTCLASSPATH_DEX_FILES=out/soong/test_device/dex_artjars_input/core1.jar out/soong/test_device/dex_artjars_input/core2.jar out/soong/test_device/dex_bootjars_input/framework.jar +DEXPREOPT_BOOTCLASSPATH_DEX_FILES=out/soong/dexpreopt_arm64/dex_artjars_input/core1.jar out/soong/dexpreopt_arm64/dex_artjars_input/core2.jar out/soong/dexpreopt_arm64/dex_bootjars_input/framework.jar DEXPREOPT_BOOTCLASSPATH_DEX_LOCATIONS=/apex/com.android.art/javalib/core1.jar /apex/com.android.art/javalib/core2.jar /system/framework/framework.jar DEXPREOPT_BOOT_JARS_MODULES=platform:framework DEXPREOPT_GEN=out/host/linux-x86/bin/dexpreopt_gen -DEXPREOPT_IMAGE_BUILT_INSTALLED_art_arm=out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art:/apex/art_boot_images/javalib/arm/boot.art out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat:/apex/art_boot_images/javalib/arm/boot.oat out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.art:/apex/art_boot_images/javalib/arm/boot-core2.art out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.oat:/apex/art_boot_images/javalib/arm/boot-core2.oat -DEXPREOPT_IMAGE_BUILT_INSTALLED_art_arm64=out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art:/apex/art_boot_images/javalib/arm64/boot.art out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat:/apex/art_boot_images/javalib/arm64/boot.oat out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art:/apex/art_boot_images/javalib/arm64/boot-core2.art out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat:/apex/art_boot_images/javalib/arm64/boot-core2.oat -DEXPREOPT_IMAGE_BUILT_INSTALLED_art_host_x86=out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art:/apex/art_boot_images/javalib/x86/boot.art out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat:/apex/art_boot_images/javalib/x86/boot.oat out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art:/apex/art_boot_images/javalib/x86/boot-core2.art out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat:/apex/art_boot_images/javalib/x86/boot-core2.oat -DEXPREOPT_IMAGE_BUILT_INSTALLED_art_host_x86_64=out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art:/apex/art_boot_images/javalib/x86_64/boot.art out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat:/apex/art_boot_images/javalib/x86_64/boot.oat out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art:/apex/art_boot_images/javalib/x86_64/boot-core2.art out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat:/apex/art_boot_images/javalib/x86_64/boot-core2.oat -DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_arm=out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.art:/system/framework/arm/boot-framework.art out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.oat:/system/framework/arm/boot-framework.oat -DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_arm64=out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.art:/system/framework/arm64/boot-framework.art out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.oat:/system/framework/arm64/boot-framework.oat -DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_host_x86=out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art:/system/framework/x86/boot-framework.art out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat:/system/framework/x86/boot-framework.oat -DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_host_x86_64=out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art:/system/framework/x86_64/boot-framework.art out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat:/system/framework/x86_64/boot-framework.oat -DEXPREOPT_IMAGE_BUILT_INSTALLED_mainline_arm=out/soong/test_device/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.art:/system/framework/arm/boot-framework-foo.art out/soong/test_device/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.oat:/system/framework/arm/boot-framework-foo.oat -DEXPREOPT_IMAGE_BUILT_INSTALLED_mainline_arm64=out/soong/test_device/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.art:/system/framework/arm64/boot-framework-foo.art out/soong/test_device/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.oat:/system/framework/arm64/boot-framework-foo.oat -DEXPREOPT_IMAGE_BUILT_INSTALLED_mainline_host_x86=out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.art:/system/framework/x86/boot-framework-foo.art out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.oat:/system/framework/x86/boot-framework-foo.oat -DEXPREOPT_IMAGE_BUILT_INSTALLED_mainline_host_x86_64=out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.art:/system/framework/x86_64/boot-framework-foo.art out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.oat:/system/framework/x86_64/boot-framework-foo.oat -DEXPREOPT_IMAGE_DEPS_art_arm=out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.art out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.oat out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.vdex -DEXPREOPT_IMAGE_DEPS_art_arm64=out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex -DEXPREOPT_IMAGE_DEPS_art_host_x86=out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex -DEXPREOPT_IMAGE_DEPS_art_host_x86_64=out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex -DEXPREOPT_IMAGE_DEPS_boot_arm=out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.art out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.oat out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.vdex -DEXPREOPT_IMAGE_DEPS_boot_arm64=out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.art out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.oat out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.vdex -DEXPREOPT_IMAGE_DEPS_boot_host_x86=out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex -DEXPREOPT_IMAGE_DEPS_boot_host_x86_64=out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex -DEXPREOPT_IMAGE_DEPS_mainline_arm=out/soong/test_device/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.art out/soong/test_device/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.oat out/soong/test_device/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.vdex -DEXPREOPT_IMAGE_DEPS_mainline_arm64=out/soong/test_device/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.art out/soong/test_device/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.oat out/soong/test_device/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.vdex -DEXPREOPT_IMAGE_DEPS_mainline_host_x86=out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.art out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.oat out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.vdex -DEXPREOPT_IMAGE_DEPS_mainline_host_x86_64=out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.art out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.oat out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.vdex +DEXPREOPT_IMAGE_BUILT_INSTALLED_art_arm=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art:/apex/art_boot_images/javalib/arm/boot.art out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat:/apex/art_boot_images/javalib/arm/boot.oat out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.art:/apex/art_boot_images/javalib/arm/boot-core2.art out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.oat:/apex/art_boot_images/javalib/arm/boot-core2.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_art_arm64=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art:/apex/art_boot_images/javalib/arm64/boot.art out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat:/apex/art_boot_images/javalib/arm64/boot.oat out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art:/apex/art_boot_images/javalib/arm64/boot-core2.art out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat:/apex/art_boot_images/javalib/arm64/boot-core2.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_art_host_x86=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art:/apex/art_boot_images/javalib/x86/boot.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat:/apex/art_boot_images/javalib/x86/boot.oat out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art:/apex/art_boot_images/javalib/x86/boot-core2.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat:/apex/art_boot_images/javalib/x86/boot-core2.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_art_host_x86_64=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art:/apex/art_boot_images/javalib/x86_64/boot.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat:/apex/art_boot_images/javalib/x86_64/boot.oat out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art:/apex/art_boot_images/javalib/x86_64/boot-core2.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat:/apex/art_boot_images/javalib/x86_64/boot-core2.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art:/system/framework/arm/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.oat:/system/framework/arm/boot-framework.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art:/system/framework/arm64/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.oat:/system/framework/arm64/boot-framework.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art:/system/framework/x86/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat:/system/framework/x86/boot-framework.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art:/system/framework/x86_64/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat:/system/framework/x86_64/boot-framework.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_mainline_arm=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.art:/system/framework/arm/boot-framework-foo.art out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.oat:/system/framework/arm/boot-framework-foo.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_mainline_arm64=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.art:/system/framework/arm64/boot-framework-foo.art out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.oat:/system/framework/arm64/boot-framework-foo.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_mainline_host_x86=out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.art:/system/framework/x86/boot-framework-foo.art out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.oat:/system/framework/x86/boot-framework-foo.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_mainline_host_x86_64=out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.art:/system/framework/x86_64/boot-framework-foo.art out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.oat:/system/framework/x86_64/boot-framework-foo.oat +DEXPREOPT_IMAGE_DEPS_art_arm=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.art out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.oat out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.vdex +DEXPREOPT_IMAGE_DEPS_art_arm64=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex +DEXPREOPT_IMAGE_DEPS_art_host_x86=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex +DEXPREOPT_IMAGE_DEPS_art_host_x86_64=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex +DEXPREOPT_IMAGE_DEPS_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.vdex +DEXPREOPT_IMAGE_DEPS_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.vdex +DEXPREOPT_IMAGE_DEPS_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex +DEXPREOPT_IMAGE_DEPS_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex +DEXPREOPT_IMAGE_DEPS_mainline_arm=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.art out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.oat out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.vdex +DEXPREOPT_IMAGE_DEPS_mainline_arm64=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.art out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.oat out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.vdex +DEXPREOPT_IMAGE_DEPS_mainline_host_x86=out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.art out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.oat out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.vdex +DEXPREOPT_IMAGE_DEPS_mainline_host_x86_64=out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.art out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.oat out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.vdex DEXPREOPT_IMAGE_LICENSE_METADATA_art_arm=%[1]s DEXPREOPT_IMAGE_LICENSE_METADATA_art_arm64=%[1]s DEXPREOPT_IMAGE_LICENSE_METADATA_art_host_x86=%[1]s @@ -1099,51 +1099,51 @@ DEXPREOPT_IMAGE_LICENSE_METADATA_mainline_host_x86_64=out/soong/.intermediates/f DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICEart=/system/framework/boot.art DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICEboot=/system/framework/boot.art:/system/framework/boot-framework.art DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICEmainline=/system/framework/boot.art:/system/framework/boot-framework.art:/system/framework/boot-framework-foo.art -DEXPREOPT_IMAGE_LOCATIONS_ON_HOSTart=out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/boot.art -DEXPREOPT_IMAGE_LOCATIONS_ON_HOSTboot=out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/boot.art:out/soong/test_device/dex_bootjars/android/system/framework/boot-framework.art -DEXPREOPT_IMAGE_LOCATIONS_ON_HOSTmainline=out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/boot.art:out/soong/test_device/dex_bootjars/android/system/framework/boot-framework.art:out/soong/test_device/dex_mainlinejars/android/system/framework/boot-framework-foo.art +DEXPREOPT_IMAGE_LOCATIONS_ON_HOSTart=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/boot.art +DEXPREOPT_IMAGE_LOCATIONS_ON_HOSTboot=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/boot.art:out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/boot-framework.art +DEXPREOPT_IMAGE_LOCATIONS_ON_HOSTmainline=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/boot.art:out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/boot-framework.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/test_device/dex_bootjars/boot.bprof:/system/etc/boot-image.bprof out/soong/test_device/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/dexpreopt_arm64/dex_bootjars/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/test_device/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm/boot.oat:/apex/art_boot_images/javalib/arm/boot.oat out/soong/test_device/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/test_device/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm64/boot.oat:/apex/art_boot_images/javalib/arm64/boot.oat out/soong/test_device/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm64/boot-core2.oat:/apex/art_boot_images/javalib/arm64/boot-core2.oat -DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_art_host_x86=out/soong/test_device/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat:/apex/art_boot_images/javalib/x86/boot.oat out/soong/test_device/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat:/apex/art_boot_images/javalib/x86/boot-core2.oat -DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_art_host_x86_64=out/soong/test_device/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat:/apex/art_boot_images/javalib/x86_64/boot.oat out/soong/test_device/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat:/apex/art_boot_images/javalib/x86_64/boot-core2.oat -DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_arm=out/soong/test_device/dex_bootjars_unstripped/android/system/framework/arm/boot-framework.oat:/system/framework/arm/boot-framework.oat -DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_arm64=out/soong/test_device/dex_bootjars_unstripped/android/system/framework/arm64/boot-framework.oat:/system/framework/arm64/boot-framework.oat -DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_host_x86=out/soong/test_device/dex_bootjars_unstripped/linux_glibc/system/framework/x86/boot-framework.oat:/system/framework/x86/boot-framework.oat -DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_host_x86_64=out/soong/test_device/dex_bootjars_unstripped/linux_glibc/system/framework/x86_64/boot-framework.oat:/system/framework/x86_64/boot-framework.oat -DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_mainline_arm=out/soong/test_device/dex_mainlinejars_unstripped/android/system/framework/arm/boot-framework-foo.oat:/system/framework/arm/boot-framework-foo.oat -DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_mainline_arm64=out/soong/test_device/dex_mainlinejars_unstripped/android/system/framework/arm64/boot-framework-foo.oat:/system/framework/arm64/boot-framework-foo.oat -DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_mainline_host_x86=out/soong/test_device/dex_mainlinejars_unstripped/linux_glibc/system/framework/x86/boot-framework-foo.oat:/system/framework/x86/boot-framework-foo.oat -DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_mainline_host_x86_64=out/soong/test_device/dex_mainlinejars_unstripped/linux_glibc/system/framework/x86_64/boot-framework-foo.oat:/system/framework/x86_64/boot-framework-foo.oat -DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_art_arm=out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex:/apex/art_boot_images/javalib/arm/boot.vdex out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.vdex:/apex/art_boot_images/javalib/arm/boot-core2.vdex -DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_art_arm64=out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex:/apex/art_boot_images/javalib/arm64/boot.vdex out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex:/apex/art_boot_images/javalib/arm64/boot-core2.vdex -DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_art_host_x86=out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex:/apex/art_boot_images/javalib/x86/boot.vdex out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex:/apex/art_boot_images/javalib/x86/boot-core2.vdex -DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_art_host_x86_64=out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex:/apex/art_boot_images/javalib/x86_64/boot.vdex out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex:/apex/art_boot_images/javalib/x86_64/boot-core2.vdex -DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_arm=out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.vdex:/system/framework/arm/boot-framework.vdex -DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_arm64=out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.vdex:/system/framework/arm64/boot-framework.vdex -DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_host_x86=out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex:/system/framework/x86/boot-framework.vdex -DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_host_x86_64=out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex:/system/framework/x86_64/boot-framework.vdex -DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_mainline_arm=out/soong/test_device/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.vdex:/system/framework/arm/boot-framework-foo.vdex -DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_mainline_arm64=out/soong/test_device/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.vdex:/system/framework/arm64/boot-framework-foo.vdex -DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_mainline_host_x86=out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.vdex:/system/framework/x86/boot-framework-foo.vdex -DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_mainline_host_x86_64=out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.vdex:/system/framework/x86_64/boot-framework-foo.vdex -DEXPREOPT_IMAGE_ZIP_art=out/soong/test_device/dex_artjars/art.zip -DEXPREOPT_IMAGE_ZIP_boot=out/soong/test_device/dex_bootjars/boot.zip -DEXPREOPT_IMAGE_ZIP_mainline=out/soong/test_device/dex_mainlinejars/mainline.zip -DEXPREOPT_IMAGE_art_arm=out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art -DEXPREOPT_IMAGE_art_arm64=out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art -DEXPREOPT_IMAGE_art_host_x86=out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art -DEXPREOPT_IMAGE_art_host_x86_64=out/soong/test_device/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art -DEXPREOPT_IMAGE_boot_arm=out/soong/test_device/dex_bootjars/android/system/framework/arm/boot-framework.art -DEXPREOPT_IMAGE_boot_arm64=out/soong/test_device/dex_bootjars/android/system/framework/arm64/boot-framework.art -DEXPREOPT_IMAGE_boot_host_x86=out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art -DEXPREOPT_IMAGE_boot_host_x86_64=out/soong/test_device/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art -DEXPREOPT_IMAGE_mainline_arm=out/soong/test_device/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.art -DEXPREOPT_IMAGE_mainline_arm64=out/soong/test_device/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.art -DEXPREOPT_IMAGE_mainline_host_x86=out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.art -DEXPREOPT_IMAGE_mainline_host_x86_64=out/soong/test_device/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.art +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 +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_art_host_x86=out/soong/dexpreopt_arm64/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat:/apex/art_boot_images/javalib/x86/boot.oat out/soong/dexpreopt_arm64/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat:/apex/art_boot_images/javalib/x86/boot-core2.oat +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_art_host_x86_64=out/soong/dexpreopt_arm64/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat:/apex/art_boot_images/javalib/x86_64/boot.oat out/soong/dexpreopt_arm64/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat:/apex/art_boot_images/javalib/x86_64/boot-core2.oat +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm/boot-framework.oat:/system/framework/arm/boot-framework.oat +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-framework.oat:/system/framework/arm64/boot-framework.oat +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86/boot-framework.oat:/system/framework/x86/boot-framework.oat +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86_64/boot-framework.oat:/system/framework/x86_64/boot-framework.oat +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_mainline_arm=out/soong/dexpreopt_arm64/dex_mainlinejars_unstripped/android/system/framework/arm/boot-framework-foo.oat:/system/framework/arm/boot-framework-foo.oat +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_mainline_arm64=out/soong/dexpreopt_arm64/dex_mainlinejars_unstripped/android/system/framework/arm64/boot-framework-foo.oat:/system/framework/arm64/boot-framework-foo.oat +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_mainline_host_x86=out/soong/dexpreopt_arm64/dex_mainlinejars_unstripped/linux_glibc/system/framework/x86/boot-framework-foo.oat:/system/framework/x86/boot-framework-foo.oat +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_mainline_host_x86_64=out/soong/dexpreopt_arm64/dex_mainlinejars_unstripped/linux_glibc/system/framework/x86_64/boot-framework-foo.oat:/system/framework/x86_64/boot-framework-foo.oat +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_art_arm=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex:/apex/art_boot_images/javalib/arm/boot.vdex out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.vdex:/apex/art_boot_images/javalib/arm/boot-core2.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_art_arm64=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex:/apex/art_boot_images/javalib/arm64/boot.vdex out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex:/apex/art_boot_images/javalib/arm64/boot-core2.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_art_host_x86=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex:/apex/art_boot_images/javalib/x86/boot.vdex out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex:/apex/art_boot_images/javalib/x86/boot-core2.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_art_host_x86_64=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex:/apex/art_boot_images/javalib/x86_64/boot.vdex out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex:/apex/art_boot_images/javalib/x86_64/boot-core2.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.vdex:/system/framework/arm/boot-framework.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.vdex:/system/framework/arm64/boot-framework.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex:/system/framework/x86/boot-framework.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex:/system/framework/x86_64/boot-framework.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_mainline_arm=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.vdex:/system/framework/arm/boot-framework-foo.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_mainline_arm64=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.vdex:/system/framework/arm64/boot-framework-foo.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_mainline_host_x86=out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.vdex:/system/framework/x86/boot-framework-foo.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_mainline_host_x86_64=out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.vdex:/system/framework/x86_64/boot-framework-foo.vdex +DEXPREOPT_IMAGE_ZIP_art=out/soong/dexpreopt_arm64/dex_artjars/art.zip +DEXPREOPT_IMAGE_ZIP_boot=out/soong/dexpreopt_arm64/dex_bootjars/boot.zip +DEXPREOPT_IMAGE_ZIP_mainline=out/soong/dexpreopt_arm64/dex_mainlinejars/mainline.zip +DEXPREOPT_IMAGE_art_arm=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art +DEXPREOPT_IMAGE_art_arm64=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art +DEXPREOPT_IMAGE_art_host_x86=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art +DEXPREOPT_IMAGE_art_host_x86_64=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art +DEXPREOPT_IMAGE_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art +DEXPREOPT_IMAGE_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art +DEXPREOPT_IMAGE_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art +DEXPREOPT_IMAGE_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art +DEXPREOPT_IMAGE_mainline_arm=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.art +DEXPREOPT_IMAGE_mainline_arm64=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.art +DEXPREOPT_IMAGE_mainline_host_x86=out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.art +DEXPREOPT_IMAGE_mainline_host_x86_64=out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.art ` expected := strings.TrimSpace(fmt.Sprintf(format, expectedLicenseMetadataFile)) actual := strings.TrimSpace(out.String()) From c67528bf7e236d8789c356ba75f408e69561506e Mon Sep 17 00:00:00 2001 From: Jiakai Zhang Date: Thu, 11 May 2023 16:39:27 +0100 Subject: [PATCH 146/172] Prepare tests for dexpreopt changes. After this change, there is a clear separation between tests that are related to dexpreopt and tests that are not. The former uses PrepareForTestWithDexpreopt, while the latter uses PrepareForTestWithJavaDefaultModules. The benefit is that the latter will no longer affected by any dexpreopt changes. Bug: 280776428 Test: m nothing (cherry picked from https://android-review.googlesource.com/q/commit:b95998be731406209f18fab764b96421a17ab4c9) Merged-In: Ib957765b9287d51c082e0a33cee17a6bb56daeef Change-Id: Ib957765b9287d51c082e0a33cee17a6bb56daeef --- apex/Android.bp | 1 + apex/apex_test.go | 2 +- apex/bootclasspath_fragment_test.go | 2 +- {java => apex}/dexpreopt_bootjars_test.go | 11 ++++++----- apex/metadata_test.go | 2 +- apex/platform_bootclasspath_test.go | 8 ++++---- java/Android.bp | 1 - java/dexpreopt_test.go | 8 ++++---- java/hiddenapi_singleton_test.go | 4 +++- java/java_test.go | 3 +-- java/platform_bootclasspath_test.go | 2 -- java/testing.go | 18 ++++++++++++------ sdk/bootclasspath_fragment_sdk_test.go | 2 +- 13 files changed, 35 insertions(+), 29 deletions(-) rename {java => apex}/dexpreopt_bootjars_test.go (94%) diff --git a/apex/Android.bp b/apex/Android.bp index 7ffca0ea5..61d7fb2e2 100644 --- a/apex/Android.bp +++ b/apex/Android.bp @@ -38,6 +38,7 @@ bootstrap_go_package { "apex_test.go", "bootclasspath_fragment_test.go", "classpath_element_test.go", + "dexpreopt_bootjars_test.go", "metadata_test.go", "platform_bootclasspath_test.go", "systemserver_classpath_fragment_test.go", diff --git a/apex/apex_test.go b/apex/apex_test.go index 5a96b8e7b..9e0757708 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -146,7 +146,7 @@ var prepareForApexTest = android.GroupFixturePreparers( android.PrepareForTestWithAndroidBuildComponents, bpf.PrepareForTestWithBpf, cc.PrepareForTestWithCcBuildComponents, - java.PrepareForTestWithJavaDefaultModules, + java.PrepareForTestWithDexpreopt, prebuilt_etc.PrepareForTestWithPrebuiltEtc, rust.PrepareForTestWithRustDefaultModules, sh.PrepareForTestWithShBuildComponents, diff --git a/apex/bootclasspath_fragment_test.go b/apex/bootclasspath_fragment_test.go index 3e55ccc11..0a72116a6 100644 --- a/apex/bootclasspath_fragment_test.go +++ b/apex/bootclasspath_fragment_test.go @@ -1250,7 +1250,7 @@ func TestBootclasspathFragment_AndroidNonUpdatable(t *testing.T) { func TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks(t *testing.T) { result := android.GroupFixturePreparers( prepareForTestWithBootclasspathFragment, - java.PrepareForTestWithJavaDefaultModules, + java.PrepareForTestWithDexpreopt, prepareForTestWithArtApex, prepareForTestWithMyapex, // Configure bootclasspath jars to ensure that hidden API encoding is performed on them. diff --git a/java/dexpreopt_bootjars_test.go b/apex/dexpreopt_bootjars_test.go similarity index 94% rename from java/dexpreopt_bootjars_test.go rename to apex/dexpreopt_bootjars_test.go index 908380813..ef66807f0 100644 --- a/java/dexpreopt_bootjars_test.go +++ b/apex/dexpreopt_bootjars_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package java +package apex import ( "path/filepath" @@ -20,6 +20,7 @@ import ( "testing" "android/soong/android" + "android/soong/java" ) func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOutputs []string) { @@ -48,10 +49,10 @@ func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOu ` result := android.GroupFixturePreparers( - prepareForJavaTest, - PrepareForTestWithJavaSdkLibraryFiles, - FixtureWithLastReleaseApis("foo"), - FixtureConfigureBootJars("platform:foo", "system_ext:bar", "platform:baz"), + java.PrepareForTestWithDexpreopt, + java.PrepareForTestWithJavaSdkLibraryFiles, + java.FixtureWithLastReleaseApis("foo"), + java.FixtureConfigureBootJars("platform:foo", "system_ext:bar", "platform:baz"), ).RunTestWithBp(t, bp) platformBootclasspath := result.ModuleForTests("platform-bootclasspath", "android_common") diff --git a/apex/metadata_test.go b/apex/metadata_test.go index f6ead424e..fed5beae7 100644 --- a/apex/metadata_test.go +++ b/apex/metadata_test.go @@ -27,7 +27,7 @@ import ( func TestModulesSingleton(t *testing.T) { result := android.GroupFixturePreparers( PrepareForTestWithApexMultitreeSingleton, - java.PrepareForTestWithDexpreopt, + java.PrepareForTestWithJavaDefaultModules, PrepareForTestWithApexBuildComponents, java.FixtureConfigureApexBootJars("myapex:foo"), java.PrepareForTestWithJavaSdkLibraryFiles, diff --git a/apex/platform_bootclasspath_test.go b/apex/platform_bootclasspath_test.go index 4b48da8e2..05bb13689 100644 --- a/apex/platform_bootclasspath_test.go +++ b/apex/platform_bootclasspath_test.go @@ -20,6 +20,7 @@ import ( "testing" "android/soong/android" + "android/soong/dexpreopt" "android/soong/java" "github.com/google/blueprint" @@ -30,7 +31,7 @@ import ( // apexes. var prepareForTestWithPlatformBootclasspath = android.GroupFixturePreparers( - java.PrepareForTestWithDexpreopt, + java.PrepareForTestWithJavaDefaultModules, PrepareForTestWithApexBuildComponents, ) @@ -249,6 +250,8 @@ func TestPlatformBootclasspathDependencies(t *testing.T) { java.FixtureConfigureApexBootJars("myapex:bar"), java.PrepareForTestWithJavaSdkLibraryFiles, java.FixtureWithLastReleaseApis("foo"), + java.PrepareForTestWithDexpreopt, + dexpreopt.FixtureDisableDexpreoptBootImages(false), ).RunTestWithBp(t, ` apex { name: "com.android.art", @@ -539,9 +542,6 @@ func TestPlatformBootclasspath_AlwaysUsePrebuiltSdks(t *testing.T) { // Not a prebuilt as no prebuilt existed when it was added. "platform:legacy.core.platform.api.stubs", - // Needed for generating the boot image. - "platform:dex2oatd", - // The platform_bootclasspath intentionally adds dependencies on both source and prebuilt // modules when available as it does not know which one will be preferred. "myapex:foo", diff --git a/java/Android.bp b/java/Android.bp index 27a0a3853..4af2a14eb 100644 --- a/java/Android.bp +++ b/java/Android.bp @@ -87,7 +87,6 @@ bootstrap_go_package { "device_host_converter_test.go", "dex_test.go", "dexpreopt_test.go", - "dexpreopt_bootjars_test.go", "dexpreopt_config_test.go", "droiddoc_test.go", "droidstubs_test.go", diff --git a/java/dexpreopt_test.go b/java/dexpreopt_test.go index f91ac5cc3..fedd5640e 100644 --- a/java/dexpreopt_test.go +++ b/java/dexpreopt_test.go @@ -212,7 +212,7 @@ func TestDexpreoptEnabled(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { preparers := android.GroupFixturePreparers( - PrepareForTestWithJavaDefaultModules, + PrepareForTestWithDexpreopt, PrepareForTestWithFakeApexMutator, dexpreopt.FixtureSetApexSystemServerJars("com.android.apex1:service-foo"), ) @@ -257,7 +257,7 @@ func TestDex2oatToolDeps(t *testing.T) { preparers := android.GroupFixturePreparers( cc.PrepareForTestWithCcDefaultModules, - PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd, + PrepareForTestWithDexpreoptWithoutFakeDex2oatd, dexpreopt.PrepareForTestByEnablingDexpreopt) testDex2oatToolDep := func(sourceEnabled, prebuiltEnabled, prebuiltPreferred bool, @@ -299,7 +299,7 @@ func TestDex2oatToolDeps(t *testing.T) { func TestDexpreoptBuiltInstalledForApex(t *testing.T) { preparers := android.GroupFixturePreparers( - PrepareForTestWithJavaDefaultModules, + PrepareForTestWithDexpreopt, PrepareForTestWithFakeApexMutator, dexpreopt.FixtureSetApexSystemServerJars("com.android.apex1:service-foo"), ) @@ -386,7 +386,7 @@ func verifyEntries(t *testing.T, message string, expectedModule string, func TestAndroidMkEntriesForApex(t *testing.T) { preparers := android.GroupFixturePreparers( - PrepareForTestWithJavaDefaultModules, + PrepareForTestWithDexpreopt, PrepareForTestWithFakeApexMutator, dexpreopt.FixtureSetApexSystemServerJars("com.android.apex1:service-foo"), ) diff --git a/java/hiddenapi_singleton_test.go b/java/hiddenapi_singleton_test.go index 75b7bb7c8..ef792f970 100644 --- a/java/hiddenapi_singleton_test.go +++ b/java/hiddenapi_singleton_test.go @@ -39,7 +39,9 @@ var prepareForTestWithDefaultPlatformBootclasspath = android.FixtureAddTextFile( `) var hiddenApiFixtureFactory = android.GroupFixturePreparers( - prepareForJavaTest, PrepareForTestWithHiddenApiBuildComponents) + PrepareForTestWithJavaDefaultModules, + PrepareForTestWithHiddenApiBuildComponents, +) func TestHiddenAPISingleton(t *testing.T) { result := android.GroupFixturePreparers( diff --git a/java/java_test.go b/java/java_test.go index 553b762ee..2a4913ecd 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -46,12 +46,11 @@ var prepareForJavaTest = android.GroupFixturePreparers( // Get the CC build components but not default modules. cc.PrepareForTestWithCcBuildComponents, // Include all the default java modules. - PrepareForTestWithJavaDefaultModules, + PrepareForTestWithDexpreopt, PrepareForTestWithOverlayBuildComponents, android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { ctx.RegisterPreSingletonType("sdk_versions", sdkPreSingletonFactory) }), - PrepareForTestWithDexpreopt, ) func TestMain(m *testing.M) { diff --git a/java/platform_bootclasspath_test.go b/java/platform_bootclasspath_test.go index 10c918715..ff2da4bb2 100644 --- a/java/platform_bootclasspath_test.go +++ b/java/platform_bootclasspath_test.go @@ -18,14 +18,12 @@ import ( "testing" "android/soong/android" - "android/soong/dexpreopt" ) // Contains some simple tests for platform_bootclasspath. var prepareForTestWithPlatformBootclasspath = android.GroupFixturePreparers( PrepareForTestWithJavaDefaultModules, - dexpreopt.PrepareForTestByEnablingDexpreopt, ) func TestPlatformBootclasspath(t *testing.T) { diff --git a/java/testing.go b/java/testing.go index f68e12ff4..4ff2aa497 100644 --- a/java/testing.go +++ b/java/testing.go @@ -80,9 +80,7 @@ var prepareForTestWithFrameworkDeps = android.GroupFixturePreparers( }.AddToFixture(), ) -// Test fixture preparer that will define all default java modules except the -// fake_tool_binary for dex2oatd. -var PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd = android.GroupFixturePreparers( +var prepareForTestWithJavaDefaultModulesBase = android.GroupFixturePreparers( // Make sure that all the module types used in the defaults are registered. PrepareForTestWithJavaBuildComponents, prepareForTestWithFrameworkDeps, @@ -92,13 +90,21 @@ var PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd = android.GroupFixtu // Test fixture preparer that will define default java modules, e.g. standard prebuilt modules. var PrepareForTestWithJavaDefaultModules = android.GroupFixturePreparers( - PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd, - dexpreopt.PrepareForTestWithFakeDex2oatd, + prepareForTestWithJavaDefaultModulesBase, + dexpreopt.FixtureDisableDexpreoptBootImages(true), + dexpreopt.FixtureDisableDexpreopt(true), ) // Provides everything needed by dexpreopt. var PrepareForTestWithDexpreopt = android.GroupFixturePreparers( - PrepareForTestWithJavaDefaultModules, + prepareForTestWithJavaDefaultModulesBase, + dexpreopt.PrepareForTestWithFakeDex2oatd, + dexpreopt.PrepareForTestByEnablingDexpreopt, +) + +// Provides everything needed by dexpreopt except the fake_tool_binary for dex2oatd. +var PrepareForTestWithDexpreoptWithoutFakeDex2oatd = android.GroupFixturePreparers( + prepareForTestWithJavaDefaultModulesBase, dexpreopt.PrepareForTestByEnablingDexpreopt, ) diff --git a/sdk/bootclasspath_fragment_sdk_test.go b/sdk/bootclasspath_fragment_sdk_test.go index 0d6496dd3..bef82d601 100644 --- a/sdk/bootclasspath_fragment_sdk_test.go +++ b/sdk/bootclasspath_fragment_sdk_test.go @@ -74,7 +74,7 @@ func fixtureAddPrebuiltApexForBootclasspathFragment(apex, fragment string) andro func TestSnapshotWithBootclasspathFragment_ImageName(t *testing.T) { result := android.GroupFixturePreparers( prepareForSdkTestWithJava, - java.PrepareForTestWithJavaDefaultModules, + java.PrepareForTestWithDexpreopt, prepareForSdkTestWithApex, // Some additional files needed for the art apex. From 4e9eb1ae46ea2d5914a616454f0a92579cdc85f2 Mon Sep 17 00:00:00 2001 From: Jiakai Zhang Date: Wed, 10 May 2023 16:40:18 +0100 Subject: [PATCH 147/172] Remove the ability to install boot images by bootclasspath_fragments. We don't need this anymore because we are going to compile ART jars and framework jars together. Bug: 280776428 Test: m (cherry picked from https://android-review.googlesource.com/q/commit:b47caccbc037b65462f757c462a99732ad6dd51c) Merged-In: I070157530449a1bb5779e25984c367df3dde7b36 Change-Id: I070157530449a1bb5779e25984c367df3dde7b36 --- apex/apex.go | 18 +--- apex/bootclasspath_fragment_test.go | 161 +--------------------------- apex/prebuilt.go | 5 +- java/bootclasspath_fragment.go | 132 ++--------------------- java/dexpreopt_bootjars.go | 24 ++--- 5 files changed, 17 insertions(+), 323 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index d2c535c5e..7fb6f504e 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -2276,16 +2276,13 @@ func (a *apexBundle) depVisitor(vctx *visitorContext, ctx android.ModuleContext, ctx.PropertyErrorf("sh_binaries", "%q is not a sh_binary module", depName) } case bcpfTag: - bcpfModule, ok := child.(*java.BootclasspathFragmentModule) + _, ok := child.(*java.BootclasspathFragmentModule) if !ok { ctx.PropertyErrorf("bootclasspath_fragments", "%q is not a bootclasspath_fragment module", depName) return false } vctx.filesInfo = append(vctx.filesInfo, apexBootclasspathFragmentFiles(ctx, child)...) - for _, makeModuleName := range bcpfModule.BootImageDeviceInstallMakeModules() { - a.makeModulesToInstall = append(a.makeModulesToInstall, makeModuleName) - } return true case sscpfTag: if _, ok := child.(*java.SystemServerClasspathModule); !ok { @@ -2651,19 +2648,6 @@ func apexBootclasspathFragmentFiles(ctx android.ModuleContext, module blueprint. bootclasspathFragmentInfo := ctx.OtherModuleProvider(module, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo) var filesToAdd []apexFile - // Add the boot image files, e.g. .art, .oat and .vdex files. - if bootclasspathFragmentInfo.ShouldInstallBootImageInApex() { - for arch, files := range bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() { - dirInApex := filepath.Join("javalib", arch.String()) - for _, f := range files { - androidMkModuleName := "javalib_" + arch.String() + "_" + filepath.Base(f.String()) - // TODO(b/177892522) - consider passing in the bootclasspath fragment module here instead of nil - af := newApexFile(ctx, f, androidMkModuleName, dirInApex, etc, nil) - filesToAdd = append(filesToAdd, af) - } - } - } - // Add classpaths.proto config. if af := apexClasspathFragmentProtoFile(ctx, module); af != nil { filesToAdd = append(filesToAdd, *af) diff --git a/apex/bootclasspath_fragment_test.go b/apex/bootclasspath_fragment_test.go index 0a72116a6..1b5288696 100644 --- a/apex/bootclasspath_fragment_test.go +++ b/apex/bootclasspath_fragment_test.go @@ -115,20 +115,7 @@ func TestBootclasspathFragments(t *testing.T) { // 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", ` -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.art -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.oat -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.vdex -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.art -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.oat -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.vdex -`) + "com.android.art:baz,com.android.art:quuz") } func TestBootclasspathFragments_FragmentDependency(t *testing.T) { @@ -261,7 +248,7 @@ func TestBootclasspathFragments_FragmentDependency(t *testing.T) { checkAPIScopeStubs("other", otherInfo, java.CorePlatformHiddenAPIScope) } -func checkBootclasspathFragment(t *testing.T, result *android.TestResult, moduleName, variantName string, expectedConfiguredModules string, expectedBootclasspathFragmentFiles string) { +func checkBootclasspathFragment(t *testing.T, result *android.TestResult, moduleName, variantName string, expectedConfiguredModules string) { t.Helper() bootclasspathFragment := result.ModuleForTests(moduleName, variantName).Module().(*java.BootclasspathFragmentModule) @@ -269,19 +256,6 @@ func checkBootclasspathFragment(t *testing.T, result *android.TestResult, module bootclasspathFragmentInfo := result.ModuleProvider(bootclasspathFragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo) modules := bootclasspathFragmentInfo.Modules() android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String()) - - // Get a list of all the paths in the boot image sorted by arch type. - allPaths := []string{} - bootImageFilesByArchType := bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() - for _, archType := range android.ArchTypeList() { - if paths, ok := bootImageFilesByArchType[archType]; ok { - for _, path := range paths { - allPaths = append(allPaths, android.NormalizePathForTesting(path)) - } - } - } - - android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootclasspathFragmentFiles, strings.Join(allPaths, "\n")) } func TestBootclasspathFragmentInArtApex(t *testing.T) { @@ -420,18 +394,6 @@ func TestBootclasspathFragmentInArtApex(t *testing.T) { ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ "etc/boot-image.prof", "etc/classpaths/bootclasspath.pb", - "javalib/arm/boot.art", - "javalib/arm/boot.oat", - "javalib/arm/boot.vdex", - "javalib/arm/boot-bar.art", - "javalib/arm/boot-bar.oat", - "javalib/arm/boot-bar.vdex", - "javalib/arm64/boot.art", - "javalib/arm64/boot.oat", - "javalib/arm64/boot.vdex", - "javalib/arm64/boot-bar.art", - "javalib/arm64/boot-bar.oat", - "javalib/arm64/boot-bar.vdex", "javalib/bar.jar", "javalib/foo.jar", }) @@ -441,62 +403,12 @@ func TestBootclasspathFragmentInArtApex(t *testing.T) { `mybootclasspathfragment`, }) - // The boot images are installed in the APEX by Soong, so there shouldn't be any dexpreopt-related Make modules. - ensureDoesNotContainRequiredDeps(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ - "mybootclasspathfragment-dexpreopt-arm64-boot.art", - "mybootclasspathfragment-dexpreopt-arm64-boot.oat", - "mybootclasspathfragment-dexpreopt-arm64-boot.vdex", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.art", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.oat", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.vdex", - "mybootclasspathfragment-dexpreopt-arm-boot.art", - "mybootclasspathfragment-dexpreopt-arm-boot.oat", - "mybootclasspathfragment-dexpreopt-arm-boot.vdex", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.art", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.oat", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.vdex", - }) - // 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("boot image files from source no boot image in apex", 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"), - ).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", - }) - - ensureContainsRequiredDeps(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ - "mybootclasspathfragment-dexpreopt-arm64-boot.art", - "mybootclasspathfragment-dexpreopt-arm64-boot.oat", - "mybootclasspathfragment-dexpreopt-arm64-boot.vdex", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.art", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.oat", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.vdex", - "mybootclasspathfragment-dexpreopt-arm-boot.art", - "mybootclasspathfragment-dexpreopt-arm-boot.oat", - "mybootclasspathfragment-dexpreopt-arm-boot.vdex", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.art", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.oat", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.vdex", - }) - }) - t.Run("generate boot image profile even if dexpreopt is disabled", func(t *testing.T) { result := android.GroupFixturePreparers( commonPreparer, @@ -552,18 +464,6 @@ func TestBootclasspathFragmentInArtApex(t *testing.T) { ensureExactDeapexedContents(t, result.TestContext, "com.android.art", "android_common", []string{ "etc/boot-image.prof", - "javalib/arm/boot.art", - "javalib/arm/boot.oat", - "javalib/arm/boot.vdex", - "javalib/arm/boot-bar.art", - "javalib/arm/boot-bar.oat", - "javalib/arm/boot-bar.vdex", - "javalib/arm64/boot.art", - "javalib/arm64/boot.oat", - "javalib/arm64/boot.vdex", - "javalib/arm64/boot-bar.art", - "javalib/arm64/boot-bar.oat", - "javalib/arm64/boot-bar.vdex", "javalib/bar.jar", "javalib/foo.jar", }) @@ -574,65 +474,12 @@ func TestBootclasspathFragmentInArtApex(t *testing.T) { `prebuilt_com.android.art`, }) - // The boot images are installed in the APEX by Soong, so there shouldn't be any dexpreopt-related Make modules. - ensureDoesNotContainRequiredDeps(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ - "mybootclasspathfragment-dexpreopt-arm64-boot.art", - "mybootclasspathfragment-dexpreopt-arm64-boot.oat", - "mybootclasspathfragment-dexpreopt-arm64-boot.vdex", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.art", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.oat", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.vdex", - "mybootclasspathfragment-dexpreopt-arm-boot.art", - "mybootclasspathfragment-dexpreopt-arm-boot.oat", - "mybootclasspathfragment-dexpreopt-arm-boot.vdex", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.art", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.oat", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.vdex", - }) - // 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("boot image files from preferred prebuilt no boot image in apex", 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", "system/framework"), - ).RunTest(t) - - ensureExactDeapexedContents(t, result.TestContext, "com.android.art", "android_common", []string{ - "etc/boot-image.prof", - "javalib/bar.jar", - "javalib/foo.jar", - }) - - ensureContainsRequiredDeps(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ - "mybootclasspathfragment-dexpreopt-arm64-boot.art", - "mybootclasspathfragment-dexpreopt-arm64-boot.oat", - "mybootclasspathfragment-dexpreopt-arm64-boot.vdex", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.art", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.oat", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.vdex", - "mybootclasspathfragment-dexpreopt-arm-boot.art", - "mybootclasspathfragment-dexpreopt-arm-boot.oat", - "mybootclasspathfragment-dexpreopt-arm-boot.vdex", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.art", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.oat", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.vdex", - }) - }) - t.Run("source with inconsistency between config and contents", func(t *testing.T) { android.GroupFixturePreparers( commonPreparer, @@ -782,10 +629,6 @@ func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) { module := result.ModuleForTests("mybootclasspathfragment", "android_common_com.android.art") checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo") - - // Check that the right deapexer module was chosen for a boot image. - param := module.Output("out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art") - android.AssertStringDoesContain(t, "didn't find the expected deapexer in the input path", param.Input.String(), "/com.android.art.deapexer") }) t.Run("enabled alternative APEX", func(t *testing.T) { diff --git a/apex/prebuilt.go b/apex/prebuilt.go index 31cecf111..0d83830f1 100644 --- a/apex/prebuilt.go +++ b/apex/prebuilt.go @@ -199,14 +199,11 @@ func (p *prebuiltCommon) initApexFilesForAndroidMk(ctx android.ModuleContext) { p.apexFilesForAndroidMk = append(p.apexFilesForAndroidMk, af) } } else if tag == exportedBootclasspathFragmentTag { - bcpfModule, ok := child.(*java.PrebuiltBootclasspathFragmentModule) + _, ok := child.(*java.PrebuiltBootclasspathFragmentModule) if !ok { ctx.PropertyErrorf("exported_bootclasspath_fragments", "%q is not a prebuilt_bootclasspath_fragment module", name) return false } - for _, makeModuleName := range bcpfModule.BootImageDeviceInstallMakeModules() { - p.requiredModuleNames = append(p.requiredModuleNames, makeModuleName) - } // Visit the children of the bootclasspath_fragment. return true } else if tag == exportedSystemserverclasspathFragmentTag { diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index 6ccf5a331..f45165943 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -240,11 +240,6 @@ type BootclasspathFragmentModule struct { // Collect the module directory for IDE info in java/jdeps.go. modulePaths []string - - // Installs for on-device boot image files. This list has entries only if the installs should be - // handled by Make (e.g., the boot image should be installed on the system partition, rather than - // in the APEX). - bootImageDeviceInstalls []dexpreopterInstall } // commonBootclasspathFragment defines the methods that are implemented by both source and prebuilt @@ -268,12 +263,6 @@ type commonBootclasspathFragment interface { var _ commonBootclasspathFragment = (*BootclasspathFragmentModule)(nil) -// bootImageFilesByArch is a map from android.ArchType to the paths to the boot image files. -// -// The paths include the .art, .oat and .vdex files, one for each of the modules from which the boot -// image is created. -type bootImageFilesByArch map[android.ArchType]android.Paths - func bootclasspathFragmentFactory() android.Module { m := &BootclasspathFragmentModule{} m.AddProperties(&m.properties, &m.sourceOnlyProperties) @@ -395,12 +384,6 @@ type BootclasspathFragmentApexContentInfo struct { // set image_name: "art". modules android.ConfiguredJarList - // Map from arch type to the boot image files. - bootImageFilesByArch bootImageFilesByArch - - // True if the boot image should be installed in the APEX. - shouldInstallBootImageInApex bool - // 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 @@ -417,18 +400,6 @@ func (i BootclasspathFragmentApexContentInfo) Modules() android.ConfiguredJarLis return i.modules } -// Get a map from ArchType to the associated boot image's contents for Android. -// -// Extension boot images only return their own files, not the files of the boot images they extend. -func (i BootclasspathFragmentApexContentInfo) AndroidBootImageFilesByArchType() bootImageFilesByArch { - return i.bootImageFilesByArch -} - -// Return true if the boot image should be installed in the APEX. -func (i *BootclasspathFragmentApexContentInfo) ShouldInstallBootImageInApex() bool { - return i.shouldInstallBootImageInApex -} - // 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. @@ -566,25 +537,6 @@ func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.Mo // Copy the dex jars of this fragment's content modules to their predefined locations. copyBootJarsToPredefinedLocations(ctx, hiddenAPIOutput.EncodedBootDexFilesByModule, imageConfig.dexPathsByModule) } - - for _, variant := range bootImageFiles.variants { - archType := variant.config.target.Arch.ArchType - arch := archType.String() - for _, install := range variant.deviceInstalls { - // Remove the "/" prefix because the path should be relative to $ANDROID_PRODUCT_OUT. - installDir := strings.TrimPrefix(filepath.Dir(install.To), "/") - installBase := filepath.Base(install.To) - installPath := android.PathForModuleInPartitionInstall(ctx, "", installDir) - - b.bootImageDeviceInstalls = append(b.bootImageDeviceInstalls, dexpreopterInstall{ - name: arch + "-" + installBase, - moduleName: b.Name(), - outputPathOnHost: install.From, - installDirOnDevice: installPath, - installFileOnDevice: installBase, - }) - } - } } // A prebuilt fragment cannot contribute to an apex. @@ -643,12 +595,8 @@ func (b *BootclasspathFragmentModule) provideApexContentInfo(ctx android.ModuleC info.profilePathOnHost = bootImageFiles.profile info.profileInstallPathInApex = imageConfig.profileInstallPathInApex } - - info.shouldInstallBootImageInApex = imageConfig.shouldInstallInApex() } - info.bootImageFilesByArch = bootImageFiles.byArch - // Make the apex content info available for other modules. ctx.SetProvider(BootclasspathFragmentApexContentInfoProvider, info) } @@ -960,21 +908,9 @@ func (b *BootclasspathFragmentModule) AndroidMkEntries() []android.AndroidMkEntr }, }, }} - for _, install := range b.bootImageDeviceInstalls { - entriesList = append(entriesList, install.ToMakeEntries()) - } return entriesList } -// Returns the names of all Make modules that handle the installation of the boot image. -func (b *BootclasspathFragmentModule) BootImageDeviceInstallMakeModules() []string { - var makeModules []string - for _, install := range b.bootImageDeviceInstalls { - makeModules = append(makeModules, install.FullModuleName()) - } - return makeModules -} - // Collect information for opening IDE project files in java/jdeps.go. func (b *BootclasspathFragmentModule) IDEInfo(dpInfo *android.IdeInfo) { dpInfo.Deps = append(dpInfo.Deps, b.properties.Contents...) @@ -1262,59 +1198,17 @@ func (module *PrebuiltBootclasspathFragmentModule) produceBootImageFiles(ctx and // built without a profile as the prebuilt modules do not provide a profile. buildBootImageVariantsForBuildOs(ctx, imageConfig, profile) - if imageConfig.shouldInstallInApex() { - // If the boot image files for the android variants are in the prebuilt apex, we must use those - // rather than building new ones because those boot image files are going to be used on device. - files := bootImageFilesByArch{} - bootImageFiles := bootImageOutputs{ - byArch: files, - profile: profile, - } - for _, variant := range imageConfig.apexVariants() { - arch := variant.target.Arch.ArchType - bootImageFiles.variants = append(bootImageFiles.variants, bootImageVariantOutputs{ - variant, - // No device installs needed when installed in APEX. - nil, - }) - for _, toPath := range variant.imagesDeps { - apexRelativePath := apexRootRelativePathToBootImageFile(arch, toPath.Base()) - // Get the path to the file that the deapexer extracted from the prebuilt apex file. - fromPath := di.PrebuiltExportPath(apexRelativePath) - - // Return the toPath as the calling code expects the paths in the returned map to be the - // paths predefined in the bootImageConfig. - files[arch] = append(files[arch], toPath) - - // Copy the file to the predefined location. - ctx.Build(pctx, android.BuildParams{ - Rule: android.Cp, - Input: fromPath, - Output: toPath, - }) - } - } - return bootImageFiles - } else { - if profile == nil && imageConfig.isProfileGuided() { - ctx.ModuleErrorf("Unable to produce boot image files: neither boot image files nor profiles exists in the prebuilt apex") - return bootImageOutputs{} - } - // Build boot image files for the android variants from the dex files provided by the contents - // of this module. - return buildBootImageVariantsForAndroidOs(ctx, imageConfig, profile) + if profile == nil && imageConfig.isProfileGuided() { + ctx.ModuleErrorf("Unable to produce boot image files: profiles not found in the prebuilt apex") + return bootImageOutputs{} } + // Build boot image files for the android variants from the dex files provided by the contents + // of this module. + return buildBootImageVariantsForAndroidOs(ctx, imageConfig, profile) } var _ commonBootclasspathFragment = (*PrebuiltBootclasspathFragmentModule)(nil) -// createBootImageTag creates the tag to uniquely identify the boot image file among all of the -// files that a module requires from the prebuilt .apex file. -func createBootImageTag(arch android.ArchType, baseName string) string { - tag := fmt.Sprintf(".bootimage-%s-%s", arch, baseName) - return tag -} - // RequiredFilesFromPrebuiltApex returns the list of all files the prebuilt_bootclasspath_fragment // requires from a prebuilt .apex file. // @@ -1328,25 +1222,11 @@ func (module *PrebuiltBootclasspathFragmentModule) RequiredFilesFromPrebuiltApex // Add the boot image profile. files = append(files, imageConfig.profileInstallPathInApex) } - if imageConfig.shouldInstallInApex() { - // Add the boot image files, e.g. .art, .oat and .vdex files. - for _, variant := range imageConfig.apexVariants() { - arch := variant.target.Arch.ArchType - for _, path := range variant.imagesDeps.Paths() { - base := path.Base() - files = append(files, apexRootRelativePathToBootImageFile(arch, base)) - } - } - } return files } return nil } -func apexRootRelativePathToBootImageFile(arch android.ArchType, base string) string { - return filepath.Join("javalib", arch.String(), base) -} - var _ android.RequiredFilesFromPrebuiltApex = (*PrebuiltBootclasspathFragmentModule)(nil) func prebuiltBootclasspathFragmentFactory() android.Module { diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go index 8e79674fb..7b5c294a0 100644 --- a/java/dexpreopt_bootjars.go +++ b/java/dexpreopt_bootjars.go @@ -421,11 +421,6 @@ func (image *bootImageConfig) apexVariants() []*bootImageVariant { return variants } -// Returns true if the boot image should be installed in the APEX. -func (image *bootImageConfig) shouldInstallInApex() bool { - return strings.HasPrefix(image.installDirOnDevice, "apex/") -} - // Return boot image locations (as a list of symbolic paths). // // The image "location" is a symbolic path that, with multiarchitecture support, doesn't really @@ -596,6 +591,12 @@ func buildBootImageVariantsForBuildOs(ctx android.ModuleContext, image *bootImag buildBootImageForOsType(ctx, image, profile, ctx.Config().BuildOS) } +// bootImageFilesByArch is a map from android.ArchType to the paths to the boot image files. +// +// The paths include the .art, .oat and .vdex files, one for each of the modules from which the boot +// image is created. +type bootImageFilesByArch map[android.ArchType]android.Paths + // bootImageOutputs encapsulates information about boot images that were created/obtained by // commonBootclasspathFragment.produceBootImageFiles. type bootImageOutputs struct { @@ -656,8 +657,7 @@ func buildBootImageZipInPredefinedLocation(ctx android.ModuleContext, image *boo } type bootImageVariantOutputs struct { - config *bootImageVariant - deviceInstalls android.RuleBuilderInstalls + config *bootImageVariant } // Generate boot image build rules for a specific target. @@ -800,7 +800,6 @@ func buildBootImageVariant(ctx android.ModuleContext, image *bootImageVariant, p var vdexInstalls android.RuleBuilderInstalls var unstrippedInstalls android.RuleBuilderInstalls - var deviceInstalls android.RuleBuilderInstalls for _, artOrOat := range image.moduleFiles(ctx, outputDir, ".art", ".oat") { cmd.ImplicitOutput(artOrOat) @@ -826,14 +825,6 @@ func buildBootImageVariant(ctx android.ModuleContext, image *bootImageVariant, p android.RuleBuilderInstall{unstrippedOat, filepath.Join(installDir, unstrippedOat.Base())}) } - if image.installDirOnHost != image.installDirOnDevice && !image.shouldInstallInApex() && !ctx.Config().UnbundledBuild() { - installDirOnDevice := filepath.Join("/", image.installDirOnDevice, arch.String()) - for _, file := range image.moduleFiles(ctx, outputDir, ".art", ".oat", ".vdex") { - deviceInstalls = append(deviceInstalls, - android.RuleBuilderInstall{file, filepath.Join(installDirOnDevice, file.Base())}) - } - } - rule.Build(image.name+"JarsDexpreopt_"+image.target.String(), "dexpreopt "+image.name+" jars "+arch.String()) // save output and installed files for makevars @@ -849,7 +840,6 @@ func buildBootImageVariant(ctx android.ModuleContext, image *bootImageVariant, p return bootImageVariantOutputs{ image, - deviceInstalls, } } From 7ba1ca0ac3f08cfda1d5455ed194123ac654bf03 Mon Sep 17 00:00:00 2001 From: Jiakai Zhang Date: Wed, 10 May 2023 17:04:53 +0100 Subject: [PATCH 148/172] Unify installDirOnHost and installDirOnDevice. These two fields never do what they are described to do. This CL unifies them to avoid the confusion. Bug: 280440941 Test: m (cherry picked from https://android-review.googlesource.com/q/commit:09d88df0407263e846b01c226184b262f2e36678) Merged-In: I3652d73a50832a2e494d9f5cae750f5fc38293b4 Change-Id: I3652d73a50832a2e494d9f5cae750f5fc38293b4 --- java/dexpreopt_bootjars.go | 17 +++++++++-------- java/dexpreopt_config.go | 25 +++++++++++-------------- java/dexpreopt_config_testing.go | 29 ++++++++++++----------------- java/testing.go | 4 ++-- 4 files changed, 34 insertions(+), 41 deletions(-) diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go index 7b5c294a0..792fa6396 100644 --- a/java/dexpreopt_bootjars.go +++ b/java/dexpreopt_bootjars.go @@ -250,11 +250,12 @@ type bootImageConfig struct { // Output directory for the image files with debug symbols. symbolsDir android.OutputPath - // Subdirectory where the image files are installed. - installDirOnHost string - - // Subdirectory where the image files on device are installed. - installDirOnDevice string + // The relative location where the image files are installed. On host, the location is relative to + // $ANDROID_PRODUCT_OUT. + // + // Only the configs that are built by platform_bootclasspath are installable on device. On device, + // the location is relative to "/". + installDir string // Install path of the boot image profile if it needs to be installed in the APEX, or empty if not // needed. @@ -668,9 +669,9 @@ func buildBootImageVariant(ctx android.ModuleContext, image *bootImageVariant, p arch := image.target.Arch.ArchType os := image.target.Os.String() // We need to distinguish host-x86 and device-x86. - symbolsDir := image.symbolsDir.Join(ctx, os, image.installDirOnHost, arch.String()) + symbolsDir := image.symbolsDir.Join(ctx, os, image.installDir, arch.String()) symbolsFile := symbolsDir.Join(ctx, image.stem+".oat") - outputDir := image.dir.Join(ctx, os, image.installDirOnHost, arch.String()) + outputDir := image.dir.Join(ctx, os, image.installDir, arch.String()) outputPath := outputDir.Join(ctx, image.stem+".oat") oatLocation := dexpreopt.PathToLocation(outputPath, arch) imagePath := outputPath.ReplaceExtension(ctx, "art") @@ -796,7 +797,7 @@ func buildBootImageVariant(ctx android.ModuleContext, image *bootImageVariant, p cmd.Textf(`|| ( echo %s ; false )`, proptools.ShellEscape(failureMessage)) - installDir := filepath.Join("/", image.installDirOnHost, arch.String()) + installDir := filepath.Dir(image.imagePathOnDevice) var vdexInstalls android.RuleBuilderInstalls var unstrippedInstalls android.RuleBuilderInstalls diff --git a/java/dexpreopt_config.go b/java/dexpreopt_config.go index 8f732cf56..5f168e70a 100644 --- a/java/dexpreopt_config.go +++ b/java/dexpreopt_config.go @@ -62,8 +62,7 @@ func genBootImageConfigRaw(ctx android.PathContext) map[string]*bootImageConfig artCfg := bootImageConfig{ name: artBootImageName, stem: bootImageStem, - installDirOnHost: "apex/art_boot_images/javalib", - installDirOnDevice: frameworkSubdir, + installDir: "apex/art_boot_images/javalib", profileInstallPathInApex: "etc/boot-image.prof", modules: artModules, preloadedClassesFile: "art/build/boot/preloaded-classes", @@ -77,8 +76,7 @@ func genBootImageConfigRaw(ctx android.PathContext) map[string]*bootImageConfig extends: &artCfg, name: frameworkBootImageName, stem: bootImageStem, - installDirOnHost: frameworkSubdir, - installDirOnDevice: frameworkSubdir, + installDir: frameworkSubdir, modules: frameworkModules, preloadedClassesFile: "frameworks/base/config/preloaded-classes", compilerFilter: "speed-profile", @@ -86,14 +84,13 @@ func genBootImageConfigRaw(ctx android.PathContext) map[string]*bootImageConfig } mainlineCfg := bootImageConfig{ - extends: &frameworkCfg, - name: mainlineBootImageName, - stem: bootImageStem, - installDirOnHost: frameworkSubdir, - installDirOnDevice: frameworkSubdir, - modules: mainlineBcpModules, - compilerFilter: "verify", - singleImage: true, + extends: &frameworkCfg, + name: mainlineBootImageName, + stem: bootImageStem, + installDir: frameworkSubdir, + modules: mainlineBcpModules, + compilerFilter: "verify", + singleImage: true, } return map[string]*bootImageConfig{ @@ -132,12 +129,12 @@ func genBootImageConfigs(ctx android.PathContext) map[string]*bootImageConfig { // Create target-specific variants. for _, target := range targets { arch := target.Arch.ArchType - imageDir := c.dir.Join(ctx, target.Os.String(), c.installDirOnHost, arch.String()) + imageDir := c.dir.Join(ctx, target.Os.String(), c.installDir, arch.String()) variant := &bootImageVariant{ bootImageConfig: c, target: target, imagePathOnHost: imageDir.Join(ctx, imageName), - imagePathOnDevice: filepath.Join("/", c.installDirOnDevice, arch.String(), imageName), + imagePathOnDevice: filepath.Join("/", c.installDir, arch.String(), imageName), imagesDeps: c.moduleFiles(ctx, imageDir, ".art", ".oat", ".vdex"), dexLocations: c.modules.DevicePaths(ctx.Config(), target.Os), } diff --git a/java/dexpreopt_config_testing.go b/java/dexpreopt_config_testing.go index 6b98ca58c..3ee3bd553 100644 --- a/java/dexpreopt_config_testing.go +++ b/java/dexpreopt_config_testing.go @@ -147,8 +147,7 @@ type expectedConfig struct { stem string dir string symbolsDir string - installDirOnDevice string - installDirOnHost string + installDir string profileInstallPathInApex string modules android.ConfiguredJarList dexPaths []string @@ -209,8 +208,7 @@ func checkArtBootImageConfig(t *testing.T, result *android.TestResult, mutated b stem: "boot", dir: "out/soong/dexpreopt_arm64/dex_artjars", symbolsDir: "out/soong/dexpreopt_arm64/dex_artjars_unstripped", - installDirOnDevice: "system/framework", - installDirOnHost: "apex/art_boot_images/javalib", + installDir: "apex/art_boot_images/javalib", profileInstallPathInApex: "etc/boot-image.prof", modules: android.CreateTestConfiguredJarList([]string{"com.android.art:core1", "com.android.art:core2"}), dexPaths: []string{"out/soong/dexpreopt_arm64/dex_artjars_input/core1.jar", "out/soong/dexpreopt_arm64/dex_artjars_input/core2.jar"}, @@ -222,7 +220,7 @@ func checkArtBootImageConfig(t *testing.T, result *android.TestResult, mutated b dexLocations: []string{"/apex/com.android.art/javalib/core1.jar", "/apex/com.android.art/javalib/core2.jar"}, dexLocationsDeps: []string{"/apex/com.android.art/javalib/core1.jar", "/apex/com.android.art/javalib/core2.jar"}, imagePathOnHost: "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", - imagePathOnDevice: "/system/framework/arm64/boot.art", + imagePathOnDevice: "/apex/art_boot_images/javalib/arm64/boot.art", imagesDeps: []string{ "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat", @@ -276,7 +274,7 @@ func checkArtBootImageConfig(t *testing.T, result *android.TestResult, mutated b dexLocations: []string{"/apex/com.android.art/javalib/core1.jar", "/apex/com.android.art/javalib/core2.jar"}, dexLocationsDeps: []string{"/apex/com.android.art/javalib/core1.jar", "/apex/com.android.art/javalib/core2.jar"}, imagePathOnHost: "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", - imagePathOnDevice: "/system/framework/arm/boot.art", + imagePathOnDevice: "/apex/art_boot_images/javalib/arm/boot.art", imagesDeps: []string{ "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat", @@ -330,7 +328,7 @@ func checkArtBootImageConfig(t *testing.T, result *android.TestResult, mutated b dexLocations: []string{"host/linux-x86/apex/com.android.art/javalib/core1.jar", "host/linux-x86/apex/com.android.art/javalib/core2.jar"}, dexLocationsDeps: []string{"host/linux-x86/apex/com.android.art/javalib/core1.jar", "host/linux-x86/apex/com.android.art/javalib/core2.jar"}, imagePathOnHost: "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", - imagePathOnDevice: "/system/framework/x86_64/boot.art", + imagePathOnDevice: "/apex/art_boot_images/javalib/x86_64/boot.art", imagesDeps: []string{ "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat", @@ -382,7 +380,7 @@ func checkArtBootImageConfig(t *testing.T, result *android.TestResult, mutated b dexLocations: []string{"host/linux-x86/apex/com.android.art/javalib/core1.jar", "host/linux-x86/apex/com.android.art/javalib/core2.jar"}, dexLocationsDeps: []string{"host/linux-x86/apex/com.android.art/javalib/core1.jar", "host/linux-x86/apex/com.android.art/javalib/core2.jar"}, imagePathOnHost: "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", - imagePathOnDevice: "/system/framework/x86/boot.art", + imagePathOnDevice: "/apex/art_boot_images/javalib/x86/boot.art", imagesDeps: []string{ "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat", @@ -462,8 +460,7 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut stem: "boot", dir: "out/soong/dexpreopt_arm64/dex_bootjars", symbolsDir: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped", - installDirOnDevice: "system/framework", - installDirOnHost: "system/framework", + installDir: "system/framework", profileInstallPathInApex: "", modules: android.CreateTestConfiguredJarList([]string{"platform:framework"}), dexPaths: []string{"out/soong/dexpreopt_arm64/dex_bootjars_input/framework.jar"}, @@ -693,8 +690,7 @@ func CheckMainlineBootImageConfig(t *testing.T, result *android.TestResult) { stem: "boot", dir: "out/soong/dexpreopt_arm64/dex_mainlinejars", symbolsDir: "out/soong/dexpreopt_arm64/dex_mainlinejars_unstripped", - installDirOnDevice: "system/framework", - installDirOnHost: "system/framework", + installDir: "system/framework", profileInstallPathInApex: "", modules: android.CreateTestConfiguredJarList([]string{ "com.android.foo:framework-foo", @@ -999,8 +995,7 @@ func nestedCheckBootImageConfig(t *testing.T, imageConfig *bootImageConfig, expe android.AssertStringEquals(t, "stem", expected.stem, imageConfig.stem) android.AssertPathRelativeToTopEquals(t, "dir", expected.dir, imageConfig.dir) android.AssertPathRelativeToTopEquals(t, "symbolsDir", expected.symbolsDir, imageConfig.symbolsDir) - android.AssertStringEquals(t, "installDirOnDevice", expected.installDirOnDevice, imageConfig.installDirOnDevice) - android.AssertStringEquals(t, "installDirOnHost", expected.installDirOnHost, imageConfig.installDirOnHost) + 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()) @@ -1096,9 +1091,9 @@ DEXPREOPT_IMAGE_LICENSE_METADATA_mainline_arm=out/soong/.intermediates/framework DEXPREOPT_IMAGE_LICENSE_METADATA_mainline_arm64=out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/meta_lic DEXPREOPT_IMAGE_LICENSE_METADATA_mainline_host_x86=out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/meta_lic DEXPREOPT_IMAGE_LICENSE_METADATA_mainline_host_x86_64=out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/meta_lic -DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICEart=/system/framework/boot.art -DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICEboot=/system/framework/boot.art:/system/framework/boot-framework.art -DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICEmainline=/system/framework/boot.art:/system/framework/boot-framework.art:/system/framework/boot-framework-foo.art +DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICEart=/apex/art_boot_images/javalib/boot.art +DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICEboot=/apex/art_boot_images/javalib/boot.art:/system/framework/boot-framework.art +DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICEmainline=/apex/art_boot_images/javalib/boot.art:/system/framework/boot-framework.art:/system/framework/boot-framework-foo.art DEXPREOPT_IMAGE_LOCATIONS_ON_HOSTart=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/boot.art DEXPREOPT_IMAGE_LOCATIONS_ON_HOSTboot=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/boot.art:out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/boot-framework.art DEXPREOPT_IMAGE_LOCATIONS_ON_HOSTmainline=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/boot.art:out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/boot-framework.art:out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/boot-framework-foo.art diff --git a/java/testing.go b/java/testing.go index 4ff2aa497..6671bf0c7 100644 --- a/java/testing.go +++ b/java/testing.go @@ -610,9 +610,9 @@ func FixtureModifyBootImageConfig(name string, configModifier func(*bootImageCon }) } -// Sets the value of `installDirOnDevice` of the boot image config with the given name. +// Sets the value of `installDir` of the boot image config with the given name. func FixtureSetBootImageInstallDirOnDevice(name string, installDir string) android.FixturePreparer { return FixtureModifyBootImageConfig(name, func(config *bootImageConfig) { - config.installDirOnDevice = installDir + config.installDir = installDir }) } From 5f5a17fd6b7ea404d9df2f31f2d074586b086326 Mon Sep 17 00:00:00 2001 From: Jiakai Zhang Date: Wed, 10 May 2023 18:38:34 +0100 Subject: [PATCH 149/172] Dexpreopt ART jars and framework jars together. Bug: 280776428 Test: atest art_standalone_dexpreopt_tests Test: - 1. m 2. Check .invocation file (http://gpaste/6498044089466880) 3. Check files in $ANDROID_PRODUCT_OUT/system/framework/x86_64 Test: - 1. m dist 2. Check files in out/dist/boot.zip Test: - 1. art/tools/buildbot-build.sh --host 2. m test-art-host-gtest 3. art/test/testrunner/testrunner.py --host Test: m build-art-target-golem (cherry picked from https://android-review.googlesource.com/q/commit:c08c162b5a82ddfc44e9944d798636b2241308de) Merged-In: I89490252e56a05edab03fdddc6539fa4d7f79756 Change-Id: I89490252e56a05edab03fdddc6539fa4d7f79756 --- apex/apex_test.go | 14 +- apex/dexpreopt_bootjars_test.go | 193 +++++++++++++--- java/bootclasspath_fragment.go | 26 +++ java/dexpreopt_bootjars.go | 33 +++ java/dexpreopt_config.go | 4 +- java/dexpreopt_config_testing.go | 372 +++++++++++++++++++++---------- java/platform_bootclasspath.go | 48 +++- 7 files changed, 520 insertions(+), 170 deletions(-) diff --git a/apex/apex_test.go b/apex/apex_test.go index 9e0757708..139b77ef6 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -8289,8 +8289,8 @@ func TestNoUpdatableJarsInBootImage(t *testing.T) { testNoUpdatableJarsInBootImage(t, "", preparer, fragments...) }) - t.Run("updatable jar from ART apex in the framework boot image => error", func(t *testing.T) { - err := `module "some-art-lib" from updatable apexes \["com.android.art.debug"\] is not allowed in the framework boot image` + 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"), @@ -8313,8 +8313,8 @@ func TestNoUpdatableJarsInBootImage(t *testing.T) { testNoUpdatableJarsInBootImage(t, err, preparer) }) - t.Run("updatable jar from some other apex in the framework boot image => error", func(t *testing.T) { - err := `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the framework boot image` + 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"), @@ -8322,7 +8322,7 @@ func TestNoUpdatableJarsInBootImage(t *testing.T) { testNoUpdatableJarsInBootImage(t, err, preparer) }) - t.Run("non-updatable jar from some other apex in the framework boot image => ok", func(t *testing.T) { + 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"), @@ -8337,7 +8337,7 @@ func TestNoUpdatableJarsInBootImage(t *testing.T) { testNoUpdatableJarsInBootImage(t, err, preparer) }) - t.Run("nonexistent jar in the framework boot image => error", func(t *testing.T) { + 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) @@ -8350,7 +8350,7 @@ func TestNoUpdatableJarsInBootImage(t *testing.T) { testNoUpdatableJarsInBootImage(t, err, preparer) }) - t.Run("platform jar in the framework boot image => ok", func(t *testing.T) { + 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"), diff --git a/apex/dexpreopt_bootjars_test.go b/apex/dexpreopt_bootjars_test.go index ef66807f0..bba8bb6cb 100644 --- a/apex/dexpreopt_bootjars_test.go +++ b/apex/dexpreopt_bootjars_test.go @@ -15,6 +15,7 @@ package apex import ( + "fmt" "path/filepath" "sort" "testing" @@ -23,8 +24,10 @@ import ( "android/soong/java" ) -func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOutputs []string) { +func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOutputs []string, preferPrebuilt bool) { bp := ` + // Platform. + java_sdk_library { name: "foo", srcs: ["a.java"], @@ -45,6 +48,84 @@ func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOu platform_bootclasspath { name: "platform-bootclasspath", + fragments: [ + { + apex: "com.android.art", + module: "art-bootclasspath-fragment", + }, + ], + } + + // Source ART APEX. + + java_library { + name: "core-oj", + srcs: ["core-oj.java"], + installable: true, + apex_available: [ + "com.android.art", + ], + } + + bootclasspath_fragment { + name: "art-bootclasspath-fragment", + image_name: "art", + contents: ["core-oj"], + apex_available: [ + "com.android.art", + ], + hidden_api: { + split_packages: ["*"], + }, + } + + apex_key { + name: "com.android.art.key", + public_key: "com.android.art.avbpubkey", + private_key: "com.android.art.pem", + } + + apex { + name: "com.android.art", + key: "com.android.art.key", + bootclasspath_fragments: ["art-bootclasspath-fragment"], + updatable: false, + } + + // Prebuilt ART APEX. + + java_import { + name: "core-oj", + prefer: %[1]t, + jars: ["core-oj.jar"], + apex_available: [ + "com.android.art", + ], + } + + prebuilt_bootclasspath_fragment { + name: "art-bootclasspath-fragment", + prefer: %[1]t, + image_name: "art", + contents: ["core-oj"], + hidden_api: { + annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", + metadata: "my-bootclasspath-fragment/metadata.csv", + index: "my-bootclasspath-fragment/index.csv", + stub_flags: "my-bootclasspath-fragment/stub-flags.csv", + all_flags: "my-bootclasspath-fragment/all-flags.csv", + }, + apex_available: [ + "com.android.art", + ], + } + + prebuilt_apex { + name: "com.android.art", + prefer: %[1]t, + apex_name: "com.android.art", + src: "com.android.art-arm.apex", + exported_bootclasspath_fragments: ["art-bootclasspath-fragment"], } ` @@ -52,20 +133,14 @@ func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOu java.PrepareForTestWithDexpreopt, java.PrepareForTestWithJavaSdkLibraryFiles, java.FixtureWithLastReleaseApis("foo"), - java.FixtureConfigureBootJars("platform:foo", "system_ext:bar", "platform:baz"), - ).RunTestWithBp(t, bp) + java.FixtureConfigureBootJars("com.android.art:core-oj", "platform:foo", "system_ext:bar", "platform:baz"), + PrepareForTestWithApexBuildComponents, + prepareForTestWithArtApex, + ).RunTestWithBp(t, fmt.Sprintf(bp, preferPrebuilt)) platformBootclasspath := result.ModuleForTests("platform-bootclasspath", "android_common") rule := platformBootclasspath.Output(ruleFile) - for i := range expectedInputs { - expectedInputs[i] = filepath.Join("out/soong/dexpreopt_arm64", expectedInputs[i]) - } - - for i := range expectedOutputs { - expectedOutputs[i] = filepath.Join("out/soong/dexpreopt_arm64", expectedOutputs[i]) - } - inputs := rule.Implicits.Strings() sort.Strings(inputs) sort.Strings(expectedInputs) @@ -79,33 +154,76 @@ func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOu android.AssertStringPathsRelativeToTopEquals(t, "outputs", result.Config, expectedOutputs, outputs) } -func TestDexpreoptBootJars(t *testing.T) { - ruleFile := "boot-foo.art" +func TestDexpreoptBootJarsWithSourceArtApex(t *testing.T) { + ruleFile := "boot.art" expectedInputs := []string{ - "dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", - "dex_bootjars_input/foo.jar", - "dex_bootjars_input/bar.jar", - "dex_bootjars_input/baz.jar", + "out/soong/dexpreopt_arm64/dex_bootjars_input/core-oj.jar", + "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", } expectedOutputs := []string{ - "dex_bootjars/android/system/framework/arm64/boot.invocation", - "dex_bootjars/android/system/framework/arm64/boot-foo.art", - "dex_bootjars/android/system/framework/arm64/boot-bar.art", - "dex_bootjars/android/system/framework/arm64/boot-baz.art", - "dex_bootjars/android/system/framework/arm64/boot-foo.oat", - "dex_bootjars/android/system/framework/arm64/boot-bar.oat", - "dex_bootjars/android/system/framework/arm64/boot-baz.oat", - "dex_bootjars/android/system/framework/arm64/boot-foo.vdex", - "dex_bootjars/android/system/framework/arm64/boot-bar.vdex", - "dex_bootjars/android/system/framework/arm64/boot-baz.vdex", - "dex_bootjars_unstripped/android/system/framework/arm64/boot-foo.oat", - "dex_bootjars_unstripped/android/system/framework/arm64/boot-bar.oat", - "dex_bootjars_unstripped/android/system/framework/arm64/boot-baz.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.invocation", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-foo.oat", + "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-bar.oat", + "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-baz.oat", } - testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs) + testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs, false) +} + +// 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" + + expectedInputs := []string{ + "out/soong/dexpreopt_arm64/dex_bootjars_input/core-oj.jar", + "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/.intermediates/com.android.art.deapexer/android_common/deapexer/etc/boot-image.prof", + "out/soong/dexpreopt_arm64/dex_bootjars/boot.prof", + } + + expectedOutputs := []string{ + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.invocation", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-foo.oat", + "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-bar.oat", + "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-baz.oat", + } + + testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs, true) } // Changes to the boot.zip structure may break the ART APK scanner. @@ -116,16 +234,21 @@ func TestDexpreoptBootZip(t *testing.T) { expectedInputs := []string{} for _, target := range ctx.Config().Targets[android.Android] { for _, ext := range []string{".art", ".oat", ".vdex"} { - for _, jar := range []string{"foo", "bar", "baz"} { + for _, suffix := range []string{"", "-foo", "-bar", "-baz"} { expectedInputs = append(expectedInputs, - filepath.Join("dex_bootjars", target.Os.String(), "system/framework", target.Arch.ArchType.String(), "boot-"+jar+ext)) + filepath.Join( + "out/soong/dexpreopt_arm64/dex_bootjars", + target.Os.String(), + "system/framework", + target.Arch.ArchType.String(), + "boot"+suffix+ext)) } } } expectedOutputs := []string{ - "dex_bootjars/boot.zip", + "out/soong/dexpreopt_arm64/dex_bootjars/boot.zip", } - testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs) + testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs, false) } diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index f45165943..108fdd483 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -240,6 +240,9 @@ type BootclasspathFragmentModule struct { // Collect the module directory for IDE info in java/jdeps.go. modulePaths []string + + // Path to the boot image profile. + profilePath android.Path } // commonBootclasspathFragment defines the methods that are implemented by both source and prebuilt @@ -259,6 +262,12 @@ type commonBootclasspathFragment interface { // If it could not create the files then it will return nil. Otherwise, it will return a map from // android.ArchType to the predefined paths of the boot image files. produceBootImageFiles(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageOutputs + + // getImageName returns the `image_name` property of this fragment. + getImageName() *string + + // getProfilePath returns the path to the boot image profile. + getProfilePath() android.Path } var _ commonBootclasspathFragment = (*BootclasspathFragmentModule)(nil) @@ -528,6 +537,7 @@ func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.Mo // Delegate the production of the boot image files to a module type specific method. common := ctx.Module().(commonBootclasspathFragment) bootImageFiles = common.produceBootImageFiles(ctx, imageConfig) + b.profilePath = bootImageFiles.profile if shouldCopyBootFilesToPredefinedLocations(ctx, imageConfig) { // Zip the boot image files up, if available. This will generate the zip file in a @@ -911,6 +921,14 @@ func (b *BootclasspathFragmentModule) AndroidMkEntries() []android.AndroidMkEntr return entriesList } +func (b *BootclasspathFragmentModule) getImageName() *string { + return b.properties.Image_name +} + +func (b *BootclasspathFragmentModule) getProfilePath() android.Path { + return b.profilePath +} + // Collect information for opening IDE project files in java/jdeps.go. func (b *BootclasspathFragmentModule) IDEInfo(dpInfo *android.IdeInfo) { dpInfo.Deps = append(dpInfo.Deps, b.properties.Contents...) @@ -1207,6 +1225,14 @@ func (module *PrebuiltBootclasspathFragmentModule) produceBootImageFiles(ctx and return buildBootImageVariantsForAndroidOs(ctx, imageConfig, profile) } +func (b *PrebuiltBootclasspathFragmentModule) getImageName() *string { + return b.properties.Image_name +} + +func (b *PrebuiltBootclasspathFragmentModule) getProfilePath() android.Path { + return b.profilePath +} + var _ commonBootclasspathFragment = (*PrebuiltBootclasspathFragmentModule)(nil) // RequiredFilesFromPrebuiltApex returns the list of all files the prebuilt_bootclasspath_fragment diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go index 792fa6396..f477f404e 100644 --- a/java/dexpreopt_bootjars.go +++ b/java/dexpreopt_bootjars.go @@ -295,6 +295,11 @@ type bootImageConfig struct { // The "--single-image" argument. singleImage bool + + // Profiles imported from other boot image configs. Each element must represent a + // `bootclasspath_fragment` of an APEX (i.e., the `name` field of each element must refer to the + // `image_name` property of a `bootclasspath_fragment`). + profileImports []*bootImageConfig } // Target-dependent description of a boot image. @@ -711,6 +716,34 @@ func buildBootImageVariant(ctx android.ModuleContext, image *bootImageVariant, p cmd.FlagWithInput("--profile-file=", profile) } + fragments := make(map[string]commonBootclasspathFragment) + ctx.VisitDirectDepsWithTag(bootclasspathFragmentDepTag, func(child android.Module) { + fragment := child.(commonBootclasspathFragment) + if fragment.getImageName() != nil && android.IsModulePreferred(child) { + fragments[*fragment.getImageName()] = fragment + } + }) + + for _, profileImport := range image.profileImports { + fragment := fragments[profileImport.name] + if fragment == nil { + ctx.ModuleErrorf("Boot image config '%[1]s' imports profile from '%[2]s', but a "+ + "bootclasspath_fragment with image name '%[2]s' doesn't exist or is not added as a "+ + "dependency of '%[1]s'", + image.name, + profileImport.name) + return bootImageVariantOutputs{} + } + if fragment.getProfilePath() == nil { + ctx.ModuleErrorf("Boot image config '%[1]s' imports profile from '%[2]s', but '%[2]s' "+ + "doesn't provide a profile", + image.name, + profileImport.name) + return bootImageVariantOutputs{} + } + cmd.FlagWithInput("--profile-file=", fragment.getProfilePath()) + } + dirtyImageFile := "frameworks/base/config/dirty-image-objects" dirtyImagePath := android.ExistentPathForSource(ctx, dirtyImageFile) if dirtyImagePath.Valid() { diff --git a/java/dexpreopt_config.go b/java/dexpreopt_config.go index 5f168e70a..9100e87c6 100644 --- a/java/dexpreopt_config.go +++ b/java/dexpreopt_config.go @@ -53,7 +53,7 @@ func genBootImageConfigRaw(ctx android.PathContext) map[string]*bootImageConfig global := dexpreopt.GetGlobalConfig(ctx) artModules := global.ArtApexJars - frameworkModules := global.BootJars.RemoveList(artModules) + frameworkModules := global.BootJars // This includes `artModules`. mainlineBcpModules := global.ApexBootJars frameworkSubdir := "system/framework" @@ -73,7 +73,6 @@ func genBootImageConfigRaw(ctx android.PathContext) map[string]*bootImageConfig // Framework config for the boot image extension. // It includes framework libraries and depends on the ART config. frameworkCfg := bootImageConfig{ - extends: &artCfg, name: frameworkBootImageName, stem: bootImageStem, installDir: frameworkSubdir, @@ -81,6 +80,7 @@ func genBootImageConfigRaw(ctx android.PathContext) map[string]*bootImageConfig preloadedClassesFile: "frameworks/base/config/preloaded-classes", compilerFilter: "speed-profile", singleImage: false, + profileImports: []*bootImageConfig{&artCfg}, } mainlineCfg := bootImageConfig{ diff --git a/java/dexpreopt_config_testing.go b/java/dexpreopt_config_testing.go index 3ee3bd553..6f3aa2be8 100644 --- a/java/dexpreopt_config_testing.go +++ b/java/dexpreopt_config_testing.go @@ -462,36 +462,65 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut symbolsDir: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped", installDir: "system/framework", profileInstallPathInApex: "", - modules: android.CreateTestConfiguredJarList([]string{"platform:framework"}), - dexPaths: []string{"out/soong/dexpreopt_arm64/dex_bootjars_input/framework.jar"}, - dexPathsDeps: []string{"out/soong/dexpreopt_arm64/dex_artjars_input/core1.jar", "out/soong/dexpreopt_arm64/dex_artjars_input/core2.jar", "out/soong/dexpreopt_arm64/dex_bootjars_input/framework.jar"}, - zip: "out/soong/dexpreopt_arm64/dex_bootjars/boot.zip", + modules: android.CreateTestConfiguredJarList([]string{ + "com.android.art:core1", + "com.android.art:core2", + "platform:framework", + }), + dexPaths: []string{ + "out/soong/dexpreopt_arm64/dex_bootjars_input/core1.jar", + "out/soong/dexpreopt_arm64/dex_bootjars_input/core2.jar", + "out/soong/dexpreopt_arm64/dex_bootjars_input/framework.jar", + }, + dexPathsDeps: []string{ + "out/soong/dexpreopt_arm64/dex_bootjars_input/core1.jar", + "out/soong/dexpreopt_arm64/dex_bootjars_input/core2.jar", + "out/soong/dexpreopt_arm64/dex_bootjars_input/framework.jar", + }, + zip: "out/soong/dexpreopt_arm64/dex_bootjars/boot.zip", variants: []*expectedVariant{ { - archType: android.Arm64, - dexLocations: []string{"/system/framework/framework.jar"}, + archType: android.Arm64, + dexLocations: []string{ + "/apex/com.android.art/javalib/core1.jar", + "/apex/com.android.art/javalib/core2.jar", + "/system/framework/framework.jar", + }, dexLocationsDeps: []string{ "/apex/com.android.art/javalib/core1.jar", "/apex/com.android.art/javalib/core2.jar", "/system/framework/framework.jar", }, - imagePathOnHost: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art", - imagePathOnDevice: "/system/framework/arm64/boot-framework.art", + imagePathOnHost: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art", + imagePathOnDevice: "/system/framework/arm64/boot.art", imagesDeps: []string{ + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.vdex", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.oat", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.vdex", }, - baseImages: []string{"out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art"}, - baseImagesDeps: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex", - }, installs: []normalizedInstall{ + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art", + to: "/system/framework/arm64/boot.art", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.oat", + to: "/system/framework/arm64/boot.oat", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.art", + to: "/system/framework/arm64/boot-core2.art", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.oat", + to: "/system/framework/arm64/boot-core2.oat", + }, { from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art", to: "/system/framework/arm64/boot-framework.art", @@ -502,12 +531,28 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut }, }, vdexInstalls: []normalizedInstall{ + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.vdex", + to: "/system/framework/arm64/boot.vdex", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.vdex", + to: "/system/framework/arm64/boot-core2.vdex", + }, { from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.vdex", to: "/system/framework/arm64/boot-framework.vdex", }, }, unstrippedInstalls: []normalizedInstall{ + { + from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot.oat", + to: "/system/framework/arm64/boot.oat", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-core2.oat", + to: "/system/framework/arm64/boot-core2.oat", + }, { from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-framework.oat", to: "/system/framework/arm64/boot-framework.oat", @@ -516,30 +561,47 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut licenseMetadataFile: expectedLicenseMetadataFile, }, { - archType: android.Arm, - dexLocations: []string{"/system/framework/framework.jar"}, + archType: android.Arm, + dexLocations: []string{ + "/apex/com.android.art/javalib/core1.jar", + "/apex/com.android.art/javalib/core2.jar", + "/system/framework/framework.jar", + }, dexLocationsDeps: []string{ "/apex/com.android.art/javalib/core1.jar", "/apex/com.android.art/javalib/core2.jar", "/system/framework/framework.jar", }, - imagePathOnHost: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art", - imagePathOnDevice: "/system/framework/arm/boot-framework.art", + imagePathOnHost: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.art", + imagePathOnDevice: "/system/framework/arm/boot.art", imagesDeps: []string{ + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.vdex", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.oat", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.vdex", }, - baseImages: []string{"out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art"}, - baseImagesDeps: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.art", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.oat", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.vdex", - }, installs: []normalizedInstall{ + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.art", + to: "/system/framework/arm/boot.art", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.oat", + to: "/system/framework/arm/boot.oat", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.art", + to: "/system/framework/arm/boot-core2.art", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.oat", + to: "/system/framework/arm/boot-core2.oat", + }, { from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art", to: "/system/framework/arm/boot-framework.art", @@ -550,12 +612,28 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut }, }, vdexInstalls: []normalizedInstall{ + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.vdex", + to: "/system/framework/arm/boot.vdex", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.vdex", + to: "/system/framework/arm/boot-core2.vdex", + }, { from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.vdex", to: "/system/framework/arm/boot-framework.vdex", }, }, unstrippedInstalls: []normalizedInstall{ + { + from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm/boot.oat", + to: "/system/framework/arm/boot.oat", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm/boot-core2.oat", + to: "/system/framework/arm/boot-core2.oat", + }, { from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm/boot-framework.oat", to: "/system/framework/arm/boot-framework.oat", @@ -564,30 +642,47 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut licenseMetadataFile: expectedLicenseMetadataFile, }, { - archType: android.X86_64, - dexLocations: []string{"host/linux-x86/system/framework/framework.jar"}, + archType: android.X86_64, + dexLocations: []string{ + "host/linux-x86/apex/com.android.art/javalib/core1.jar", + "host/linux-x86/apex/com.android.art/javalib/core2.jar", + "host/linux-x86/system/framework/framework.jar", + }, dexLocationsDeps: []string{ "host/linux-x86/apex/com.android.art/javalib/core1.jar", "host/linux-x86/apex/com.android.art/javalib/core2.jar", "host/linux-x86/system/framework/framework.jar", }, - imagePathOnHost: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art", - imagePathOnDevice: "/system/framework/x86_64/boot-framework.art", + imagePathOnHost: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.art", + imagePathOnDevice: "/system/framework/x86_64/boot.art", imagesDeps: []string{ + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.vdex", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex", }, - baseImages: []string{"out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art"}, - baseImagesDeps: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex", - }, installs: []normalizedInstall{ + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.art", + to: "/system/framework/x86_64/boot.art", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.oat", + to: "/system/framework/x86_64/boot.oat", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.art", + to: "/system/framework/x86_64/boot-core2.art", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.oat", + to: "/system/framework/x86_64/boot-core2.oat", + }, { from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art", to: "/system/framework/x86_64/boot-framework.art", @@ -598,12 +693,28 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut }, }, vdexInstalls: []normalizedInstall{ + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.vdex", + to: "/system/framework/x86_64/boot.vdex", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.vdex", + to: "/system/framework/x86_64/boot-core2.vdex", + }, { from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex", to: "/system/framework/x86_64/boot-framework.vdex", }, }, unstrippedInstalls: []normalizedInstall{ + { + from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86_64/boot.oat", + to: "/system/framework/x86_64/boot.oat", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86_64/boot-core2.oat", + to: "/system/framework/x86_64/boot-core2.oat", + }, { from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86_64/boot-framework.oat", to: "/system/framework/x86_64/boot-framework.oat", @@ -612,30 +723,47 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut licenseMetadataFile: expectedLicenseMetadataFile, }, { - archType: android.X86, - dexLocations: []string{"host/linux-x86/system/framework/framework.jar"}, + archType: android.X86, + dexLocations: []string{ + "host/linux-x86/apex/com.android.art/javalib/core1.jar", + "host/linux-x86/apex/com.android.art/javalib/core2.jar", + "host/linux-x86/system/framework/framework.jar", + }, dexLocationsDeps: []string{ "host/linux-x86/apex/com.android.art/javalib/core1.jar", "host/linux-x86/apex/com.android.art/javalib/core2.jar", "host/linux-x86/system/framework/framework.jar", }, - imagePathOnHost: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art", - imagePathOnDevice: "/system/framework/x86/boot-framework.art", + imagePathOnHost: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.art", + imagePathOnDevice: "/system/framework/x86/boot.art", imagesDeps: []string{ + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.vdex", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex", }, - baseImages: []string{"out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art"}, - baseImagesDeps: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex", - }, installs: []normalizedInstall{ + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.art", + to: "/system/framework/x86/boot.art", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.oat", + to: "/system/framework/x86/boot.oat", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.art", + to: "/system/framework/x86/boot-core2.art", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.oat", + to: "/system/framework/x86/boot-core2.oat", + }, { from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art", to: "/system/framework/x86/boot-framework.art", @@ -646,12 +774,28 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut }, }, vdexInstalls: []normalizedInstall{ + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.vdex", + to: "/system/framework/x86/boot.vdex", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.vdex", + to: "/system/framework/x86/boot-core2.vdex", + }, { from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex", to: "/system/framework/x86/boot-framework.vdex", }, }, unstrippedInstalls: []normalizedInstall{ + { + from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86/boot.oat", + to: "/system/framework/x86/boot.oat", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86/boot-core2.oat", + to: "/system/framework/x86/boot-core2.oat", + }, { from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86/boot-framework.oat", to: "/system/framework/x86/boot-framework.oat", @@ -701,8 +845,8 @@ func CheckMainlineBootImageConfig(t *testing.T, result *android.TestResult) { "out/soong/dexpreopt_arm64/dex_mainlinejars_input/framework-bar.jar", }, dexPathsDeps: []string{ - "out/soong/dexpreopt_arm64/dex_artjars_input/core1.jar", - "out/soong/dexpreopt_arm64/dex_artjars_input/core2.jar", + "out/soong/dexpreopt_arm64/dex_bootjars_input/core1.jar", + "out/soong/dexpreopt_arm64/dex_bootjars_input/core2.jar", "out/soong/dexpreopt_arm64/dex_bootjars_input/framework.jar", "out/soong/dexpreopt_arm64/dex_mainlinejars_input/framework-foo.jar", "out/soong/dexpreopt_arm64/dex_mainlinejars_input/framework-bar.jar", @@ -730,16 +874,15 @@ func CheckMainlineBootImageConfig(t *testing.T, result *android.TestResult) { "out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.vdex", }, baseImages: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", - "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art", }, baseImagesDeps: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.vdex", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.oat", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.vdex", @@ -789,16 +932,15 @@ func CheckMainlineBootImageConfig(t *testing.T, result *android.TestResult) { "out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.vdex", }, baseImages: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", - "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.art", }, baseImagesDeps: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.art", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.oat", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.vdex", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.oat", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.vdex", @@ -848,16 +990,15 @@ func CheckMainlineBootImageConfig(t *testing.T, result *android.TestResult) { "out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.vdex", }, baseImages: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", - "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.art", }, baseImagesDeps: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.vdex", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex", @@ -907,16 +1048,15 @@ func CheckMainlineBootImageConfig(t *testing.T, result *android.TestResult) { "out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.vdex", }, baseImages: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", - "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.art", }, baseImagesDeps: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.vdex", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex", @@ -1051,18 +1191,18 @@ func checkDexpreoptMakeVars(t *testing.T, result *android.TestResult, expectedLi fmt.Fprintf(out, "%s=%s\n", v.Name(), android.StringRelativeToTop(result.Config, v.Value())) } format := ` -DEXPREOPT_BOOTCLASSPATH_DEX_FILES=out/soong/dexpreopt_arm64/dex_artjars_input/core1.jar out/soong/dexpreopt_arm64/dex_artjars_input/core2.jar out/soong/dexpreopt_arm64/dex_bootjars_input/framework.jar +DEXPREOPT_BOOTCLASSPATH_DEX_FILES=out/soong/dexpreopt_arm64/dex_bootjars_input/core1.jar out/soong/dexpreopt_arm64/dex_bootjars_input/core2.jar out/soong/dexpreopt_arm64/dex_bootjars_input/framework.jar DEXPREOPT_BOOTCLASSPATH_DEX_LOCATIONS=/apex/com.android.art/javalib/core1.jar /apex/com.android.art/javalib/core2.jar /system/framework/framework.jar -DEXPREOPT_BOOT_JARS_MODULES=platform:framework +DEXPREOPT_BOOT_JARS_MODULES=com.android.art:core1:com.android.art:core2:platform:framework DEXPREOPT_GEN=out/host/linux-x86/bin/dexpreopt_gen DEXPREOPT_IMAGE_BUILT_INSTALLED_art_arm=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art:/apex/art_boot_images/javalib/arm/boot.art out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat:/apex/art_boot_images/javalib/arm/boot.oat out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.art:/apex/art_boot_images/javalib/arm/boot-core2.art out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.oat:/apex/art_boot_images/javalib/arm/boot-core2.oat DEXPREOPT_IMAGE_BUILT_INSTALLED_art_arm64=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art:/apex/art_boot_images/javalib/arm64/boot.art out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat:/apex/art_boot_images/javalib/arm64/boot.oat out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art:/apex/art_boot_images/javalib/arm64/boot-core2.art out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat:/apex/art_boot_images/javalib/arm64/boot-core2.oat DEXPREOPT_IMAGE_BUILT_INSTALLED_art_host_x86=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art:/apex/art_boot_images/javalib/x86/boot.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat:/apex/art_boot_images/javalib/x86/boot.oat out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art:/apex/art_boot_images/javalib/x86/boot-core2.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat:/apex/art_boot_images/javalib/x86/boot-core2.oat DEXPREOPT_IMAGE_BUILT_INSTALLED_art_host_x86_64=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art:/apex/art_boot_images/javalib/x86_64/boot.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat:/apex/art_boot_images/javalib/x86_64/boot.oat out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art:/apex/art_boot_images/javalib/x86_64/boot-core2.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat:/apex/art_boot_images/javalib/x86_64/boot-core2.oat -DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art:/system/framework/arm/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.oat:/system/framework/arm/boot-framework.oat -DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art:/system/framework/arm64/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.oat:/system/framework/arm64/boot-framework.oat -DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art:/system/framework/x86/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat:/system/framework/x86/boot-framework.oat -DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art:/system/framework/x86_64/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat:/system/framework/x86_64/boot-framework.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.art:/system/framework/arm/boot.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.oat:/system/framework/arm/boot.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.art:/system/framework/arm/boot-core2.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.oat:/system/framework/arm/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art:/system/framework/arm/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.oat:/system/framework/arm/boot-framework.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art:/system/framework/arm64/boot.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.oat:/system/framework/arm64/boot.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.art:/system/framework/arm64/boot-core2.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.oat:/system/framework/arm64/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art:/system/framework/arm64/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.oat:/system/framework/arm64/boot-framework.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.art:/system/framework/x86/boot.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.oat:/system/framework/x86/boot.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.art:/system/framework/x86/boot-core2.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.oat:/system/framework/x86/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art:/system/framework/x86/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat:/system/framework/x86/boot-framework.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.art:/system/framework/x86_64/boot.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.oat:/system/framework/x86_64/boot.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.art:/system/framework/x86_64/boot-core2.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.oat:/system/framework/x86_64/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art:/system/framework/x86_64/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat:/system/framework/x86_64/boot-framework.oat DEXPREOPT_IMAGE_BUILT_INSTALLED_mainline_arm=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.art:/system/framework/arm/boot-framework-foo.art out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.oat:/system/framework/arm/boot-framework-foo.oat DEXPREOPT_IMAGE_BUILT_INSTALLED_mainline_arm64=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.art:/system/framework/arm64/boot-framework-foo.art out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.oat:/system/framework/arm64/boot-framework-foo.oat DEXPREOPT_IMAGE_BUILT_INSTALLED_mainline_host_x86=out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.art:/system/framework/x86/boot-framework-foo.art out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.oat:/system/framework/x86/boot-framework-foo.oat @@ -1071,10 +1211,10 @@ DEXPREOPT_IMAGE_DEPS_art_arm=out/soong/dexpreopt_arm64/dex_artjars/android/apex/ DEXPREOPT_IMAGE_DEPS_art_arm64=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex DEXPREOPT_IMAGE_DEPS_art_host_x86=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex DEXPREOPT_IMAGE_DEPS_art_host_x86_64=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex -DEXPREOPT_IMAGE_DEPS_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.vdex -DEXPREOPT_IMAGE_DEPS_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.vdex -DEXPREOPT_IMAGE_DEPS_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex -DEXPREOPT_IMAGE_DEPS_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex +DEXPREOPT_IMAGE_DEPS_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.vdex out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.vdex out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.vdex +DEXPREOPT_IMAGE_DEPS_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.vdex out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.vdex out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.vdex +DEXPREOPT_IMAGE_DEPS_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.vdex out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.vdex out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex +DEXPREOPT_IMAGE_DEPS_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.vdex out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.vdex out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex DEXPREOPT_IMAGE_DEPS_mainline_arm=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.art out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.oat out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.vdex DEXPREOPT_IMAGE_DEPS_mainline_arm64=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.art out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.oat out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.vdex DEXPREOPT_IMAGE_DEPS_mainline_host_x86=out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.art out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.oat out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.vdex @@ -1092,11 +1232,11 @@ DEXPREOPT_IMAGE_LICENSE_METADATA_mainline_arm64=out/soong/.intermediates/framewo DEXPREOPT_IMAGE_LICENSE_METADATA_mainline_host_x86=out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/meta_lic DEXPREOPT_IMAGE_LICENSE_METADATA_mainline_host_x86_64=out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/meta_lic DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICEart=/apex/art_boot_images/javalib/boot.art -DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICEboot=/apex/art_boot_images/javalib/boot.art:/system/framework/boot-framework.art -DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICEmainline=/apex/art_boot_images/javalib/boot.art:/system/framework/boot-framework.art:/system/framework/boot-framework-foo.art +DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICEboot=/system/framework/boot.art +DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICEmainline=/system/framework/boot.art:/system/framework/boot-framework-foo.art DEXPREOPT_IMAGE_LOCATIONS_ON_HOSTart=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/boot.art -DEXPREOPT_IMAGE_LOCATIONS_ON_HOSTboot=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/boot.art:out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/boot-framework.art -DEXPREOPT_IMAGE_LOCATIONS_ON_HOSTmainline=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/boot.art:out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/boot-framework.art:out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/boot-framework-foo.art +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_LICENSE_METADATA=out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/meta_lic @@ -1104,10 +1244,10 @@ DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_art_arm=out/soong/dexpreopt_arm64/dex 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 DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_art_host_x86=out/soong/dexpreopt_arm64/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat:/apex/art_boot_images/javalib/x86/boot.oat out/soong/dexpreopt_arm64/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat:/apex/art_boot_images/javalib/x86/boot-core2.oat DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_art_host_x86_64=out/soong/dexpreopt_arm64/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat:/apex/art_boot_images/javalib/x86_64/boot.oat out/soong/dexpreopt_arm64/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat:/apex/art_boot_images/javalib/x86_64/boot-core2.oat -DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm/boot-framework.oat:/system/framework/arm/boot-framework.oat -DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-framework.oat:/system/framework/arm64/boot-framework.oat -DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86/boot-framework.oat:/system/framework/x86/boot-framework.oat -DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86_64/boot-framework.oat:/system/framework/x86_64/boot-framework.oat +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm/boot.oat:/system/framework/arm/boot.oat out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm/boot-core2.oat:/system/framework/arm/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm/boot-framework.oat:/system/framework/arm/boot-framework.oat +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot.oat:/system/framework/arm64/boot.oat out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-core2.oat:/system/framework/arm64/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-framework.oat:/system/framework/arm64/boot-framework.oat +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86/boot.oat:/system/framework/x86/boot.oat out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86/boot-core2.oat:/system/framework/x86/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86/boot-framework.oat:/system/framework/x86/boot-framework.oat +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86_64/boot.oat:/system/framework/x86_64/boot.oat out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86_64/boot-core2.oat:/system/framework/x86_64/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86_64/boot-framework.oat:/system/framework/x86_64/boot-framework.oat DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_mainline_arm=out/soong/dexpreopt_arm64/dex_mainlinejars_unstripped/android/system/framework/arm/boot-framework-foo.oat:/system/framework/arm/boot-framework-foo.oat DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_mainline_arm64=out/soong/dexpreopt_arm64/dex_mainlinejars_unstripped/android/system/framework/arm64/boot-framework-foo.oat:/system/framework/arm64/boot-framework-foo.oat DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_mainline_host_x86=out/soong/dexpreopt_arm64/dex_mainlinejars_unstripped/linux_glibc/system/framework/x86/boot-framework-foo.oat:/system/framework/x86/boot-framework-foo.oat @@ -1116,10 +1256,10 @@ DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_art_arm=out/soong/dexpreopt_arm64/dex_artja DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_art_arm64=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex:/apex/art_boot_images/javalib/arm64/boot.vdex out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex:/apex/art_boot_images/javalib/arm64/boot-core2.vdex DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_art_host_x86=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex:/apex/art_boot_images/javalib/x86/boot.vdex out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex:/apex/art_boot_images/javalib/x86/boot-core2.vdex DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_art_host_x86_64=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex:/apex/art_boot_images/javalib/x86_64/boot.vdex out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex:/apex/art_boot_images/javalib/x86_64/boot-core2.vdex -DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.vdex:/system/framework/arm/boot-framework.vdex -DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.vdex:/system/framework/arm64/boot-framework.vdex -DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex:/system/framework/x86/boot-framework.vdex -DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex:/system/framework/x86_64/boot-framework.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.vdex:/system/framework/arm/boot.vdex out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.vdex:/system/framework/arm/boot-core2.vdex out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.vdex:/system/framework/arm/boot-framework.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.vdex:/system/framework/arm64/boot.vdex out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.vdex:/system/framework/arm64/boot-core2.vdex out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.vdex:/system/framework/arm64/boot-framework.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.vdex:/system/framework/x86/boot.vdex out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.vdex:/system/framework/x86/boot-core2.vdex out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex:/system/framework/x86/boot-framework.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.vdex:/system/framework/x86_64/boot.vdex out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.vdex:/system/framework/x86_64/boot-core2.vdex out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex:/system/framework/x86_64/boot-framework.vdex DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_mainline_arm=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.vdex:/system/framework/arm/boot-framework-foo.vdex DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_mainline_arm64=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.vdex:/system/framework/arm64/boot-framework-foo.vdex DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_mainline_host_x86=out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.vdex:/system/framework/x86/boot-framework-foo.vdex @@ -1131,10 +1271,10 @@ DEXPREOPT_IMAGE_art_arm=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_b DEXPREOPT_IMAGE_art_arm64=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art DEXPREOPT_IMAGE_art_host_x86=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art DEXPREOPT_IMAGE_art_host_x86_64=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art -DEXPREOPT_IMAGE_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art -DEXPREOPT_IMAGE_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art -DEXPREOPT_IMAGE_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art -DEXPREOPT_IMAGE_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art +DEXPREOPT_IMAGE_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.art +DEXPREOPT_IMAGE_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art +DEXPREOPT_IMAGE_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.art +DEXPREOPT_IMAGE_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.art DEXPREOPT_IMAGE_mainline_arm=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.art DEXPREOPT_IMAGE_mainline_arm64=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.art DEXPREOPT_IMAGE_mainline_host_x86=out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.art diff --git a/java/platform_bootclasspath.go b/java/platform_bootclasspath.go index d5779f75b..07fb92cfe 100644 --- a/java/platform_bootclasspath.go +++ b/java/platform_bootclasspath.go @@ -129,8 +129,7 @@ func (b *platformBootclasspathModule) BootclasspathDepsMutator(ctx android.Botto // Add dependencies on all the non-updatable module configured in the "boot" boot image. That does // not include modules configured in the "art" boot image. - bootImageConfig := defaultBootImageConfig(ctx) - addDependenciesOntoBootImageModules(ctx, bootImageConfig.modules, platformBootclasspathBootJarDepTag) + addDependenciesOntoBootImageModules(ctx, b.platformJars(ctx), platformBootclasspathBootJarDepTag) // Add dependencies on all the apex jars. apexJars := dexpreopt.GetGlobalConfig(ctx).ApexBootJars @@ -187,7 +186,8 @@ func (b *platformBootclasspathModule) GenerateAndroidBuildActions(ctx android.Mo bootDexJarByModule := b.generateHiddenAPIBuildActions(ctx, b.configuredModules, b.fragments) buildRuleForBootJarsPackageCheck(ctx, bootDexJarByModule) - b.generateBootImageBuildActions(ctx, platformModules, apexModules) + b.generateBootImageBuildActions(ctx) + b.copyApexBootJarsForAppsDexpreopt(ctx, apexModules) } // Generate classpaths.proto config @@ -200,7 +200,7 @@ func (b *platformBootclasspathModule) generateClasspathProtoBuildActions(ctx and func (b *platformBootclasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList { // Include all non APEX jars - jars := defaultBootImageConfig(ctx).modules + jars := b.platformJars(ctx) // Include jars from APEXes that don't populate their classpath proto config. remainingJars := dexpreopt.GetGlobalConfig(ctx).ApexBootJars @@ -217,6 +217,10 @@ func (b *platformBootclasspathModule) configuredJars(ctx android.ModuleContext) return jars } +func (b *platformBootclasspathModule) platformJars(ctx android.PathContext) android.ConfiguredJarList { + return defaultBootImageConfig(ctx).modules.RemoveList(artBootImageConfig(ctx).modules) +} + // checkPlatformModules ensures that the non-updatable modules supplied are not part of an // apex module. func (b *platformBootclasspathModule) checkPlatformModules(ctx android.ModuleContext, modules []android.Module) { @@ -226,7 +230,7 @@ func (b *platformBootclasspathModule) checkPlatformModules(ctx android.ModuleCon fromUpdatableApex := apexInfo.Updatable if fromUpdatableApex { // error: this jar is part of an updatable apex - ctx.ModuleErrorf("module %q from updatable apexes %q is not allowed in the framework boot image", ctx.OtherModuleName(m), apexInfo.InApexVariants) + ctx.ModuleErrorf("module %q from updatable apexes %q is not allowed in the platform bootclasspath", ctx.OtherModuleName(m), apexInfo.InApexVariants) } else { // ok: this jar is part of the platform or a non-updatable apex } @@ -396,7 +400,7 @@ func (b *platformBootclasspathModule) generateHiddenApiMakeVars(ctx android.Make } // generateBootImageBuildActions generates ninja rules related to the boot image creation. -func (b *platformBootclasspathModule) generateBootImageBuildActions(ctx android.ModuleContext, platformModules, apexModules []android.Module) { +func (b *platformBootclasspathModule) generateBootImageBuildActions(ctx android.ModuleContext) { // Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars // GenerateSingletonBuildActions method as it cannot create it for itself. dexpreopt.GetGlobalSoongConfig(ctx) @@ -408,15 +412,16 @@ func (b *platformBootclasspathModule) generateBootImageBuildActions(ctx android. frameworkBootImageConfig := defaultBootImageConfig(ctx) bootFrameworkProfileRule(ctx, frameworkBootImageConfig) - b.generateBootImage(ctx, frameworkBootImageName, platformModules) - b.generateBootImage(ctx, mainlineBootImageName, apexModules) - b.copyApexBootJarsForAppsDexpreopt(ctx, apexModules) + b.generateBootImage(ctx, frameworkBootImageName) + b.generateBootImage(ctx, mainlineBootImageName) dumpOatRules(ctx, frameworkBootImageConfig) } -func (b *platformBootclasspathModule) generateBootImage(ctx android.ModuleContext, imageName string, modules []android.Module) { +func (b *platformBootclasspathModule) generateBootImage(ctx android.ModuleContext, imageName string) { imageConfig := genBootImageConfigs(ctx)[imageName] + modules := b.getModulesForImage(ctx, imageConfig) + // Copy module dex jars to their predefined locations. bootDexJarsByModule := extractEncodedDexJarsFromModules(ctx, modules) copyBootJarsToPredefinedLocations(ctx, bootDexJarsByModule, imageConfig.dexPathsByModule) @@ -446,3 +451,26 @@ func (b *platformBootclasspathModule) copyApexBootJarsForAppsDexpreopt(ctx andro apexBootDexJarsByModule := extractEncodedDexJarsFromModules(ctx, apexModules) copyBootJarsToPredefinedLocations(ctx, apexBootDexJarsByModule, config.dexPathsByModule) } + +func (b *platformBootclasspathModule) getModulesForImage(ctx android.ModuleContext, imageConfig *bootImageConfig) []android.Module { + modules := make([]android.Module, 0, imageConfig.modules.Len()) + for i := 0; i < imageConfig.modules.Len(); i++ { + found := false + for _, module := range b.configuredModules { + name := android.RemoveOptionalPrebuiltPrefix(module.Name()) + if name == imageConfig.modules.Jar(i) { + modules = append(modules, module) + found = true + break + } + } + if !found && !ctx.Config().AllowMissingDependencies() { + ctx.ModuleErrorf( + "Boot image '%s' module '%s' not added as a dependency of platform_bootclasspath", + imageConfig.name, + imageConfig.modules.Jar(i)) + return []android.Module{} + } + } + return modules +} From 82283a3b4fb04533c4423ded979999f088575146 Mon Sep 17 00:00:00 2001 From: Justin Yun Date: Fri, 12 May 2023 15:53:06 +0900 Subject: [PATCH 150/172] VSDK: etc snapshot may have sub_dir for relative_install_path prebuilt_etc may use sub_dir property to define a relative install path. Use SubDir() to read either sub_dir or relative_install_path property. Bug: 282080219 Test: m vendor-image Merged-In: I07a21c5aeb87b403854ed32976d26e70b046b8c1 Change-Id: I07a21c5aeb87b403854ed32976d26e70b046b8c1 (cherry picked from commit 8bd3afe68c2670db7a39c7730a605d4b17c94122) --- etc/prebuilt_etc.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/etc/prebuilt_etc.go b/etc/prebuilt_etc.go index 6817dcef0..3e1bbded6 100644 --- a/etc/prebuilt_etc.go +++ b/etc/prebuilt_etc.go @@ -652,9 +652,7 @@ func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.Singleto prop := snapshot.SnapshotJsonFlags{} propOut := snapshotLibOut + ".json" prop.InitBaseSnapshotProps(m) - if m.subdirProperties.Relative_install_path != nil { - prop.RelativeInstallPath = *m.subdirProperties.Relative_install_path - } + prop.RelativeInstallPath = m.SubDir() if m.properties.Filename != nil { prop.Filename = *m.properties.Filename From 74ac376769275b97d6878025856104944acc32d1 Mon Sep 17 00:00:00 2001 From: Chris Parsons Date: Wed, 10 May 2023 21:10:08 +0000 Subject: [PATCH 151/172] Touch soong_build output at the end of main This fixes an incrementality bug that resulted in superfluous build.ninja regeneration after a new glob definition is added. (cherry picked from https://android-review.git.corp.google.com/c/platform/build/soong/+/2585669) Fixes: 279674820 Test: Treehugger Test; New integration test in this CL Merged-In: Ifefe66a0eb1c125e9ad5373d60437a1cb1e6fdec Change-Id: Ifefe66a0eb1c125e9ad5373d60437a1cb1e6fdec --- cmd/soong_build/main.go | 15 ++++++++------- tests/bootstrap_test.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go index 79a5ce498..2c35d76f2 100644 --- a/cmd/soong_build/main.go +++ b/cmd/soong_build/main.go @@ -443,10 +443,16 @@ func main() { } writeMetrics(configuration, ctx.EventHandler, metricsDir) } - writeUsedEnvironmentFile(configuration, finalOutputFile) + writeUsedEnvironmentFile(configuration) + + // Touch the output file so that it's the newest file created by soong_build. + // This is necessary because, if soong_build generated any files which + // are ninja inputs to the main output file, then ninja would superfluously + // rebuild this output file on the next build invocation. + touch(shared.JoinPath(topDir, finalOutputFile)) } -func writeUsedEnvironmentFile(configuration android.Config, finalOutputFile string) { +func writeUsedEnvironmentFile(configuration android.Config) { if usedEnvFile == "" { return } @@ -465,11 +471,6 @@ func writeUsedEnvironmentFile(configuration android.Config, finalOutputFile stri } err = os.WriteFile(path, data, 0666) maybeQuit(err, "error writing used environment file '%s'", usedEnvFile) - - // Touch the output file so that it's not older than the file we just - // wrote. We can't write the environment file earlier because one an access - // new environment variables while writing it. - touch(shared.JoinPath(topDir, finalOutputFile)) } func touch(path string) { diff --git a/tests/bootstrap_test.sh b/tests/bootstrap_test.sh index fda5ca086..59352477c 100755 --- a/tests/bootstrap_test.sh +++ b/tests/bootstrap_test.sh @@ -885,4 +885,37 @@ function test_queryview_null_build() { fi } +# This test verifies that adding a new glob to a blueprint file only +# causes build.ninja to be regenerated on the *next* build, and *not* +# the build after. (This is a regression test for a bug where globs +# resulted in two successive regenerations.) +function test_new_glob_incrementality { + setup + + run_soong nothing + local -r mtime1=$(stat -c "%y" out/soong/build.ninja) + + mkdir -p globdefpkg/ + cat > globdefpkg/Android.bp <<'EOF' +filegroup { + name: "fg_with_glob", + srcs: ["*.txt"], +} +EOF + + run_soong nothing + local -r mtime2=$(stat -c "%y" out/soong/build.ninja) + + if [[ "$mtime1" == "$mtime2" ]]; then + fail "Ninja file was not regenerated, despite a new bp file" + fi + + run_soong nothing + local -r mtime3=$(stat -c "%y" out/soong/build.ninja) + + if [[ "$mtime2" != "$mtime3" ]]; then + fail "Ninja file was regenerated despite no previous bp changes" + fi +} + scan_and_run_tests From b20a12553ef65a6401dfe0f67ab8b882da0f89db Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Wed, 17 May 2023 22:51:43 +0000 Subject: [PATCH 152/172] Revert "Restrict plugins to an existing allowlist" This reverts commit 09ddb3a73e14823d51d8227ecaf1997fa010bc14. Reason for revert: breaks branches without vendor Change-Id: I2de95d7b99e4e5fd3d696f51d5b4d6a68a298365 --- android/Android.bp | 1 - android/config.go | 4 -- android/plugin.go | 139 ---------------------------------------- android/variable.go | 1 - tests/bootstrap_test.sh | 24 +++---- 5 files changed, 12 insertions(+), 157 deletions(-) delete mode 100644 android/plugin.go diff --git a/android/Android.bp b/android/Android.bp index 94d2c04f6..118087db7 100644 --- a/android/Android.bp +++ b/android/Android.bp @@ -77,7 +77,6 @@ bootstrap_go_package { "path_properties.go", "paths.go", "phony.go", - "plugin.go", "prebuilt.go", "prebuilt_build_tool.go", "proto.go", diff --git a/android/config.go b/android/config.go index e0cf173f0..7141e54c3 100644 --- a/android/config.go +++ b/android/config.go @@ -1819,10 +1819,6 @@ func (c *deviceConfig) ShippingApiLevel() ApiLevel { return uncheckedFinalApiLevel(apiLevel) } -func (c *deviceConfig) BuildBrokenPluginValidation() []string { - return c.config.productVariables.BuildBrokenPluginValidation -} - func (c *deviceConfig) BuildBrokenClangAsFlags() bool { return c.config.productVariables.BuildBrokenClangAsFlags } diff --git a/android/plugin.go b/android/plugin.go deleted file mode 100644 index 5be3d3ad8..000000000 --- a/android/plugin.go +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright 2022 Google Inc. All rights reserved. -// -// 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 android - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "os" - "strings" - - "github.com/google/blueprint" -) - -func init() { - RegisterPluginSingletonBuildComponents(InitRegistrationContext) -} - -func RegisterPluginSingletonBuildComponents(ctx RegistrationContext) { - ctx.RegisterSingletonType("plugins", pluginSingletonFactory) -} - -// pluginSingleton is a singleton to handle allowlisting of the final Android-.mk file -// output. -func pluginSingletonFactory() Singleton { - return &pluginSingleton{} -} - -type pluginSingleton struct{} - -var allowedPluginsByName = map[string]bool{ - "aidl-soong-rules": true, - "arm_compute_library_nn_driver": true, - "cuttlefish-soong-rules": true, - "gki-soong-rules": true, - "hidl-soong-rules": true, - "kernel-config-soong-rules": true, - "soong-angle-codegen": true, - "soong-api": true, - "soong-art": true, - "soong-ca-certificates": true, - "soong-clang": true, - "soong-clang-prebuilts": true, - "soong-csuite": true, - "soong-fluoride": true, - "soong-fs_config": true, - "soong-icu": true, - "soong-java-config-error_prone": true, - "soong-libchrome": true, - "soong-llvm": true, - "soong-robolectric": true, - "soong-rust-prebuilts": true, - "soong-selinux": true, - "soong-wayland-protocol-codegen": true, - "treble_report_app": true, - "treble_report_local": true, - "treble_report_module": true, - "vintf-compatibility-matrix-soong-rules": true, - "xsdc-soong-rules": true, -} - -const ( - internalPluginsPath = "vendor/google/build/soong/internal_plugins.json" -) - -type pluginProvider interface { - IsPluginFor(string) bool -} - -func maybeAddInternalPluginsToAllowlist(ctx SingletonContext) { - if path := ExistentPathForSource(ctx, internalPluginsPath); path.Valid() { - ctx.AddNinjaFileDeps(path.String()) - absPath := absolutePath(path.String()) - var moreAllowed map[string]bool - data, err := ioutil.ReadFile(absPath) - if err != nil { - ctx.Errorf("Failed to open internal plugins path %q %q", internalPluginsPath, err) - } - if err := json.Unmarshal(data, &moreAllowed); err != nil { - fmt.Fprintf(os.Stderr, "Internal plugins file %q did not parse correctly: %q", data, err) - } - for k, v := range moreAllowed { - allowedPluginsByName[k] = v - } - } -} - -func (p *pluginSingleton) GenerateBuildActions(ctx SingletonContext) { - for _, p := range ctx.DeviceConfig().BuildBrokenPluginValidation() { - allowedPluginsByName[p] = true - } - maybeAddInternalPluginsToAllowlist(ctx) - - disallowedPlugins := map[string]bool{} - ctx.VisitAllModulesBlueprint(func(module blueprint.Module) { - if ctx.ModuleType(module) != "bootstrap_go_package" { - return - } - - p, ok := module.(pluginProvider) - if !ok || !p.IsPluginFor("soong_build") { - return - } - - name := ctx.ModuleName(module) - if _, ok := allowedPluginsByName[name]; ok { - return - } - - dir := ctx.ModuleDir(module) - - // allow use of plugins within Soong to not allowlist everything - if strings.HasPrefix(dir, "build/soong") { - return - } - - // allow third party users outside of external to create new plugins, i.e. non-google paths - // under vendor or hardware - if !strings.HasPrefix(dir, "external/") && IsThirdPartyPath(dir) { - return - } - disallowedPlugins[name] = true - }) - if len(disallowedPlugins) > 0 { - ctx.Errorf("New plugins are not supported; however %q were found. Please reach out to the build team or use BUILD_BROKEN_PLUGIN_VALIDATION (see Changes.md for more info).", SortedStringKeys(disallowedPlugins)) - } -} diff --git a/android/variable.go b/android/variable.go index b5d966668..249d53b07 100644 --- a/android/variable.go +++ b/android/variable.go @@ -437,7 +437,6 @@ type productVariables struct { ShippingApiLevel *string `json:",omitempty"` - BuildBrokenPluginValidation []string `json:",omitempty"` BuildBrokenClangAsFlags bool `json:",omitempty"` BuildBrokenClangCFlags bool `json:",omitempty"` BuildBrokenClangProperty bool `json:",omitempty"` diff --git a/tests/bootstrap_test.sh b/tests/bootstrap_test.sh index c5a6336a8..fda5ca086 100755 --- a/tests/bootstrap_test.sh +++ b/tests/bootstrap_test.sh @@ -207,8 +207,8 @@ EOF function test_soong_build_rerun_iff_environment_changes() { setup - mkdir -p build/soong/cherry - cat > build/soong/cherry/Android.bp <<'EOF' + mkdir -p cherry + cat > cherry/Android.bp <<'EOF' bootstrap_go_package { name: "cherry", pkgPath: "android/soong/cherry", @@ -224,7 +224,7 @@ bootstrap_go_package { } EOF - cat > build/soong/cherry/cherry.go <<'EOF' + cat > cherry/cherry.go <<'EOF' package cherry import ( @@ -317,8 +317,8 @@ function test_add_file_to_soong_build() { run_soong local -r mtime1=$(stat -c "%y" out/soong/build.ninja) - mkdir -p vendor/foo/picard - cat > vendor/foo/picard/Android.bp <<'EOF' + mkdir -p a + cat > a/Android.bp <<'EOF' bootstrap_go_package { name: "picard-soong-rules", pkgPath: "android/soong/picard", @@ -334,7 +334,7 @@ bootstrap_go_package { } EOF - cat > vendor/foo/picard/picard.go <<'EOF' + cat > a/picard.go <<'EOF' package picard import ( @@ -390,11 +390,11 @@ EOF function test_glob_during_bootstrapping() { setup - mkdir -p build/soong/picard - cat > build/soong/picard/Android.bp <<'EOF' + mkdir -p a + cat > a/Android.bp <<'EOF' build=["foo*.bp"] EOF - cat > build/soong/picard/fooa.bp <<'EOF' + cat > a/fooa.bp <<'EOF' bootstrap_go_package { name: "picard-soong-rules", pkgPath: "android/soong/picard", @@ -410,7 +410,7 @@ bootstrap_go_package { } EOF - cat > build/soong/picard/picard.go <<'EOF' + cat > a/picard.go <<'EOF' package picard import ( @@ -459,7 +459,7 @@ EOF grep -q "Make it so" out/soong/build.ninja || fail "Original action not present" - cat > build/soong/picard/foob.bp <<'EOF' + cat > a/foob.bp <<'EOF' bootstrap_go_package { name: "worf-soong-rules", pkgPath: "android/soong/worf", @@ -476,7 +476,7 @@ bootstrap_go_package { } EOF - cat > build/soong/picard/worf.go <<'EOF' + cat > a/worf.go <<'EOF' package worf import "android/soong/picard" From d1f548a19d1058ff806a4db89f40a64a06a7f14f Mon Sep 17 00:00:00 2001 From: Zyan Wu Date: Thu, 18 May 2023 15:46:31 +0800 Subject: [PATCH 153/172] Don't panic if no certificates found Getting the first certificate will panic if there are no certificates, which can happen when AllowMissingDependencies is set and the certificate property is a module reference to a missing module. Only get the first certificate if the list is not nil. Use mainCertificate since it handles the logic already. Test: TestAppMissingCertificateAllowMissingDependencies Bug: 283102635 Merged-In: : I8b27f65aa7d071041171ad45ac52bf47fa31bf2b Change-Id: Icaaa45d48ca4edb876687c0813165d107d28ef8a --- java/app.go | 27 ++++++++++++++------------- java/app_test.go | 8 ++++++++ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/java/app.go b/java/app.go index 03e233059..706f99a83 100755 --- a/java/app.go +++ b/java/app.go @@ -563,19 +563,6 @@ func processMainCert(m android.ModuleBase, certPropValue string, certificates [] certificates = append([]Certificate{mainCert}, certificates...) } - if !m.Platform() { - certPath := certificates[0].Pem.String() - systemCertPath := ctx.Config().DefaultAppCertificateDir(ctx).String() - if strings.HasPrefix(certPath, systemCertPath) { - enforceSystemCert := ctx.Config().EnforceSystemCertificate() - allowed := ctx.Config().EnforceSystemCertificateAllowList() - - if enforceSystemCert && !inList(m.Name(), allowed) { - ctx.PropertyErrorf("certificate", "The module in product partition cannot be signed with certificate in system.") - } - } - } - if len(certificates) > 0 { mainCertificate = certificates[0] } else { @@ -591,6 +578,20 @@ func processMainCert(m android.ModuleBase, certPropValue string, certificates [] } } + if !m.Platform() { + certPath := mainCertificate.Pem.String() + systemCertPath := ctx.Config().DefaultAppCertificateDir(ctx).String() + if strings.HasPrefix(certPath, systemCertPath) { + enforceSystemCert := ctx.Config().EnforceSystemCertificate() + allowed := ctx.Config().EnforceSystemCertificateAllowList() + + if enforceSystemCert && !inList(m.Name(), allowed) { + ctx.PropertyErrorf("certificate", "The module in product partition cannot be signed with certificate in system.") + } + } + } + + return mainCertificate, certificates } diff --git a/java/app_test.go b/java/app_test.go index 7e97b0fb1..b154bc990 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -3382,6 +3382,14 @@ func TestAppMissingCertificateAllowMissingDependencies(t *testing.T) { srcs: ["a.java"], certificate: ":missing_certificate", sdk_version: "current", + } + + android_app { + name: "bar", + srcs: ["a.java"], + certificate: ":missing_certificate", + product_specific: true, + sdk_version: "current", }`) foo := result.ModuleForTests("foo", "android_common") From dfe4a9e4dd088f42ba5e0a3c4f7777c253d378d3 Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Thu, 18 May 2023 11:54:46 +0000 Subject: [PATCH 154/172] Revert "Revert "Restrict plugins to an existing allowlist"" This reverts commit b20a12553ef65a6401dfe0f67ab8b882da0f89db. Reason for revert: Rollforward with fix soong-ca-certificates-apex was missing from allowlist Test: verify fixes CI breakages Change-Id: I00687bd2962dbdaaf55189ca4aa82183264eb8d7 --- android/Android.bp | 1 + android/config.go | 4 ++ android/plugin.go | 140 ++++++++++++++++++++++++++++++++++++++++ android/variable.go | 1 + tests/bootstrap_test.sh | 24 +++---- 5 files changed, 158 insertions(+), 12 deletions(-) create mode 100644 android/plugin.go diff --git a/android/Android.bp b/android/Android.bp index 118087db7..94d2c04f6 100644 --- a/android/Android.bp +++ b/android/Android.bp @@ -77,6 +77,7 @@ bootstrap_go_package { "path_properties.go", "paths.go", "phony.go", + "plugin.go", "prebuilt.go", "prebuilt_build_tool.go", "proto.go", diff --git a/android/config.go b/android/config.go index 7141e54c3..e0cf173f0 100644 --- a/android/config.go +++ b/android/config.go @@ -1819,6 +1819,10 @@ func (c *deviceConfig) ShippingApiLevel() ApiLevel { return uncheckedFinalApiLevel(apiLevel) } +func (c *deviceConfig) BuildBrokenPluginValidation() []string { + return c.config.productVariables.BuildBrokenPluginValidation +} + func (c *deviceConfig) BuildBrokenClangAsFlags() bool { return c.config.productVariables.BuildBrokenClangAsFlags } diff --git a/android/plugin.go b/android/plugin.go new file mode 100644 index 000000000..c9d1338f8 --- /dev/null +++ b/android/plugin.go @@ -0,0 +1,140 @@ +// Copyright 2022 Google Inc. All rights reserved. +// +// 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 android + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "os" + "strings" + + "github.com/google/blueprint" +) + +func init() { + RegisterPluginSingletonBuildComponents(InitRegistrationContext) +} + +func RegisterPluginSingletonBuildComponents(ctx RegistrationContext) { + ctx.RegisterSingletonType("plugins", pluginSingletonFactory) +} + +// pluginSingleton is a singleton to handle allowlisting of the final Android-.mk file +// output. +func pluginSingletonFactory() Singleton { + return &pluginSingleton{} +} + +type pluginSingleton struct{} + +var allowedPluginsByName = map[string]bool{ + "aidl-soong-rules": true, + "arm_compute_library_nn_driver": true, + "cuttlefish-soong-rules": true, + "gki-soong-rules": true, + "hidl-soong-rules": true, + "kernel-config-soong-rules": true, + "soong-angle-codegen": true, + "soong-api": true, + "soong-art": true, + "soong-ca-certificates": true, + "soong-ca-certificates-apex": true, + "soong-clang": true, + "soong-clang-prebuilts": true, + "soong-csuite": true, + "soong-fluoride": true, + "soong-fs_config": true, + "soong-icu": true, + "soong-java-config-error_prone": true, + "soong-libchrome": true, + "soong-llvm": true, + "soong-robolectric": true, + "soong-rust-prebuilts": true, + "soong-selinux": true, + "soong-wayland-protocol-codegen": true, + "treble_report_app": true, + "treble_report_local": true, + "treble_report_module": true, + "vintf-compatibility-matrix-soong-rules": true, + "xsdc-soong-rules": true, +} + +const ( + internalPluginsPath = "vendor/google/build/soong/internal_plugins.json" +) + +type pluginProvider interface { + IsPluginFor(string) bool +} + +func maybeAddInternalPluginsToAllowlist(ctx SingletonContext) { + if path := ExistentPathForSource(ctx, internalPluginsPath); path.Valid() { + ctx.AddNinjaFileDeps(path.String()) + absPath := absolutePath(path.String()) + var moreAllowed map[string]bool + data, err := ioutil.ReadFile(absPath) + if err != nil { + ctx.Errorf("Failed to open internal plugins path %q %q", internalPluginsPath, err) + } + if err := json.Unmarshal(data, &moreAllowed); err != nil { + fmt.Fprintf(os.Stderr, "Internal plugins file %q did not parse correctly: %q", data, err) + } + for k, v := range moreAllowed { + allowedPluginsByName[k] = v + } + } +} + +func (p *pluginSingleton) GenerateBuildActions(ctx SingletonContext) { + for _, p := range ctx.DeviceConfig().BuildBrokenPluginValidation() { + allowedPluginsByName[p] = true + } + maybeAddInternalPluginsToAllowlist(ctx) + + disallowedPlugins := map[string]bool{} + ctx.VisitAllModulesBlueprint(func(module blueprint.Module) { + if ctx.ModuleType(module) != "bootstrap_go_package" { + return + } + + p, ok := module.(pluginProvider) + if !ok || !p.IsPluginFor("soong_build") { + return + } + + name := ctx.ModuleName(module) + if _, ok := allowedPluginsByName[name]; ok { + return + } + + dir := ctx.ModuleDir(module) + + // allow use of plugins within Soong to not allowlist everything + if strings.HasPrefix(dir, "build/soong") { + return + } + + // allow third party users outside of external to create new plugins, i.e. non-google paths + // under vendor or hardware + if !strings.HasPrefix(dir, "external/") && IsThirdPartyPath(dir) { + return + } + disallowedPlugins[name] = true + }) + if len(disallowedPlugins) > 0 { + ctx.Errorf("New plugins are not supported; however %q were found. Please reach out to the build team or use BUILD_BROKEN_PLUGIN_VALIDATION (see Changes.md for more info).", SortedStringKeys(disallowedPlugins)) + } +} diff --git a/android/variable.go b/android/variable.go index 249d53b07..b5d966668 100644 --- a/android/variable.go +++ b/android/variable.go @@ -437,6 +437,7 @@ type productVariables struct { ShippingApiLevel *string `json:",omitempty"` + BuildBrokenPluginValidation []string `json:",omitempty"` BuildBrokenClangAsFlags bool `json:",omitempty"` BuildBrokenClangCFlags bool `json:",omitempty"` BuildBrokenClangProperty bool `json:",omitempty"` diff --git a/tests/bootstrap_test.sh b/tests/bootstrap_test.sh index fda5ca086..c5a6336a8 100755 --- a/tests/bootstrap_test.sh +++ b/tests/bootstrap_test.sh @@ -207,8 +207,8 @@ EOF function test_soong_build_rerun_iff_environment_changes() { setup - mkdir -p cherry - cat > cherry/Android.bp <<'EOF' + mkdir -p build/soong/cherry + cat > build/soong/cherry/Android.bp <<'EOF' bootstrap_go_package { name: "cherry", pkgPath: "android/soong/cherry", @@ -224,7 +224,7 @@ bootstrap_go_package { } EOF - cat > cherry/cherry.go <<'EOF' + cat > build/soong/cherry/cherry.go <<'EOF' package cherry import ( @@ -317,8 +317,8 @@ function test_add_file_to_soong_build() { run_soong local -r mtime1=$(stat -c "%y" out/soong/build.ninja) - mkdir -p a - cat > a/Android.bp <<'EOF' + mkdir -p vendor/foo/picard + cat > vendor/foo/picard/Android.bp <<'EOF' bootstrap_go_package { name: "picard-soong-rules", pkgPath: "android/soong/picard", @@ -334,7 +334,7 @@ bootstrap_go_package { } EOF - cat > a/picard.go <<'EOF' + cat > vendor/foo/picard/picard.go <<'EOF' package picard import ( @@ -390,11 +390,11 @@ EOF function test_glob_during_bootstrapping() { setup - mkdir -p a - cat > a/Android.bp <<'EOF' + mkdir -p build/soong/picard + cat > build/soong/picard/Android.bp <<'EOF' build=["foo*.bp"] EOF - cat > a/fooa.bp <<'EOF' + cat > build/soong/picard/fooa.bp <<'EOF' bootstrap_go_package { name: "picard-soong-rules", pkgPath: "android/soong/picard", @@ -410,7 +410,7 @@ bootstrap_go_package { } EOF - cat > a/picard.go <<'EOF' + cat > build/soong/picard/picard.go <<'EOF' package picard import ( @@ -459,7 +459,7 @@ EOF grep -q "Make it so" out/soong/build.ninja || fail "Original action not present" - cat > a/foob.bp <<'EOF' + cat > build/soong/picard/foob.bp <<'EOF' bootstrap_go_package { name: "worf-soong-rules", pkgPath: "android/soong/worf", @@ -476,7 +476,7 @@ bootstrap_go_package { } EOF - cat > a/worf.go <<'EOF' + cat > build/soong/picard/worf.go <<'EOF' package worf import "android/soong/picard" From 79b9b94ea334158d194453753ca908daff6c8279 Mon Sep 17 00:00:00 2001 From: Yi Kong Date: Fri, 12 May 2023 12:12:38 +0100 Subject: [PATCH 155/172] Revert "Turn off stack protector check for noreturn calls" clang-r487747c contains upstream fix for the excessive stack protactor checks (fc4494dffa54) and checks are no longer inserted for C only code or C++ code built without exeception. The Android platform does not enable C++ exception by default, thus turning on the check should not have significant performance impact. This reverts commit ecc18df6ff68853517749c49f411070a0b8d219f. Test: presubmit Bug: 277565884 Bug: 279955553 (cherry picked from https://android-review.googlesource.com/q/commit:e9850f81531f070ac5cd193fdcd767bc91605bfe) Merged-In: I2fc5826048ba5d00cabcc8401ac40a6f54812a44 Change-Id: I2fc5826048ba5d00cabcc8401ac40a6f54812a44 --- cc/config/global.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cc/config/global.go b/cc/config/global.go index 3df739e7f..a0fe4b7a0 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -111,9 +111,6 @@ var ( // Turn off FMA which got enabled by default in clang-r445002 (http://b/218805949) "-ffp-contract=off", - - // Turn off stack protector check for noreturn calls. (http://b/264965700) - "-mllvm -disable-check-noreturn-call", } commonGlobalConlyflags = []string{} @@ -150,9 +147,6 @@ var ( commonGlobalLldflags = []string{ "-fuse-ld=lld", "-Wl,--icf=safe", - - // Turn off stack protector check for noreturn calls. (http://b/264965700) - "-Wl,-mllvm,-disable-check-noreturn-call", } deviceGlobalCppflags = []string{ From 9d307945bee607f3fa95030f2ead6cbdb19883ab Mon Sep 17 00:00:00 2001 From: Wei Li Date: Wed, 26 Apr 2023 12:15:55 -0700 Subject: [PATCH 156/172] Allowlist SBOM generation tool so it can be used in Bazel. Bug: 275472038 Test: b build //build/make/tools/sbom:generate-sbom && bazel-out/aosp_cf_x86_64_phone-userdebug_linux_x86_64-opt/bin/build/make/tools/sbom/generate-sbom (cherry picked from https://android-review.googlesource.com/q/commit:74e3e003148d202749cc79456e61f65ba1f4f25a) Merged-In: I4ad68b0613410f40c79ee24d3eef779c2ad57815 Change-Id: I4ad68b0613410f40c79ee24d3eef779c2ad57815 --- android/allowlists/allowlists.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go index e3e4dba90..63d4e11e0 100644 --- a/android/allowlists/allowlists.go +++ b/android/allowlists/allowlists.go @@ -59,7 +59,9 @@ var ( "build/bazel": Bp2BuildDefaultTrueRecursively, "build/make/target/product/security": Bp2BuildDefaultTrue, + "build/make/tools/protos": Bp2BuildDefaultTrue, "build/make/tools/releasetools": Bp2BuildDefaultTrue, + "build/make/tools/sbom": Bp2BuildDefaultTrue, "build/make/tools/signapk": Bp2BuildDefaultTrue, "build/make/tools/zipalign": Bp2BuildDefaultTrueRecursively, "build/soong": Bp2BuildDefaultTrue, @@ -1427,6 +1429,9 @@ var ( "styleprotoslite", "CtsPkgInstallerConstants", "guava-android-testlib", + + // python_test_host with test data + "sbom_writers_test", } MixedBuildsDisabledList = []string{ From 5cfedc80626829d815c8cb1d2335a5230b69f22b Mon Sep 17 00:00:00 2001 From: Wei Li Date: Thu, 4 May 2023 09:06:06 -0700 Subject: [PATCH 157/172] Export some make variables to Bazel through product variables. Bug: 275472038 Test: CIs (cherry picked from https://android-review.googlesource.com/q/commit:c642d688d6a091766536f0e02696d43e393f93e0) Merged-In: I4fdd0f989d75045644e8f2e32d1eb77543a3b9f3 Change-Id: I4fdd0f989d75045644e8f2e32d1eb77543a3b9f3 --- android/variable.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/android/variable.go b/android/variable.go index 496f523b2..aaf0606e1 100644 --- a/android/variable.go +++ b/android/variable.go @@ -469,6 +469,10 @@ type productVariables struct { SourceRootDirs []string `json:",omitempty"` AfdoProfiles []string `json:",omitempty"` + + ProductManufacturer string `json:",omitempty"` + ProductBrand string `json:",omitempty"` + BuildVersionTags []string `json:",omitempty"` } func boolPtr(v bool) *bool { From dff65b01147abe76daba97e80eee9634c0a29aa3 Mon Sep 17 00:00:00 2001 From: Wei Li Date: Fri, 5 May 2023 01:07:15 -0700 Subject: [PATCH 158/172] Change bp2build converter of module "package". 1) Use attribute name "default_package_metadata" instead of "default_applicable_licenses" in packages to better describe its use. 2) Add a filegroup "default_metadata_file" in packages to search for METADATA file in each package. 3) Include "default_metadata_file" in each package's "default_package_metadata" attribute. Bug: 275472038 Test: CIs (cherry picked from https://android-review.googlesource.com/q/commit:2c9e8d612819840020b2d110d23fb2771b6c92f0) Merged-In: I645c013c39e3190fd96c4a549d39a331aced16bd Change-Id: I645c013c39e3190fd96c4a549d39a331aced16bd --- android/filegroup.go | 3 +- android/package.go | 27 +++++++++++-- bp2build/package_conversion_test.go | 60 +++++++++++++++++++++++++++-- ui/build/finder.go | 9 +++++ ui/build/soong.go | 2 + 5 files changed, 94 insertions(+), 7 deletions(-) diff --git a/android/filegroup.go b/android/filegroup.go index 0ca5dc50e..f30ee5143 100644 --- a/android/filegroup.go +++ b/android/filegroup.go @@ -75,7 +75,8 @@ func isFilegroupWithPattern(pattern *regexp.Regexp) bazel.LabelMapper { // https://docs.bazel.build/versions/master/be/general.html#filegroup type bazelFilegroupAttributes struct { - Srcs bazel.LabelListAttribute + Srcs bazel.LabelListAttribute + Applicable_licenses bazel.LabelListAttribute } type bazelAidlLibraryAttributes struct { diff --git a/android/package.go b/android/package.go index 2bf652126..7fbc70041 100644 --- a/android/package.go +++ b/android/package.go @@ -15,6 +15,8 @@ package android import ( + "path/filepath" + "android/soong/bazel" "github.com/google/blueprint" "github.com/google/blueprint/proptools" @@ -39,8 +41,8 @@ type packageProperties struct { } type bazelPackageAttributes struct { - Default_visibility []string - Default_applicable_licenses bazel.LabelListAttribute + Default_visibility []string + Default_package_metadata bazel.LabelListAttribute } type packageModule struct { @@ -53,13 +55,32 @@ type packageModule struct { var _ Bazelable = &packageModule{} func (p *packageModule) ConvertWithBp2build(ctx TopDownMutatorContext) { + defaultPackageMetadata := bazel.MakeLabelListAttribute(BazelLabelForModuleDeps(ctx, p.properties.Default_applicable_licenses)) + // If METADATA file exists in the package, add it to package(default_package_metadata=) using a + // filegroup(name="default_metadata_file") which can be accessed later on each module in Bazel + // using attribute "applicable_licenses". + // Attribute applicable_licenses of filegroup "default_metadata_file" has to be set to [], + // otherwise Bazel reports cyclic reference error. + if existed, _, _ := ctx.Config().fs.Exists(filepath.Join(ctx.ModuleDir(), "METADATA")); existed { + ctx.CreateBazelTargetModule( + bazel.BazelTargetModuleProperties{ + Rule_class: "filegroup", + }, + CommonAttributes{Name: "default_metadata_file"}, + &bazelFilegroupAttributes{ + Srcs: bazel.MakeLabelListAttribute(BazelLabelForModuleSrc(ctx, []string{"METADATA"})), + Applicable_licenses: bazel.LabelListAttribute{Value: bazel.LabelList{Includes: []bazel.Label{}}, EmitEmptyList: true}, + }) + defaultPackageMetadata.Value.Add(&bazel.Label{Label: ":default_metadata_file"}) + } + ctx.CreateBazelTargetModule( bazel.BazelTargetModuleProperties{ Rule_class: "package", }, CommonAttributes{}, &bazelPackageAttributes{ - Default_applicable_licenses: bazel.MakeLabelListAttribute(BazelLabelForModuleDeps(ctx, p.properties.Default_applicable_licenses)), + Default_package_metadata: defaultPackageMetadata, // FIXME(asmundak): once b/221436821 is resolved Default_visibility: []string{"//visibility:public"}, }) diff --git a/bp2build/package_conversion_test.go b/bp2build/package_conversion_test.go index 3704b2d7b..ce848e42d 100644 --- a/bp2build/package_conversion_test.go +++ b/bp2build/package_conversion_test.go @@ -15,9 +15,10 @@ package bp2build import ( + "testing" + "android/soong/android" "android/soong/genrule" - "testing" ) func registerDependentModules(ctx android.RegistrationContext) { @@ -29,6 +30,7 @@ func TestPackage(t *testing.T) { tests := []struct { description string modules string + fs map[string]string expected []ExpectedRuleTarget }{ { @@ -50,8 +52,8 @@ package { "package", "", AttrNameToString{ - "default_applicable_licenses": `[":my_license"]`, - "default_visibility": `["//visibility:public"]`, + "default_package_metadata": `[":my_license"]`, + "default_visibility": `["//visibility:public"]`, }, android.HostAndDeviceDefault, }, @@ -67,6 +69,57 @@ package { }, }, }, + { + description: "package has METADATA file", + fs: map[string]string{ + "METADATA": ``, + }, + modules: ` +license { + name: "my_license", + visibility: [":__subpackages__"], + license_kinds: ["SPDX-license-identifier-Apache-2.0"], + license_text: ["NOTICE"], +} + +package { + default_applicable_licenses: ["my_license"], +} +`, + expected: []ExpectedRuleTarget{ + { + "package", + "", + AttrNameToString{ + "default_package_metadata": `[ + ":my_license", + ":default_metadata_file", + ]`, + "default_visibility": `["//visibility:public"]`, + }, + android.HostAndDeviceDefault, + }, + { + "android_license", + "my_license", + AttrNameToString{ + "license_kinds": `["SPDX-license-identifier-Apache-2.0"]`, + "license_text": `"NOTICE"`, + "visibility": `[":__subpackages__"]`, + }, + android.HostAndDeviceDefault, + }, + { + "filegroup", + "default_metadata_file", + AttrNameToString{ + "applicable_licenses": `[]`, + "srcs": `["METADATA"]`, + }, + android.HostAndDeviceDefault, + }, + }, + }, } for _, test := range tests { expected := make([]string, 0, len(test.expected)) @@ -80,6 +133,7 @@ package { ModuleTypeUnderTestFactory: android.PackageFactory, Blueprint: test.modules, ExpectedBazelTargets: expected, + Filesystem: test.fs, }) } } diff --git a/ui/build/finder.go b/ui/build/finder.go index 3f628cf7b..62079fee9 100644 --- a/ui/build/finder.go +++ b/ui/build/finder.go @@ -87,6 +87,8 @@ func NewSourceFinder(ctx Context, config Config) (f *finder.Finder) { "TEST_MAPPING", // Bazel top-level file to mark a directory as a Bazel workspace. "WORKSPACE", + // METADATA file of packages + "METADATA", }, // Bazel Starlark configuration files and all .mk files for product/board configuration. IncludeSuffixes: []string{".bzl", ".mk"}, @@ -189,6 +191,13 @@ func FindSources(ctx Context, config Config, f *finder.Finder) { ctx.Fatalf("Could not find OWNERS: %v", err) } + // Recursively look for all METADATA files. + metadataFiles := f.FindNamedAt(".", "METADATA") + err = dumpListToFile(ctx, config, metadataFiles, filepath.Join(dumpDir, "METADATA.list")) + if err != nil { + ctx.Fatalf("Could not find METADATA: %v", err) + } + // Recursively look for all TEST_MAPPING files. testMappings := f.FindNamedAt(".", "TEST_MAPPING") err = dumpListToFile(ctx, config, testMappings, filepath.Join(dumpDir, "TEST_MAPPING.list")) diff --git a/ui/build/soong.go b/ui/build/soong.go index 9287731f1..8ead4c9bb 100644 --- a/ui/build/soong.go +++ b/ui/build/soong.go @@ -397,6 +397,8 @@ func bootstrapBlueprint(ctx Context, config Config) { pbi.Inputs = append(pbi.Inputs, config.Bp2BuildFilesMarkerFile(), filepath.Join(config.FileListDir(), "bazel.list")) + case bp2buildFilesTag: + pbi.Inputs = append(pbi.Inputs, filepath.Join(config.FileListDir(), "METADATA.list")) } invocations = append(invocations, pbi) } From 19f380eb6ab5c33e788578eb17bb01110a2aeaab Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Thu, 18 May 2023 11:54:46 +0000 Subject: [PATCH 159/172] Revert "Revert "Restrict plugins to an existing allowlist"" This reverts commit b20a12553ef65a6401dfe0f67ab8b882da0f89db. Reason for revert: Rollforward with fix soong-ca-certificates-apex was missing from allowlist Test: verify fixes CI breakages (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:dfe4a9e4dd088f42ba5e0a3c4f7777c253d378d3) Merged-In: I00687bd2962dbdaaf55189ca4aa82183264eb8d7 Change-Id: I00687bd2962dbdaaf55189ca4aa82183264eb8d7 --- android/Android.bp | 1 + android/config.go | 4 ++ android/plugin.go | 140 ++++++++++++++++++++++++++++++++++++++++ android/variable.go | 1 + tests/bootstrap_test.sh | 24 +++---- 5 files changed, 158 insertions(+), 12 deletions(-) create mode 100644 android/plugin.go diff --git a/android/Android.bp b/android/Android.bp index 118087db7..94d2c04f6 100644 --- a/android/Android.bp +++ b/android/Android.bp @@ -77,6 +77,7 @@ bootstrap_go_package { "path_properties.go", "paths.go", "phony.go", + "plugin.go", "prebuilt.go", "prebuilt_build_tool.go", "proto.go", diff --git a/android/config.go b/android/config.go index 4f0a64dfe..d0f2ea44c 100644 --- a/android/config.go +++ b/android/config.go @@ -1880,6 +1880,10 @@ func (c *deviceConfig) ShippingApiLevel() ApiLevel { return uncheckedFinalApiLevel(apiLevel) } +func (c *deviceConfig) BuildBrokenPluginValidation() []string { + return c.config.productVariables.BuildBrokenPluginValidation +} + func (c *deviceConfig) BuildBrokenClangAsFlags() bool { return c.config.productVariables.BuildBrokenClangAsFlags } diff --git a/android/plugin.go b/android/plugin.go new file mode 100644 index 000000000..c9d1338f8 --- /dev/null +++ b/android/plugin.go @@ -0,0 +1,140 @@ +// Copyright 2022 Google Inc. All rights reserved. +// +// 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 android + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "os" + "strings" + + "github.com/google/blueprint" +) + +func init() { + RegisterPluginSingletonBuildComponents(InitRegistrationContext) +} + +func RegisterPluginSingletonBuildComponents(ctx RegistrationContext) { + ctx.RegisterSingletonType("plugins", pluginSingletonFactory) +} + +// pluginSingleton is a singleton to handle allowlisting of the final Android-.mk file +// output. +func pluginSingletonFactory() Singleton { + return &pluginSingleton{} +} + +type pluginSingleton struct{} + +var allowedPluginsByName = map[string]bool{ + "aidl-soong-rules": true, + "arm_compute_library_nn_driver": true, + "cuttlefish-soong-rules": true, + "gki-soong-rules": true, + "hidl-soong-rules": true, + "kernel-config-soong-rules": true, + "soong-angle-codegen": true, + "soong-api": true, + "soong-art": true, + "soong-ca-certificates": true, + "soong-ca-certificates-apex": true, + "soong-clang": true, + "soong-clang-prebuilts": true, + "soong-csuite": true, + "soong-fluoride": true, + "soong-fs_config": true, + "soong-icu": true, + "soong-java-config-error_prone": true, + "soong-libchrome": true, + "soong-llvm": true, + "soong-robolectric": true, + "soong-rust-prebuilts": true, + "soong-selinux": true, + "soong-wayland-protocol-codegen": true, + "treble_report_app": true, + "treble_report_local": true, + "treble_report_module": true, + "vintf-compatibility-matrix-soong-rules": true, + "xsdc-soong-rules": true, +} + +const ( + internalPluginsPath = "vendor/google/build/soong/internal_plugins.json" +) + +type pluginProvider interface { + IsPluginFor(string) bool +} + +func maybeAddInternalPluginsToAllowlist(ctx SingletonContext) { + if path := ExistentPathForSource(ctx, internalPluginsPath); path.Valid() { + ctx.AddNinjaFileDeps(path.String()) + absPath := absolutePath(path.String()) + var moreAllowed map[string]bool + data, err := ioutil.ReadFile(absPath) + if err != nil { + ctx.Errorf("Failed to open internal plugins path %q %q", internalPluginsPath, err) + } + if err := json.Unmarshal(data, &moreAllowed); err != nil { + fmt.Fprintf(os.Stderr, "Internal plugins file %q did not parse correctly: %q", data, err) + } + for k, v := range moreAllowed { + allowedPluginsByName[k] = v + } + } +} + +func (p *pluginSingleton) GenerateBuildActions(ctx SingletonContext) { + for _, p := range ctx.DeviceConfig().BuildBrokenPluginValidation() { + allowedPluginsByName[p] = true + } + maybeAddInternalPluginsToAllowlist(ctx) + + disallowedPlugins := map[string]bool{} + ctx.VisitAllModulesBlueprint(func(module blueprint.Module) { + if ctx.ModuleType(module) != "bootstrap_go_package" { + return + } + + p, ok := module.(pluginProvider) + if !ok || !p.IsPluginFor("soong_build") { + return + } + + name := ctx.ModuleName(module) + if _, ok := allowedPluginsByName[name]; ok { + return + } + + dir := ctx.ModuleDir(module) + + // allow use of plugins within Soong to not allowlist everything + if strings.HasPrefix(dir, "build/soong") { + return + } + + // allow third party users outside of external to create new plugins, i.e. non-google paths + // under vendor or hardware + if !strings.HasPrefix(dir, "external/") && IsThirdPartyPath(dir) { + return + } + disallowedPlugins[name] = true + }) + if len(disallowedPlugins) > 0 { + ctx.Errorf("New plugins are not supported; however %q were found. Please reach out to the build team or use BUILD_BROKEN_PLUGIN_VALIDATION (see Changes.md for more info).", SortedStringKeys(disallowedPlugins)) + } +} diff --git a/android/variable.go b/android/variable.go index 97171e7b9..40eb00675 100644 --- a/android/variable.go +++ b/android/variable.go @@ -440,6 +440,7 @@ type productVariables struct { ShippingApiLevel *string `json:",omitempty"` + BuildBrokenPluginValidation []string `json:",omitempty"` BuildBrokenClangAsFlags bool `json:",omitempty"` BuildBrokenClangCFlags bool `json:",omitempty"` BuildBrokenClangProperty bool `json:",omitempty"` diff --git a/tests/bootstrap_test.sh b/tests/bootstrap_test.sh index 59352477c..5fc05f8b1 100755 --- a/tests/bootstrap_test.sh +++ b/tests/bootstrap_test.sh @@ -207,8 +207,8 @@ EOF function test_soong_build_rerun_iff_environment_changes() { setup - mkdir -p cherry - cat > cherry/Android.bp <<'EOF' + mkdir -p build/soong/cherry + cat > build/soong/cherry/Android.bp <<'EOF' bootstrap_go_package { name: "cherry", pkgPath: "android/soong/cherry", @@ -224,7 +224,7 @@ bootstrap_go_package { } EOF - cat > cherry/cherry.go <<'EOF' + cat > build/soong/cherry/cherry.go <<'EOF' package cherry import ( @@ -317,8 +317,8 @@ function test_add_file_to_soong_build() { run_soong local -r mtime1=$(stat -c "%y" out/soong/build.ninja) - mkdir -p a - cat > a/Android.bp <<'EOF' + mkdir -p vendor/foo/picard + cat > vendor/foo/picard/Android.bp <<'EOF' bootstrap_go_package { name: "picard-soong-rules", pkgPath: "android/soong/picard", @@ -334,7 +334,7 @@ bootstrap_go_package { } EOF - cat > a/picard.go <<'EOF' + cat > vendor/foo/picard/picard.go <<'EOF' package picard import ( @@ -390,11 +390,11 @@ EOF function test_glob_during_bootstrapping() { setup - mkdir -p a - cat > a/Android.bp <<'EOF' + mkdir -p build/soong/picard + cat > build/soong/picard/Android.bp <<'EOF' build=["foo*.bp"] EOF - cat > a/fooa.bp <<'EOF' + cat > build/soong/picard/fooa.bp <<'EOF' bootstrap_go_package { name: "picard-soong-rules", pkgPath: "android/soong/picard", @@ -410,7 +410,7 @@ bootstrap_go_package { } EOF - cat > a/picard.go <<'EOF' + cat > build/soong/picard/picard.go <<'EOF' package picard import ( @@ -459,7 +459,7 @@ EOF grep -q "Make it so" out/soong/build.ninja || fail "Original action not present" - cat > a/foob.bp <<'EOF' + cat > build/soong/picard/foob.bp <<'EOF' bootstrap_go_package { name: "worf-soong-rules", pkgPath: "android/soong/worf", @@ -476,7 +476,7 @@ bootstrap_go_package { } EOF - cat > a/worf.go <<'EOF' + cat > build/soong/picard/worf.go <<'EOF' package worf import "android/soong/picard" From 9a65ff8d1ff726153bc4bae50724ba511dec9ca1 Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Thu, 11 May 2023 15:58:13 +0000 Subject: [PATCH 160/172] Revert "Make min_sdk overridable in override_apex" This reverts commit 133c55b48abe73a51efc6f7cd30b6b6e318ba6f9. Reason for revert: change was untested and not working Bug: 266945903 (cherry picked from https://android-review.googlesource.com/q/commit:bd58e746928bdfd618ba81e66a19dc42f7b15380) Merged-In: I06d6e3c439ba541ae85dc148f91b184b9731b92d Change-Id: I06d6e3c439ba541ae85dc148f91b184b9731b92d --- apex/apex.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index 7fb6f504e..c1c9e5c88 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -137,6 +137,10 @@ type apexBundleProperties struct { // List of filesystem images that are embedded inside this APEX bundle. Filesystems []string + // The minimum SDK version that this APEX must support at minimum. This is usually set to + // the SDK version that the APEX was first introduced. + Min_sdk_version *string + // Whether this APEX is considered updatable or not. When set to true, this will enforce // additional rules for making sure that the APEX is truly updatable. To be updatable, // min_sdk_version should be set as well. This will also disable the size optimizations like @@ -380,10 +384,6 @@ type overridableProperties struct { // Trim against a specific Dynamic Common Lib APEX Trim_against *string - - // The minimum SDK version that this APEX must support at minimum. This is usually set to - // the SDK version that the APEX was first introduced. - Min_sdk_version *string } type apexBundle struct { @@ -2924,7 +2924,7 @@ func (a *apexBundle) minSdkVersionValue(ctx android.EarlyModuleContext) string { // Only override the minSdkVersion value on Apexes which already specify // a min_sdk_version (it's optional for non-updatable apexes), and that its // min_sdk_version value is lower than the one to override with. - minApiLevel := minSdkVersionFromValue(ctx, proptools.String(a.overridableProperties.Min_sdk_version)) + minApiLevel := minSdkVersionFromValue(ctx, proptools.String(a.properties.Min_sdk_version)) if minApiLevel.IsNone() { return "" } @@ -3575,8 +3575,8 @@ func convertWithBp2build(a *apexBundle, ctx android.TopDownMutatorContext) (baze // TODO(b/219503907) this would need to be set to a.MinSdkVersionValue(ctx) but // given it's coming via config, we probably don't want to put it in here. var minSdkVersion bazel.StringAttribute - if a.overridableProperties.Min_sdk_version != nil { - minSdkVersion.SetValue(*a.overridableProperties.Min_sdk_version) + if a.properties.Min_sdk_version != nil { + minSdkVersion.SetValue(*a.properties.Min_sdk_version) } if props, ok := productVariableProps[minSdkVersionPropName]; ok { for c, p := range props { From de41a698f1da14ef623adaeed46fb02f084586a7 Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Thu, 27 Apr 2023 19:34:08 +0000 Subject: [PATCH 161/172] Differentiate between empty and nil input Previously, CopyOf on an empty list was returning nil. With the updates to SortedUniqueStrings and FirstUniqueStrings, we need to differentiate between empty lists and nil. Bug: 275313114 Test: m nothing (cherry picked from https://android-review.googlesource.com/q/commit:cc4da765113299fa11dcb1e651ec4ae33e6f8f9b) Merged-In: I91063ebbe5013cbda5d8f70efde4683c66581599 Change-Id: I91063ebbe5013cbda5d8f70efde4683c66581599 --- android/util.go | 6 +++++- android/util_test.go | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/android/util.go b/android/util.go index 38e0a4dbb..20d007d74 100644 --- a/android/util.go +++ b/android/util.go @@ -26,7 +26,11 @@ import ( // CopyOf returns a new slice that has the same contents as s. func CopyOf(s []string) []string { - return append([]string(nil), s...) + // If the input is nil, return nil and not an empty list + if s == nil { + return s + } + return append([]string{}, s...) } // Concat returns a new slice concatenated from the two input slices. It does not change the input diff --git a/android/util_test.go b/android/util_test.go index 5584b38f7..a2ef58958 100644 --- a/android/util_test.go +++ b/android/util_test.go @@ -381,6 +381,14 @@ func TestRemoveFromList(t *testing.T) { } } +func TestCopyOfEmptyAndNil(t *testing.T) { + emptyList := []string{} + copyOfEmptyList := CopyOf(emptyList) + AssertBoolEquals(t, "Copy of an empty list should be an empty list and not nil", true, copyOfEmptyList != nil) + copyOfNilList := CopyOf(nil) + AssertBoolEquals(t, "Copy of a nil list should be a nil list and not an empty list", true, copyOfNilList == nil) +} + func ExampleCopyOf() { a := []string{"1", "2", "3"} b := CopyOf(a) From 2050c90e2f574f9962cddc3f5532e08119520169 Mon Sep 17 00:00:00 2001 From: Jeongik Cha Date: Wed, 26 Apr 2023 21:06:24 +0900 Subject: [PATCH 162/172] BUILD_NUMBER and BUILD_HOSTNAME doesn't affect kati regeneration * Extract BUILD_NUMBER, BUILD_HOSTNAME to file to avoid kati change * Handle FILE_NAME_TAG_PLACEHOLDER string in dist in build/make/packaging/distdir.mk Ignore-AOSP-First: there are internal use cases of FILE_NAME_TAG Test: check if kati isn't invoked even though BUILD_NUMBER, BUILD_HOSTNAME is changed Test: m && m, and check if the second m is no-op Bug: 278060169 (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:1fb4ece718bd34f9c47754c14281c7ad644bb174) Merged-In: I65eefc6bb86d4076098a1bf8b317b4cb88201499 Change-Id: I65eefc6bb86d4076098a1bf8b317b4cb88201499 --- android_sdk/sdk_repo_host.go | 2 +- ui/build/kati.go | 60 +++++++++++++++++++++++++++++++----- 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/android_sdk/sdk_repo_host.go b/android_sdk/sdk_repo_host.go index 61058df09..9623a8bc4 100644 --- a/android_sdk/sdk_repo_host.go +++ b/android_sdk/sdk_repo_host.go @@ -242,7 +242,7 @@ func (s *sdkRepoHost) AndroidMk() android.AndroidMkData { fmt.Fprintln(w, ".PHONY:", name, "sdk_repo", "sdk-repo-"+name) fmt.Fprintln(w, "sdk_repo", "sdk-repo-"+name+":", strings.Join(s.FilesToInstall().Strings(), " ")) - fmt.Fprintf(w, "$(call dist-for-goals,sdk_repo sdk-repo-%s,%s:%s-$(FILE_NAME_TAG).zip)\n\n", s.BaseModuleName(), s.outputFile.String(), s.outputBaseName) + fmt.Fprintf(w, "$(call dist-for-goals,sdk_repo sdk-repo-%s,%s:%s-FILE_NAME_TAG_PLACEHOLDER.zip)\n\n", s.BaseModuleName(), s.outputFile.String(), s.outputBaseName) }, } } diff --git a/ui/build/kati.go b/ui/build/kati.go index dad68fac2..4297378b3 100644 --- a/ui/build/kati.go +++ b/ui/build/kati.go @@ -22,6 +22,7 @@ import ( "os/user" "path/filepath" "strings" + "time" "android/soong/ui/metrics" "android/soong/ui/status" @@ -66,6 +67,21 @@ func genKatiSuffix(ctx Context, config Config) { } } +func writeValueIfChanged(ctx Context, config Config, dir string, filename string, value string) { + filePath := filepath.Join(dir, filename) + previousValue := "" + rawPreviousValue, err := ioutil.ReadFile(filePath) + if err == nil { + previousValue = string(rawPreviousValue) + } + + if previousValue != value { + if err = ioutil.WriteFile(filePath, []byte(value), 0666); err != nil { + ctx.Fatalf("Failed to write: %v", err) + } + } +} + // Base function to construct and run the Kati command line with additional // arguments, and a custom function closure to mutate the environment Kati runs // in. @@ -157,28 +173,57 @@ func runKati(ctx Context, config Config, extraSuffix string, args []string, envF } cmd.Stderr = cmd.Stdout - // Apply the caller's function closure to mutate the environment variables. - envFunc(cmd.Environment) - + var username string // Pass on various build environment metadata to Kati. - if _, ok := cmd.Environment.Get("BUILD_USERNAME"); !ok { - username := "unknown" + if usernameFromEnv, ok := cmd.Environment.Get("BUILD_USERNAME"); !ok { + username = "unknown" if u, err := user.Current(); err == nil { username = u.Username } else { ctx.Println("Failed to get current user:", err) } cmd.Environment.Set("BUILD_USERNAME", username) + } else { + username = usernameFromEnv } - if _, ok := cmd.Environment.Get("BUILD_HOSTNAME"); !ok { - hostname, err := os.Hostname() + hostname, ok := cmd.Environment.Get("BUILD_HOSTNAME") + if !ok { + hostname, err = os.Hostname() if err != nil { ctx.Println("Failed to read hostname:", err) hostname = "unknown" } cmd.Environment.Set("BUILD_HOSTNAME", hostname) } + writeValueIfChanged(ctx, config, config.SoongOutDir(), "build_hostname.txt", hostname) + + // BUILD_NUMBER should be set to the source control value that + // represents the current state of the source code. E.g., a + // perforce changelist number or a git hash. Can be an arbitrary string + // (to allow for source control that uses something other than numbers), + // but must be a single word and a valid file name. + // + // If no BUILD_NUMBER is set, create a useful "I am an engineering build + // from this date/time" value. Make it start with a non-digit so that + // anyone trying to parse it as an integer will probably get "0". + cmd.Environment.Unset("HAS_BUILD_NUMBER") + buildNumber, ok := cmd.Environment.Get("BUILD_NUMBER") + if ok { + cmd.Environment.Set("HAS_BUILD_NUMBER", "true") + writeValueIfChanged(ctx, config, config.OutDir(), "file_name_tag.txt", buildNumber) + } else { + buildNumber = fmt.Sprintf("eng.%.6s.%s", username, time.Now().Format("20060102.150405" /* YYYYMMDD.HHMMSS */)) + cmd.Environment.Set("HAS_BUILD_NUMBER", "false") + writeValueIfChanged(ctx, config, config.OutDir(), "file_name_tag.txt", username) + } + // Write the build number to a file so it can be read back in + // without changing the command line every time. Avoids rebuilds + // when using ninja. + writeValueIfChanged(ctx, config, config.SoongOutDir(), "build_number.txt", buildNumber) + + // Apply the caller's function closure to mutate the environment variables. + envFunc(cmd.Environment) cmd.StartOrFatal() // Set up the ToolStatus command line reader for Kati for a consistent UI @@ -336,6 +381,7 @@ func runKatiPackage(ctx Context, config Config) { "ANDROID_BUILD_SHELL", "DIST_DIR", "OUT_DIR", + "FILE_NAME_TAG", }...) if config.Dist() { From ee84727d9578548e48607b907c0cf1bc0551bfcc Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Tue, 25 Apr 2023 18:03:54 +0000 Subject: [PATCH 163/172] Do not modify input in-place SortedUniqueStrings and FirstUniqueStrings dedupes repeating elements and returns the deduped list. Currently, it also modifies the input list in-place, which causes non-determinisitc failures like b/275313114 Operate on a copy of the input so that the input remains untouched. SortedUniqueStrings is O(NlogN) and FirstUniqueStrings is ~O(N), so creating a copy (O(N)) should not result in major performance regressions. Numbers for this single unit test: ``` go test . -run TestStubsForLibraryInMultipleApexes -v -count 1000 Before: 174s After: 172s ``` Bug: 275313114 Test: go test ./android Test: go test . -run TestStubsForLibraryInMultipleApexes -v -count 1000 (cherry picked from https://android-review.googlesource.com/q/commit:8a8714c781175f8f1a6c189d919ee8b0ee8c1e27) Merged-In: Id859723b2c2ebdc0023876c4b6fabe75d870bad7 Change-Id: Id859723b2c2ebdc0023876c4b6fabe75d870bad7 --- android/util.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/android/util.go b/android/util.go index 38e0a4dbb..fb09128f8 100644 --- a/android/util.go +++ b/android/util.go @@ -276,6 +276,8 @@ func RemoveFromList(s string, list []string) (bool, []string) { // FirstUniqueStrings returns all unique elements of a slice of strings, keeping the first copy of // each. It modifies the slice contents in place, and returns a subslice of the original slice. func FirstUniqueStrings(list []string) []string { + // Do not moodify the input in-place, operate on a copy instead. + list = CopyOf(list) // 128 was chosen based on BenchmarkFirstUniqueStrings results. if len(list) > 128 { return firstUniqueStringsMap(list) @@ -332,6 +334,7 @@ func LastUniqueStrings(list []string) []string { // SortedUniqueStrings returns what the name says func SortedUniqueStrings(list []string) []string { + // FirstUniqueStrings creates a copy of `list`, so the input remains untouched. unique := FirstUniqueStrings(list) sort.Strings(unique) return unique From db5d662663bfc3a8e8f98e2df4d8c6bbe8e0e128 Mon Sep 17 00:00:00 2001 From: Sam Delmerico Date: Thu, 20 Apr 2023 13:13:25 +0000 Subject: [PATCH 164/172] Revert "Revert "mixed builds correctly reference stubs libs"" This reverts commit 1db4348734acfd0b4a38e2ff49dca2df4bac0d84. Changes from original: - extracted function to add the current version to stub versions for bp2build. - added libc++ to mixed builds denylist Reason for revert: re-uploading with fix in topic Bug: 270408757 (cherry picked from https://android-review.googlesource.com/q/commit:75dbca2eae78bb280b50828d3c2165bda5d87ba5) Merged-In: Ifa0ed456bf8cb4a7f861d6826263adfedb4fdd9c Change-Id: Ifa0ed456bf8cb4a7f861d6826263adfedb4fdd9c --- bazel/cquery/request_type.go | 3 + bp2build/cc_library_shared_conversion_test.go | 63 +++++++++ cc/bp2build.go | 9 +- cc/cc.go | 19 ++- cc/cc_test.go | 127 ++++++++++++++++++ cc/library.go | 29 +++- 6 files changed, 235 insertions(+), 15 deletions(-) diff --git a/bazel/cquery/request_type.go b/bazel/cquery/request_type.go index bf3a6b5c6..6a3b3c82c 100644 --- a/bazel/cquery/request_type.go +++ b/bazel/cquery/request_type.go @@ -149,6 +149,7 @@ sharedLibraries = [] rootSharedLibraries = [] shared_info_tag = "//build/bazel/rules/cc:cc_library_shared.bzl%CcSharedLibraryOutputInfo" +stubs_tag = "//build/bazel/rules/cc:cc_stub_library.bzl%CcStubInfo" unstripped_tag = "//build/bazel/rules/cc:stripped_cc_common.bzl%CcUnstrippedInfo" unstripped = "" @@ -160,6 +161,8 @@ if shared_info_tag in p: unstripped = path if unstripped_tag in p: unstripped = p[unstripped_tag].unstripped.path +elif stubs_tag in p: + rootSharedLibraries.extend([f.path for f in target.files.to_list()]) else: for linker_input in linker_inputs: for library in linker_input.libraries: diff --git a/bp2build/cc_library_shared_conversion_test.go b/bp2build/cc_library_shared_conversion_test.go index cbea943e1..9ba933717 100644 --- a/bp2build/cc_library_shared_conversion_test.go +++ b/bp2build/cc_library_shared_conversion_test.go @@ -1250,3 +1250,66 @@ cc_library_shared { }, }) } + +func TestCcLibrarySharedStubsDessertVersionConversion(t *testing.T) { + runCcLibrarySharedTestCase(t, Bp2buildTestCase{ + Description: "cc_library_shared converts dessert codename versions to numerical versions", + Blueprint: ` +cc_library_shared { + name: "a", + include_build_directory: false, + stubs: { + symbol_file: "a.map.txt", + versions: [ + "Q", + "R", + "31", + ], + }, +} +cc_library_shared { + name: "b", + include_build_directory: false, + stubs: { + symbol_file: "b.map.txt", + versions: [ + "Q", + "R", + "31", + "current", + ], + }, +} +`, + ExpectedBazelTargets: []string{ + makeCcStubSuiteTargets("a", AttrNameToString{ + "soname": `"a.so"`, + "source_library_label": `"//:a"`, + "stubs_symbol_file": `"a.map.txt"`, + "stubs_versions": `[ + "29", + "30", + "31", + "current", + ]`, + }), + MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ + "stubs_symbol_file": `"a.map.txt"`, + }), + makeCcStubSuiteTargets("b", AttrNameToString{ + "soname": `"b.so"`, + "source_library_label": `"//:b"`, + "stubs_symbol_file": `"b.map.txt"`, + "stubs_versions": `[ + "29", + "30", + "31", + "current", + ]`, + }), + MakeBazelTarget("cc_library_shared", "b", AttrNameToString{ + "stubs_symbol_file": `"b.map.txt"`, + }), + }, + }) +} diff --git a/cc/bp2build.go b/cc/bp2build.go index c8f516cdc..04a18fe74 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -762,8 +762,13 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) if libraryProps, ok := archVariantLibraryProperties[axis][cfg].(*LibraryProperties); ok { if axis == bazel.NoConfigAxis { - compilerAttrs.stubsSymbolFile = libraryProps.Stubs.Symbol_file - compilerAttrs.stubsVersions.SetSelectValue(axis, cfg, libraryProps.Stubs.Versions) + if libraryProps.Stubs.Symbol_file != nil { + compilerAttrs.stubsSymbolFile = libraryProps.Stubs.Symbol_file + versions := android.CopyOf(libraryProps.Stubs.Versions) + normalizeVersions(ctx, versions) + versions = addCurrentVersionIfNotPresent(versions) + compilerAttrs.stubsVersions.SetSelectValue(axis, cfg, versions) + } } if suffix := libraryProps.Suffix; suffix != nil { compilerAttrs.suffix.SetSelectValue(axis, cfg, suffix) diff --git a/cc/cc.go b/cc/cc.go index 1997e94cd..0addb60b4 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -1964,6 +1964,17 @@ func (c *Module) ProcessBazelQueryResponse(ctx android.ModuleContext) { c.maybeInstall(mctx, apexInfo) } +func moduleContextFromAndroidModuleContext(actx android.ModuleContext, c *Module) ModuleContext { + ctx := &moduleContext{ + ModuleContext: actx, + moduleContextImpl: moduleContextImpl{ + mod: c, + }, + } + ctx.ctx = ctx + return ctx +} + func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { // Handle the case of a test module split by `test_per_src` mutator. // @@ -1983,13 +1994,7 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { c.makeLinkType = GetMakeLinkType(actx, c) - ctx := &moduleContext{ - ModuleContext: actx, - moduleContextImpl: moduleContextImpl{ - mod: c, - }, - } - ctx.ctx = ctx + ctx := moduleContextFromAndroidModuleContext(actx, c) deps := c.depsToPaths(ctx) if ctx.Failed() { diff --git a/cc/cc_test.go b/cc/cc_test.go index b986511f0..3ae4b1561 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -3680,6 +3680,133 @@ func TestStubsForLibraryInMultipleApexes(t *testing.T) { } } +func TestMixedBuildUsesStubs(t *testing.T) { + // TODO(b/275313114): Test exposes non-determinism which should be corrected and the test + // reenabled. + t.Skip() + t.Parallel() + bp := ` + cc_library_shared { + name: "libFoo", + bazel_module: { label: "//:libFoo" }, + srcs: ["foo.c"], + stubs: { + symbol_file: "foo.map.txt", + versions: ["current"], + }, + apex_available: ["bar", "a1"], + } + + cc_library_shared { + name: "libBar", + srcs: ["bar.c"], + shared_libs: ["libFoo"], + apex_available: ["a1"], + } + + cc_library_shared { + name: "libA1", + srcs: ["a1.c"], + shared_libs: ["libFoo"], + apex_available: ["a1"], + } + + cc_library_shared { + name: "libBarA1", + srcs: ["bara1.c"], + shared_libs: ["libFoo"], + apex_available: ["bar", "a1"], + } + + cc_library_shared { + name: "libAnyApex", + srcs: ["anyApex.c"], + shared_libs: ["libFoo"], + apex_available: ["//apex_available:anyapex"], + } + + cc_library_shared { + name: "libBaz", + srcs: ["baz.c"], + shared_libs: ["libFoo"], + apex_available: ["baz"], + } + + cc_library_shared { + name: "libQux", + srcs: ["qux.c"], + shared_libs: ["libFoo"], + apex_available: ["qux", "bar"], + }` + + result := android.GroupFixturePreparers( + prepareForCcTest, + android.FixtureModifyConfig(func(config android.Config) { + config.BazelContext = android.MockBazelContext{ + OutputBaseDir: "out/bazel", + LabelToCcInfo: map[string]cquery.CcInfo{ + "//:libFoo": { + RootDynamicLibraries: []string{"libFoo.so"}, + }, + "//:libFoo_stub_libs-current": { + RootDynamicLibraries: []string{"libFoo_stub_libs-current.so"}, + }, + }, + } + }), + ).RunTestWithBp(t, bp) + ctx := result.TestContext + + variants := ctx.ModuleVariantsForTests("libFoo") + expectedVariants := []string{ + "android_arm64_armv8-a_shared", + "android_arm64_armv8-a_shared_current", + "android_arm_armv7-a-neon_shared", + "android_arm_armv7-a-neon_shared_current", + } + variantsMismatch := false + if len(variants) != len(expectedVariants) { + variantsMismatch = true + } else { + for _, v := range expectedVariants { + if !inList(v, variants) { + variantsMismatch = false + } + } + } + if variantsMismatch { + t.Errorf("variants of libFoo expected:\n") + for _, v := range expectedVariants { + t.Errorf("%q\n", v) + } + t.Errorf(", but got:\n") + for _, v := range variants { + t.Errorf("%q\n", v) + } + } + + linkAgainstFoo := []string{"libBarA1"} + linkAgainstFooStubs := []string{"libBar", "libA1", "libBaz", "libQux", "libAnyApex"} + + libFooPath := "out/bazel/execroot/__main__/libFoo.so" + for _, lib := range linkAgainstFoo { + libLinkRule := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld") + libFlags := libLinkRule.Args["libFlags"] + if !strings.Contains(libFlags, libFooPath) { + t.Errorf("%q: %q is not found in %q", lib, libFooPath, libFlags) + } + } + + libFooStubPath := "out/bazel/execroot/__main__/libFoo_stub_libs-current.so" + for _, lib := range linkAgainstFooStubs { + libLinkRule := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld") + libFlags := libLinkRule.Args["libFlags"] + if !strings.Contains(libFlags, libFooStubPath) { + t.Errorf("%q: %q is not found in %q", lib, libFooStubPath, libFlags) + } + } +} + func TestVersioningMacro(t *testing.T) { t.Parallel() for _, tc := range []struct{ moduleName, expected string }{ diff --git a/cc/library.go b/cc/library.go index 172ca6459..7051f723c 100644 --- a/cc/library.go +++ b/cc/library.go @@ -931,9 +931,17 @@ func (handler *ccLibraryBazelHandler) generateSharedBazelBuildActions(ctx androi func (handler *ccLibraryBazelHandler) QueueBazelCall(ctx android.BaseModuleContext, label string) { bazelCtx := ctx.Config().BazelContext bazelCtx.QueueBazelRequest(label, cquery.GetCcInfo, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx))) + if v := handler.module.library.stubsVersion(); v != "" { + stubsLabel := label + "_stub_libs-" + v + bazelCtx.QueueBazelRequest(stubsLabel, cquery.GetCcInfo, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx))) + } } func (handler *ccLibraryBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleContext, label string) { + if v := handler.module.library.stubsVersion(); v != "" { + // if we are a stubs variant, just use the Bazel stubs target + label = label + "_stub_libs-" + v + } bazelCtx := ctx.Config().BazelContext ccInfo, err := bazelCtx.GetCcInfo(label, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx))) if err != nil { @@ -962,6 +970,9 @@ func (handler *ccLibraryBazelHandler) ProcessBazelQueryResponse(ctx android.Modu } handler.module.setAndroidMkVariablesFromCquery(ccInfo.CcAndroidMkInfo) + + cctx := moduleContextFromAndroidModuleContext(ctx, handler.module) + addStubDependencyProviders(cctx) } func (library *libraryDecorator) setFlagExporterInfoFromCcInfo(ctx android.ModuleContext, ccInfo cquery.CcInfo) { @@ -1787,6 +1798,12 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext, Target: ctx.Target(), }) + addStubDependencyProviders(ctx) + + return unstrippedOutputFile +} + +func addStubDependencyProviders(ctx ModuleContext) { stubs := ctx.GetDirectDepsWithTag(stubImplDepTag) if len(stubs) > 0 { var stubsInfo []SharedStubLibrary @@ -1801,12 +1818,9 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext, } ctx.SetProvider(SharedLibraryStubsProvider, SharedLibraryStubsInfo{ SharedStubLibraries: stubsInfo, - - IsLLNDK: ctx.IsLlndk(), + IsLLNDK: ctx.IsLlndk(), }) } - - return unstrippedOutputFile } func (library *libraryDecorator) unstrippedOutputFilePath() android.Path { @@ -2392,7 +2406,10 @@ func (library *libraryDecorator) stubsVersions(ctx android.BaseMutatorContext) [ } // Future API level is implicitly added if there isn't - vers := library.Properties.Stubs.Versions + return addCurrentVersionIfNotPresent(library.Properties.Stubs.Versions) +} + +func addCurrentVersionIfNotPresent(vers []string) []string { if inList(android.FutureApiLevel.String(), vers) { return vers } @@ -2657,7 +2674,7 @@ func LinkageMutator(mctx android.BottomUpMutatorContext) { // normalizeVersions modifies `versions` in place, so that each raw version // string becomes its normalized canonical form. // Validates that the versions in `versions` are specified in least to greatest order. -func normalizeVersions(ctx android.BaseModuleContext, versions []string) { +func normalizeVersions(ctx android.BazelConversionPathContext, versions []string) { var previous android.ApiLevel for i, v := range versions { ver, err := android.ApiLevelFromUser(ctx, v) From 3de0cb7b4ddbbb7c768b82b0a1bb3209f22597d2 Mon Sep 17 00:00:00 2001 From: Yi Kong Date: Fri, 12 May 2023 15:03:29 +0100 Subject: [PATCH 165/172] Update clang version for Rust bindgen to clang-r487747c Test: presubmit Bug: 279955553 (cherry picked from https://android-review.googlesource.com/q/commit:6974c7ec725a948a56cd8e83bff4a2cc9cf909e3) Merged-In: I9092263024b5b8dc7a1538b00f318ef0d5c29bb7 Change-Id: I9092263024b5b8dc7a1538b00f318ef0d5c29bb7 --- rust/bindgen.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/bindgen.go b/rust/bindgen.go index 13fa81e66..96645b075 100644 --- a/rust/bindgen.go +++ b/rust/bindgen.go @@ -29,7 +29,7 @@ var ( defaultBindgenFlags = []string{""} // bindgen should specify its own Clang revision so updating Clang isn't potentially blocked on bindgen failures. - bindgenClangVersion = "clang-r487747" + bindgenClangVersion = "clang-r487747c" _ = pctx.VariableFunc("bindgenClangVersion", func(ctx android.PackageVarContext) string { if override := ctx.Config().Getenv("LLVM_BINDGEN_PREBUILTS_VERSION"); override != "" { From 67c131f75f82f41fa9de2914006d68b2d1c56b26 Mon Sep 17 00:00:00 2001 From: Yu Liu Date: Mon, 1 May 2023 13:49:52 -0700 Subject: [PATCH 166/172] Fix a bug where CppFlags should have been Cppflags Bug: 284009449 Test: unit test and manual build (cherry picked from https://android-review.googlesource.com/q/commit:93893ba061e774c30a647d42e011838822153511) Merged-In: I9abb056e6b820414707247d1b19ba6aabffc26ea Change-Id: I9abb056e6b820414707247d1b19ba6aabffc26ea --- bp2build/cc_library_conversion_test.go | 40 ++++++++++++++++++++++++++ cc/bp2build.go | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go index d2c463dbb..7165ac45b 100644 --- a/bp2build/cc_library_conversion_test.go +++ b/bp2build/cc_library_conversion_test.go @@ -4350,3 +4350,43 @@ cc_library { }, }) } + +func TestCcLibraryCppFlagsInProductVariables(t *testing.T) { + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library cppflags in product variables", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcLibraryPreamble + `cc_library { + name: "a", + srcs: ["a.cpp"], + cppflags: [ + "-Wextra", + "-DDEBUG_ONLY_CODE=0", + ], + product_variables: { + eng: { + cppflags: [ + "-UDEBUG_ONLY_CODE", + "-DDEBUG_ONLY_CODE=1", + ], + }, + }, + include_build_directory: false, +} +`, + ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ + "cppflags": `[ + "-Wextra", + "-DDEBUG_ONLY_CODE=0", + ] + select({ + "//build/bazel/product_variables:eng": [ + "-UDEBUG_ONLY_CODE", + "-DDEBUG_ONLY_CODE=1", + ], + "//conditions:default": [], + })`, + "srcs": `["a.cpp"]`, + }), + }, + ) +} diff --git a/cc/bp2build.go b/cc/bp2build.go index c8f516cdc..2b92d3be5 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -517,7 +517,7 @@ func (ca *compilerAttributes) convertProductVariables(ctx android.BazelConversio productVarPropNameToAttribute := map[string]*bazel.StringListAttribute{ "Cflags": &ca.copts, "Asflags": &ca.asFlags, - "CppFlags": &ca.cppFlags, + "Cppflags": &ca.cppFlags, } for propName, attr := range productVarPropNameToAttribute { if productConfigProps, exists := productVariableProps[propName]; exists { From 9825a6c7f8a246cb9eb84a553067e68c972d8909 Mon Sep 17 00:00:00 2001 From: Yi Kong Date: Tue, 6 Jun 2023 16:17:58 +0800 Subject: [PATCH 167/172] afdo: Remove -fprofile-sample-accurate flag -fprofile-sample-accurate allows the compiler to de-optimize cold code paths according to the profile. However we have a number of micro- benchmarks that tests these paths and we often trigger regression reports from those benchmarks. Turning off the flag mitigates the issue at a cost of ~2MB increase in system image size. But the more deterministic codegen could reduce the differential OTA size. Test: presubmit Bug: 283235002 (cherry picked from https://android-review.googlesource.com/q/commit:febf8b9bdf40b086a50930901a7ccfaaa628bcba) Merged-In: I1016f573f21a60223a97c64f5818f0e7e66e41e3 Change-Id: I1016f573f21a60223a97c64f5818f0e7e66e41e3 --- cc/afdo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cc/afdo.go b/cc/afdo.go index 49f69873c..137ea97fe 100644 --- a/cc/afdo.go +++ b/cc/afdo.go @@ -34,7 +34,7 @@ var ( var afdoProfileProjectsConfigKey = android.NewOnceKey("AfdoProfileProjects") -const afdoCFlagsFormat = "-fprofile-sample-accurate -fprofile-sample-use=%s" +const afdoCFlagsFormat = "-fprofile-sample-use=%s" func recordMissingAfdoProfileFile(ctx android.BaseModuleContext, missing string) { getNamedMapForConfig(ctx.Config(), modulesMissingProfileFileKey).Store(missing, true) From 8a7dad00c2cc83d7d52b36f6684cb940066552a3 Mon Sep 17 00:00:00 2001 From: Gurpreet Singh Date: Fri, 21 Apr 2023 16:30:03 +0000 Subject: [PATCH 168/172] DO NOT MERGE Add genrule to build *.latest.version build target. Build a new target *.latest.version which will contain a text file containing the last finalized version. Bug: 242316893 Test: atest prebuilt_apis_test (cherry picked from https://android-review.googlesource.com/q/commit:daa314ac97d5ab8076113ee7f269b4e4cc3cf620) Merged-In: I41fa91c9ec273f342b7807c66c4d65ba13260124 Change-Id: I41fa91c9ec273f342b7807c66c4d65ba13260124 --- java/prebuilt_apis.go | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/java/prebuilt_apis.go b/java/prebuilt_apis.go index 944970783..c7d8999e1 100644 --- a/java/prebuilt_apis.go +++ b/java/prebuilt_apis.go @@ -135,6 +135,19 @@ func createApiModule(mctx android.LoadHookContext, name string, path string) { mctx.CreateModule(genrule.GenRuleFactory, &genruleProps) } +func createLatestApiModuleExtensionVersionFile(mctx android.LoadHookContext, name string, version string) { + genruleProps := struct { + Name *string + Srcs []string + Out []string + Cmd *string + }{} + genruleProps.Name = proptools.StringPtr(name) + genruleProps.Out = []string{name} + genruleProps.Cmd = proptools.StringPtr("echo " + version + " > $(out)") + mctx.CreateModule(genrule.GenRuleFactory, &genruleProps) +} + func createEmptyFile(mctx android.LoadHookContext, name string) { props := struct { Name *string @@ -233,9 +246,10 @@ func prebuiltApiFiles(mctx android.LoadHookContext, p *prebuiltApis) { type latestApiInfo struct { module, scope, path string version int + isExtensionApiFile bool } - getLatest := func(files []string) map[string]latestApiInfo { + getLatest := func(files []string, isExtensionApiFile bool) map[string]latestApiInfo { m := make(map[string]latestApiInfo) for _, f := range files { module, version, scope := parseFinalizedPrebuiltPath(mctx, f) @@ -245,16 +259,16 @@ func prebuiltApiFiles(mctx android.LoadHookContext, p *prebuiltApis) { key := module + "." + scope info, exists := m[key] if !exists || version > info.version { - m[key] = latestApiInfo{module, scope, f, version} + m[key] = latestApiInfo{module, scope, f, version, isExtensionApiFile} } } return m } - latest := getLatest(apiLevelFiles) + latest := getLatest(apiLevelFiles, false) if p.properties.Extensions_dir != nil { extensionApiFiles := globExtensionDirs(mctx, p, "api/*.txt") - for k, v := range getLatest(extensionApiFiles) { + for k, v := range getLatest(extensionApiFiles, true) { if v.version > mctx.Config().PlatformBaseSdkExtensionVersion() { if _, exists := latest[k]; !exists { mctx.ModuleErrorf("Module %v finalized for extension %d but never during an API level; likely error", v.module, v.version) @@ -268,6 +282,12 @@ func prebuiltApiFiles(mctx android.LoadHookContext, p *prebuiltApis) { for _, k := range android.SortedStringKeys(latest) { info := latest[k] name := PrebuiltApiModuleName(info.module, info.scope, "latest") + latestExtensionVersionModuleName := PrebuiltApiModuleName(info.module, info.scope, "latest.extension_version") + if info.isExtensionApiFile { + createLatestApiModuleExtensionVersionFile(mctx, latestExtensionVersionModuleName, strconv.Itoa(info.version)) + } else { + createLatestApiModuleExtensionVersionFile(mctx, latestExtensionVersionModuleName, "-1") + } createApiModule(mctx, name, info.path) } From dbfb42e50b358fa587f0c476e40e03b5d38391e1 Mon Sep 17 00:00:00 2001 From: Wei Li Date: Thu, 25 May 2023 16:29:20 -0700 Subject: [PATCH 169/172] Exclude diffs caught by sbom_test. Bug: 284279034 Test: build/soong/tests/sbom_test.sh (cherry picked from https://android-review.googlesource.com/q/commit:704146094a262f1f7e99ee8606469834ec142a34) (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:92275ff913c6d41d6e85f5f622735df69bb9ad5f) Merged-In: I152c2e2c55b6547b2dddf7b1b2524681c9af952e Change-Id: I152c2e2c55b6547b2dddf7b1b2524681c9af952e --- tests/sbom_test.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/sbom_test.sh b/tests/sbom_test.sh index 2f154cde5..94fe51d2d 100755 --- a/tests/sbom_test.sh +++ b/tests/sbom_test.sh @@ -90,10 +90,12 @@ diff_excludes[system]=\ -I /system/lib64/android.hardware.security.sharedsecret-V1-ndk.so \ -I /system/lib64/android.security.compat-ndk.so \ -I /system/lib64/libkeymaster4_1support.so \ + -I /system/lib64/libkeymaster4support.so \ -I /system/lib64/libkeymint.so \ -I /system/lib64/libkeystore2_aaid.so \ -I /system/lib64/libkeystore2_apc_compat.so \ -I /system/lib64/libkeystore2_crypto.so \ + -I /system/lib64/libkeystore-attestation-application-id.so \ -I /system/lib64/libkm_compat_service.so \ -I /system/lib64/libkm_compat.so \ -I /system/lib64/vndk-29 \ From 7e6fdb5d329febf8565b48f6b1671bf7551f15f1 Mon Sep 17 00:00:00 2001 From: Wei Li Date: Thu, 22 Jun 2023 17:52:31 -0700 Subject: [PATCH 170/172] Cleanup SBOM test script for later adding tests of generating SBOM of unbundled APKs/APEXs. Bug: 266726655 Test: build/soong/tests/sbom_test.sh (cherry picked from https://android-review.googlesource.com/q/commit:cd9948f66e9686e83cbe86d2b8ee998564caff0f) (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:1b2badc435c135e3e2c5996f4a5a352da1bb179a) Merged-In: I2bb3e8405dad716837d3004d4c6fd54ae80527c1 Change-Id: I2bb3e8405dad716837d3004d4c6fd54ae80527c1 --- tests/sbom_test.sh | 366 +++++++++++++++++++++++---------------------- 1 file changed, 188 insertions(+), 178 deletions(-) diff --git a/tests/sbom_test.sh b/tests/sbom_test.sh index 94fe51d2d..19987f204 100755 --- a/tests/sbom_test.sh +++ b/tests/sbom_test.sh @@ -23,194 +23,204 @@ if [ ! -e "build/make/core/Makefile" ]; then exit 1 fi -tmp_dir="$(mktemp -d tmp.XXXXXX)" +function setup { + tmp_dir="$(mktemp -d tmp.XXXXXX)" + trap 'cleanup "${tmp_dir}"' EXIT + echo "${tmp_dir}" +} + function cleanup { + tmp_dir="$1"; shift rm -rf "${tmp_dir}" } -trap cleanup EXIT - -out_dir=$tmp_dir -droid_target=droid - -debug=false -if [ $debug = "true" ]; then - out_dir=out - droid_target= -fi function run_soong { - TARGET_PRODUCT="aosp_cf_x86_64_phone" TARGET_BUILD_VARIANT=userdebug OUT_DIR=$out_dir \ - build/soong/soong_ui.bash --make-mode "$@" + target_product="$1";shift + out_dir="$1"; shift + targets="$1"; shift + if [ "$#" -ge 1 ]; then + apps=$1; shift + TARGET_PRODUCT="${target_product}" TARGET_BUILD_VARIANT=userdebug OUT_DIR="${out_dir}" TARGET_BUILD_UNBUNDLED=true TARGET_BUILD_APPS=$apps build/soong/soong_ui.bash --make-mode ${targets} + else + TARGET_PRODUCT="${target_product}" TARGET_BUILD_VARIANT=userdebug OUT_DIR="${out_dir}" build/soong/soong_ui.bash --make-mode ${targets} + fi } -# m droid, build sbom later in case additional dependencies might be built and included in partition images. -run_soong $droid_target dump.erofs lz4 - -product_out=$out_dir/target/product/vsoc_x86_64 -sbom_test=$product_out/sbom_test -mkdir $sbom_test -cp $product_out/*.img $sbom_test - -# m sbom -run_soong sbom - -# Generate installed file list from .img files in PRODUCT_OUT -dump_erofs=$out_dir/host/linux-x86/bin/dump.erofs -lz4=$out_dir/host/linux-x86/bin/lz4 - -declare -A diff_excludes -diff_excludes[odm]="-I /odm/lib/modules" -diff_excludes[vendor]=\ -"-I /vendor/lib64/libkeystore2_crypto.so \ - -I /vendor/lib/modules \ - -I /vendor/odm" -diff_excludes[system]=\ -"-I /bin \ - -I /bugreports \ - -I /cache \ - -I /d \ - -I /etc \ - -I /init \ - -I /odm/app \ - -I /odm/bin \ - -I /odm_dlkm/etc \ - -I /odm/etc \ - -I /odm/firmware \ - -I /odm/framework \ - -I /odm/lib \ - -I /odm/lib64 \ - -I /odm/overlay \ - -I /odm/priv-app \ - -I /odm/usr \ - -I /sdcard \ - -I /system/lib64/android.hardware.confirmationui@1.0.so \ - -I /system/lib64/android.hardware.confirmationui-V1-ndk.so \ - -I /system/lib64/android.hardware.keymaster@4.1.so \ - -I /system/lib64/android.hardware.security.rkp-V3-ndk.so \ - -I /system/lib64/android.hardware.security.sharedsecret-V1-ndk.so \ - -I /system/lib64/android.security.compat-ndk.so \ - -I /system/lib64/libkeymaster4_1support.so \ - -I /system/lib64/libkeymaster4support.so \ - -I /system/lib64/libkeymint.so \ - -I /system/lib64/libkeystore2_aaid.so \ - -I /system/lib64/libkeystore2_apc_compat.so \ - -I /system/lib64/libkeystore2_crypto.so \ - -I /system/lib64/libkeystore-attestation-application-id.so \ - -I /system/lib64/libkm_compat_service.so \ - -I /system/lib64/libkm_compat.so \ - -I /system/lib64/vndk-29 \ - -I /system/lib64/vndk-sp-29 \ - -I /system/lib/vndk-29 \ - -I /system/lib/vndk-sp-29 \ - -I /system/usr/icu \ - -I /vendor_dlkm/etc" - function diff_files { - file_list_file="$1"; shift - files_in_spdx_file="$1"; shift - partition_name="$1"; shift - exclude= - if [ -v 'diff_excludes[$partition_name]' ]; then - exclude=${diff_excludes[$partition_name]} - fi - - diff "$file_list_file" "$files_in_spdx_file" $exclude - if [ $? != "0" ]; then - echo Found diffs in $f and SBOM. - exit 1 - else - echo No diffs. - fi - } - -# Example output of dump.erofs is as below, and the data used in the test start -# at line 11. Column 1 is inode id, column 2 is inode type and column 3 is name. -# Each line is captured in variable "entry", awk is used to get type and name. -# Output of dump.erofs: -# File : / -# Size: 160 On-disk size: 160 directory -# NID: 39 Links: 10 Layout: 2 Compression ratio: 100.00% -# Inode size: 64 Extent size: 0 Xattr size: 16 -# Uid: 0 Gid: 0 Access: 0755/rwxr-xr-x -# Timestamp: 2023-02-14 01:15:54.000000000 -# -# NID TYPE FILENAME -# 39 2 . -# 39 2 .. -# 47 2 app -# 1286748 2 bin -# 1286754 2 etc -# 5304814 2 lib -# 5309056 2 lib64 -# 5309130 2 media -# 5388910 2 overlay -# 5479537 2 priv-app -EROFS_IMAGES="\ - $sbom_test/product.img \ - $sbom_test/system.img \ - $sbom_test/system_ext.img \ - $sbom_test/system_dlkm.img \ - $sbom_test/system_other.img \ - $sbom_test/odm.img \ - $sbom_test/odm_dlkm.img \ - $sbom_test/vendor.img \ - $sbom_test/vendor_dlkm.img" -for f in $EROFS_IMAGES; do - partition_name=$(basename $f | cut -d. -f1) - file_list_file="${sbom_test}/sbom-${partition_name}-files.txt" - files_in_spdx_file="${sbom_test}/sbom-${partition_name}-files-in-spdx.txt" - rm "$file_list_file" > /dev/null 2>&1 - all_dirs="/" - while [ ! -z "$all_dirs" ]; do - dir=$(echo "$all_dirs" | cut -d ' ' -f1) - all_dirs=$(echo "$all_dirs" | cut -d ' ' -f1 --complement -s) - entries=$($dump_erofs --ls --path "$dir" $f | tail -n +11) - while read -r entry; do - inode_type=$(echo $entry | awk -F ' ' '{print $2}') - name=$(echo $entry | awk -F ' ' '{print $3}') - case $inode_type in - "2") # directory - all_dirs=$(echo "$all_dirs $dir/$name" | sed 's/^\s*//') - ;; - "1"|"7") # 1: file, 7: symlink - ( - if [ "$partition_name" != "system" ]; then - # system partition is mounted to /, not to prepend partition name. - printf %s "/$partition_name" - fi - echo "$dir/$name" | sed 's#^//#/#' - ) >> "$file_list_file" - ;; - esac - done <<< "$entries" - done - sort -n -o "$file_list_file" "$file_list_file" - - grep "FileName: /${partition_name}/" $product_out/sbom.spdx | sed 's/^FileName: //' > "$files_in_spdx_file" - if [ "$partition_name" = "system" ]; then - # system partition is mounted to /, so include FileName starts with /root/ too. - grep "FileName: /root/" $product_out/sbom.spdx | sed 's/^FileName: \/root//' >> "$files_in_spdx_file" + file_list_file="$1"; shift + files_in_spdx_file="$1"; shift + partition_name="$1"; shift + exclude= + if [ -v 'diff_excludes[$partition_name]' ]; then + exclude=${diff_excludes[$partition_name]} fi - sort -n -o "$files_in_spdx_file" "$files_in_spdx_file" - echo ============ Diffing files in $f and SBOM - diff_files "$file_list_file" "$files_in_spdx_file" "$partition_name" -done + diff "$file_list_file" "$files_in_spdx_file" $exclude + if [ $? != "0" ]; then + echo Found diffs in $f and SBOM. + exit 1 + else + echo No diffs. + fi +} -RAMDISK_IMAGES="$product_out/ramdisk.img" -for f in $RAMDISK_IMAGES; do - partition_name=$(basename $f | cut -d. -f1) - file_list_file="${sbom_test}/sbom-${partition_name}-files.txt" - files_in_spdx_file="${sbom_test}/sbom-${partition_name}-files-in-spdx.txt" - # lz4 decompress $f to stdout - # cpio list all entries like ls -l - # grep filter normal files and symlinks - # awk get entry names - # sed remove partition name from entry names - $lz4 -c -d $f | cpio -tv 2>/dev/null | grep '^[-l]' | awk -F ' ' '{print $9}' | sed "s:^:/$partition_name/:" | sort -n > "$file_list_file" +function test_sbom_aosp_cf_x86_64_phone { + # Setup + out_dir="$(setup)" - grep "FileName: /${partition_name}/" $product_out/sbom.spdx | sed 's/^FileName: //' | sort -n > "$files_in_spdx_file" + # Test + # m droid, build sbom later in case additional dependencies might be built and included in partition images. + run_soong "aosp_cf_x86_64_phone" "${out_dir}" "droid dump.erofs lz4" - echo ============ Diffing files in $f and SBOM - diff_files "$file_list_file" "$files_in_spdx_file" "$partition_name" -done \ No newline at end of file + product_out=$out_dir/target/product/vsoc_x86_64 + sbom_test=$product_out/sbom_test + mkdir -p $sbom_test + cp $product_out/*.img $sbom_test + + # m sbom + run_soong "aosp_cf_x86_64_phone" "${out_dir}" sbom + + # Generate installed file list from .img files in PRODUCT_OUT + dump_erofs=$out_dir/host/linux-x86/bin/dump.erofs + lz4=$out_dir/host/linux-x86/bin/lz4 + + declare -A diff_excludes + diff_excludes[vendor]="-I /vendor/lib64/libkeystore2_crypto.so" + diff_excludes[system]="\ + -I /bin \ + -I /bugreports \ + -I /cache \ + -I /d \ + -I /etc \ + -I /init \ + -I /odm/app \ + -I /odm/bin \ + -I /odm_dlkm/etc \ + -I /odm/etc \ + -I /odm/firmware \ + -I /odm/framework \ + -I /odm/lib \ + -I /odm/lib64 \ + -I /odm/overlay \ + -I /odm/priv-app \ + -I /odm/usr \ + -I /sdcard \ + -I /system/lib64/android.hardware.confirmationui@1.0.so \ + -I /system/lib64/android.hardware.confirmationui-V1-ndk.so \ + -I /system/lib64/android.hardware.keymaster@4.1.so \ + -I /system/lib64/android.hardware.security.rkp-V3-ndk.so \ + -I /system/lib64/android.hardware.security.sharedsecret-V1-ndk.so \ + -I /system/lib64/android.security.compat-ndk.so \ + -I /system/lib64/libkeymaster4_1support.so \ + -I /system/lib64/libkeymaster4support.so \ + -I /system/lib64/libkeymint.so \ + -I /system/lib64/libkeystore2_aaid.so \ + -I /system/lib64/libkeystore2_apc_compat.so \ + -I /system/lib64/libkeystore2_crypto.so \ + -I /system/lib64/libkeystore-attestation-application-id.so \ + -I /system/lib64/libkm_compat_service.so \ + -I /system/lib64/libkm_compat.so \ + -I /system/lib64/vndk-29 \ + -I /system/lib64/vndk-sp-29 \ + -I /system/lib/vndk-29 \ + -I /system/lib/vndk-sp-29 \ + -I /system/usr/icu \ + -I /vendor_dlkm/etc" + + # Example output of dump.erofs is as below, and the data used in the test start + # at line 11. Column 1 is inode id, column 2 is inode type and column 3 is name. + # Each line is captured in variable "entry", awk is used to get type and name. + # Output of dump.erofs: + # File : / + # Size: 160 On-disk size: 160 directory + # NID: 39 Links: 10 Layout: 2 Compression ratio: 100.00% + # Inode size: 64 Extent size: 0 Xattr size: 16 + # Uid: 0 Gid: 0 Access: 0755/rwxr-xr-x + # Timestamp: 2023-02-14 01:15:54.000000000 + # + # NID TYPE FILENAME + # 39 2 . + # 39 2 .. + # 47 2 app + # 1286748 2 bin + # 1286754 2 etc + # 5304814 2 lib + # 5309056 2 lib64 + # 5309130 2 media + # 5388910 2 overlay + # 5479537 2 priv-app + EROFS_IMAGES="\ + $sbom_test/product.img \ + $sbom_test/system.img \ + $sbom_test/system_ext.img \ + $sbom_test/system_dlkm.img \ + $sbom_test/system_other.img \ + $sbom_test/odm.img \ + $sbom_test/odm_dlkm.img \ + $sbom_test/vendor.img \ + $sbom_test/vendor_dlkm.img" + for f in $EROFS_IMAGES; do + partition_name=$(basename $f | cut -d. -f1) + file_list_file="${sbom_test}/sbom-${partition_name}-files.txt" + files_in_spdx_file="${sbom_test}/sbom-${partition_name}-files-in-spdx.txt" + rm "$file_list_file" > /dev/null 2>&1 || true + all_dirs="/" + while [ ! -z "$all_dirs" ]; do + dir=$(echo "$all_dirs" | cut -d ' ' -f1) + all_dirs=$(echo "$all_dirs" | cut -d ' ' -f1 --complement -s) + entries=$($dump_erofs --ls --path "$dir" $f | tail -n +11) + while read -r entry; do + inode_type=$(echo $entry | awk -F ' ' '{print $2}') + name=$(echo $entry | awk -F ' ' '{print $3}') + case $inode_type in + "2") # directory + all_dirs=$(echo "$all_dirs $dir/$name" | sed 's/^\s*//') + ;; + "1"|"7") # 1: file, 7: symlink + ( + if [ "$partition_name" != "system" ]; then + # system partition is mounted to /, not to prepend partition name. + printf %s "/$partition_name" + fi + echo "$dir/$name" | sed 's#^//#/#' + ) >> "$file_list_file" + ;; + esac + done <<< "$entries" + done + sort -n -o "$file_list_file" "$file_list_file" + + grep "FileName: /${partition_name}/" $product_out/sbom.spdx | sed 's/^FileName: //' > "$files_in_spdx_file" + if [ "$partition_name" = "system" ]; then + # system partition is mounted to /, so include FileName starts with /root/ too. + grep "FileName: /root/" $product_out/sbom.spdx | sed 's/^FileName: \/root//' >> "$files_in_spdx_file" + fi + sort -n -o "$files_in_spdx_file" "$files_in_spdx_file" + + echo ============ Diffing files in $f and SBOM + diff_files "$file_list_file" "$files_in_spdx_file" "$partition_name" + done + + RAMDISK_IMAGES="$product_out/ramdisk.img" + for f in $RAMDISK_IMAGES; do + partition_name=$(basename $f | cut -d. -f1) + file_list_file="${sbom_test}/sbom-${partition_name}-files.txt" + files_in_spdx_file="${sbom_test}/sbom-${partition_name}-files-in-spdx.txt" + # lz4 decompress $f to stdout + # cpio list all entries like ls -l + # grep filter normal files and symlinks + # awk get entry names + # sed remove partition name from entry names + $lz4 -c -d $f | cpio -tv 2>/dev/null | grep '^[-l]' | awk -F ' ' '{print $9}' | sed "s:^:/$partition_name/:" | sort -n > "$file_list_file" + + grep "FileName: /${partition_name}/" $product_out/sbom.spdx | sed 's/^FileName: //' | sort -n > "$files_in_spdx_file" + + echo ============ Diffing files in $f and SBOM + diff_files "$file_list_file" "$files_in_spdx_file" "$partition_name" + done + + # Teardown + cleanup "${out_dir}" +} + +test_sbom_aosp_cf_x86_64_phone \ No newline at end of file From a0b85cd7316729d978973c13e9bd5ccf8073a591 Mon Sep 17 00:00:00 2001 From: Wei Li Date: Mon, 10 Jul 2023 15:50:38 -0700 Subject: [PATCH 171/172] Add integration test for m build SBOM of APEXs/APKs. Bug: 266726655 Test: build/soong/tests/sbom_test.sh (cherry picked from https://android-review.googlesource.com/q/commit:59df0ee44206557cbe18ce42117b201f4d858bee) (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:b68bfc65d82c360656adeec56efaf24775658d30) Merged-In: Id8002042f607f8e158f561ca47e0a84a8b8927e2 Change-Id: Id8002042f607f8e158f561ca47e0a84a8b8927e2 --- tests/sbom_test.sh | 63 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/tests/sbom_test.sh b/tests/sbom_test.sh index 19987f204..30a1d377f 100755 --- a/tests/sbom_test.sh +++ b/tests/sbom_test.sh @@ -223,4 +223,65 @@ function test_sbom_aosp_cf_x86_64_phone { cleanup "${out_dir}" } -test_sbom_aosp_cf_x86_64_phone \ No newline at end of file +function test_sbom_unbundled_apex { + # Setup + out_dir="$(setup)" + + # run_soong to build com.android.adbd.apex + run_soong "module_arm64" "${out_dir}" "sbom deapexer" "com.android.adbd" + + deapexer=${out_dir}/host/linux-x86/bin/deapexer + debugfs=${out_dir}/host/linux-x86/bin/debugfs_static + apex_file=${out_dir}/target/product/module_arm64/system/apex/com.android.adbd.apex + echo "============ Diffing files in $apex_file and SBOM" + set +e + # deapexer prints the list of all files and directories + # sed extracts the file/directory names + # grep removes directories + # sed removes leading ./ in file names + diff -I /system/apex/com.android.adbd.apex -I apex_manifest.pb \ + <($deapexer --debugfs_path=$debugfs list --extents ${apex_file} | sed -E 's#(.*) \[.*\]$#\1#' | grep -v "/$" | sed -E 's#^\./(.*)#\1#' | sort -n) \ + <(grep '"fileName": ' ${apex_file}.spdx.json | sed -E 's/.*"fileName": "(.*)",/\1/' | sort -n ) + + if [ $? != "0" ]; then + echo "Diffs found in $apex_file and SBOM" + exit 1 + else + echo "No diffs." + fi + set -e + + # Teardown + cleanup "${out_dir}" +} + +function test_sbom_unbundled_apk { + # Setup + out_dir="$(setup)" + + # run_soong to build Browser2.apk + run_soong "module_arm64" "${out_dir}" "sbom" "Browser2" + + sbom_file=${out_dir}/target/product/module_arm64/system/product/app/Browser2/Browser2.apk.spdx.json + echo "============ Diffing files in Browser2.apk and SBOM" + set +e + # There is only one file in SBOM of APKs + diff \ + <(echo "/system/product/app/Browser2/Browser2.apk" ) \ + <(grep '"fileName": ' ${sbom_file} | sed -E 's/.*"fileName": "(.*)",/\1/' ) + + if [ $? != "0" ]; then + echo "Diffs found in $sbom_file" + exit 1 + else + echo "No diffs." + fi + set -e + + # Teardown + cleanup "${out_dir}" +} + +test_sbom_aosp_cf_x86_64_phone +test_sbom_unbundled_apex +test_sbom_unbundled_apk \ No newline at end of file From 5623aa81e14f892a617cff588644b7cb0060eb22 Mon Sep 17 00:00:00 2001 From: Jihoon Kang Date: Thu, 21 Sep 2023 01:11:04 +0000 Subject: [PATCH 172/172] Move java_api_library modules to f/b/api/StubLibraries.bp This change was already submitted with https://android-review.git.corp.google.com/q/topic:%22revert-2713677-revert-2655262-move_java_api_libraries-JTESUMBERD-FPSEKJYXCE%22 but was never propagated to downstream. Ignore-AOSP-First: change already merged in aosp Test: m nothing --build-from-text-stub Merged-In: If66b5bba719bb389a69f2353d2218a89b2b96b90 Change-Id: Ia6867e8e4f8f57a2bbb0b763e7e11c7a6a76fdfd --- java/core-libraries/Android.bp | 54 +++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/java/core-libraries/Android.bp b/java/core-libraries/Android.bp index de9a82d09..4380f4f5c 100644 --- a/java/core-libraries/Android.bp +++ b/java/core-libraries/Android.bp @@ -55,6 +55,19 @@ java_library { ], } +java_api_library { + name: "core.current.stubs.from-text", + api_surface: "core", + api_contributions: [ + "art.module.public.api.stubs.source.api.contribution", + "conscrypt.module.public.api.stubs.source.api.contribution", + "i18n.module.public.api.stubs.source.api.contribution", + ], + libs: [ + "stub-annotations", + ], +} + java_library { name: "core.current.stubs", defaults: [ @@ -153,7 +166,6 @@ java_defaults { system_modules: "none", } - // A stubs target containing the parts of the public SDK & @SystemApi(MODULE_LIBRARIES) API // provided by the core libraries. // @@ -265,6 +277,32 @@ java_library { ], } +java_defaults { + name: "android_core_platform_stubs_current_contributions", + api_surface: "core_platform", + api_contributions: [ + "art.module.public.api.stubs.source.api.contribution", + "art.module.public.api.stubs.source.system.api.contribution", + "art.module.public.api.stubs.source.module_lib.api.contribution", + "conscrypt.module.platform.api.stubs.source.api.contribution", + "i18n.module.public.api.stubs.source.api.contribution", + ], +} + +java_api_library { + name: "legacy.core.platform.api.stubs.from-text", + api_surface: "core_platform", + defaults: [ + "android_core_platform_stubs_current_contributions", + ], + api_contributions: [ + "legacy.i18n.module.platform.api.stubs.source.api.contribution", + ], + libs: [ + "stub-annotations", + ], +} + java_library { name: "legacy.core.platform.api.stubs", visibility: core_platform_visibility, @@ -328,6 +366,20 @@ java_library { ], } +java_api_library { + name: "stable.core.platform.api.stubs.from-text", + api_surface: "core_platform", + defaults: [ + "android_core_platform_stubs_current_contributions", + ], + api_contributions: [ + "stable.i18n.module.platform.api.stubs.source.api.contribution", + ], + libs: [ + "stub-annotations", + ], +} + java_library { name: "stable.core.platform.api.stubs", visibility: core_platform_visibility,