diff options
| -rw-r--r-- | android/config.go | 4 | ||||
| -rw-r--r-- | android/variable.go | 2 | ||||
| -rw-r--r-- | apex/apex_test.go | 9 | ||||
| -rw-r--r-- | apex/vndk_test.go | 1 | ||||
| -rw-r--r-- | cc/androidmk.go | 18 | ||||
| -rw-r--r-- | cc/cc.go | 82 | ||||
| -rw-r--r-- | cc/cc_test.go | 266 | ||||
| -rw-r--r-- | cc/compiler.go | 4 | ||||
| -rw-r--r-- | cc/config/clang.go | 3 | ||||
| -rw-r--r-- | cc/config/global.go | 4 | ||||
| -rw-r--r-- | cc/genrule.go | 10 | ||||
| -rw-r--r-- | cc/image.go | 29 | ||||
| -rw-r--r-- | cc/library.go | 8 | ||||
| -rw-r--r-- | cc/llndk_library.go | 21 | ||||
| -rw-r--r-- | cc/makevars.go | 1 | ||||
| -rw-r--r-- | cc/sanitize.go | 20 | ||||
| -rw-r--r-- | cc/snapshot_prebuilt.go | 343 | ||||
| -rw-r--r-- | cc/snapshot_utils.go | 4 | ||||
| -rw-r--r-- | cc/testing.go | 2 | ||||
| -rw-r--r-- | cc/vendor_snapshot.go | 30 | ||||
| -rw-r--r-- | cc/vndk.go | 100 | ||||
| -rw-r--r-- | go.mod | 2 | ||||
| -rw-r--r-- | java/java.go | 5 | ||||
| -rw-r--r-- | java/java_test.go | 16 | ||||
| -rw-r--r-- | rust/bindgen.go | 11 |
25 files changed, 789 insertions, 206 deletions
diff --git a/android/config.go b/android/config.go index 58372ec89..ddb2de35d 100644 --- a/android/config.go +++ b/android/config.go @@ -1053,6 +1053,10 @@ func (c *deviceConfig) VndkVersion() string { return String(c.config.productVariables.DeviceVndkVersion) } +func (c *deviceConfig) RecoverySnapshotVersion() string { + return String(c.config.productVariables.RecoverySnapshotVersion) +} + func (c *deviceConfig) CurrentApiLevelForVendorModules() string { return StringDefault(c.config.productVariables.DeviceCurrentApiLevelForVendorModules, "current") } diff --git a/android/variable.go b/android/variable.go index 1455fc216..7532797b8 100644 --- a/android/variable.go +++ b/android/variable.go @@ -181,6 +181,8 @@ type productVariables struct { DeviceCurrentApiLevelForVendorModules *string `json:",omitempty"` DeviceSystemSdkVersions []string `json:",omitempty"` + RecoverySnapshotVersion *string `json:",omitempty"` + DeviceSecondaryArch *string `json:",omitempty"` DeviceSecondaryArchVariant *string `json:",omitempty"` DeviceSecondaryCpuVariant *string `json:",omitempty"` diff --git a/apex/apex_test.go b/apex/apex_test.go index 84a835639..fc746724a 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -250,7 +250,7 @@ func testApexContext(_ *testing.T, bp string, handlers ...testCustomizer) (*andr ctx.RegisterModuleType("cc_test", cc.TestFactory) ctx.RegisterModuleType("vndk_prebuilt_shared", cc.VndkPrebuiltSharedFactory) - ctx.RegisterModuleType("vndk_libraries_txt", cc.VndkLibrariesTxtFactory) + cc.RegisterVndkLibraryTxtTypes(ctx) prebuilt_etc.RegisterPrebuiltEtcBuildComponents(ctx) ctx.RegisterModuleType("platform_compat_config", java.PlatformCompatConfigFactory) ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory) @@ -3150,6 +3150,7 @@ func TestVndkApexCurrent(t *testing.T) { "etc/vndkcore.libraries.VER.txt", "etc/vndksp.libraries.VER.txt", "etc/vndkprivate.libraries.VER.txt", + "etc/vndkproduct.libraries.VER.txt", }) } @@ -3216,15 +3217,15 @@ func TestVndkApexWithPrebuilt(t *testing.T) { func vndkLibrariesTxtFiles(vers ...string) (result string) { for _, v := range vers { if v == "current" { - for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} { + for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate", "vndkproduct"} { result += ` - vndk_libraries_txt { + ` + txt + `_libraries_txt { name: "` + txt + `.libraries.txt", } ` } } else { - for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} { + for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate", "vndkproduct"} { result += ` prebuilt_etc { name: "` + txt + `.libraries.` + v + `.txt", diff --git a/apex/vndk_test.go b/apex/vndk_test.go index 27d93ee0a..ccf4e57e6 100644 --- a/apex/vndk_test.go +++ b/apex/vndk_test.go @@ -60,6 +60,7 @@ func TestVndkApexForVndkLite(t *testing.T) { "etc/vndkcore.libraries.VER.txt", "etc/vndksp.libraries.VER.txt", "etc/vndkprivate.libraries.VER.txt", + "etc/vndkproduct.libraries.VER.txt", }) } diff --git a/cc/androidmk.go b/cc/androidmk.go index 4ada55dd3..040aa0b9f 100644 --- a/cc/androidmk.go +++ b/cc/androidmk.go @@ -519,9 +519,7 @@ func (c *snapshotLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entrie entries.SubName += ".cfi" } - if c.androidMkVendorSuffix { - entries.SubName += vendorSuffix - } + entries.SubName += c.androidMkSuffix entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) { c.libraryDecorator.androidMkWriteExportedFlags(entries) @@ -548,12 +546,7 @@ func (c *snapshotLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entrie func (c *snapshotBinaryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { entries.Class = "EXECUTABLES" - - if c.androidMkVendorSuffix { - entries.SubName = vendorSuffix - } else { - entries.SubName = "" - } + entries.SubName = c.androidMkSuffix entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) { entries.AddStrings("LOCAL_MODULE_SYMLINKS", c.Properties.Symlinks...) @@ -562,12 +555,7 @@ func (c *snapshotBinaryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries func (c *snapshotObjectLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { entries.Class = "STATIC_LIBRARIES" - - if c.androidMkVendorSuffix { - entries.SubName = vendorSuffix - } else { - entries.SubName = "" - } + entries.SubName = c.androidMkSuffix entries.ExtraFooters = append(entries.ExtraFooters, func(w io.Writer, name, prefix, moduleDir string) { @@ -52,6 +52,8 @@ func RegisterCCBuildComponents(ctx android.RegistrationContext) { ctx.BottomUp("sysprop_cc", SyspropMutator).Parallel() ctx.BottomUp("vendor_snapshot", VendorSnapshotMutator).Parallel() ctx.BottomUp("vendor_snapshot_source", VendorSnapshotSourceMutator).Parallel() + ctx.BottomUp("recovery_snapshot", RecoverySnapshotMutator).Parallel() + ctx.BottomUp("recovery_snapshot_source", RecoverySnapshotSourceMutator).Parallel() }) ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { @@ -334,10 +336,16 @@ type BaseProperties struct { // Normally Soong uses the directory structure to decide which modules // should be included (framework) or excluded (non-framework) from the - // different snapshots (vendor, recovery, etc.), but these properties - // allow a partner to exclude a module normally thought of as a - // framework module from a snapshot. - Exclude_from_vendor_snapshot *bool + // different snapshots (vendor, recovery, etc.), but this property + // allows a partner to exclude a module normally thought of as a + // framework module from the vendor snapshot. + Exclude_from_vendor_snapshot *bool + + // Normally Soong uses the directory structure to decide which modules + // should be included (framework) or excluded (non-framework) from the + // different snapshots (vendor, recovery, etc.), but this property + // allows a partner to exclude a module normally thought of as a + // framework module from the recovery snapshot. Exclude_from_recovery_snapshot *bool // List of APEXes that this module has private access to for testing purpose. The module @@ -1634,8 +1642,9 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { // Note: this is still non-installable } - // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current. - if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" { + // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current or + // RECOVERY_SNAPSHOT_VERSION is current. + if i, ok := c.linker.(snapshotLibraryInterface); ok { if shouldCollectHeadersForSnapshot(ctx, c, apexInfo) { i.collectHeadersForSnapshot(ctx) } @@ -1877,6 +1886,7 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { vendorPublicLibraries := vendorPublicLibraries(actx.Config()) vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config()) + recoverySnapshotSharedLibs := recoverySnapshotSharedLibs(actx.Config()) rewriteVendorLibs := func(lib string) string { // only modules with BOARD_VNDK_VERSION uses snapshot. @@ -1897,7 +1907,19 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { for _, entry := range list { // strip #version suffix out name, _ := StubsLibNameAndVersion(entry) - if ctx.useSdk() && inList(name, *getNDKKnownLibs(ctx.Config())) { + if c.InRecovery() { + recoverySnapshotVersion := + actx.DeviceConfig().RecoverySnapshotVersion() + if recoverySnapshotVersion == "current" || + recoverySnapshotVersion == "" { + nonvariantLibs = append(nonvariantLibs, name) + } else if snapshot, ok := recoverySnapshotSharedLibs.get( + name, actx.Arch().ArchType); ok { + nonvariantLibs = append(nonvariantLibs, snapshot) + } else { + nonvariantLibs = append(nonvariantLibs, name) + } + } else if ctx.useSdk() && inList(name, *getNDKKnownLibs(ctx.Config())) { variantLibs = append(variantLibs, name+ndkLibrarySuffix) } else if ctx.useVndk() { nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry)) @@ -1942,14 +1964,36 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { return lib } - vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config()) + snapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config()) + snapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config()) + snapshotObjects := vendorSnapshotObjects(actx.Config()) + + if c.InRecovery() { + rewriteSnapshotLibs = func(lib string, snapshotMap *snapshotMap) string { + recoverySnapshotVersion := + actx.DeviceConfig().RecoverySnapshotVersion() + if recoverySnapshotVersion == "current" || + recoverySnapshotVersion == "" { + return lib + } else if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok { + return snapshot + } + + return lib + } + + snapshotHeaderLibs = recoverySnapshotHeaderLibs(actx.Config()) + snapshotStaticLibs = recoverySnapshotStaticLibs(actx.Config()) + snapshotObjects = recoverySnapshotObjects(actx.Config()) + } + for _, lib := range deps.HeaderLibs { depTag := libraryDependencyTag{Kind: headerLibraryDependency} if inList(lib, deps.ReexportHeaderLibHeaders) { depTag.reexportFlags = true } - lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs) + lib = rewriteSnapshotLibs(lib, snapshotHeaderLibs) if c.IsStubs() { actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()), @@ -1965,7 +2009,6 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { // map from sysprop_library to implementation library; it will be used in whole_static_libs, // static_libs, and shared_libs. syspropImplLibraries := syspropImplLibraries(actx.Config()) - vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config()) for _, lib := range deps.WholeStaticLibs { depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true} @@ -1973,7 +2016,7 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { lib = impl } - lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs) + lib = rewriteSnapshotLibs(lib, snapshotStaticLibs) actx.AddVariationDependencies([]blueprint.Variation{ {Mutator: "link", Variation: "static"}, @@ -1993,7 +2036,7 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { lib = impl } - lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs) + lib = rewriteSnapshotLibs(lib, snapshotStaticLibs) actx.AddVariationDependencies([]blueprint.Variation{ {Mutator: "link", Variation: "static"}, @@ -2007,14 +2050,14 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true} actx.AddVariationDependencies([]blueprint.Variation{ {Mutator: "link", Variation: "static"}, - }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs)) + }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), snapshotStaticLibs)) } for _, lib := range deps.LateStaticLibs { depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency} actx.AddVariationDependencies([]blueprint.Variation{ {Mutator: "link", Variation: "static"}, - }, depTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)) + }, depTag, rewriteSnapshotLibs(lib, snapshotStaticLibs)) } // shared lib names without the #version suffix @@ -2074,17 +2117,15 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { actx.AddDependency(c, depTag, gen) } - vendorSnapshotObjects := vendorSnapshotObjects(actx.Config()) - crtVariations := GetCrtVariations(ctx, c) actx.AddVariationDependencies(crtVariations, objDepTag, deps.ObjFiles...) if deps.CrtBegin != "" { actx.AddVariationDependencies(crtVariations, CrtBeginDepTag, - rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects)) + rewriteSnapshotLibs(deps.CrtBegin, snapshotObjects)) } if deps.CrtEnd != "" { actx.AddVariationDependencies(crtVariations, CrtEndDepTag, - rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects)) + rewriteSnapshotLibs(deps.CrtEnd, snapshotObjects)) } if deps.LinkerFlagsFile != "" { actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile) @@ -2796,6 +2837,7 @@ func baseLibName(depName string) string { func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string { vendorSuffixModules := vendorSuffixModules(ctx.Config()) + recoverySuffixModules := recoverySuffixModules(ctx.Config()) vendorPublicLibraries := vendorPublicLibraries(ctx.Config()) libName := baseLibName(depName) @@ -2813,8 +2855,10 @@ func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, return baseName + ".vendor" } - if vendorSuffixModules[baseName] { + if c.inVendor() && vendorSuffixModules[baseName] { return baseName + ".vendor" + } else if c.InRecovery() && recoverySuffixModules[baseName] { + return baseName + ".recovery" } else { return baseName } diff --git a/cc/cc_test.go b/cc/cc_test.go index fb8533641..71c6b7091 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -68,6 +68,7 @@ func testCc(t *testing.T, bp string) *android.TestContext { t.Helper() config := TestConfig(buildDir, android.Android, nil, bp, nil) config.TestProductVariables.DeviceVndkVersion = StringPtr("current") + config.TestProductVariables.ProductVndkVersion = StringPtr("current") config.TestProductVariables.Platform_vndk_version = StringPtr("VER") return testCcWithConfig(t, config) @@ -81,6 +82,15 @@ func testCcNoVndk(t *testing.T, bp string) *android.TestContext { return testCcWithConfig(t, config) } +func testCcNoProductVndk(t *testing.T, bp string) *android.TestContext { + t.Helper() + config := TestConfig(buildDir, android.Android, nil, bp, nil) + config.TestProductVariables.DeviceVndkVersion = StringPtr("current") + config.TestProductVariables.Platform_vndk_version = StringPtr("VER") + + return testCcWithConfig(t, config) +} + func testCcErrorWithConfig(t *testing.T, pattern string, config android.Config) { t.Helper() @@ -408,20 +418,24 @@ func TestVndk(t *testing.T) { }, } - vndk_libraries_txt { + llndk_libraries_txt { name: "llndk.libraries.txt", } - vndk_libraries_txt { + vndkcore_libraries_txt { name: "vndkcore.libraries.txt", } - vndk_libraries_txt { + vndksp_libraries_txt { name: "vndksp.libraries.txt", } - vndk_libraries_txt { + vndkprivate_libraries_txt { name: "vndkprivate.libraries.txt", } - vndk_libraries_txt { + vndkproduct_libraries_txt { + name: "vndkproduct.libraries.txt", + } + vndkcorevariant_libraries_txt { name: "vndkcorevariant.libraries.txt", + insert_vndk_version: false, } ` @@ -445,7 +459,6 @@ func TestVndk(t *testing.T) { checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", productVariant) // Check VNDK snapshot output. - snapshotDir := "vndk-snapshot" snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64") @@ -476,6 +489,7 @@ func TestVndk(t *testing.T) { checkSnapshot(t, ctx, snapshotSingleton, "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "") checkSnapshot(t, ctx, snapshotSingleton, "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "") checkSnapshot(t, ctx, snapshotSingleton, "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "") + checkSnapshot(t, ctx, snapshotSingleton, "vndkproduct.libraries.txt", "vndkproduct.libraries.txt", snapshotConfigsPath, "") checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{ "LLNDK: libc.so", @@ -493,11 +507,15 @@ func TestVndk(t *testing.T) { "VNDK-private: libvndk-private.so", "VNDK-private: libvndk_sp_private-x.so", "VNDK-private: libvndk_sp_product_private-x.so", + "VNDK-product: libc++.so", + "VNDK-product: libvndk_product.so", + "VNDK-product: libvndk_sp_product_private-x.so", }) checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libm.so"}) checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so", "libvndk_product.so"}) checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"}) checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt", []string{"libft2.so", "libvndk-private.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"}) + checkVndkLibrariesOutput(t, ctx, "vndkproduct.libraries.txt", []string{"libc++.so", "libvndk_product.so", "libvndk_sp_product_private-x.so"}) checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil) } @@ -529,7 +547,7 @@ func TestVndkWithHostSupported(t *testing.T) { } } - vndk_libraries_txt { + vndkcore_libraries_txt { name: "vndkcore.libraries.txt", } `) @@ -539,8 +557,9 @@ func TestVndkWithHostSupported(t *testing.T) { func TestVndkLibrariesTxtAndroidMk(t *testing.T) { bp := ` - vndk_libraries_txt { + llndk_libraries_txt { name: "llndk.libraries.txt", + insert_vndk_version: true, }` config := TestConfig(buildDir, android.Android, nil, bp, nil) config.TestProductVariables.DeviceVndkVersion = StringPtr("current") @@ -586,8 +605,9 @@ func TestVndkUsingCoreVariant(t *testing.T) { nocrt: true, } - vndk_libraries_txt { + vndkcorevariant_libraries_txt { name: "vndkcorevariant.libraries.txt", + insert_vndk_version: false, } ` @@ -711,6 +731,15 @@ func TestVndkWhenVndkVersionIsNotSet(t *testing.T) { }, nocrt: true, } + cc_library { + name: "libvndk-private", + vendor_available: false, + product_available: false, + vndk: { + enabled: true, + }, + nocrt: true, + } `) checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{ @@ -719,8 +748,13 @@ func TestVndkWhenVndkVersionIsNotSet(t *testing.T) { "LLNDK: libft2.so", "LLNDK: libm.so", "VNDK-SP: libc++.so", + "VNDK-core: libvndk-private.so", "VNDK-core: libvndk.so", "VNDK-private: libft2.so", + "VNDK-private: libvndk-private.so", + "VNDK-product: libc++.so", + "VNDK-product: libvndk-private.so", + "VNDK-product: libvndk.so", }) } @@ -1492,6 +1526,13 @@ func assertExcludeFromVendorSnapshotIs(t *testing.T, c *Module, expected bool) { } } +func assertExcludeFromRecoverySnapshotIs(t *testing.T, c *Module, expected bool) { + t.Helper() + if c.ExcludeFromRecoverySnapshot() != expected { + t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", c.String(), expected) + } +} + func TestVendorSnapshotExclude(t *testing.T) { // This test verifies that the exclude_from_vendor_snapshot property @@ -1739,7 +1780,7 @@ func TestRecoverySnapshotCapture(t *testing.T) { } ` config := TestConfig(buildDir, android.Android, nil, bp, nil) - config.TestProductVariables.DeviceVndkVersion = StringPtr("current") + config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current") config.TestProductVariables.Platform_vndk_version = StringPtr("VER") ctx := testCcWithConfig(t, config) @@ -1810,6 +1851,111 @@ func TestRecoverySnapshotCapture(t *testing.T) { } } +func TestRecoverySnapshotExclude(t *testing.T) { + // This test verifies that the exclude_from_recovery_snapshot property + // makes its way from the Android.bp source file into the module data + // structure. It also verifies that modules are correctly included or + // excluded in the recovery snapshot based on their path (framework or + // vendor) and the exclude_from_recovery_snapshot property. + + frameworkBp := ` + cc_library_shared { + name: "libinclude", + srcs: ["src/include.cpp"], + recovery_available: true, + } + cc_library_shared { + name: "libexclude", + srcs: ["src/exclude.cpp"], + recovery: true, + exclude_from_recovery_snapshot: true, + } + ` + + vendorProprietaryBp := ` + cc_library_shared { + name: "libvendor", + srcs: ["vendor.cpp"], + recovery: true, + } + ` + + depsBp := GatherRequiredDepsForTest(android.Android) + + mockFS := map[string][]byte{ + "deps/Android.bp": []byte(depsBp), + "framework/Android.bp": []byte(frameworkBp), + "framework/include.cpp": nil, + "framework/exclude.cpp": nil, + "device/Android.bp": []byte(vendorProprietaryBp), + "device/vendor.cpp": nil, + } + + config := TestConfig(buildDir, android.Android, nil, "", mockFS) + config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current") + config.TestProductVariables.Platform_vndk_version = StringPtr("VER") + ctx := CreateTestContext(config) + ctx.Register() + + _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"}) + android.FailIfErrored(t, errs) + _, errs = ctx.PrepareBuildActions(config) + android.FailIfErrored(t, errs) + + // Test an include and exclude framework module. + assertExcludeFromRecoverySnapshotIs(t, ctx.ModuleForTests("libinclude", coreVariant).Module().(*Module), false) + assertExcludeFromRecoverySnapshotIs(t, ctx.ModuleForTests("libinclude", recoveryVariant).Module().(*Module), false) + assertExcludeFromRecoverySnapshotIs(t, ctx.ModuleForTests("libexclude", recoveryVariant).Module().(*Module), true) + + // A vendor module is excluded, but by its path, not the + // exclude_from_recovery_snapshot property. + assertExcludeFromRecoverySnapshotIs(t, ctx.ModuleForTests("libvendor", recoveryVariant).Module().(*Module), false) + + // Verify the content of the recovery snapshot. + + snapshotDir := "recovery-snapshot" + snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64") + snapshotSingleton := ctx.SingletonForTests("recovery-snapshot") + + var includeJsonFiles []string + var excludeJsonFiles []string + + for _, arch := range [][]string{ + []string{"arm64", "armv8-a"}, + } { + archType := arch[0] + archVariant := arch[1] + archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) + + sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant) + sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") + + // Included modules + checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant) + includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json")) + + // Excluded modules + checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant) + excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json")) + checkSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant) + excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json")) + } + + // Verify that each json file for an included module has a rule. + for _, jsonFile := range includeJsonFiles { + if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { + t.Errorf("include json file %q not found", jsonFile) + } + } + + // Verify that each json file for an excluded module has no rule. + for _, jsonFile := range excludeJsonFiles { + if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil { + t.Errorf("exclude json file %q found", jsonFile) + } + } +} + func TestDoubleLoadableDepError(t *testing.T) { // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib. testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` @@ -2088,7 +2234,7 @@ func TestVndkExtWithoutBoardVndkVersion(t *testing.T) { func TestVndkExtWithoutProductVndkVersion(t *testing.T) { // This test checks the VNDK-Ext properties when PRODUCT_PRODUCT_VNDK_VERSION is not set. - ctx := testCc(t, ` + ctx := testCcNoProductVndk(t, ` cc_library { name: "libvndk", vendor_available: true, @@ -3400,27 +3546,28 @@ func checkRuntimeLibs(t *testing.T, expected []string, module *Module) { const runtimeLibAndroidBp = ` cc_library { - name: "libvendor_available1", + name: "liball_available", vendor_available: true, + product_available: true, no_libcrt : true, nocrt : true, system_shared_libs : [], } cc_library { - name: "libvendor_available2", + name: "libvendor_available1", vendor_available: true, - runtime_libs: ["libvendor_available1"], + runtime_libs: ["liball_available"], no_libcrt : true, nocrt : true, system_shared_libs : [], } cc_library { - name: "libvendor_available3", + name: "libvendor_available2", vendor_available: true, - runtime_libs: ["libvendor_available1"], + runtime_libs: ["liball_available"], target: { vendor: { - exclude_runtime_libs: ["libvendor_available1"], + exclude_runtime_libs: ["liball_available"], } }, no_libcrt : true, @@ -3429,7 +3576,7 @@ const runtimeLibAndroidBp = ` } cc_library { name: "libcore", - runtime_libs: ["libvendor_available1"], + runtime_libs: ["liball_available"], no_libcrt : true, nocrt : true, system_shared_libs : [], @@ -3444,7 +3591,30 @@ const runtimeLibAndroidBp = ` cc_library { name: "libvendor2", vendor: true, - runtime_libs: ["libvendor_available1", "libvendor1"], + runtime_libs: ["liball_available", "libvendor1"], + no_libcrt : true, + nocrt : true, + system_shared_libs : [], + } + cc_library { + name: "libproduct_available1", + product_available: true, + runtime_libs: ["liball_available"], + no_libcrt : true, + nocrt : true, + system_shared_libs : [], + } + cc_library { + name: "libproduct1", + product_specific: true, + no_libcrt : true, + nocrt : true, + system_shared_libs : [], + } + cc_library { + name: "libproduct2", + product_specific: true, + runtime_libs: ["liball_available", "libproduct1"], no_libcrt : true, nocrt : true, system_shared_libs : [], @@ -3457,32 +3627,45 @@ func TestRuntimeLibs(t *testing.T) { // runtime_libs for core variants use the module names without suffixes. variant := "android_arm64_armv8-a_shared" - module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) - checkRuntimeLibs(t, []string{"libvendor_available1"}, module) + module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module) + checkRuntimeLibs(t, []string{"liball_available"}, module) + + module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module) + checkRuntimeLibs(t, []string{"liball_available"}, module) module = ctx.ModuleForTests("libcore", variant).Module().(*Module) - checkRuntimeLibs(t, []string{"libvendor_available1"}, module) + checkRuntimeLibs(t, []string{"liball_available"}, module) // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core // and vendor variants. variant = "android_vendor.VER_arm64_armv8-a_shared" - module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) - checkRuntimeLibs(t, []string{"libvendor_available1.vendor"}, module) + module = ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module) + checkRuntimeLibs(t, []string{"liball_available.vendor"}, module) module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module) - checkRuntimeLibs(t, []string{"libvendor_available1.vendor", "libvendor1"}, module) + checkRuntimeLibs(t, []string{"liball_available.vendor", "libvendor1"}, module) + + // runtime_libs for product variants have '.product' suffixes if the modules have both core + // and product variants. + variant = "android_product.VER_arm64_armv8-a_shared" + + module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module) + checkRuntimeLibs(t, []string{"liball_available.product"}, module) + + module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module) + checkRuntimeLibs(t, []string{"liball_available.product", "libproduct1"}, module) } func TestExcludeRuntimeLibs(t *testing.T) { ctx := testCc(t, runtimeLibAndroidBp) variant := "android_arm64_armv8-a_shared" - module := ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module) - checkRuntimeLibs(t, []string{"libvendor_available1"}, module) + module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) + checkRuntimeLibs(t, []string{"liball_available"}, module) variant = "android_vendor.VER_arm64_armv8-a_shared" - module = ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module) + module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) checkRuntimeLibs(t, nil, module) } @@ -3493,11 +3676,14 @@ func TestRuntimeLibsNoVndk(t *testing.T) { variant := "android_arm64_armv8-a_shared" - module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) - checkRuntimeLibs(t, []string{"libvendor_available1"}, module) + module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module) + checkRuntimeLibs(t, []string{"liball_available"}, module) module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module) - checkRuntimeLibs(t, []string{"libvendor_available1", "libvendor1"}, module) + checkRuntimeLibs(t, []string{"liball_available", "libvendor1"}, module) + + module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module) + checkRuntimeLibs(t, []string{"liball_available", "libproduct1"}, module) } func checkStaticLibs(t *testing.T, expected []string, module *Module) { @@ -4244,3 +4430,21 @@ func TestStubsLibReexportsHeaders(t *testing.T) { t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags) } } + +func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) { + ctx := testCc(t, ` + cc_library { + name: "libfoo", + srcs: ["a/Foo.aidl"], + aidl: { flags: ["-Werror"], }, + } + `) + + libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static") + manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto")) + aidlCommand := manifest.Commands[0].GetCommand() + expectedAidlFlag := "-Werror" + if !strings.Contains(aidlCommand, expectedAidlFlag) { + t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) + } +} diff --git a/cc/compiler.go b/cc/compiler.go index 2c058995e..eb2b5666a 100644 --- a/cc/compiler.go +++ b/cc/compiler.go @@ -123,6 +123,9 @@ type BaseCompilerProperties struct { // whether to generate traces (for systrace) for this interface Generate_traces *bool + + // list of flags that will be passed to the AIDL compiler + Flags []string } Renderscript struct { @@ -521,6 +524,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps } if compiler.hasSrcExt(".aidl") { + flags.aidlFlags = append(flags.aidlFlags, compiler.Properties.Aidl.Flags...) if len(compiler.Properties.Aidl.Local_include_dirs) > 0 { localAidlIncludeDirs := android.PathsForModuleSrc(ctx, compiler.Properties.Aidl.Local_include_dirs) flags.aidlFlags = append(flags.aidlFlags, includeDirsToFlags(localAidlIncludeDirs)) diff --git a/cc/config/clang.go b/cc/config/clang.go index 519a9e2d2..328295896 100644 --- a/cc/config/clang.go +++ b/cc/config/clang.go @@ -94,6 +94,7 @@ var ClangLibToolingUnknownCflags = sorted([]string{}) // `modernize-*`. var ClangTidyDisableChecks = []string{ "misc-no-recursion", + "readability-function-cognitive-complexity", // http://b/175055536 } func init() { @@ -190,6 +191,8 @@ func init() { "-Wno-pessimizing-move", // http://b/154270751 // New warnings to be fixed after clang-r399163 "-Wno-non-c-typedef-for-linkage", // http://b/161304145 + // New warnings to be fixed after clang-r407598 + "-Wno-string-concatenation", // http://b/175068488 }, " ")) // Extra cflags for external third-party projects to disable warnings that diff --git a/cc/config/global.go b/cc/config/global.go index e5cb7eefd..fa8e0fba2 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -135,8 +135,8 @@ var ( // prebuilts/clang default settings. ClangDefaultBase = "prebuilts/clang/host" - ClangDefaultVersion = "clang-r399163b" - ClangDefaultShortVersion = "11.0.5" + ClangDefaultVersion = "clang-r407598" + ClangDefaultShortVersion = "12.0.1" // Directories with warnings from Android.bp files. WarningAllowedProjects = []string{ diff --git a/cc/genrule.go b/cc/genrule.go index 9648869d9..1ce216989 100644 --- a/cc/genrule.go +++ b/cc/genrule.go @@ -75,7 +75,15 @@ func (g *GenruleExtraProperties) VendorRamdiskVariantNeeded(ctx android.BaseModu } func (g *GenruleExtraProperties) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { - return Bool(g.Recovery_available) + // If the build is using a snapshot, the recovery variant under AOSP directories + // is not needed. + recoverySnapshotVersion := ctx.DeviceConfig().RecoverySnapshotVersion() + if recoverySnapshotVersion != "current" && recoverySnapshotVersion != "" && + !isRecoveryProprietaryModule(ctx) { + return false + } else { + return Bool(g.Recovery_available) + } } func (g *GenruleExtraProperties) ExtraImageVariations(ctx android.BaseModuleContext) []string { diff --git a/cc/image.go b/cc/image.go index 13d77cc2d..11ba55c84 100644 --- a/cc/image.go +++ b/cc/image.go @@ -67,9 +67,8 @@ const ( ) func (ctx *moduleContext) ProductSpecific() bool { - //TODO(b/150902910): Replace HasNonSystemVariants() with HasProductVariant() return ctx.ModuleContext.ProductSpecific() || - (ctx.mod.HasNonSystemVariants() && ctx.mod.InProduct()) + (ctx.mod.HasProductVariant() && ctx.mod.InProduct()) } func (ctx *moduleContext) SocSpecific() bool { @@ -277,6 +276,9 @@ func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) { platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion() boardVndkVersion := mctx.DeviceConfig().VndkVersion() productVndkVersion := mctx.DeviceConfig().ProductVndkVersion() + recoverySnapshotVersion := mctx.DeviceConfig().RecoverySnapshotVersion() + usingRecoverySnapshot := recoverySnapshotVersion != "current" && + recoverySnapshotVersion != "" if boardVndkVersion == "current" { boardVndkVersion = platformVndkVersion } @@ -315,7 +317,11 @@ func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) { if snapshot, ok := m.linker.(interface { version() string }); ok { - vendorVariants = append(vendorVariants, snapshot.version()) + if m.InstallInRecovery() { + recoveryVariantNeeded = true + } else { + vendorVariants = append(vendorVariants, snapshot.version()) + } } else { mctx.ModuleErrorf("version is unknown for snapshot prebuilt") } @@ -421,6 +427,15 @@ func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) { coreVariantNeeded = false } + // If using a snapshot, the recovery variant under AOSP directories is not needed, + // except for kernel headers, which needs all variants. + if _, ok := m.linker.(*kernelHeadersDecorator); !ok && + !m.isSnapshotPrebuilt() && + usingRecoverySnapshot && + !isRecoveryProprietaryModule(mctx) { + recoveryVariantNeeded = false + } + for _, variant := range android.FirstUniqueStrings(vendorVariants) { m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant) } @@ -433,6 +448,14 @@ func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) { m.Properties.VendorRamdiskVariantNeeded = vendorRamdiskVariantNeeded m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded m.Properties.CoreVariantNeeded = coreVariantNeeded + + // Disable the module if no variants are needed. + if !ramdiskVariantNeeded && + !recoveryVariantNeeded && + !coreVariantNeeded && + len(m.Properties.ExtraVariants) == 0 { + m.Disable() + } } func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool { diff --git a/cc/library.go b/cc/library.go index 23556b096..bc6ff69e1 100644 --- a/cc/library.go +++ b/cc/library.go @@ -1738,12 +1738,9 @@ func LinkageMutator(mctx android.BottomUpMutatorContext) { isLLNDK := false if m, ok := mctx.Module().(*Module); ok { - isLLNDK = m.IsLlndk() // Don't count the vestigial llndk_library module as isLLNDK, it needs a static // variant so that a cc_library_prebuilt can depend on it. - if _, ok := m.linker.(*llndkStubDecorator); ok { - isLLNDK = false - } + isLLNDK = m.IsLlndk() && !isVestigialLLNDKModule(m) } buildStatic := library.BuildStaticVariant() && !isLLNDK buildShared := library.BuildSharedVariant() @@ -1855,9 +1852,8 @@ func CanBeOrLinkAgainstVersionVariants(module interface { Host() bool InRamdisk() bool InVendorRamdisk() bool - InRecovery() bool }) bool { - return !module.Host() && !module.InRamdisk() && !module.InVendorRamdisk() && !module.InRecovery() + return !module.Host() && !module.InRamdisk() && !module.InVendorRamdisk() } func CanBeVersionVariant(module interface { diff --git a/cc/llndk_library.go b/cc/llndk_library.go index d0fbc480e..0c4bcfdbc 100644 --- a/cc/llndk_library.go +++ b/cc/llndk_library.go @@ -100,6 +100,11 @@ func (stub *llndkStubDecorator) Name(name string) string { return name + llndkLibrarySuffix } +func (stub *llndkStubDecorator) linkerProps() []interface{} { + props := stub.libraryDecorator.linkerProps() + return append(props, &stub.Properties) +} + func (stub *llndkStubDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { stub.libraryDecorator.libName = stub.implementationModuleName(ctx.ModuleName()) return stub.libraryDecorator.linkerFlags(ctx, flags) @@ -137,12 +142,6 @@ func NewLLndkStubLibrary() *Module { module.installer = nil module.library = stub - module.AddProperties( - &module.Properties, - &stub.Properties, - &library.MutatedProperties, - &library.flagExporter.Properties) - return module } @@ -156,8 +155,14 @@ func NewLLndkStubLibrary() *Module { // } func LlndkLibraryFactory() android.Module { module := NewLLndkStubLibrary() - android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth) - return module + return module.Init() +} + +// isVestigialLLNDKModule returns true if m is a vestigial llndk_library module used to provide +// properties to the LLNDK variant of a cc_library. +func isVestigialLLNDKModule(m *Module) bool { + _, ok := m.linker.(*llndkStubDecorator) + return ok } type llndkHeadersDecorator struct { diff --git a/cc/makevars.go b/cc/makevars.go index bd8aab532..8301c6b38 100644 --- a/cc/makevars.go +++ b/cc/makevars.go @@ -99,6 +99,7 @@ func makeVarsProvider(ctx android.MakeVarsContext) { ctx.Strict("GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE", "") ctx.Strict("BOARD_VNDK_VERSION", ctx.DeviceConfig().VndkVersion()) + ctx.Strict("RECOVERY_SNAPSHOT_VERSION", ctx.DeviceConfig().RecoverySnapshotVersion()) // Filter vendor_public_library that are exported to make exportedVendorPublicLibraries := []string{} diff --git a/cc/sanitize.go b/cc/sanitize.go index 0e2d01a45..bb92a882d 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -458,6 +458,22 @@ func toDisableImplicitIntegerChange(flags []string) bool { return false } +func toDisableUnsignedShiftBaseChange(flags []string) bool { + // Returns true if any flag is fsanitize*integer, and there is + // no explicit flag about sanitize=unsigned-shift-base. + for _, f := range flags { + if strings.Contains(f, "sanitize=unsigned-shift-base") { + return false + } + } + for _, f := range flags { + if strings.HasPrefix(f, "-fsanitize") && strings.Contains(f, "integer") { + return true + } + } + return false +} + func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags { minimalRuntimeLib := config.UndefinedBehaviorSanitizerMinimalRuntimeLibrary(ctx.toolchain()) + ".a" minimalRuntimePath := "${config.ClangAsanLibDir}/" + minimalRuntimeLib @@ -614,6 +630,10 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags { if toDisableImplicitIntegerChange(flags.Local.CFlags) { flags.Local.CFlags = append(flags.Local.CFlags, "-fno-sanitize=implicit-integer-sign-change") } + // http://b/171275751, Android doesn't build with this sanitizer yet. + if toDisableUnsignedShiftBaseChange(flags.Local.CFlags) { + flags.Local.CFlags = append(flags.Local.CFlags, "-fno-sanitize=unsigned-shift-base") + } } if len(sanitize.Properties.DiagSanitizers) > 0 { diff --git a/cc/snapshot_prebuilt.go b/cc/snapshot_prebuilt.go index 4c4e9b605..8c5d1a405 100644 --- a/cc/snapshot_prebuilt.go +++ b/cc/snapshot_prebuilt.go @@ -22,6 +22,8 @@ import ( "sync" "android/soong/android" + + "github.com/google/blueprint/proptools" ) // Defines the specifics of different images to which the snapshot process is applicable, e.g., @@ -30,6 +32,9 @@ type snapshotImage interface { // Used to register callbacks with the build system. init() + // Returns true if a snapshot should be generated for this image. + shouldGenerateSnapshot(ctx android.SingletonContext) bool + // Function that returns true if the module is included in this image. // Using a function return instead of a value to prevent early // evalution of a function that may be not be defined. @@ -55,6 +60,28 @@ type snapshotImage interface { // snapshot, e.g., using the exclude_from_vendor_snapshot or // exclude_from_recovery_snapshot properties. excludeFromSnapshot(m *Module) bool + + // Returns the snapshotMap to be used for a given module and config, or nil if the + // module is not included in this image. + getSnapshotMap(m *Module, cfg android.Config) *snapshotMap + + // Returns mutex used for mutual exclusion when updating the snapshot maps. + getMutex() *sync.Mutex + + // For a given arch, a maps of which modules are included in this image. + suffixModules(config android.Config) map[string]bool + + // Whether to add a given module to the suffix map. + shouldBeAddedToSuffixModules(m *Module) bool + + // Returns true if the build is using a snapshot for this image. + isUsingSnapshot(cfg android.DeviceConfig) bool + + // Whether to skip the module mutator for a module in a given context. + skipModuleMutator(ctx android.BottomUpMutatorContext) bool + + // Whether to skip the source mutator for a given module. + skipSourceMutator(ctx android.BottomUpMutatorContext) bool } type vendorSnapshotImage struct{} @@ -69,6 +96,11 @@ func (vendorSnapshotImage) init() { android.RegisterModuleType("vendor_snapshot_object", VendorSnapshotObjectFactory) } +func (vendorSnapshotImage) shouldGenerateSnapshot(ctx android.SingletonContext) bool { + // BOARD_VNDK_VERSION must be set to 'current' in order to generate a snapshot. + return ctx.DeviceConfig().VndkVersion() == "current" +} + func (vendorSnapshotImage) inImage(m *Module) func() bool { return m.inVendor } @@ -90,6 +122,75 @@ func (vendorSnapshotImage) excludeFromSnapshot(m *Module) bool { return m.ExcludeFromVendorSnapshot() } +func (vendorSnapshotImage) getSnapshotMap(m *Module, cfg android.Config) *snapshotMap { + if lib, ok := m.linker.(libraryInterface); ok { + if lib.static() { + return vendorSnapshotStaticLibs(cfg) + } else if lib.shared() { + return vendorSnapshotSharedLibs(cfg) + } else { + // header + return vendorSnapshotHeaderLibs(cfg) + } + } else if m.binary() { + return vendorSnapshotBinaries(cfg) + } else if m.object() { + return vendorSnapshotObjects(cfg) + } else { + return nil + } +} + +func (vendorSnapshotImage) getMutex() *sync.Mutex { + return &vendorSnapshotsLock +} + +func (vendorSnapshotImage) suffixModules(config android.Config) map[string]bool { + return vendorSuffixModules(config) +} + +func (vendorSnapshotImage) shouldBeAddedToSuffixModules(module *Module) bool { + // vendor suffix should be added to snapshots if the source module isn't vendor: true. + if module.SocSpecific() { + return false + } + + // But we can't just check SocSpecific() since we already passed the image mutator. + // Check ramdisk and recovery to see if we are real "vendor: true" module. + ramdiskAvailable := module.InRamdisk() && !module.OnlyInRamdisk() + vendorRamdiskAvailable := module.InVendorRamdisk() && !module.OnlyInVendorRamdisk() + recoveryAvailable := module.InRecovery() && !module.OnlyInRecovery() + + return !ramdiskAvailable && !recoveryAvailable && !vendorRamdiskAvailable +} + +func (vendorSnapshotImage) isUsingSnapshot(cfg android.DeviceConfig) bool { + vndkVersion := cfg.VndkVersion() + return vndkVersion != "current" && vndkVersion != "" +} + +func (vendorSnapshotImage) skipModuleMutator(ctx android.BottomUpMutatorContext) bool { + vndkVersion := ctx.DeviceConfig().VndkVersion() + module, ok := ctx.Module().(*Module) + return !ok || module.VndkVersion() != vndkVersion +} + +func (vendorSnapshotImage) skipSourceMutator(ctx android.BottomUpMutatorContext) bool { + vndkVersion := ctx.DeviceConfig().VndkVersion() + module, ok := ctx.Module().(*Module) + if !ok { + return true + } + if module.VndkVersion() != vndkVersion { + return true + } + // .. and also filter out llndk library + if module.IsLlndk() { + return true + } + return false +} + func (recoverySnapshotImage) init() { android.RegisterSingletonType("recovery-snapshot", RecoverySnapshotSingleton) android.RegisterModuleType("recovery_snapshot_shared", RecoverySnapshotSharedFactory) @@ -99,6 +200,12 @@ func (recoverySnapshotImage) init() { android.RegisterModuleType("recovery_snapshot_object", RecoverySnapshotObjectFactory) } +func (recoverySnapshotImage) shouldGenerateSnapshot(ctx android.SingletonContext) bool { + // RECOVERY_SNAPSHOT_VERSION must be set to 'current' in order to generate a + // snapshot. + return ctx.DeviceConfig().RecoverySnapshotVersion() == "current" +} + func (recoverySnapshotImage) inImage(m *Module) func() bool { return m.InRecovery } @@ -120,6 +227,52 @@ func (recoverySnapshotImage) excludeFromSnapshot(m *Module) bool { return m.ExcludeFromRecoverySnapshot() } +func (recoverySnapshotImage) getSnapshotMap(m *Module, cfg android.Config) *snapshotMap { + if lib, ok := m.linker.(libraryInterface); ok { + if lib.static() { + return recoverySnapshotStaticLibs(cfg) + } else if lib.shared() { + return recoverySnapshotSharedLibs(cfg) + } else { + // header + return recoverySnapshotHeaderLibs(cfg) + } + } else if m.binary() { + return recoverySnapshotBinaries(cfg) + } else if m.object() { + return recoverySnapshotObjects(cfg) + } else { + return nil + } +} + +func (recoverySnapshotImage) getMutex() *sync.Mutex { + return &recoverySnapshotsLock +} + +func (recoverySnapshotImage) suffixModules(config android.Config) map[string]bool { + return recoverySuffixModules(config) +} + +func (recoverySnapshotImage) shouldBeAddedToSuffixModules(module *Module) bool { + return proptools.BoolDefault(module.Properties.Recovery_available, false) +} + +func (recoverySnapshotImage) isUsingSnapshot(cfg android.DeviceConfig) bool { + recoverySnapshotVersion := cfg.RecoverySnapshotVersion() + return recoverySnapshotVersion != "current" && recoverySnapshotVersion != "" +} + +func (recoverySnapshotImage) skipModuleMutator(ctx android.BottomUpMutatorContext) bool { + module, ok := ctx.Module().(*Module) + return !ok || !module.InRecovery() +} + +func (recoverySnapshotImage) skipSourceMutator(ctx android.BottomUpMutatorContext) bool { + module, ok := ctx.Module().(*Module) + return !ok || !module.InRecovery() +} + var vendorSnapshotImageSingleton vendorSnapshotImage var recoverySnapshotImageSingleton recoverySnapshotImage @@ -154,6 +307,16 @@ var ( vendorSnapshotObjectsKey = android.NewOnceKey("vendorSnapshotObjects") ) +var ( + recoverySnapshotsLock sync.Mutex + recoverySuffixModulesKey = android.NewOnceKey("recoverySuffixModules") + recoverySnapshotHeaderLibsKey = android.NewOnceKey("recoverySnapshotHeaderLibs") + recoverySnapshotStaticLibsKey = android.NewOnceKey("recoverySnapshotStaticLibs") + recoverySnapshotSharedLibsKey = android.NewOnceKey("recoverySnapshotSharedLibs") + recoverySnapshotBinariesKey = android.NewOnceKey("recoverySnapshotBinaries") + recoverySnapshotObjectsKey = android.NewOnceKey("recoverySnapshotObjects") +) + // vendorSuffixModules holds names of modules whose vendor variants should have the vendor suffix. // This is determined by source modules, and then this will be used when exporting snapshot modules // to Makefile. @@ -200,12 +363,52 @@ func vendorSnapshotObjects(config android.Config) *snapshotMap { }).(*snapshotMap) } +func recoverySuffixModules(config android.Config) map[string]bool { + return config.Once(recoverySuffixModulesKey, func() interface{} { + return make(map[string]bool) + }).(map[string]bool) +} + +func recoverySnapshotHeaderLibs(config android.Config) *snapshotMap { + return config.Once(recoverySnapshotHeaderLibsKey, func() interface{} { + return newSnapshotMap() + }).(*snapshotMap) +} + +func recoverySnapshotSharedLibs(config android.Config) *snapshotMap { + return config.Once(recoverySnapshotSharedLibsKey, func() interface{} { + return newSnapshotMap() + }).(*snapshotMap) +} + +func recoverySnapshotStaticLibs(config android.Config) *snapshotMap { + return config.Once(recoverySnapshotStaticLibsKey, func() interface{} { + return newSnapshotMap() + }).(*snapshotMap) +} + +func recoverySnapshotBinaries(config android.Config) *snapshotMap { + return config.Once(recoverySnapshotBinariesKey, func() interface{} { + return newSnapshotMap() + }).(*snapshotMap) +} + +func recoverySnapshotObjects(config android.Config) *snapshotMap { + return config.Once(recoverySnapshotObjectsKey, func() interface{} { + return newSnapshotMap() + }).(*snapshotMap) +} + type baseSnapshotDecoratorProperties struct { // snapshot version. Version string // Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64') Target_arch string + + // Suffix to be added to the module name, e.g., vendor_shared, + // recovery_shared, etc. + Module_suffix string } // baseSnapshotDecorator provides common basic functions for all snapshot modules, such as snapshot @@ -222,7 +425,6 @@ type baseSnapshotDecoratorProperties struct { // will be seen as "libbase.vendor_static.30.arm64" by Soong. type baseSnapshotDecorator struct { baseProperties baseSnapshotDecoratorProperties - moduleSuffix string } func (p *baseSnapshotDecorator) Name(name string) string { @@ -235,7 +437,7 @@ func (p *baseSnapshotDecorator) NameSuffix() string { versionSuffix += "." + p.arch() } - return p.moduleSuffix + versionSuffix + return p.baseProperties.Module_suffix + versionSuffix } func (p *baseSnapshotDecorator) version() string { @@ -246,6 +448,10 @@ func (p *baseSnapshotDecorator) arch() string { return p.baseProperties.Target_arch } +func (p *baseSnapshotDecorator) module_suffix() string { + return p.baseProperties.Module_suffix +} + func (p *baseSnapshotDecorator) isSnapshotPrebuilt() bool { return true } @@ -253,7 +459,7 @@ func (p *baseSnapshotDecorator) isSnapshotPrebuilt() bool { // Call this with a module suffix after creating a snapshot module, such as // vendorSnapshotSharedSuffix, recoverySnapshotBinarySuffix, etc. func (p *baseSnapshotDecorator) init(m *Module, suffix string) { - p.moduleSuffix = suffix + p.baseProperties.Module_suffix = suffix m.AddProperties(&p.baseProperties) android.AddLoadHook(m, func(ctx android.LoadHookContext) { vendorSnapshotLoadHook(ctx, p) @@ -313,7 +519,7 @@ type snapshotLibraryDecorator struct { // Library flags for cfi variant. Cfi snapshotLibraryProperties `android:"arch_variant"` } - androidMkVendorSuffix bool + androidMkSuffix string } func (p *snapshotLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { @@ -337,7 +543,12 @@ func (p *snapshotLibraryDecorator) matchesWithDevice(config android.DeviceConfig // done by normal library decorator, e.g. exporting flags. func (p *snapshotLibraryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path { m := ctx.Module().(*Module) - p.androidMkVendorSuffix = vendorSuffixModules(ctx.Config())[m.BaseModuleName()] + + if m.inVendor() && vendorSuffixModules(ctx.Config())[m.BaseModuleName()] { + p.androidMkSuffix = vendorSuffix + } else if m.InRecovery() && recoverySuffixModules(ctx.Config())[m.BaseModuleName()] { + p.androidMkSuffix = recoverySuffix + } if p.header() { return p.libraryDecorator.link(ctx, flags, deps, objs) @@ -530,8 +741,8 @@ type snapshotBinaryProperties struct { type snapshotBinaryDecorator struct { baseSnapshotDecorator *binaryDecorator - properties snapshotBinaryProperties - androidMkVendorSuffix bool + properties snapshotBinaryProperties + androidMkSuffix string } func (p *snapshotBinaryDecorator) matchesWithDevice(config android.DeviceConfig) bool { @@ -556,7 +767,12 @@ func (p *snapshotBinaryDecorator) link(ctx ModuleContext, flags Flags, deps Path binName := in.Base() m := ctx.Module().(*Module) - p.androidMkVendorSuffix = vendorSuffixModules(ctx.Config())[m.BaseModuleName()] + if m.inVendor() && vendorSuffixModules(ctx.Config())[m.BaseModuleName()] { + p.androidMkSuffix = vendorSuffix + } else if m.InRecovery() && recoverySuffixModules(ctx.Config())[m.BaseModuleName()] { + p.androidMkSuffix = recoverySuffix + + } // use cpExecutable to make it executable outputFile := android.PathForModuleOut(ctx, binName) @@ -627,8 +843,8 @@ type vendorSnapshotObjectProperties struct { type snapshotObjectLinker struct { baseSnapshotDecorator objectLinker - properties vendorSnapshotObjectProperties - androidMkVendorSuffix bool + properties vendorSnapshotObjectProperties + androidMkSuffix string } func (p *snapshotObjectLinker) matchesWithDevice(config android.DeviceConfig) bool { @@ -649,7 +865,12 @@ func (p *snapshotObjectLinker) link(ctx ModuleContext, flags Flags, deps PathDep } m := ctx.Module().(*Module) - p.androidMkVendorSuffix = vendorSuffixModules(ctx.Config())[m.BaseModuleName()] + + if m.inVendor() && vendorSuffixModules(ctx.Config())[m.BaseModuleName()] { + p.androidMkSuffix = vendorSuffix + } else if m.InRecovery() && recoverySuffixModules(ctx.Config())[m.BaseModuleName()] { + p.androidMkSuffix = recoverySuffix + } return android.PathForModuleSrc(ctx, *p.properties.Src) } @@ -717,17 +938,24 @@ var _ snapshotInterface = (*snapshotObjectLinker)(nil) // // TODO(b/145966707): remove mutator and utilize android.Prebuilt to override source modules func VendorSnapshotMutator(ctx android.BottomUpMutatorContext) { - vndkVersion := ctx.DeviceConfig().VndkVersion() - // don't need snapshot if current - if vndkVersion == "current" || vndkVersion == "" { + snapshotMutator(ctx, vendorSnapshotImageSingleton) +} + +func RecoverySnapshotMutator(ctx android.BottomUpMutatorContext) { + snapshotMutator(ctx, recoverySnapshotImageSingleton) +} + +func snapshotMutator(ctx android.BottomUpMutatorContext, image snapshotImage) { + if !image.isUsingSnapshot(ctx.DeviceConfig()) { return } - module, ok := ctx.Module().(*Module) - if !ok || !module.Enabled() || module.VndkVersion() != vndkVersion { + if !ok || !module.Enabled() { + return + } + if image.skipModuleMutator(ctx) { return } - if !module.isSnapshotPrebuilt() { return } @@ -742,39 +970,31 @@ func VendorSnapshotMutator(ctx android.BottomUpMutatorContext) { return } - var snapshotMap *snapshotMap - - if lib, ok := module.linker.(libraryInterface); ok { - if lib.static() { - snapshotMap = vendorSnapshotStaticLibs(ctx.Config()) - } else if lib.shared() { - snapshotMap = vendorSnapshotSharedLibs(ctx.Config()) - } else { - // header - snapshotMap = vendorSnapshotHeaderLibs(ctx.Config()) - } - } else if _, ok := module.linker.(*snapshotBinaryDecorator); ok { - snapshotMap = vendorSnapshotBinaries(ctx.Config()) - } else if _, ok := module.linker.(*snapshotObjectLinker); ok { - snapshotMap = vendorSnapshotObjects(ctx.Config()) - } else { + var snapshotMap *snapshotMap = image.getSnapshotMap(module, ctx.Config()) + if snapshotMap == nil { return } - vendorSnapshotsLock.Lock() - defer vendorSnapshotsLock.Unlock() + mutex := image.getMutex() + mutex.Lock() + defer mutex.Unlock() snapshotMap.add(module.BaseModuleName(), ctx.Arch().ArchType, ctx.ModuleName()) } // VendorSnapshotSourceMutator disables source modules which have corresponding snapshots. func VendorSnapshotSourceMutator(ctx android.BottomUpMutatorContext) { + snapshotSourceMutator(ctx, vendorSnapshotImageSingleton) +} + +func RecoverySnapshotSourceMutator(ctx android.BottomUpMutatorContext) { + snapshotSourceMutator(ctx, recoverySnapshotImageSingleton) +} + +func snapshotSourceMutator(ctx android.BottomUpMutatorContext, image snapshotImage) { if !ctx.Device() { return } - - vndkVersion := ctx.DeviceConfig().VndkVersion() - // don't need snapshot if current - if vndkVersion == "current" || vndkVersion == "" { + if !image.isUsingSnapshot(ctx.DeviceConfig()) { return } @@ -783,48 +1003,23 @@ func VendorSnapshotSourceMutator(ctx android.BottomUpMutatorContext) { return } - // vendor suffix should be added to snapshots if the source module isn't vendor: true. - if !module.SocSpecific() { - // But we can't just check SocSpecific() since we already passed the image mutator. - // Check ramdisk and recovery to see if we are real "vendor: true" module. - ramdiskAvailable := module.InRamdisk() && !module.OnlyInRamdisk() - vendorRamdiskAvailable := module.InVendorRamdisk() && !module.OnlyInVendorRamdisk() - recoveryAvailable := module.InRecovery() && !module.OnlyInRecovery() - - if !ramdiskAvailable && !recoveryAvailable && !vendorRamdiskAvailable { - vendorSnapshotsLock.Lock() - defer vendorSnapshotsLock.Unlock() - - vendorSuffixModules(ctx.Config())[ctx.ModuleName()] = true - } + if image.shouldBeAddedToSuffixModules(module) { + mutex := image.getMutex() + mutex.Lock() + defer mutex.Unlock() + + image.suffixModules(ctx.Config())[ctx.ModuleName()] = true } - if module.isSnapshotPrebuilt() || module.VndkVersion() != ctx.DeviceConfig().VndkVersion() { - // only non-snapshot modules with BOARD_VNDK_VERSION + if module.isSnapshotPrebuilt() { return } - - // .. and also filter out llndk library - if module.IsLlndk() { + if image.skipSourceMutator(ctx) { return } - var snapshotMap *snapshotMap - - if lib, ok := module.linker.(libraryInterface); ok { - if lib.static() { - snapshotMap = vendorSnapshotStaticLibs(ctx.Config()) - } else if lib.shared() { - snapshotMap = vendorSnapshotSharedLibs(ctx.Config()) - } else { - // header - snapshotMap = vendorSnapshotHeaderLibs(ctx.Config()) - } - } else if module.binary() { - snapshotMap = vendorSnapshotBinaries(ctx.Config()) - } else if module.object() { - snapshotMap = vendorSnapshotObjects(ctx.Config()) - } else { + var snapshotMap *snapshotMap = image.getSnapshotMap(module, ctx.Config()) + if snapshotMap == nil { return } diff --git a/cc/snapshot_utils.go b/cc/snapshot_utils.go index e841a547b..77d82f1b5 100644 --- a/cc/snapshot_utils.go +++ b/cc/snapshot_utils.go @@ -71,6 +71,10 @@ func (s *snapshotMap) get(name string, arch android.ArchType) (snapshot string, // shouldCollectHeadersForSnapshot determines if the module is a possible candidate for snapshot. // If it's true, collectHeadersForSnapshot will be called in GenerateAndroidBuildActions. func shouldCollectHeadersForSnapshot(ctx android.ModuleContext, m *Module, apexInfo android.ApexInfo) bool { + if ctx.DeviceConfig().VndkVersion() != "current" && + ctx.DeviceConfig().RecoverySnapshotVersion() != "current" { + return false + } if _, _, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo); ok { return ctx.Config().VndkSnapshotBuildArtifacts() } else if isVendorSnapshotAware(m, isVendorProprietaryPath(ctx.ModuleDir()), apexInfo) || diff --git a/cc/testing.go b/cc/testing.go index fc5b030c7..f834205cf 100644 --- a/cc/testing.go +++ b/cc/testing.go @@ -568,10 +568,10 @@ func CreateTestContext(config android.Config) *android.TestContext { ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory) ctx.RegisterModuleType("filegroup", android.FileGroupFactory) ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory) - ctx.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory) ctx.RegisterModuleType("vendor_snapshot_shared", VendorSnapshotSharedFactory) ctx.RegisterModuleType("vendor_snapshot_static", VendorSnapshotStaticFactory) ctx.RegisterModuleType("vendor_snapshot_binary", VendorSnapshotBinaryFactory) + RegisterVndkLibraryTxtTypes(ctx) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) android.RegisterPrebuiltMutators(ctx) RegisterRequiredBuildComponentsForTest(ctx) diff --git a/cc/vendor_snapshot.go b/cc/vendor_snapshot.go index d2c29d631..417516bf9 100644 --- a/cc/vendor_snapshot.go +++ b/cc/vendor_snapshot.go @@ -85,7 +85,6 @@ var ( // Modules under following directories are ignored. They are OEM's and vendor's // proprietary modules(device/, kernel/, vendor/, and hardware/). recoveryProprietaryDirs = []string{ - "bootable/recovery", "device", "hardware", "kernel", @@ -156,6 +155,28 @@ func isVendorProprietaryModule(ctx android.BaseModuleContext) bool { return false } +func isRecoveryProprietaryModule(ctx android.BaseModuleContext) bool { + + // Any module in a vendor proprietary path is a vendor proprietary + // module. + if isRecoveryProprietaryPath(ctx.ModuleDir()) { + return true + } + + // However if the module is not in a vendor proprietary path, it may + // still be a vendor proprietary module. This happens for cc modules + // that are excluded from the vendor snapshot, and it means that the + // vendor has assumed control of the framework-provided module. + + if c, ok := ctx.Module().(*Module); ok { + if c.ExcludeFromRecoverySnapshot() { + return true + } + } + + return false +} + // Determine if a module is going to be included in vendor snapshot or not. // // Targets of vendor snapshot are "vendor: true" or "vendor_available: true" modules in @@ -192,7 +213,7 @@ func isSnapshotAware(m *Module, inProprietaryPath bool, apexInfo android.ApexInf } // If the module would be included based on its path, check to see if // the module is marked to be excluded. If so, skip it. - if m.ExcludeFromVendorSnapshot() { + if image.excludeFromSnapshot(m) { return false } if m.Target().Os.Class != android.Device { @@ -290,8 +311,7 @@ type snapshotJsonFlags struct { } func (c *snapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) { - // BOARD_VNDK_VERSION must be set to 'current' in order to generate a vendor snapshot. - if ctx.DeviceConfig().VndkVersion() != "current" { + if !c.image.shouldGenerateSnapshot(ctx) { return } @@ -480,7 +500,7 @@ func (c *snapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) { inProprietaryPath := c.image.isProprietaryPath(moduleDir) apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo) - if m.ExcludeFromVendorSnapshot() { + if c.image.excludeFromSnapshot(m) { if inProprietaryPath { // Error: exclude_from_vendor_snapshot applies // to framework-path modules only. diff --git a/cc/vndk.go b/cc/vndk.go index 6bc713135..31c77874e 100644 --- a/cc/vndk.go +++ b/cc/vndk.go @@ -35,6 +35,7 @@ const ( vndkCoreLibrariesTxt = "vndkcore.libraries.txt" vndkSpLibrariesTxt = "vndksp.libraries.txt" vndkPrivateLibrariesTxt = "vndkprivate.libraries.txt" + vndkProductLibrariesTxt = "vndkproduct.libraries.txt" vndkUsingCoreVariantLibrariesTxt = "vndkcorevariant.libraries.txt" ) @@ -45,6 +46,7 @@ func VndkLibrariesTxtModules(vndkVersion string) []string { vndkCoreLibrariesTxt, vndkSpLibrariesTxt, vndkPrivateLibrariesTxt, + vndkProductLibrariesTxt, } } // Snapshot vndks have their own *.libraries.VER.txt files. @@ -54,6 +56,7 @@ func VndkLibrariesTxtModules(vndkVersion string) []string { insertVndkVersion(vndkCoreLibrariesTxt, vndkVersion), insertVndkVersion(vndkSpLibrariesTxt, vndkVersion), insertVndkVersion(vndkPrivateLibrariesTxt, vndkVersion), + insertVndkVersion(vndkProductLibrariesTxt, vndkVersion), } } @@ -229,10 +232,11 @@ func vndkIsVndkDepAllowed(from *vndkdep, to *vndkdep) error { } var ( - vndkCoreLibrariesKey = android.NewOnceKey("vndkCoreLibrarires") - vndkSpLibrariesKey = android.NewOnceKey("vndkSpLibrarires") - llndkLibrariesKey = android.NewOnceKey("llndkLibrarires") - vndkPrivateLibrariesKey = android.NewOnceKey("vndkPrivateLibrarires") + vndkCoreLibrariesKey = android.NewOnceKey("vndkCoreLibraries") + vndkSpLibrariesKey = android.NewOnceKey("vndkSpLibraries") + llndkLibrariesKey = android.NewOnceKey("llndkLibraries") + vndkPrivateLibrariesKey = android.NewOnceKey("vndkPrivateLibraries") + vndkProductLibrariesKey = android.NewOnceKey("vndkProductLibraries") vndkUsingCoreVariantLibrariesKey = android.NewOnceKey("vndkUsingCoreVariantLibraries") vndkMustUseVendorVariantListKey = android.NewOnceKey("vndkMustUseVendorVariantListKey") vndkLibrariesLock sync.Mutex @@ -262,6 +266,12 @@ func vndkPrivateLibraries(config android.Config) map[string]string { }).(map[string]string) } +func vndkProductLibraries(config android.Config) map[string]string { + return config.Once(vndkProductLibrariesKey, func() interface{} { + return make(map[string]string) + }).(map[string]string) +} + func vndkUsingCoreVariantLibraries(config android.Config) map[string]string { return config.Once(vndkUsingCoreVariantLibrariesKey, func() interface{} { return make(map[string]string) @@ -299,6 +309,12 @@ func processLlndkLibrary(mctx android.BottomUpMutatorContext, m *Module) { } func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) { + if m.InProduct() { + // We may skip the steps for the product variants because they + // are already covered by the vendor variants. + return + } + name := m.BaseModuleName() filename, err := getVndkFileName(m) if err != nil { @@ -318,12 +334,6 @@ func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) { vndkLibrariesLock.Lock() defer vndkLibrariesLock.Unlock() - if m.InProduct() { - // We may skip the other steps for the product variants because they - // are already covered by the vendor variants. - return - } - if inList(name, vndkMustUseVendorVariantList(mctx.Config())) { m.Properties.MustUseVendorVariant = true } @@ -339,6 +349,9 @@ func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) { if m.IsVndkPrivate() { vndkPrivateLibraries(mctx.Config())[name] = filename } + if m.VendorProperties.Product_available != nil { + vndkProductLibraries(mctx.Config())[name] = filename + } } // Check for modules that mustn't be VNDK @@ -436,15 +449,32 @@ func VndkMutator(mctx android.BottomUpMutatorContext) { } func init() { - android.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory) + RegisterVndkLibraryTxtTypes(android.InitRegistrationContext) android.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton) } +func RegisterVndkLibraryTxtTypes(ctx android.RegistrationContext) { + ctx.RegisterModuleType("llndk_libraries_txt", VndkLibrariesTxtFactory(libclangRTRemover(llndkLibraries))) + ctx.RegisterModuleType("vndksp_libraries_txt", VndkLibrariesTxtFactory(vndkSpLibraries)) + ctx.RegisterModuleType("vndkcore_libraries_txt", VndkLibrariesTxtFactory(vndkCoreLibraries)) + ctx.RegisterModuleType("vndkprivate_libraries_txt", VndkLibrariesTxtFactory(vndkPrivateLibraries)) + ctx.RegisterModuleType("vndkproduct_libraries_txt", VndkLibrariesTxtFactory(vndkProductLibraries)) + ctx.RegisterModuleType("vndkcorevariant_libraries_txt", VndkLibrariesTxtFactory(vndkUsingCoreVariantLibraries)) +} + type vndkLibrariesTxt struct { android.ModuleBase + + lister func(android.Config) map[string]string + properties VndkLibrariesTxtProperties + outputFile android.OutputPath } +type VndkLibrariesTxtProperties struct { + Insert_vndk_version *bool +} + var _ etc.PrebuiltEtcModule = &vndkLibrariesTxt{} var _ android.OutputFileProducer = &vndkLibrariesTxt{} @@ -453,14 +483,20 @@ var _ android.OutputFileProducer = &vndkLibrariesTxt{} // - vndkcore.libraries.txt // - vndksp.libraries.txt // - vndkprivate.libraries.txt +// - vndkproduct.libraries.txt // - vndkcorevariant.libraries.txt // A module behaves like a prebuilt_etc but its content is generated by soong. // By being a soong module, these files can be referenced by other soong modules. // For example, apex_vndk can depend on these files as prebuilt. -func VndkLibrariesTxtFactory() android.Module { - m := &vndkLibrariesTxt{} - android.InitAndroidModule(m) - return m +func VndkLibrariesTxtFactory(lister func(android.Config) map[string]string) android.ModuleFactory { + return func() android.Module { + m := &vndkLibrariesTxt{ + lister: lister, + } + m.AddProperties(&m.properties) + android.InitAndroidModule(m) + return m + } } func insertVndkVersion(filename string, vndkVersion string) string { @@ -470,31 +506,25 @@ func insertVndkVersion(filename string, vndkVersion string) string { return filename } -func (txt *vndkLibrariesTxt) GenerateAndroidBuildActions(ctx android.ModuleContext) { - var list []string - switch txt.Name() { - case llndkLibrariesTxt: - for _, filename := range android.SortedStringMapValues(llndkLibraries(ctx.Config())) { - if strings.HasPrefix(filename, "libclang_rt.hwasan-") { +func libclangRTRemover(lister func(android.Config) map[string]string) func(android.Config) map[string]string { + return func(config android.Config) map[string]string { + libs := lister(config) + filteredLibs := make(map[string]string, len(libs)) + for lib, v := range libs { + if strings.HasPrefix(lib, "libclang_rt.hwasan-") { continue } - list = append(list, filename) + filteredLibs[lib] = v } - case vndkCoreLibrariesTxt: - list = android.SortedStringMapValues(vndkCoreLibraries(ctx.Config())) - case vndkSpLibrariesTxt: - list = android.SortedStringMapValues(vndkSpLibraries(ctx.Config())) - case vndkPrivateLibrariesTxt: - list = android.SortedStringMapValues(vndkPrivateLibraries(ctx.Config())) - case vndkUsingCoreVariantLibrariesTxt: - list = android.SortedStringMapValues(vndkUsingCoreVariantLibraries(ctx.Config())) - default: - ctx.ModuleErrorf("name(%s) is unknown.", txt.Name()) - return + return filteredLibs } +} + +func (txt *vndkLibrariesTxt) GenerateAndroidBuildActions(ctx android.ModuleContext) { + list := android.SortedStringMapValues(txt.lister(ctx.Config())) var filename string - if txt.Name() != vndkUsingCoreVariantLibrariesTxt { + if BoolDefault(txt.properties.Insert_vndk_version, true) { filename = insertVndkVersion(txt.Name(), ctx.DeviceConfig().PlatformVndkVersion()) } else { filename = txt.Name() @@ -807,6 +837,7 @@ func (c *vndkSnapshotSingleton) buildVndkLibrariesTxtFiles(ctx android.Singleton vndkcore := android.SortedStringMapValues(vndkCoreLibraries(ctx.Config())) vndksp := android.SortedStringMapValues(vndkSpLibraries(ctx.Config())) vndkprivate := android.SortedStringMapValues(vndkPrivateLibraries(ctx.Config())) + vndkproduct := android.SortedStringMapValues(vndkProductLibraries(ctx.Config())) // Build list of vndk libs as merged & tagged & filter-out(libclang_rt): // Since each target have different set of libclang_rt.* files, @@ -824,6 +855,7 @@ func (c *vndkSnapshotSingleton) buildVndkLibrariesTxtFiles(ctx android.Singleton merged = append(merged, addPrefix(vndksp, "VNDK-SP: ")...) merged = append(merged, addPrefix(filterOutLibClangRt(vndkcore), "VNDK-core: ")...) merged = append(merged, addPrefix(vndkprivate, "VNDK-private: ")...) + merged = append(merged, addPrefix(filterOutLibClangRt(vndkproduct), "VNDK-product: ")...) c.vndkLibrariesFile = android.PathForOutput(ctx, "vndk", "vndk.libraries.txt") android.WriteFileRule(ctx, c.vndkLibrariesFile, strings.Join(merged, "\n")) } @@ -8,4 +8,4 @@ replace github.com/golang/protobuf v0.0.0 => ../../external/golang-protobuf replace github.com/google/blueprint v0.0.0 => ../blueprint -go 1.15 +go 1.15.6 diff --git a/java/java.go b/java/java.go index 18dd9bda4..82b53be1d 100644 --- a/java/java.go +++ b/java/java.go @@ -304,6 +304,9 @@ type CompilerDeviceProperties struct { // whether to generate Binder#GetTransaction name method. Generate_get_transaction_name *bool + + // list of flags that will be passed to the AIDL compiler + Flags []string } // If true, export a copy of the module as a -hostdex module for host testing. @@ -872,6 +875,8 @@ func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.Opt var flags []string var deps android.Paths + flags = append(flags, j.deviceProperties.Aidl.Flags...) + if aidlPreprocess.Valid() { flags = append(flags, "-p"+aidlPreprocess.String()) deps = append(deps, aidlPreprocess.Path()) diff --git a/java/java_test.go b/java/java_test.go index d1ba3dbe4..a2466f995 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -2424,6 +2424,22 @@ func TestAidlExportIncludeDirsFromImports(t *testing.T) { } } +func TestAidlFlagsArePassedToTheAidlCompiler(t *testing.T) { + ctx, _ := testJava(t, ` + java_library { + name: "foo", + srcs: ["aidl/foo/IFoo.aidl"], + aidl: { flags: ["-Werror"], }, + } + `) + + aidlCommand := ctx.ModuleForTests("foo", "android_common").Rule("aidl").RuleParams.Command + expectedAidlFlag := "-Werror" + if !strings.Contains(aidlCommand, expectedAidlFlag) { + t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) + } +} + func TestDataNativeBinaries(t *testing.T) { ctx, config := testJava(t, ` java_test_host { diff --git a/rust/bindgen.go b/rust/bindgen.go index 35a807bfd..56d660eca 100644 --- a/rust/bindgen.go +++ b/rust/bindgen.go @@ -31,12 +31,19 @@ var ( // bindgen should specify its own Clang revision so updating Clang isn't potentially blocked on bindgen failures. bindgenClangVersion = "clang-r399163b" + _ = pctx.VariableFunc("bindgenClangVersion", func(ctx android.PackageVarContext) string { + if override := ctx.Config().Getenv("LLVM_BINDGEN_PREBUILTS_VERSION"); override != "" { + return override + } + return bindgenClangVersion + }) + //TODO(b/160803703) Use a prebuilt bindgen instead of the built bindgen. _ = pctx.HostBinToolVariable("bindgenCmd", "bindgen") _ = pctx.SourcePathVariable("bindgenClang", - "${cc_config.ClangBase}/${config.HostPrebuiltTag}/"+bindgenClangVersion+"/bin/clang") + "${cc_config.ClangBase}/${config.HostPrebuiltTag}/${bindgenClangVersion}/bin/clang") _ = pctx.SourcePathVariable("bindgenLibClang", - "${cc_config.ClangBase}/${config.HostPrebuiltTag}/"+bindgenClangVersion+"/lib64/") + "${cc_config.ClangBase}/${config.HostPrebuiltTag}/${bindgenClangVersion}/lib64/") //TODO(ivanlozano) Switch this to RuleBuilder bindgen = pctx.AndroidStaticRule("bindgen", |