diff --git a/Android.bp b/Android.bp index 432c7fc4f..535246e65 100644 --- a/Android.bp +++ b/Android.bp @@ -1,5 +1,8 @@ package { default_applicable_licenses: ["Android-Apache-2.0"], + default_visibility: [ + "//build/soong:__subpackages__", + ], } subdirs = [ @@ -23,6 +26,8 @@ bootstrap_go_package { srcs: [ "doc.go", ], + // Used by plugins, though probably shouldn't be. + visibility: ["//visibility:public"], } // @@ -40,6 +45,7 @@ cc_defaults { enabled: true, }, }, + defaults_visibility: ["//visibility:public"], } // @@ -51,6 +57,7 @@ kernel_headers { vendor: true, recovery_available: true, min_sdk_version: "apex_inherit", + visibility: ["//visibility:public"], } cc_genrule { @@ -75,6 +82,7 @@ cc_genrule { cmd: "$(location) -s $(out) $(in)", srcs: [":linker"], out: ["linker.s"], + visibility: ["//bionic/libc"], } cc_genrule { @@ -99,11 +107,13 @@ cc_genrule { cmd: "$(location) -T $(out) $(in)", srcs: [":linker"], out: ["linker.script"], + visibility: ["//visibility:public"], } // Instantiate the dex_bootjars singleton module. dex_bootjars { name: "dex_bootjars", + visibility: ["//visibility:public"], } // Pseudo-test that's run on checkbuilds to ensure that get_clang_version can @@ -123,6 +133,7 @@ dexpreopt_systemserver_check { // container for apex_contributions selected using build flags all_apex_contributions { name: "all_apex_contributions", + visibility: ["//visibility:public"], } product_config { diff --git a/aidl_library/Android.bp b/aidl_library/Android.bp index ec2150427..07472a492 100644 --- a/aidl_library/Android.bp +++ b/aidl_library/Android.bp @@ -29,4 +29,5 @@ bootstrap_go_package { "aidl_library_test.go", ], pluginFor: ["soong_build"], + visibility: ["//visibility:public"], } diff --git a/android/Android.bp b/android/Android.bp index 9f3400c6e..2adedfea7 100644 --- a/android/Android.bp +++ b/android/Android.bp @@ -155,4 +155,6 @@ bootstrap_go_package { "vintf_fragment_test.go", "visibility_test.go", ], + // Used by plugins + visibility: ["//visibility:public"], } diff --git a/android/init.go b/android/init.go index d5b486b10..b46229282 100644 --- a/android/init.go +++ b/android/init.go @@ -18,5 +18,6 @@ import "encoding/gob" func init() { gob.Register(ModuleOutPath{}) + gob.Register(PhonyPath{}) gob.Register(unstableInfo{}) } diff --git a/android/team_proto/Android.bp b/android/team_proto/Android.bp index 7e2a4c137..5faaaf10e 100644 --- a/android/team_proto/Android.bp +++ b/android/team_proto/Android.bp @@ -40,4 +40,8 @@ python_library_host { proto: { canonical_path_from_root: false, }, + visibility: [ + "//build/soong:__subpackages__", + "//tools/asuite/team_build_scripts", + ], } diff --git a/apex/Android.bp b/apex/Android.bp index ef2f75570..4848513f2 100644 --- a/apex/Android.bp +++ b/apex/Android.bp @@ -42,4 +42,6 @@ bootstrap_go_package { "systemserver_classpath_fragment_test.go", ], pluginFor: ["soong_build"], + // Used by plugins + visibility: ["//visibility:public"], } diff --git a/apex/apex_test.go b/apex/apex_test.go index 08ac20bf2..acb598fee 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -4885,236 +4885,6 @@ type moduleErrorfTestCtx struct { func (ctx moduleErrorfTestCtx) ModuleErrorf(format string, args ...interface{}) { } -// These tests verify that the prebuilt_apex/deapexer to java_import wiring allows for the -// propagation of paths to dex implementation jars from the former to the latter. -func TestPrebuiltExportDexImplementationJars(t *testing.T) { - transform := android.NullFixturePreparer - - checkDexJarBuildPath := func(t *testing.T, ctx *android.TestContext, name string) { - t.Helper() - // Make sure the import has been given the correct path to the dex jar. - p := ctx.ModuleForTests(name, "android_common_myapex").Module().(java.UsesLibraryDependency) - dexJarBuildPath := p.DexJarBuildPath(moduleErrorfTestCtx{}).PathOrNil() - stem := android.RemoveOptionalPrebuiltPrefix(name) - android.AssertStringEquals(t, "DexJarBuildPath should be apex-related path.", - ".intermediates/prebuilt_myapex.deapexer/android_common/deapexer/javalib/"+stem+".jar", - android.NormalizePathForTesting(dexJarBuildPath)) - } - - checkDexJarInstallPath := func(t *testing.T, ctx *android.TestContext, name string) { - t.Helper() - // Make sure the import has been given the correct path to the dex jar. - p := ctx.ModuleForTests(name, "android_common_myapex").Module().(java.UsesLibraryDependency) - dexJarBuildPath := p.DexJarInstallPath() - stem := android.RemoveOptionalPrebuiltPrefix(name) - android.AssertStringEquals(t, "DexJarInstallPath should be apex-related path.", - "target/product/test_device/apex/myapex/javalib/"+stem+".jar", - android.NormalizePathForTesting(dexJarBuildPath)) - } - - ensureNoSourceVariant := func(t *testing.T, ctx *android.TestContext, name string) { - t.Helper() - // Make sure that an apex variant is not created for the source module. - android.AssertArrayString(t, "Check if there is no source variant", - []string{"android_common"}, - ctx.ModuleVariantsForTests(name)) - } - - t.Run("prebuilt only", func(t *testing.T) { - bp := ` - prebuilt_apex { - name: "myapex", - arch: { - arm64: { - src: "myapex-arm64.apex", - }, - arm: { - src: "myapex-arm.apex", - }, - }, - exported_java_libs: ["libfoo", "libbar"], - } - - java_import { - name: "libfoo", - jars: ["libfoo.jar"], - sdk_version: "core_current", - } - - java_sdk_library_import { - name: "libbar", - public: { - jars: ["libbar.jar"], - }, - } - ` - - // Make sure that dexpreopt can access dex implementation files from the prebuilt. - ctx := testDexpreoptWithApexes(t, bp, "", transform) - - deapexerName := deapexerModuleName("prebuilt_myapex") - android.AssertStringEquals(t, "APEX module name from deapexer name", "prebuilt_myapex", apexModuleName(deapexerName)) - - // Make sure that the deapexer has the correct input APEX. - deapexer := ctx.ModuleForTests(deapexerName, "android_common") - rule := deapexer.Rule("deapexer") - if expected, actual := []string{"myapex-arm64.apex"}, android.NormalizePathsForTesting(rule.Implicits); !reflect.DeepEqual(expected, actual) { - t.Errorf("expected: %q, found: %q", expected, actual) - } - - // Make sure that the prebuilt_apex has the correct input APEX. - prebuiltApex := ctx.ModuleForTests("myapex", "android_common_myapex") - rule = prebuiltApex.Rule("android/soong/android.Cp") - if expected, actual := "myapex-arm64.apex", android.NormalizePathForTesting(rule.Input); !reflect.DeepEqual(expected, actual) { - t.Errorf("expected: %q, found: %q", expected, actual) - } - - checkDexJarBuildPath(t, ctx, "libfoo") - checkDexJarInstallPath(t, ctx, "libfoo") - - checkDexJarBuildPath(t, ctx, "libbar") - checkDexJarInstallPath(t, ctx, "libbar") - }) - - t.Run("prebuilt with source preferred", func(t *testing.T) { - - bp := ` - apex { - name: "myapex", - key: "myapex.key", - updatable: false, - java_libs: [ - "libfoo", - "libbar", - ], - } - - apex_key { - name: "myapex.key", - public_key: "testkey.avbpubkey", - private_key: "testkey.pem", - } - - prebuilt_apex { - name: "myapex", - arch: { - arm64: { - src: "myapex-arm64.apex", - }, - arm: { - src: "myapex-arm.apex", - }, - }, - exported_java_libs: ["libfoo", "libbar"], - } - - java_import { - name: "libfoo", - jars: ["libfoo.jar"], - apex_available: [ - "myapex", - ], - compile_dex: true, - sdk_version: "core_current", - } - - java_library { - name: "libfoo", - srcs: ["foo/bar/MyClass.java"], - apex_available: [ - "myapex", - ], - compile_dex: true, - sdk_version: "core_current", - } - - java_sdk_library_import { - name: "libbar", - public: { - jars: ["libbar.jar"], - }, - apex_available: [ - "myapex", - ], - compile_dex: true, - } - - java_sdk_library { - name: "libbar", - srcs: ["foo/bar/MyClass.java"], - unsafe_ignore_missing_latest_api: true, - apex_available: [ - "myapex", - ], - compile_dex: true, - sdk_version: "core_current", - } - ` - - // Make sure that dexpreopt can access dex implementation files from the prebuilt. - ctx := testDexpreoptWithApexes(t, bp, "", transform) - - checkDexJarBuildPath(t, ctx, "prebuilt_libfoo") - checkDexJarInstallPath(t, ctx, "prebuilt_libfoo") - - checkDexJarBuildPath(t, ctx, "prebuilt_libbar") - checkDexJarInstallPath(t, ctx, "prebuilt_libbar") - }) - - t.Run("prebuilt preferred with source", func(t *testing.T) { - bp := ` - prebuilt_apex { - name: "myapex", - arch: { - arm64: { - src: "myapex-arm64.apex", - }, - arm: { - src: "myapex-arm.apex", - }, - }, - exported_java_libs: ["libfoo", "libbar"], - } - - java_import { - name: "libfoo", - prefer: true, - jars: ["libfoo.jar"], - } - - java_library { - name: "libfoo", - sdk_version: "core_current", - } - - java_sdk_library_import { - name: "libbar", - prefer: true, - public: { - jars: ["libbar.jar"], - }, - } - - java_sdk_library { - name: "libbar", - srcs: ["foo/bar/MyClass.java"], - unsafe_ignore_missing_latest_api: true, - } - ` - - // Make sure that dexpreopt can access dex implementation files from the prebuilt. - ctx := testDexpreoptWithApexes(t, bp, "", transform) - - checkDexJarBuildPath(t, ctx, "prebuilt_libfoo") - checkDexJarInstallPath(t, ctx, "prebuilt_libfoo") - ensureNoSourceVariant(t, ctx, "libfoo") - - checkDexJarBuildPath(t, ctx, "prebuilt_libbar") - checkDexJarInstallPath(t, ctx, "prebuilt_libbar") - ensureNoSourceVariant(t, ctx, "libbar") - }) -} - func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { preparer := android.GroupFixturePreparers( java.FixtureConfigureApexBootJars("myapex:libfoo", "myapex:libbar"), @@ -5243,18 +5013,10 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { apex_set { name: "myapex", set: "myapex.apks", - exported_java_libs: ["myjavalib"], exported_bootclasspath_fragments: ["my-bootclasspath-fragment"], exported_systemserverclasspath_fragments: ["my-systemserverclasspath-fragment"], } - java_import { - name: "myjavalib", - jars: ["myjavalib.jar"], - apex_available: ["myapex"], - permitted_packages: ["javalib"], - } - prebuilt_bootclasspath_fragment { name: "my-bootclasspath-fragment", contents: ["libfoo", "libbar"], @@ -9617,42 +9379,6 @@ func TestAndroidMk_DexpreoptBuiltInstalledForApex(t *testing.T) { ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES := foo.myapex foo-dexpreopt-arm64-apex@myapex@javalib@foo.jar@classes.odex foo-dexpreopt-arm64-apex@myapex@javalib@foo.jar@classes.vdex\n") } -func TestAndroidMk_DexpreoptBuiltInstalledForApex_Prebuilt(t *testing.T) { - ctx := testApex(t, ` - prebuilt_apex { - name: "myapex", - arch: { - arm64: { - src: "myapex-arm64.apex", - }, - arm: { - src: "myapex-arm.apex", - }, - }, - exported_java_libs: ["foo"], - } - - java_import { - name: "foo", - jars: ["foo.jar"], - apex_available: ["myapex"], - } - `, - dexpreopt.FixtureSetApexSystemServerJars("myapex:foo"), - ) - - prebuilt := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*Prebuilt) - entriesList := android.AndroidMkEntriesForTest(t, ctx, prebuilt) - mainModuleEntries := entriesList[0] - android.AssertArrayString(t, - "LOCAL_REQUIRED_MODULES", - mainModuleEntries.EntryMap["LOCAL_REQUIRED_MODULES"], - []string{ - "foo-dexpreopt-arm64-apex@myapex@javalib@foo.jar@classes.odex", - "foo-dexpreopt-arm64-apex@myapex@javalib@foo.jar@classes.vdex", - }) -} - func TestAndroidMk_RequiredModules(t *testing.T) { ctx := testApex(t, ` apex { @@ -11929,3 +11655,110 @@ func TestPrebuiltStubNoinstall(t *testing.T) { ) }) } + +func TestSdkLibraryTransitiveClassLoaderContext(t *testing.T) { + // This test case tests that listing the impl lib instead of the top level java_sdk_library + // in libs of android_app and java_library does not lead to class loader context device/host + // path mismatch errors. + android.GroupFixturePreparers( + prepareForApexTest, + android.PrepareForIntegrationTestWithAndroid, + PrepareForTestWithApexBuildComponents, + android.FixtureModifyEnv(func(env map[string]string) { + env["DISABLE_CONTAINER_CHECK"] = "true" + }), + withFiles(filesForSdkLibrary), + android.FixtureMergeMockFs(android.MockFS{ + "system/sepolicy/apex/com.android.foo30-file_contexts": nil, + }), + ).RunTestWithBp(t, ` + apex { + name: "com.android.foo30", + key: "myapex.key", + updatable: true, + bootclasspath_fragments: [ + "foo-bootclasspath-fragment", + ], + java_libs: [ + "bar", + ], + apps: [ + "bar-app", + ], + min_sdk_version: "30", + } + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + bootclasspath_fragment { + name: "foo-bootclasspath-fragment", + contents: [ + "framework-foo", + ], + apex_available: [ + "com.android.foo30", + ], + hidden_api: { + split_packages: ["*"] + }, + } + + java_sdk_library { + name: "framework-foo", + srcs: [ + "A.java" + ], + unsafe_ignore_missing_latest_api: true, + apex_available: [ + "com.android.foo30", + ], + compile_dex: true, + sdk_version: "core_current", + shared_library: false, + } + + java_library { + name: "bar", + srcs: [ + "A.java" + ], + libs: [ + "framework-foo.impl", + ], + apex_available: [ + "com.android.foo30", + ], + sdk_version: "core_current", + } + + java_library { + name: "baz", + srcs: [ + "A.java" + ], + libs: [ + "bar", + ], + sdk_version: "core_current", + } + + android_app { + name: "bar-app", + srcs: [ + "A.java" + ], + libs: [ + "baz", + "framework-foo.impl", + ], + apex_available: [ + "com.android.foo30", + ], + sdk_version: "core_current", + min_sdk_version: "30", + manifest: "AndroidManifest.xml", + } + `) +} diff --git a/apex/prebuilt.go b/apex/prebuilt.go index 792b57188..f6f3efbfb 100644 --- a/apex/prebuilt.go +++ b/apex/prebuilt.go @@ -107,11 +107,6 @@ type PrebuiltCommonProperties struct { // from PRODUCT_PACKAGES. Overrides []string - // List of java libraries that are embedded inside this prebuilt APEX bundle and for which this - // APEX bundle will create an APEX variant and provide dex implementation jars for use by - // dexpreopt and boot jars package check. - Exported_java_libs []string - // List of bootclasspath fragments inside this prebuilt APEX bundle and for which this APEX // bundle will create an APEX variant. Exported_bootclasspath_fragments []string @@ -283,8 +278,7 @@ func prebuiltApexModuleCreatorMutator(ctx android.BottomUpMutatorContext) { } func (p *prebuiltCommon) hasExportedDeps() bool { - return len(p.prebuiltCommonProperties.Exported_java_libs) > 0 || - len(p.prebuiltCommonProperties.Exported_bootclasspath_fragments) > 0 || + return len(p.prebuiltCommonProperties.Exported_bootclasspath_fragments) > 0 || len(p.prebuiltCommonProperties.Exported_systemserverclasspath_fragments) > 0 } @@ -292,11 +286,6 @@ func (p *prebuiltCommon) hasExportedDeps() bool { func (p *prebuiltCommon) prebuiltApexContentsDeps(ctx android.BottomUpMutatorContext) { module := ctx.Module() - for _, dep := range p.prebuiltCommonProperties.Exported_java_libs { - prebuiltDep := android.PrebuiltNameFromSource(dep) - ctx.AddDependency(module, exportedJavaLibTag, prebuiltDep) - } - for _, dep := range p.prebuiltCommonProperties.Exported_bootclasspath_fragments { prebuiltDep := android.PrebuiltNameFromSource(dep) ctx.AddDependency(module, exportedBootclasspathFragmentTag, prebuiltDep) @@ -559,7 +548,7 @@ func createApexSelectorModule(ctx android.BottomUpMutatorContext, name string, a // createDeapexerModuleIfNeeded will create a deapexer module if it is needed. // // A deapexer module is only needed when the prebuilt apex specifies one or more modules in either -// the `exported_java_libs` or `exported_bootclasspath_fragments` properties as that indicates that +// the `exported_bootclasspath_fragments` properties as that indicates that // the listed modules need access to files from within the prebuilt .apex file. func (p *prebuiltCommon) createDeapexerModuleIfNeeded(ctx android.BottomUpMutatorContext, deapexerName string, apexFileSource string) { // Only create the deapexer module if it is needed. @@ -666,7 +655,6 @@ func (t exportedDependencyTag) RequiresFilesFromPrebuiltApex() {} var _ android.RequiresFilesFromPrebuiltApexTag = exportedDependencyTag{} var ( - exportedJavaLibTag = exportedDependencyTag{name: "exported_java_libs"} exportedBootclasspathFragmentTag = exportedDependencyTag{name: "exported_bootclasspath_fragments"} exportedSystemserverclasspathFragmentTag = exportedDependencyTag{name: "exported_systemserverclasspath_fragments"} ) @@ -677,7 +665,7 @@ var _ prebuiltApexModuleCreator = (*Prebuilt)(nil) // build. // // If this needs to make files from within a `.apex` file available for use by other Soong modules, -// e.g. make dex implementation jars available for java_import modules listed in exported_java_libs, +// e.g. make dex implementation jars available for `contents` listed in exported_bootclasspath_fragments, // it does so as follows: // // 1. It creates a `deapexer` module that actually extracts the files from the `.apex` file and diff --git a/cc/Android.bp b/cc/Android.bp index 29526143f..3688c8a9a 100644 --- a/cc/Android.bp +++ b/cc/Android.bp @@ -116,4 +116,6 @@ bootstrap_go_package { "cmake_module_cc.txt", ], pluginFor: ["soong_build"], + // Used by plugins + visibility: ["//visibility:public"], } diff --git a/cc/config/Android.bp b/cc/config/Android.bp index 289409fb3..f514db68d 100644 --- a/cc/config/Android.bp +++ b/cc/config/Android.bp @@ -35,4 +35,8 @@ bootstrap_go_package { testSrcs: [ "tidy_test.go", ], + visibility: [ + "//build/soong:__subpackages__", + "//prebuilts/clang/host/linux-x86/soong", + ], } diff --git a/cc/libbuildversion/Android.bp b/cc/libbuildversion/Android.bp index b105a3029..c1f2c1044 100644 --- a/cc/libbuildversion/Android.bp +++ b/cc/libbuildversion/Android.bp @@ -20,4 +20,5 @@ cc_library_static { "//apex_available:anyapex", ], vendor_available: true, + visibility: ["//visibility:public"], } diff --git a/cc/ndk_abi.go b/cc/ndk_abi.go index 8202cc05a..2706261a8 100644 --- a/cc/ndk_abi.go +++ b/cc/ndk_abi.go @@ -46,7 +46,7 @@ func (n *ndkAbiDumpSingleton) GenerateBuildActions(ctx android.SingletonContext) if m, ok := module.(*Module); ok { if installer, ok := m.installer.(*stubDecorator); ok { - if canDumpAbi(ctx.Config(), ctx.ModuleDir(module)) { + if installer.hasAbiDump { depPaths = append(depPaths, installer.abiDumpPath) } } diff --git a/cc/ndk_library.go b/cc/ndk_library.go index bd6dfa301..94e0452dd 100644 --- a/cc/ndk_library.go +++ b/cc/ndk_library.go @@ -125,6 +125,7 @@ type stubDecorator struct { parsedCoverageXmlPath android.ModuleOutPath installPath android.Path abiDumpPath android.OutputPath + hasAbiDump bool abiDiffPaths android.Paths apiLevel android.ApiLevel @@ -330,11 +331,11 @@ func (this *stubDecorator) findPrebuiltAbiDump(ctx ModuleContext, } // Feature flag. -func canDumpAbi(config android.Config, moduleDir string) bool { +func (this *stubDecorator) canDumpAbi(ctx ModuleContext) bool { if runtime.GOOS == "darwin" { return false } - if strings.HasPrefix(moduleDir, "bionic/") { + if strings.HasPrefix(ctx.ModuleDir(), "bionic/") { // Bionic has enough uncommon implementation details like ifuncs and asm // code that the ABI tracking here has a ton of false positives. That's // causing pretty extreme friction for development there, so disabling @@ -343,8 +344,14 @@ func canDumpAbi(config android.Config, moduleDir string) bool { // http://b/358653811 return false } + + if this.apiLevel.IsCurrent() { + // "current" (AKA 10000) is not tracked. + return false + } + // http://b/156513478 - return config.ReleaseNdkAbiMonitored() + return ctx.Config().ReleaseNdkAbiMonitored() } // Feature flag to disable diffing against prebuilts. @@ -357,6 +364,7 @@ func (this *stubDecorator) dumpAbi(ctx ModuleContext, symbolList android.Path) { this.abiDumpPath = getNdkAbiDumpInstallBase(ctx).Join(ctx, this.apiLevel.String(), ctx.Arch().ArchType.String(), this.libraryName(ctx), "abi.stg") + this.hasAbiDump = true headersList := getNdkABIHeadersFile(ctx) ctx.Build(pctx, android.BuildParams{ Rule: stg, @@ -478,7 +486,7 @@ func (c *stubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) O nativeAbiResult := parseNativeAbiDefinition(ctx, symbolFile, c.apiLevel, "") objs := compileStubLibrary(ctx, flags, nativeAbiResult.stubSrc) c.versionScriptPath = nativeAbiResult.versionScript - if canDumpAbi(ctx.Config(), ctx.ModuleDir()) { + if c.canDumpAbi(ctx) { c.dumpAbi(ctx, nativeAbiResult.symbolList) if canDiffAbi(ctx.Config()) { c.diffAbi(ctx) diff --git a/cmd/extract_apks/bundle_proto/Android.bp b/cmd/extract_apks/bundle_proto/Android.bp index e56c0fb32..0abf1e251 100644 --- a/cmd/extract_apks/bundle_proto/Android.bp +++ b/cmd/extract_apks/bundle_proto/Android.bp @@ -10,4 +10,8 @@ python_library_host { proto: { canonical_path_from_root: false, }, + visibility: [ + "//build/soong:__subpackages__", + "//tools/mainline:__subpackages__", + ], } diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go index 24a44b4da..577c6cc74 100644 --- a/cmd/soong_build/main.go +++ b/cmd/soong_build/main.go @@ -212,7 +212,14 @@ func writeDepFile(outputFile string, eventHandler *metrics.EventHandler, ninjaDe } // Check if there are changes to the environment file, product variable file and -// soong_build binary, in which case no incremental will be performed. +// soong_build binary, in which case no incremental will be performed. For env +// variables we check the used env file, which will be removed in soong ui if +// there is any changes to the env variables used last time, in which case the +// check below will fail and a full build will be attempted. If any new env +// variables are added in the new run, soong ui won't be able to detect it, the +// used env file check below will pass. But unless there is a soong build code +// change, in which case the soong build binary check will fail, otherwise the +// new env variables shouldn't have any affect. func incrementalValid(config android.Config, configCacheFile string) (*ConfigCache, bool) { var newConfigCache ConfigCache data, err := os.ReadFile(shared.JoinPath(topDir, usedEnvFile)) diff --git a/cmd/symbols_map/Android.bp b/cmd/symbols_map/Android.bp index e3ae6ede5..272e8061a 100644 --- a/cmd/symbols_map/Android.bp +++ b/cmd/symbols_map/Android.bp @@ -30,4 +30,5 @@ bootstrap_go_package { srcs: [ "symbols_map_proto/symbols_map.pb.go", ], + visibility: ["//visibility:public"], } diff --git a/cmd/zip2zip/Android.bp b/cmd/zip2zip/Android.bp index 3ef766865..7f9b16582 100644 --- a/cmd/zip2zip/Android.bp +++ b/cmd/zip2zip/Android.bp @@ -27,4 +27,6 @@ blueprint_go_binary { "zip2zip.go", ], testSrcs: ["zip2zip_test.go"], + // Used by genrules + visibility: ["//visibility:public"], } diff --git a/compliance/license_metadata_proto/Android.bp b/compliance/license_metadata_proto/Android.bp index 3c041e48b..47612854f 100644 --- a/compliance/license_metadata_proto/Android.bp +++ b/compliance/license_metadata_proto/Android.bp @@ -24,4 +24,8 @@ bootstrap_go_package { "golang-protobuf-reflect-protoreflect", "golang-protobuf-runtime-protoimpl", ], + visibility: [ + "//build/make/tools/compliance:__subpackages__", + "//build/soong:__subpackages__", + ], } diff --git a/compliance/project_metadata_proto/Android.bp b/compliance/project_metadata_proto/Android.bp index 56e76e79f..0c807b22f 100644 --- a/compliance/project_metadata_proto/Android.bp +++ b/compliance/project_metadata_proto/Android.bp @@ -24,4 +24,5 @@ bootstrap_go_package { "golang-protobuf-reflect-protoreflect", "golang-protobuf-runtime-protoimpl", ], + visibility: ["//build/make/tools/compliance:__subpackages__"], } diff --git a/etc/Android.bp b/etc/Android.bp index f02c12a2a..580c54f9b 100644 --- a/etc/Android.bp +++ b/etc/Android.bp @@ -20,4 +20,6 @@ bootstrap_go_package { "install_symlink_test.go", ], pluginFor: ["soong_build"], + // Used by plugins + visibility: ["//visibility:public"], } diff --git a/genrule/Android.bp b/genrule/Android.bp index 7331741de..f4197e691 100644 --- a/genrule/Android.bp +++ b/genrule/Android.bp @@ -22,4 +22,6 @@ bootstrap_go_package { "genrule_test.go", ], pluginFor: ["soong_build"], + // Used by plugins + visibility: ["//visibility:public"], } diff --git a/java/Android.bp b/java/Android.bp index 9603815a1..926a294e9 100644 --- a/java/Android.bp +++ b/java/Android.bp @@ -120,4 +120,5 @@ bootstrap_go_package { "test_spec_test.go", ], pluginFor: ["soong_build"], + visibility: ["//visibility:public"], } diff --git a/java/base.go b/java/base.go index ff7e06837..86ed0e745 100644 --- a/java/base.go +++ b/java/base.go @@ -1790,14 +1790,14 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath classesJar: outputFile, jarName: jarName, } - if j.GetProfileGuided() && j.optimizeOrObfuscateEnabled() && !j.EnableProfileRewriting() { + if j.GetProfileGuided(ctx) && j.optimizeOrObfuscateEnabled() && !j.EnableProfileRewriting(ctx) { ctx.PropertyErrorf("enable_profile_rewriting", "Enable_profile_rewriting must be true when profile_guided dexpreopt and R8 optimization/obfuscation is turned on. The attached profile should be sourced from an unoptimized/unobfuscated APK.", ) } - if j.EnableProfileRewriting() { - profile := j.GetProfile() - if profile == "" || !j.GetProfileGuided() { + if j.EnableProfileRewriting(ctx) { + profile := j.GetProfile(ctx) + if profile == "" || !j.GetProfileGuided(ctx) { ctx.PropertyErrorf("enable_profile_rewriting", "Profile and Profile_guided must be set when enable_profile_rewriting is true") } params.artProfileInput = &profile diff --git a/java/config/Android.bp b/java/config/Android.bp index bfe83ab8c..6217390bb 100644 --- a/java/config/Android.bp +++ b/java/config/Android.bp @@ -17,4 +17,8 @@ bootstrap_go_package { "kotlin.go", "makevars.go", ], + visibility: [ + "//build/soong:__subpackages__", + "//external/error_prone/soong", + ], } diff --git a/java/dexpreopt.go b/java/dexpreopt.go index 4734357ab..63a863497 100644 --- a/java/dexpreopt.go +++ b/java/dexpreopt.go @@ -147,25 +147,25 @@ type dexpreopter struct { type DexpreoptProperties struct { Dex_preopt struct { // If false, prevent dexpreopting. Defaults to true. - Enabled *bool + Enabled proptools.Configurable[bool] `android:"replace_instead_of_append"` // If true, generate an app image (.art file) for this module. - App_image *bool + App_image proptools.Configurable[bool] `android:"replace_instead_of_append"` // If true, use a checked-in profile to guide optimization. Defaults to false unless // a matching profile is set or a profile is found in PRODUCT_DEX_PREOPT_PROFILE_DIR // that matches the name of this module, in which case it is defaulted to true. - Profile_guided *bool + Profile_guided proptools.Configurable[bool] `android:"replace_instead_of_append"` // If set, provides the path to profile relative to the Android.bp file. If not set, // defaults to searching for a file that matches the name of this module in the default // profile location set by PRODUCT_DEX_PREOPT_PROFILE_DIR, or empty if not found. - Profile *string `android:"path"` + Profile proptools.Configurable[string] `android:"path,replace_instead_of_append"` // If set to true, r8/d8 will use `profile` as input to generate a new profile that matches // the optimized dex. // The new profile will be subsequently used as the profile to dexpreopt the dex file. - Enable_profile_rewriting *bool + Enable_profile_rewriting proptools.Configurable[bool] `android:"replace_instead_of_append"` } Dex_preopt_result struct { @@ -244,7 +244,7 @@ func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext, libName s return true } - if !BoolDefault(d.dexpreoptProperties.Dex_preopt.Enabled, true) { + if !d.dexpreoptProperties.Dex_preopt.Enabled.GetOrDefault(ctx, true) { return true } @@ -433,12 +433,12 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, libName string, dexJa if d.inputProfilePathOnHost != nil { profileClassListing = android.OptionalPathForPath(d.inputProfilePathOnHost) - } else if BoolDefault(d.dexpreoptProperties.Dex_preopt.Profile_guided, true) && !forPrebuiltApex(ctx) { + } else if d.dexpreoptProperties.Dex_preopt.Profile_guided.GetOrDefault(ctx, true) && !forPrebuiltApex(ctx) { // If enable_profile_rewriting is set, use the rewritten profile instead of the checked-in profile - if d.EnableProfileRewriting() { + if d.EnableProfileRewriting(ctx) { profileClassListing = android.OptionalPathForPath(d.GetRewrittenProfile()) profileIsTextListing = true - } else if profile := d.GetProfile(); profile != "" { + } else if profile := d.GetProfile(ctx); profile != "" { // If dex_preopt.profile_guided is not set, default it based on the existence of the // dexprepot.profile option or the profile class listing. profileClassListing = android.OptionalPathForPath( @@ -458,6 +458,8 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, libName string, dexJa // Use the dexJar to create a unique scope for each dexJarStem := strings.TrimSuffix(dexJarFile.Base(), dexJarFile.Ext()) + appImage := d.dexpreoptProperties.Dex_preopt.App_image.Get(ctx) + // Full dexpreopt config, used to create dexpreopt build rules. dexpreoptConfig := &dexpreopt.ModuleConfig{ Name: libName, @@ -486,8 +488,8 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, libName string, dexJa PreoptBootClassPathDexFiles: dexFiles.Paths(), PreoptBootClassPathDexLocations: dexLocations, - NoCreateAppImage: !BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, true), - ForceCreateAppImage: BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, false), + NoCreateAppImage: !appImage.GetOrDefault(true), + ForceCreateAppImage: appImage.GetOrDefault(false), PresignedPrebuilt: d.isPresignedPrebuilt, } @@ -657,16 +659,16 @@ func (d *dexpreopter) disableDexpreopt() { d.shouldDisableDexpreopt = true } -func (d *dexpreopter) EnableProfileRewriting() bool { - return proptools.Bool(d.dexpreoptProperties.Dex_preopt.Enable_profile_rewriting) +func (d *dexpreopter) EnableProfileRewriting(ctx android.BaseModuleContext) bool { + return d.dexpreoptProperties.Dex_preopt.Enable_profile_rewriting.GetOrDefault(ctx, false) } -func (d *dexpreopter) GetProfile() string { - return proptools.String(d.dexpreoptProperties.Dex_preopt.Profile) +func (d *dexpreopter) GetProfile(ctx android.BaseModuleContext) string { + return d.dexpreoptProperties.Dex_preopt.Profile.GetOrDefault(ctx, "") } -func (d *dexpreopter) GetProfileGuided() bool { - return proptools.Bool(d.dexpreoptProperties.Dex_preopt.Profile_guided) +func (d *dexpreopter) GetProfileGuided(ctx android.BaseModuleContext) bool { + return d.dexpreoptProperties.Dex_preopt.Profile_guided.GetOrDefault(ctx, false) } func (d *dexpreopter) GetRewrittenProfile() android.Path { diff --git a/java/metalava/Android.bp b/java/metalava/Android.bp index ccbd191d3..6bf183296 100644 --- a/java/metalava/Android.bp +++ b/java/metalava/Android.bp @@ -15,4 +15,5 @@ filegroup { name: "metalava-config-files", srcs: ["*-config.xml"], + visibility: ["//visibility:public"], } diff --git a/linkerconfig/proto/Android.bp b/linkerconfig/proto/Android.bp index 754e7bfbb..a93050251 100644 --- a/linkerconfig/proto/Android.bp +++ b/linkerconfig/proto/Android.bp @@ -15,6 +15,7 @@ cc_library_static { "//apex_available:platform", "//apex_available:anyapex", ], + visibility: ["//system/linkerconfig"], } python_library_host { diff --git a/phony/Android.bp b/phony/Android.bp index db5efc98e..2e250c699 100644 --- a/phony/Android.bp +++ b/phony/Android.bp @@ -13,4 +13,5 @@ bootstrap_go_package { "phony.go", ], pluginFor: ["soong_build"], + visibility: ["//visibility:public"], } diff --git a/response/Android.bp b/response/Android.bp index e19981f8f..2f319fec9 100644 --- a/response/Android.bp +++ b/response/Android.bp @@ -13,4 +13,8 @@ bootstrap_go_package { testSrcs: [ "response_test.go", ], + visibility: [ + "//build/make/tools/compliance", + "//build/soong:__subpackages__", + ], } diff --git a/rust/Android.bp b/rust/Android.bp index 53c94621e..781f325d1 100644 --- a/rust/Android.bp +++ b/rust/Android.bp @@ -61,4 +61,5 @@ bootstrap_go_package { "test_test.go", ], pluginFor: ["soong_build"], + visibility: ["//visibility:public"], } diff --git a/rust/config/Android.bp b/rust/config/Android.bp index 79ea7a174..25f7580d0 100644 --- a/rust/config/Android.bp +++ b/rust/config/Android.bp @@ -24,4 +24,8 @@ bootstrap_go_package { "x86_64_device.go", "arm64_linux_host.go", ], + visibility: [ + "//build/soong:__subpackages__", + "//prebuilts/rust/soong", + ], } diff --git a/sysprop/Android.bp b/sysprop/Android.bp index a00a5e42c..22cba3bf1 100644 --- a/sysprop/Android.bp +++ b/sysprop/Android.bp @@ -21,4 +21,6 @@ bootstrap_go_package { "sysprop_test.go", ], pluginFor: ["soong_build"], + // Used by plugins + visibility: ["//visibility:public"], } diff --git a/testing/code_metadata_internal_proto/Android.bp b/testing/code_metadata_internal_proto/Android.bp index a534cc20b..396e44f52 100644 --- a/testing/code_metadata_internal_proto/Android.bp +++ b/testing/code_metadata_internal_proto/Android.bp @@ -20,10 +20,14 @@ bootstrap_go_package { name: "soong-testing-code_metadata_internal_proto", pkgPath: "android/soong/testing/code_metadata_internal_proto", deps: [ - "golang-protobuf-reflect-protoreflect", - "golang-protobuf-runtime-protoimpl", - ], + "golang-protobuf-reflect-protoreflect", + "golang-protobuf-runtime-protoimpl", + ], srcs: [ "code_metadata_internal.pb.go", ], + visibility: [ + "//build/make/tools/metadata", + "//build/soong:__subpackages__", + ], } diff --git a/testing/code_metadata_proto/Android.bp b/testing/code_metadata_proto/Android.bp index f07efffb3..ae41d4aa1 100644 --- a/testing/code_metadata_proto/Android.bp +++ b/testing/code_metadata_proto/Android.bp @@ -26,6 +26,7 @@ bootstrap_go_package { srcs: [ "code_metadata.pb.go", ], + visibility: ["//build/make/tools/metadata"], } python_library_host { @@ -40,4 +41,5 @@ python_library_host { proto: { canonical_path_from_root: false, }, + visibility: ["//tools/asuite/team_build_scripts"], } diff --git a/testing/test_spec_proto/Android.bp b/testing/test_spec_proto/Android.bp index d5ad70b73..1070d1a9c 100644 --- a/testing/test_spec_proto/Android.bp +++ b/testing/test_spec_proto/Android.bp @@ -26,6 +26,11 @@ bootstrap_go_package { srcs: [ "test_spec.pb.go", ], + visibility: [ + "//build/make/tools/metadata", + "//build/soong:__subpackages__", + "//vendor:__subpackages__", + ], } python_library_host { @@ -40,4 +45,5 @@ python_library_host { proto: { canonical_path_from_root: false, }, + visibility: ["//tools/asuite/team_build_scripts"], } diff --git a/tests/build_action_caching_test.sh b/tests/build_action_caching_test.sh new file mode 100755 index 000000000..981827d6f --- /dev/null +++ b/tests/build_action_caching_test.sh @@ -0,0 +1,110 @@ +#!/bin/bash -u + +set -o pipefail + +# Test that the mk and ninja files generated by Soong don't change if some +# incremental modules are restored from cache. + +OUTPUT_DIR="$(mktemp -d tmp.XXXXXX)" +echo ${OUTPUT_DIR} + +function cleanup { + rm -rf "${OUTPUT_DIR}" +} +trap cleanup EXIT + +function run_soong_build { + USE_RBE=false TARGET_PRODUCT=aosp_arm TARGET_RELEASE=trunk_staging TARGET_BUILD_VARIANT=userdebug build/soong/soong_ui.bash --make-mode --incremental-build-actions nothing +} + +function run_soong_clean { + build/soong/soong_ui.bash --make-mode clean +} + +function assert_files_equal { + if [ $# -ne 2 ]; then + echo "Usage: assert_files_equal file1 file2" + exit 1 + fi + + if ! cmp -s "$1" "$2"; then + echo "Files are different: $1 $2" + exit 1 + fi +} + +function compare_mtimes() { + if [ $# -ne 2 ]; then + echo "Usage: compare_mtimes file1 file2" + exit 1 + fi + + file1_mtime=$(stat -c '%Y' $1) + file2_mtime=$(stat -c '%Y' $2) + + if [ "$file1_mtime" -eq "$file2_mtime" ]; then + return 1 + else + return 0 + fi +} + +function test_build_action_restoring() { + run_soong_clean + cat > ${OUTPUT_DIR}/Android.bp <<'EOF' +python_binary_host { + name: "my_little_binary_host", + srcs: ["my_little_binary_host.py"], +} +EOF + touch ${OUTPUT_DIR}/my_little_binary_host.py + run_soong_build + mkdir -p "${OUTPUT_DIR}/before" + cp -pr out/soong/build_aosp_arm_ninja_incremental out/soong/*.mk out/soong/build.aosp_arm.*.ninja ${OUTPUT_DIR}/before + # add a comment to the bp file, this should force a new analysis but no module + # should be really impacted, so all the incremental modules should be skipped. + cat >> ${OUTPUT_DIR}/Android.bp <<'EOF' +// new comments +EOF + run_soong_build + mkdir -p "${OUTPUT_DIR}/after" + cp -pr out/soong/build_aosp_arm_ninja_incremental out/soong/*.mk out/soong/build.aosp_arm.*.ninja ${OUTPUT_DIR}/after + + compare_files +} + +function compare_files() { + for file_before in ${OUTPUT_DIR}/before/*.ninja; do + file_after="${OUTPUT_DIR}/after/$(basename "$file_before")" + assert_files_equal $file_before $file_after + compare_mtimes $file_before $file_after + if [ $? -ne 0 ]; then + echo "Files have identical mtime: $file_before $file_after" + exit 1 + fi + done + + for file_before in ${OUTPUT_DIR}/before/*.mk; do + file_after="${OUTPUT_DIR}/after/$(basename "$file_before")" + assert_files_equal $file_before $file_after + compare_mtimes $file_before $file_after + # mk files shouldn't be regenerated + if [ $? -ne 1 ]; then + echo "Files have different mtimes: $file_before $file_after" + exit 1 + fi + done + + for file_before in ${OUTPUT_DIR}/before/build_aosp_arm_ninja_incremental/*.ninja; do + file_after="${OUTPUT_DIR}/after/build_aosp_arm_ninja_incremental/$(basename "$file_before")" + assert_files_equal $file_before $file_after + compare_mtimes $file_before $file_after + # ninja files of skipped modules shouldn't be regenerated + if [ $? -ne 1 ]; then + echo "Files have different mtimes: $file_before $file_after" + exit 1 + fi + done +} + +test_build_action_restoring diff --git a/zip/cmd/Android.bp b/zip/cmd/Android.bp index 43bf232a0..16c3f698f 100644 --- a/zip/cmd/Android.bp +++ b/zip/cmd/Android.bp @@ -24,4 +24,6 @@ blueprint_go_binary { srcs: [ "main.go", ], + // Used by genrules + visibility: ["//visibility:public"], }