From 4d8d8fec4a8c3c152aa2d9e9e5252d8612d9afc3 Mon Sep 17 00:00:00 2001 From: Inseob Kim Date: Mon, 1 Jun 2020 21:53:49 +0900 Subject: [PATCH 1/4] Refine logic choosing vendor snapshot modules This refines the vendor snapshot codes in order to fix logic errors. - Capture toolchain_library and cc_library_headers correctly. - Redirect unwind static library correctly. - Filter out sanitize / coverage / lto by looking at HideFromMake. - Add binary() function for clear and shorter codes. - Include test modules. - Add more tests to prevent further snapshot breakages. Bug: 157106227 Test: m vendor-snapshot Test: m nothing for all available targets Test: EMMA_INSTRUMENT=true EMMA_INSTRUMENT_FRAMEWORK=true \ NATIVE_COVERAGE=true COVERAGE_PATHS="*" m nothing Change-Id: Id90082b5ab730f928582ad24f022ba410855400e --- cc/binary.go | 4 +++ cc/cc.go | 16 +++++++++- cc/cc_test.go | 72 +++++++++++++++++++++++++++++++------------ cc/prebuilt.go | 4 +++ cc/testing.go | 1 + cc/vendor_snapshot.go | 45 ++++++++++++++------------- 6 files changed, 99 insertions(+), 43 deletions(-) diff --git a/cc/binary.go b/cc/binary.go index 661264eef..251b7f0c4 100644 --- a/cc/binary.go +++ b/cc/binary.go @@ -231,6 +231,10 @@ func (binary *binaryDecorator) staticBinary() bool { return binary.static() } +func (binary *binaryDecorator) binary() bool { + return true +} + func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { flags = binary.baseLinker.linkerFlags(ctx, flags) diff --git a/cc/cc.go b/cc/cc.go index 01bf5f1ef..150843cd5 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -309,6 +309,7 @@ type ModuleContextIntf interface { static() bool staticBinary() bool header() bool + binary() bool toolchain() config.Toolchain canUseSdk() bool useSdk() bool @@ -1114,6 +1115,10 @@ func (ctx *moduleContextImpl) header() bool { return ctx.mod.header() } +func (ctx *moduleContextImpl) binary() bool { + return ctx.mod.binary() +} + func (ctx *moduleContextImpl) canUseSdk() bool { return ctx.mod.canUseSdk() } @@ -1896,7 +1901,7 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { if deps.StaticUnwinderIfLegacy { actx.AddVariationDependencies([]blueprint.Variation{ {Mutator: "link", Variation: "static"}, - }, staticUnwinderDepTag, staticUnwinder(actx)) + }, staticUnwinderDepTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs)) } for _, lib := range deps.LateStaticLibs { @@ -2713,6 +2718,15 @@ func (c *Module) header() bool { return false } +func (c *Module) binary() bool { + if b, ok := c.linker.(interface { + binary() bool + }); ok { + return b.binary() + } + return false +} + func (c *Module) getMakeLinkType(actx android.ModuleContext) string { if c.UseVndk() { if lib, ok := c.linker.(*llndkStubDecorator); ok { diff --git a/cc/cc_test.go b/cc/cc_test.go index 67eb248d2..0a25b5e02 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -258,9 +258,7 @@ func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string } } -func checkSnapshot(t *testing.T, ctx *android.TestContext, singletonName, moduleName, snapshotFilename, subDir, variant string) { - snapshotSingleton := ctx.SingletonForTests(singletonName) - +func checkSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) { mod, ok := ctx.ModuleForTests(moduleName, variant).Module().(android.OutputFileProducer) if !ok { t.Errorf("%q must have output\n", moduleName) @@ -273,7 +271,7 @@ func checkSnapshot(t *testing.T, ctx *android.TestContext, singletonName, module } snapshotPath := filepath.Join(subDir, snapshotFilename) - out := snapshotSingleton.Output(snapshotPath) + out := singleton.Output(snapshotPath) if out.Input.String() != outputFiles[0].String() { t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0]) } @@ -398,16 +396,18 @@ func TestVndk(t *testing.T) { variant := "android_vendor.VER_arm64_armv8-a_shared" variant2nd := "android_vendor.VER_arm_armv7-a-neon_shared" - checkSnapshot(t, ctx, "vndk-snapshot", "libvndk", "libvndk.so", vndkCoreLibPath, variant) - checkSnapshot(t, ctx, "vndk-snapshot", "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd) - checkSnapshot(t, ctx, "vndk-snapshot", "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant) - checkSnapshot(t, ctx, "vndk-snapshot", "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd) + snapshotSingleton := ctx.SingletonForTests("vndk-snapshot") + + checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLibPath, variant) + checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd) + checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant) + checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd) snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs") - checkSnapshot(t, ctx, "vndk-snapshot", "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "") - checkSnapshot(t, ctx, "vndk-snapshot", "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "") - checkSnapshot(t, ctx, "vndk-snapshot", "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "") - checkSnapshot(t, ctx, "vndk-snapshot", "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "") + checkSnapshot(t, ctx, snapshotSingleton, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "") + 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, "") checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{ "LLNDK: libc.so", @@ -839,6 +839,12 @@ func TestVendorSnapshot(t *testing.T) { vendor_available: true, nocrt: true, } + + toolchain_library { + name: "libb", + vendor_available: true, + src: "libb.a", + } ` config := TestConfig(buildDir, android.Android, nil, bp, nil) config.TestProductVariables.DeviceVndkVersion = StringPtr("current") @@ -849,6 +855,9 @@ func TestVendorSnapshot(t *testing.T) { snapshotDir := "vendor-snapshot" snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64") + snapshotSingleton := ctx.SingletonForTests("vendor-snapshot") + + var jsonFiles []string for _, arch := range [][]string{ []string{"arm64", "armv8-a"}, @@ -861,22 +870,45 @@ func TestVendorSnapshot(t *testing.T) { // For shared libraries, only non-VNDK vendor_available modules are captured sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant) sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") - checkSnapshot(t, ctx, "vendor-snapshot", "libvendor", "libvendor.so", sharedDir, sharedVariant) - checkSnapshot(t, ctx, "vendor-snapshot", "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant) + checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant) + checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant) + jsonFiles = append(jsonFiles, + filepath.Join(sharedDir, "libvendor.so.json"), + filepath.Join(sharedDir, "libvendor_available.so.json")) // For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured. staticVariant := fmt.Sprintf("android_vendor.VER_%s_%s_static", archType, archVariant) staticDir := filepath.Join(snapshotVariantPath, archDir, "static") - checkSnapshot(t, ctx, "vendor-snapshot", "libvndk", "libvndk.a", staticDir, staticVariant) - checkSnapshot(t, ctx, "vendor-snapshot", "libvendor", "libvendor.a", staticDir, staticVariant) - checkSnapshot(t, ctx, "vendor-snapshot", "libvendor_available", "libvendor_available.a", staticDir, staticVariant) + checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant) + checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.a", staticDir, staticVariant) + checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.a", staticDir, staticVariant) + checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.a", staticDir, staticVariant) + jsonFiles = append(jsonFiles, + filepath.Join(staticDir, "libb.a.json"), + filepath.Join(staticDir, "libvndk.a.json"), + filepath.Join(staticDir, "libvendor.a.json"), + filepath.Join(staticDir, "libvendor_available.a.json")) - // For binary libraries, all vendor:true and vendor_available modules are captured. + // For binary executables, all vendor:true and vendor_available modules are captured. if archType == "arm64" { binaryVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant) binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary") - checkSnapshot(t, ctx, "vendor-snapshot", "vendor_bin", "vendor_bin", binaryDir, binaryVariant) - checkSnapshot(t, ctx, "vendor-snapshot", "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant) + checkSnapshot(t, ctx, snapshotSingleton, "vendor_bin", "vendor_bin", binaryDir, binaryVariant) + checkSnapshot(t, ctx, snapshotSingleton, "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant) + jsonFiles = append(jsonFiles, + filepath.Join(binaryDir, "vendor_bin.json"), + filepath.Join(binaryDir, "vendor_available_bin.json")) + } + + // For header libraries, all vendor:true and vendor_available modules are captured. + headerDir := filepath.Join(snapshotVariantPath, archDir, "header") + jsonFiles = append(jsonFiles, filepath.Join(headerDir, "libvendor_headers.json")) + } + + for _, jsonFile := range jsonFiles { + // verify all json files exist + if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { + t.Errorf("%q expected but not found", jsonFile) } } } diff --git a/cc/prebuilt.go b/cc/prebuilt.go index 2ef31950e..d22838add 100644 --- a/cc/prebuilt.go +++ b/cc/prebuilt.go @@ -306,6 +306,10 @@ func (p *prebuiltBinaryLinker) link(ctx ModuleContext, return nil } +func (p *prebuiltBinaryLinker) binary() bool { + return true +} + // cc_prebuilt_binary installs a precompiled executable in srcs property in the // device's directory. func prebuiltBinaryFactory() android.Module { diff --git a/cc/testing.go b/cc/testing.go index 611992070..d92309f3d 100644 --- a/cc/testing.go +++ b/cc/testing.go @@ -457,6 +457,7 @@ func TestConfig(buildDir string, os android.OsType, env map[string]string, "my_include": nil, "foo.map.txt": nil, "liba.so": nil, + "libb.a": nil, } GatherRequiredFilesForTest(mockFS) diff --git a/cc/vendor_snapshot.go b/cc/vendor_snapshot.go index c79a653cd..13a6b055d 100644 --- a/cc/vendor_snapshot.go +++ b/cc/vendor_snapshot.go @@ -429,7 +429,7 @@ func isVendorProprietaryPath(dir string) bool { // depend on newer VNDK) So they are captured as vendor snapshot To build older vendor // image and newer system image altogether. func isVendorSnapshotModule(m *Module, moduleDir string) bool { - if !m.Enabled() { + if !m.Enabled() || m.Properties.HideFromMake { return false } // skip proprietary modules, but include all VNDK (static) @@ -443,37 +443,37 @@ func isVendorSnapshotModule(m *Module, moduleDir string) bool { return false } // the module must be installed in /vendor - if !m.installable() || m.isSnapshotPrebuilt() || !m.inVendor() { - return false - } - // exclude test modules - if _, ok := m.linker.(interface{ gtest() bool }); ok { - return false - } - // TODO(b/65377115): add full support for sanitizer - if m.sanitize != nil && !m.sanitize.isUnsanitizedVariant() { + if !m.IsForPlatform() || m.isSnapshotPrebuilt() || !m.inVendor() { return false } // Libraries if l, ok := m.linker.(snapshotLibraryInterface); ok { + // TODO(b/65377115): add full support for sanitizer + if m.sanitize != nil { + // cfi, scs and hwasan export both sanitized and unsanitized variants for static and header + // Always use unsanitized variants of them. + for _, t := range []sanitizerType{cfi, scs, hwasan} { + if !l.shared() && m.sanitize.isSanitizerEnabled(t) { + return false + } + } + } if l.static() { - return proptools.BoolDefault(m.VendorProperties.Vendor_available, true) + return m.outputFile.Valid() && proptools.BoolDefault(m.VendorProperties.Vendor_available, true) } if l.shared() { - return !m.IsVndk() + return m.outputFile.Valid() && !m.IsVndk() } return true } // Binaries - _, ok := m.linker.(*binaryDecorator) - if !ok { - if _, ok := m.linker.(*prebuiltBinaryLinker); !ok { - return false - } + if m.binary() { + return m.outputFile.Valid() && proptools.BoolDefault(m.VendorProperties.Vendor_available, true) } - return proptools.BoolDefault(m.VendorProperties.Vendor_available, true) + + return false } func (c *vendorSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) { @@ -620,7 +620,7 @@ func (c *vendorSnapshotSingleton) GenerateBuildActions(ctx android.SingletonCont } propOut = filepath.Join(snapshotArchDir, targetArch, libType, stem+".json") - } else { + } else if m.binary() { // binary flags prop.Symlinks = m.Symlinks() prop.SharedLibs = m.Properties.SnapshotSharedLibs @@ -630,6 +630,9 @@ func (c *vendorSnapshotSingleton) GenerateBuildActions(ctx android.SingletonCont snapshotBinOut := filepath.Join(snapshotArchDir, targetArch, "binary", binPath.Base()) ret = append(ret, copyFile(ctx, binPath, snapshotBinOut)) propOut = snapshotBinOut + ".json" + } else { + ctx.Errorf("unknown module %q in vendor snapshot", m.String()) + return nil } j, err := json.Marshal(prop) @@ -815,9 +818,7 @@ func VendorSnapshotSourceMutator(ctx android.BottomUpMutatorContext) { // header snapshotMap = vendorSnapshotHeaderLibs(ctx.Config()) } - } else if _, ok := module.linker.(*binaryDecorator); ok { - snapshotMap = vendorSnapshotBinaries(ctx.Config()) - } else if _, ok := module.linker.(*prebuiltBinaryLinker); ok { + } else if module.binary() { snapshotMap = vendorSnapshotBinaries(ctx.Config()) } else { return From 502679e0619ca0266d33ff0665217f97f15d2cdc Mon Sep 17 00:00:00 2001 From: Inseob Kim Date: Mon, 1 Jun 2020 23:23:05 +0900 Subject: [PATCH 2/4] Implement cc_object vendor snapshot cc_object modules are also necessary for vendor snapshot. Bug: 157106227 Test: m vendor-snapshot Change-Id: Idf4fd37a26f6f712f3cbab43133622f9f9bd9372 --- cc/androidmk.go | 19 +++++++ cc/cc.go | 30 ++++++---- cc/cc_test.go | 11 ++++ cc/object.go | 4 ++ cc/prebuilt.go | 4 ++ cc/vendor_snapshot.go | 129 ++++++++++++++++++++++++++++++++++++++++-- cc/vndk_prebuilt.go | 4 ++ 7 files changed, 186 insertions(+), 15 deletions(-) diff --git a/cc/androidmk.go b/cc/androidmk.go index 5438b149d..fede601b4 100644 --- a/cc/androidmk.go +++ b/cc/androidmk.go @@ -540,6 +540,25 @@ func (c *vendorSnapshotBinaryDecorator) AndroidMkEntries(ctx AndroidMkContext, e }) } +func (c *vendorSnapshotObjectLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { + entries.Class = "STATIC_LIBRARIES" + + if c.androidMkVendorSuffix { + entries.SubName = vendorSuffix + } else { + entries.SubName = "" + } + + entries.ExtraFooters = append(entries.ExtraFooters, + func(w io.Writer, name, prefix, moduleDir string, entries *android.AndroidMkEntries) { + out := entries.OutputFile.Path() + varname := fmt.Sprintf("SOONG_%sOBJECT_%s%s", prefix, name, entries.SubName) + + fmt.Fprintf(w, "\n%s := %s\n", varname, out.String()) + fmt.Fprintln(w, ".KATI_READONLY: "+varname) + }) +} + func (c *ndkPrebuiltStlLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { entries.Class = "SHARED_LIBRARIES" } diff --git a/cc/cc.go b/cc/cc.go index 150843cd5..a09b9225e 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -310,6 +310,7 @@ type ModuleContextIntf interface { staticBinary() bool header() bool binary() bool + object() bool toolchain() config.Toolchain canUseSdk() bool useSdk() bool @@ -1003,14 +1004,8 @@ func (c *Module) nativeCoverage() bool { } func (c *Module) isSnapshotPrebuilt() bool { - if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok { - return true - } - if _, ok := c.linker.(*vendorSnapshotLibraryDecorator); ok { - return true - } - if _, ok := c.linker.(*vendorSnapshotBinaryDecorator); ok { - return true + if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok { + return p.isSnapshotPrebuilt() } return false } @@ -1119,6 +1114,10 @@ func (ctx *moduleContextImpl) binary() bool { return ctx.mod.binary() } +func (ctx *moduleContextImpl) object() bool { + return ctx.mod.object() +} + func (ctx *moduleContextImpl) canUseSdk() bool { return ctx.mod.canUseSdk() } @@ -1982,11 +1981,13 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...) + vendorSnapshotObjects := vendorSnapshotObjects(actx.Config()) + if deps.CrtBegin != "" { - actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin) + actx.AddVariationDependencies(nil, CrtBeginDepTag, rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects)) } if deps.CrtEnd != "" { - actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd) + actx.AddVariationDependencies(nil, CrtEndDepTag, rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects)) } if deps.LinkerFlagsFile != "" { actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile) @@ -2727,6 +2728,15 @@ func (c *Module) binary() bool { return false } +func (c *Module) object() bool { + if o, ok := c.linker.(interface { + object() bool + }); ok { + return o.object() + } + return false +} + func (c *Module) getMakeLinkType(actx android.ModuleContext) string { if c.UseVndk() { if lib, ok := c.linker.(*llndkStubDecorator); ok { diff --git a/cc/cc_test.go b/cc/cc_test.go index 0a25b5e02..76b4e38e2 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -845,6 +845,11 @@ func TestVendorSnapshot(t *testing.T) { vendor_available: true, src: "libb.a", } + + cc_object { + name: "obj", + vendor_available: true, + } ` config := TestConfig(buildDir, android.Android, nil, bp, nil) config.TestProductVariables.DeviceVndkVersion = StringPtr("current") @@ -903,6 +908,12 @@ func TestVendorSnapshot(t *testing.T) { // For header libraries, all vendor:true and vendor_available modules are captured. headerDir := filepath.Join(snapshotVariantPath, archDir, "header") jsonFiles = append(jsonFiles, filepath.Join(headerDir, "libvendor_headers.json")) + + // For object modules, all vendor:true and vendor_available modules are captured. + objectVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant) + objectDir := filepath.Join(snapshotVariantPath, archDir, "object") + checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant) + jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json")) } for _, jsonFile := range jsonFiles { diff --git a/cc/object.go b/cc/object.go index 19decec37..15a529e85 100644 --- a/cc/object.go +++ b/cc/object.go @@ -158,3 +158,7 @@ func (object *objectLinker) nativeCoverage() bool { func (object *objectLinker) coverageOutputFilePath() android.OptionalPath { return android.OptionalPath{} } + +func (object *objectLinker) object() bool { + return true +} diff --git a/cc/prebuilt.go b/cc/prebuilt.go index d22838add..b7c0bf2fd 100644 --- a/cc/prebuilt.go +++ b/cc/prebuilt.go @@ -248,6 +248,10 @@ func (p *prebuiltObjectLinker) link(ctx ModuleContext, return nil } +func (p *prebuiltObjectLinker) object() bool { + return true +} + func newPrebuiltObject() *Module { module := newObject() prebuilt := &prebuiltObjectLinker{ diff --git a/cc/vendor_snapshot.go b/cc/vendor_snapshot.go index 13a6b055d..898ac2ab6 100644 --- a/cc/vendor_snapshot.go +++ b/cc/vendor_snapshot.go @@ -30,6 +30,7 @@ const ( vendorSnapshotSharedSuffix = ".vendor_shared." vendorSnapshotStaticSuffix = ".vendor_static." vendorSnapshotBinarySuffix = ".vendor_binary." + vendorSnapshotObjectSuffix = ".vendor_object." ) var ( @@ -39,6 +40,7 @@ var ( vendorSnapshotStaticLibsKey = android.NewOnceKey("vendorSnapshotStaticLibs") vendorSnapshotSharedLibsKey = android.NewOnceKey("vendorSnapshotSharedLibs") vendorSnapshotBinariesKey = android.NewOnceKey("vendorSnapshotBinaries") + vendorSnapshotObjectsKey = android.NewOnceKey("vendorSnapshotObjects") ) // vendor snapshot maps hold names of vendor snapshot modules per arch @@ -72,6 +74,12 @@ func vendorSnapshotBinaries(config android.Config) *snapshotMap { }).(*snapshotMap) } +func vendorSnapshotObjects(config android.Config) *snapshotMap { + return config.Once(vendorSnapshotObjectsKey, func() interface{} { + return newSnapshotMap() + }).(*snapshotMap) +} + type vendorSnapshotLibraryProperties struct { // snapshot version. Version string @@ -185,6 +193,10 @@ func (p *vendorSnapshotLibraryDecorator) nativeCoverage() bool { return false } +func (p *vendorSnapshotLibraryDecorator) isSnapshotPrebuilt() bool { + return true +} + func (p *vendorSnapshotLibraryDecorator) install(ctx ModuleContext, file android.Path) { if p.matchesWithDevice(ctx.DeviceConfig()) && (p.shared() || p.static()) { p.baseInstaller.install(ctx, file) @@ -337,6 +349,10 @@ func (p *vendorSnapshotBinaryDecorator) link(ctx ModuleContext, return outputFile } +func (p *vendorSnapshotBinaryDecorator) isSnapshotPrebuilt() bool { + return true +} + func VendorSnapshotBinaryFactory() android.Module { module, binary := NewBinary(android.DeviceSupported) binary.baseLinker.Properties.No_libcrt = BoolPtr(true) @@ -364,12 +380,98 @@ func VendorSnapshotBinaryFactory() android.Module { return module.Init() } +type vendorSnapshotObjectProperties struct { + // snapshot version. + Version string + + // Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64_ab') + Target_arch string + + // Prebuilt file for each arch. + Src *string `android:"arch_variant"` +} + +type vendorSnapshotObjectLinker struct { + objectLinker + properties vendorSnapshotObjectProperties + androidMkVendorSuffix bool +} + +func (p *vendorSnapshotObjectLinker) Name(name string) string { + return name + p.NameSuffix() +} + +func (p *vendorSnapshotObjectLinker) NameSuffix() string { + versionSuffix := p.version() + if p.arch() != "" { + versionSuffix += "." + p.arch() + } + return vendorSnapshotObjectSuffix + versionSuffix +} + +func (p *vendorSnapshotObjectLinker) version() string { + return p.properties.Version +} + +func (p *vendorSnapshotObjectLinker) arch() string { + return p.properties.Target_arch +} + +func (p *vendorSnapshotObjectLinker) matchesWithDevice(config android.DeviceConfig) bool { + if config.DeviceArch() != p.arch() { + return false + } + if p.properties.Src == nil { + return false + } + return true +} + +func (p *vendorSnapshotObjectLinker) link(ctx ModuleContext, + flags Flags, deps PathDeps, objs Objects) android.Path { + if !p.matchesWithDevice(ctx.DeviceConfig()) { + return nil + } + + m := ctx.Module().(*Module) + p.androidMkVendorSuffix = vendorSuffixModules(ctx.Config())[m.BaseModuleName()] + + return android.PathForModuleSrc(ctx, *p.properties.Src) +} + +func (p *vendorSnapshotObjectLinker) nativeCoverage() bool { + return false +} + +func (p *vendorSnapshotObjectLinker) isSnapshotPrebuilt() bool { + return true +} + +func VendorSnapshotObjectFactory() android.Module { + module := newObject() + + prebuilt := &vendorSnapshotObjectLinker{ + objectLinker: objectLinker{ + baseLinker: NewBaseLinker(nil), + }, + } + module.linker = prebuilt + + android.AddLoadHook(module, func(ctx android.LoadHookContext) { + vendorSnapshotLoadHook(ctx, prebuilt) + }) + + module.AddProperties(&prebuilt.properties) + return module.Init() +} + func init() { android.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton) android.RegisterModuleType("vendor_snapshot_shared", VendorSnapshotSharedFactory) android.RegisterModuleType("vendor_snapshot_static", VendorSnapshotStaticFactory) android.RegisterModuleType("vendor_snapshot_header", VendorSnapshotHeaderFactory) android.RegisterModuleType("vendor_snapshot_binary", VendorSnapshotBinaryFactory) + android.RegisterModuleType("vendor_snapshot_object", VendorSnapshotObjectFactory) } func VendorSnapshotSingleton() android.Singleton { @@ -468,8 +570,8 @@ func isVendorSnapshotModule(m *Module, moduleDir string) bool { return true } - // Binaries - if m.binary() { + // Binaries and Objects + if m.binary() || m.object() { return m.outputFile.Valid() && proptools.BoolDefault(m.VendorProperties.Vendor_available, true) } @@ -496,6 +598,8 @@ func (c *vendorSnapshotSingleton) GenerateBuildActions(ctx android.SingletonCont (header only libraries) binary/ (executable binaries) + object/ + (.o object files) arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/ shared/ (.so shared libraries) @@ -505,6 +609,8 @@ func (c *vendorSnapshotSingleton) GenerateBuildActions(ctx android.SingletonCont (header only libraries) binary/ (executable binaries) + object/ + (.o object files) NOTICE_FILES/ (notice files, e.g. libbase.txt) configs/ @@ -630,6 +736,14 @@ func (c *vendorSnapshotSingleton) GenerateBuildActions(ctx android.SingletonCont snapshotBinOut := filepath.Join(snapshotArchDir, targetArch, "binary", binPath.Base()) ret = append(ret, copyFile(ctx, binPath, snapshotBinOut)) propOut = snapshotBinOut + ".json" + } else if m.object() { + // object files aren't installed to the device, so their names can conflict. + // Use module name as stem. + objPath := m.outputFile.Path() + snapshotObjOut := filepath.Join(snapshotArchDir, targetArch, "object", + ctx.ModuleName(m)+filepath.Ext(objPath.Base())) + ret = append(ret, copyFile(ctx, objPath, snapshotObjOut)) + propOut = snapshotObjOut + ".json" } else { ctx.Errorf("unknown module %q in vendor snapshot", m.String()) return nil @@ -719,6 +833,7 @@ type snapshotInterface interface { var _ snapshotInterface = (*vndkPrebuiltLibraryDecorator)(nil) var _ snapshotInterface = (*vendorSnapshotLibraryDecorator)(nil) var _ snapshotInterface = (*vendorSnapshotBinaryDecorator)(nil) +var _ snapshotInterface = (*vendorSnapshotObjectLinker)(nil) // gathers all snapshot modules for vendor, and disable unnecessary snapshots // TODO(b/145966707): remove mutator and utilize android.Prebuilt to override source modules @@ -734,12 +849,12 @@ func VendorSnapshotMutator(ctx android.BottomUpMutatorContext) { return } - snapshot, ok := module.linker.(snapshotInterface) - if !ok { + if !module.isSnapshotPrebuilt() { return } - if !snapshot.matchesWithDevice(ctx.DeviceConfig()) { + // isSnapshotPrebuilt ensures snapshotInterface + if !module.linker.(snapshotInterface).matchesWithDevice(ctx.DeviceConfig()) { // Disable unnecessary snapshot module, but do not disable // vndk_prebuilt_shared because they might be packed into vndk APEX if !module.IsVndk() { @@ -761,6 +876,8 @@ func VendorSnapshotMutator(ctx android.BottomUpMutatorContext) { } } else if _, ok := module.linker.(*vendorSnapshotBinaryDecorator); ok { snapshotMap = vendorSnapshotBinaries(ctx.Config()) + } else if _, ok := module.linker.(*vendorSnapshotObjectLinker); ok { + snapshotMap = vendorSnapshotObjects(ctx.Config()) } else { return } @@ -820,6 +937,8 @@ func VendorSnapshotSourceMutator(ctx android.BottomUpMutatorContext) { } } else if module.binary() { snapshotMap = vendorSnapshotBinaries(ctx.Config()) + } else if module.object() { + snapshotMap = vendorSnapshotObjects(ctx.Config()) } else { return } diff --git a/cc/vndk_prebuilt.go b/cc/vndk_prebuilt.go index 53b518186..5a44c4663 100644 --- a/cc/vndk_prebuilt.go +++ b/cc/vndk_prebuilt.go @@ -186,6 +186,10 @@ func (p *vndkPrebuiltLibraryDecorator) nativeCoverage() bool { return false } +func (p *vndkPrebuiltLibraryDecorator) isSnapshotPrebuilt() bool { + return true +} + func (p *vndkPrebuiltLibraryDecorator) install(ctx ModuleContext, file android.Path) { arches := ctx.DeviceConfig().Arches() if len(arches) == 0 || arches[0].ArchType.String() != p.arch() { From af578ffacccb7ea4af30ecc42e9f6b99793023da Mon Sep 17 00:00:00 2001 From: Inseob Kim Date: Tue, 2 Jun 2020 00:06:15 +0900 Subject: [PATCH 3/4] Create only one vendor variant depending on path Not all vendor modules are meant to be working with multiple versions of vndk unmodified. This restricts all vendor or vendor_available modules to only one variant. Modules under proprietary directories will only have BOARD_VNDK_VERSION variant, while modules under AOSP directories will only have PLATFORM_VNDK_VERSION variant. Bug: 157106227 Bug: 157133296 Test: capture snapshot from R Test: try building master with R snapshot Change-Id: I4ebe1da8d887cd76722fa8ab5ae9305da09074d4 --- cc/cc.go | 30 +++++++++++++++++++++--------- cc/genrule.go | 10 ++++++++-- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/cc/cc.go b/cc/cc.go index a09b9225e..3d3a841ff 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -3046,20 +3046,32 @@ func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) { // This will be available in /system, /vendor and /product // or a /system directory that is available to vendor and product. coreVariantNeeded = true - vendorVariants = append(vendorVariants, platformVndkVersion) - productVariants = append(productVariants, platformVndkVersion) - // VNDK modules must not create BOARD_VNDK_VERSION variant because its - // code is PLATFORM_VNDK_VERSION. - // On the other hand, vendor_available modules which are not VNDK should - // also build BOARD_VNDK_VERSION because it's installed in /vendor. - // vendor_available modules are also available to /product. - if !m.IsVndk() { + + // We assume that modules under proprietary paths are compatible for + // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or + // PLATFORM_VNDK_VERSION. + if isVendorProprietaryPath(mctx.ModuleDir()) { vendorVariants = append(vendorVariants, boardVndkVersion) + } else { + vendorVariants = append(vendorVariants, platformVndkVersion) + } + + // vendor_available modules are also available to /product. + productVariants = append(productVariants, platformVndkVersion) + // VNDK is always PLATFORM_VNDK_VERSION + if !m.IsVndk() { productVariants = append(productVariants, productVndkVersion) } } else if vendorSpecific && String(m.Properties.Sdk_version) == "" { // This will be available in /vendor (or /odm) only - vendorVariants = append(vendorVariants, boardVndkVersion) + // We assume that modules under proprietary paths are compatible for + // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or + // PLATFORM_VNDK_VERSION. + if isVendorProprietaryPath(mctx.ModuleDir()) { + vendorVariants = append(vendorVariants, boardVndkVersion) + } else { + vendorVariants = append(vendorVariants, platformVndkVersion) + } } else { // This is either in /system (or similar: /data), or is a // modules built with the NDK. Modules built with the NDK diff --git a/cc/genrule.go b/cc/genrule.go index 9331448b8..66d178456 100644 --- a/cc/genrule.go +++ b/cc/genrule.go @@ -79,8 +79,14 @@ func (g *GenruleExtraProperties) ExtraImageVariations(ctx android.BaseModuleCont var variants []string if Bool(g.Vendor_available) || ctx.SocSpecific() || ctx.DeviceSpecific() { - variants = append(variants, VendorVariationPrefix+ctx.DeviceConfig().PlatformVndkVersion()) - if vndkVersion := ctx.DeviceConfig().VndkVersion(); vndkVersion != "current" { + vndkVersion := ctx.DeviceConfig().VndkVersion() + // If vndkVersion is current, we can always use PlatformVndkVersion. + // If not, we assume modules under proprietary paths are compatible for + // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, that is + // PLATFORM_VNDK_VERSION. + if vndkVersion == "current" || !isVendorProprietaryPath(ctx.ModuleDir()) { + variants = append(variants, VendorVariationPrefix+ctx.DeviceConfig().PlatformVndkVersion()) + } else { variants = append(variants, VendorVariationPrefix+vndkVersion) } } From 470b4cf826173cbc1328b79706777d6b524737ff Mon Sep 17 00:00:00 2001 From: Inseob Kim Date: Tue, 2 Jun 2020 23:48:32 +0900 Subject: [PATCH 4/4] Do not disable llndk libraries LLNDK libraries shouldn't be disabled in any case. Bug: 157106227 Test: m Change-Id: I059e639b21d0edb8abc00773891d37e890a36cce --- cc/vendor_snapshot.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cc/vendor_snapshot.go b/cc/vendor_snapshot.go index 898ac2ab6..2e2a779f6 100644 --- a/cc/vendor_snapshot.go +++ b/cc/vendor_snapshot.go @@ -924,6 +924,11 @@ func VendorSnapshotSourceMutator(ctx android.BottomUpMutatorContext) { return } + // .. and also filter out llndk library + if module.isLlndk(ctx.Config()) { + return + } + var snapshotMap *snapshotMap if lib, ok := module.linker.(libraryInterface); ok {