From d67a6b0a8824ec93f365b2a4777dd6773f6e352c Mon Sep 17 00:00:00 2001 From: Ivan Lozano Date: Thu, 20 May 2021 13:01:32 -0400 Subject: [PATCH] Export cc vendor functions for usage by rust. This CL exports and refactors some cc vendor-snapshot related functions so they can be reused by rust modules to support vendor snapshotting. Bug: 184042776 Test: m nothing Change-Id: I12706e62ce0ac3b2b4298085fafc1d77b8e0a0c4 --- cc/cc.go | 187 ++++++++++++++++--------------- cc/cc_test.go | 85 +++----------- cc/genrule.go | 2 +- cc/image.go | 4 +- cc/library.go | 43 ++++--- cc/sanitize.go | 4 +- cc/snapshot_prebuilt.go | 20 ++-- cc/snapshot_utils.go | 4 +- cc/testing.go | 68 ++++++++++- cc/vendor_public_library_test.go | 7 +- cc/vendor_snapshot.go | 6 +- cc/vendor_snapshot_test.go | 95 ++++++++-------- 12 files changed, 276 insertions(+), 249 deletions(-) diff --git a/cc/cc.go b/cc/cc.go index 91c441782..2ee851ba7 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -1980,15 +1980,19 @@ func GetCrtVariations(ctx android.BottomUpMutatorContext, } } -func (c *Module) addSharedLibDependenciesWithVersions(ctx android.BottomUpMutatorContext, - variations []blueprint.Variation, depTag libraryDependencyTag, name, version string, far bool) { +func AddSharedLibDependenciesWithVersions(ctx android.BottomUpMutatorContext, mod LinkableInterface, + variations []blueprint.Variation, depTag blueprint.DependencyTag, name, version string, far bool) { variations = append([]blueprint.Variation(nil), variations...) - if version != "" && CanBeOrLinkAgainstVersionVariants(c) { + if version != "" && CanBeOrLinkAgainstVersionVariants(mod) { // Version is explicitly specified. i.e. libFoo#30 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version}) - depTag.explicitlyVersioned = true + if tag, ok := depTag.(libraryDependencyTag); ok { + tag.explicitlyVersioned = true + } else { + panic(fmt.Errorf("Unexpected dependency tag: %T", depTag)) + } } if far { @@ -1998,6 +2002,74 @@ func (c *Module) addSharedLibDependenciesWithVersions(ctx android.BottomUpMutato } } +func GetSnapshot(c LinkableInterface, snapshotInfo **SnapshotInfo, actx android.BottomUpMutatorContext) SnapshotInfo { + // Only modules with BOARD_VNDK_VERSION uses snapshot. Others use the zero value of + // SnapshotInfo, which provides no mappings. + if *snapshotInfo == nil { + // Only retrieve the snapshot on demand in order to avoid circular dependencies + // between the modules in the snapshot and the snapshot itself. + var snapshotModule []blueprint.Module + if c.InVendor() && c.VndkVersion() == actx.DeviceConfig().VndkVersion() { + snapshotModule = actx.AddVariationDependencies(nil, nil, "vendor_snapshot") + } else if recoverySnapshotVersion := actx.DeviceConfig().RecoverySnapshotVersion(); recoverySnapshotVersion != "current" && recoverySnapshotVersion != "" && c.InRecovery() { + snapshotModule = actx.AddVariationDependencies(nil, nil, "recovery_snapshot") + } + if len(snapshotModule) > 0 { + snapshot := actx.OtherModuleProvider(snapshotModule[0], SnapshotInfoProvider).(SnapshotInfo) + *snapshotInfo = &snapshot + // republish the snapshot for use in later mutators on this module + actx.SetProvider(SnapshotInfoProvider, snapshot) + } else { + *snapshotInfo = &SnapshotInfo{} + } + } + + return **snapshotInfo +} + +func RewriteSnapshotLib(lib string, snapshotMap map[string]string) string { + if snapshot, ok := snapshotMap[lib]; ok { + return snapshot + } + + return lib +} + +// RewriteLibs takes a list of names of shared libraries and scans it for three types +// of names: +// +// 1. Name of an NDK library that refers to a prebuilt module. +// For each of these, it adds the name of the prebuilt module (which will be in +// prebuilts/ndk) to the list of nonvariant libs. +// 2. Name of an NDK library that refers to an ndk_library module. +// For each of these, it adds the name of the ndk_library module to the list of +// variant libs. +// 3. Anything else (so anything that isn't an NDK library). +// It adds these to the nonvariantLibs list. +// +// The caller can then know to add the variantLibs dependencies differently from the +// nonvariantLibs +func RewriteLibs(c LinkableInterface, snapshotInfo **SnapshotInfo, actx android.BottomUpMutatorContext, config android.Config, list []string) (nonvariantLibs []string, variantLibs []string) { + variantLibs = []string{} + + nonvariantLibs = []string{} + for _, entry := range list { + // strip #version suffix out + name, _ := StubsLibNameAndVersion(entry) + if c.InRecovery() { + nonvariantLibs = append(nonvariantLibs, RewriteSnapshotLib(entry, GetSnapshot(c, snapshotInfo, actx).SharedLibs)) + } else if c.UseSdk() && inList(name, *getNDKKnownLibs(config)) { + variantLibs = append(variantLibs, name+ndkLibrarySuffix) + } else if c.UseVndk() { + nonvariantLibs = append(nonvariantLibs, RewriteSnapshotLib(entry, GetSnapshot(c, snapshotInfo, actx).SharedLibs)) + } else { + // put name#version back + nonvariantLibs = append(nonvariantLibs, entry) + } + } + return nonvariantLibs, variantLibs +} + func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { if !c.Enabled() { return @@ -2016,83 +2088,16 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { c.Properties.AndroidMkSystemSharedLibs = deps.SystemSharedLibs var snapshotInfo *SnapshotInfo - getSnapshot := func() SnapshotInfo { - // Only modules with BOARD_VNDK_VERSION uses snapshot. Others use the zero value of - // SnapshotInfo, which provides no mappings. - if snapshotInfo == nil { - // Only retrieve the snapshot on demand in order to avoid circular dependencies - // between the modules in the snapshot and the snapshot itself. - var snapshotModule []blueprint.Module - if c.InVendor() && c.VndkVersion() == actx.DeviceConfig().VndkVersion() { - snapshotModule = ctx.AddVariationDependencies(nil, nil, "vendor_snapshot") - } else if recoverySnapshotVersion := actx.DeviceConfig().RecoverySnapshotVersion(); recoverySnapshotVersion != "current" && recoverySnapshotVersion != "" && c.InRecovery() { - snapshotModule = ctx.AddVariationDependencies(nil, nil, "recovery_snapshot") - } - if len(snapshotModule) > 0 { - snapshot := ctx.OtherModuleProvider(snapshotModule[0], SnapshotInfoProvider).(SnapshotInfo) - snapshotInfo = &snapshot - // republish the snapshot for use in later mutators on this module - ctx.SetProvider(SnapshotInfoProvider, snapshot) - } else { - snapshotInfo = &SnapshotInfo{} - } - } - - return *snapshotInfo - } - - rewriteSnapshotLib := func(lib string, snapshotMap map[string]string) string { - if snapshot, ok := snapshotMap[lib]; ok { - return snapshot - } - - return lib - } variantNdkLibs := []string{} variantLateNdkLibs := []string{} if ctx.Os() == android.Android { - // rewriteLibs takes a list of names of shared libraries and scans it for three types - // of names: - // - // 1. Name of an NDK library that refers to a prebuilt module. - // For each of these, it adds the name of the prebuilt module (which will be in - // prebuilts/ndk) to the list of nonvariant libs. - // 2. Name of an NDK library that refers to an ndk_library module. - // For each of these, it adds the name of the ndk_library module to the list of - // variant libs. - // 3. Anything else (so anything that isn't an NDK library). - // It adds these to the nonvariantLibs list. - // - // The caller can then know to add the variantLibs dependencies differently from the - // nonvariantLibs - - rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) { - variantLibs = []string{} - nonvariantLibs = []string{} - for _, entry := range list { - // strip #version suffix out - name, _ := StubsLibNameAndVersion(entry) - if c.InRecovery() { - nonvariantLibs = append(nonvariantLibs, rewriteSnapshotLib(entry, getSnapshot().SharedLibs)) - } else if ctx.useSdk() && inList(name, *getNDKKnownLibs(ctx.Config())) { - variantLibs = append(variantLibs, name+ndkLibrarySuffix) - } else if ctx.useVndk() { - nonvariantLibs = append(nonvariantLibs, rewriteSnapshotLib(entry, getSnapshot().SharedLibs)) - } else { - // put name#version back - nonvariantLibs = append(nonvariantLibs, entry) - } - } - return nonvariantLibs, variantLibs - } - - deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs) - deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs) - deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders) + deps.SharedLibs, variantNdkLibs = RewriteLibs(c, &snapshotInfo, actx, ctx.Config(), deps.SharedLibs) + deps.LateSharedLibs, variantLateNdkLibs = RewriteLibs(c, &snapshotInfo, actx, ctx.Config(), deps.LateSharedLibs) + deps.ReexportSharedLibHeaders, _ = RewriteLibs(c, &snapshotInfo, actx, ctx.Config(), deps.ReexportSharedLibHeaders) for idx, lib := range deps.RuntimeLibs { - deps.RuntimeLibs[idx] = rewriteSnapshotLib(lib, getSnapshot().SharedLibs) + deps.RuntimeLibs[idx] = RewriteSnapshotLib(lib, GetSnapshot(c, &snapshotInfo, actx).SharedLibs) } } @@ -2102,7 +2107,7 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { depTag.reexportFlags = true } - lib = rewriteSnapshotLib(lib, getSnapshot().HeaderLibs) + lib = RewriteSnapshotLib(lib, GetSnapshot(c, &snapshotInfo, actx).HeaderLibs) if c.IsStubs() { actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()), @@ -2125,7 +2130,7 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { lib = impl } - lib = rewriteSnapshotLib(lib, getSnapshot().StaticLibs) + lib = RewriteSnapshotLib(lib, GetSnapshot(c, &snapshotInfo, actx).StaticLibs) actx.AddVariationDependencies([]blueprint.Variation{ {Mutator: "link", Variation: "static"}, @@ -2145,7 +2150,7 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { lib = impl } - lib = rewriteSnapshotLib(lib, getSnapshot().StaticLibs) + lib = RewriteSnapshotLib(lib, GetSnapshot(c, &snapshotInfo, actx).StaticLibs) actx.AddVariationDependencies([]blueprint.Variation{ {Mutator: "link", Variation: "static"}, @@ -2159,14 +2164,14 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true} actx.AddVariationDependencies([]blueprint.Variation{ {Mutator: "link", Variation: "static"}, - }, depTag, rewriteSnapshotLib(staticUnwinder(actx), getSnapshot().StaticLibs)) + }, depTag, RewriteSnapshotLib(staticUnwinder(actx), GetSnapshot(c, &snapshotInfo, actx).StaticLibs)) } for _, lib := range deps.LateStaticLibs { depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency} actx.AddVariationDependencies([]blueprint.Variation{ {Mutator: "link", Variation: "static"}, - }, depTag, rewriteSnapshotLib(lib, getSnapshot().StaticLibs)) + }, depTag, RewriteSnapshotLib(lib, GetSnapshot(c, &snapshotInfo, actx).StaticLibs)) } // shared lib names without the #version suffix @@ -2191,7 +2196,7 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { variations := []blueprint.Variation{ {Mutator: "link", Variation: "shared"}, } - c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, name, version, false) + AddSharedLibDependenciesWithVersions(ctx, c, variations, depTag, name, version, false) } for _, lib := range deps.LateSharedLibs { @@ -2205,7 +2210,7 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { variations := []blueprint.Variation{ {Mutator: "link", Variation: "shared"}, } - c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, lib, "", false) + AddSharedLibDependenciesWithVersions(ctx, c, variations, depTag, lib, "", false) } actx.AddVariationDependencies([]blueprint.Variation{ @@ -2230,11 +2235,11 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { actx.AddVariationDependencies(crtVariations, objDepTag, deps.ObjFiles...) if deps.CrtBegin != "" { actx.AddVariationDependencies(crtVariations, CrtBeginDepTag, - rewriteSnapshotLib(deps.CrtBegin, getSnapshot().Objects)) + RewriteSnapshotLib(deps.CrtBegin, GetSnapshot(c, &snapshotInfo, actx).Objects)) } if deps.CrtEnd != "" { actx.AddVariationDependencies(crtVariations, CrtEndDepTag, - rewriteSnapshotLib(deps.CrtEnd, getSnapshot().Objects)) + RewriteSnapshotLib(deps.CrtEnd, GetSnapshot(c, &snapshotInfo, actx).Objects)) } if deps.LinkerFlagsFile != "" { actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile) @@ -2837,8 +2842,8 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { // they merely serve as Make dependencies and do not affect this lib itself. c.Properties.AndroidMkSharedLibs = append( c.Properties.AndroidMkSharedLibs, makeLibName) - // Record baseLibName for snapshots. - c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName)) + // Record BaseLibName for snapshots. + c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, BaseLibName(depName)) case libDepTag.static(): if libDepTag.wholeStatic { c.Properties.AndroidMkWholeStaticLibs = append( @@ -2855,8 +2860,8 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { case runtimeDepTag: c.Properties.AndroidMkRuntimeLibs = append( c.Properties.AndroidMkRuntimeLibs, MakeLibName(ctx, c, ccDep, depName)+libDepTag.makeSuffix) - // Record baseLibName for snapshots. - c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName)) + // Record BaseLibName for snapshots. + c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, BaseLibName(depName)) case objDepTag: depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path()) case CrtBeginDepTag: @@ -2924,8 +2929,8 @@ func orderStaticModuleDeps(staticDeps []StaticLibraryInfo, sharedDeps []SharedLi return orderedStaticPaths, transitiveStaticLibs } -// baseLibName trims known prefixes and suffixes -func baseLibName(depName string) string { +// BaseLibName trims known prefixes and suffixes +func BaseLibName(depName string) string { libName := strings.TrimSuffix(depName, llndkLibrarySuffix) libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix) libName = android.RemoveOptionalPrebuiltPrefix(libName) @@ -2933,7 +2938,7 @@ func baseLibName(depName string) string { } func MakeLibName(ctx android.ModuleContext, c LinkableInterface, ccDep LinkableInterface, depName string) string { - libName := baseLibName(depName) + libName := BaseLibName(depName) ccDepModule, _ := ccDep.(*Module) isLLndk := ccDepModule != nil && ccDepModule.IsLlndk() nonSystemVariantsExist := ccDep.HasNonSystemVariants() || isLLndk diff --git a/cc/cc_test.go b/cc/cc_test.go index 7fc044df3..e0fae5ad9 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -396,50 +396,6 @@ func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string } } -func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) { - t.Helper() - mod := ctx.ModuleForTests(moduleName, variant) - outputFiles := mod.OutputFiles(t, "") - if len(outputFiles) != 1 { - t.Errorf("%q must have single output\n", moduleName) - return - } - snapshotPath := filepath.Join(subDir, snapshotFilename) - - if include { - out := singleton.Output(snapshotPath) - if fake { - if out.Rule == nil { - t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0]) - } - } else { - 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]) - } - } - } else { - out := singleton.MaybeOutput(snapshotPath) - if out.Rule != nil { - t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0]) - } - } -} - -func checkSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) { - t.Helper() - checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false) -} - -func checkSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) { - t.Helper() - checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false) -} - -func checkSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) { - t.Helper() - checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true) -} - func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) { t.Helper() content := android.ContentFromFileRuleForTests(t, params) @@ -631,21 +587,21 @@ func TestVndk(t *testing.T) { 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_product", "libvndk_product.so", vndkCoreLibPath, variant) - checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.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) - checkSnapshot(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", llndkLibPath, variant) - checkSnapshot(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", llndkLib2ndPath, variant2nd) + CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLibPath, variant) + CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd) + CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLibPath, variant) + CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.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) + CheckSnapshot(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", llndkLibPath, variant) + CheckSnapshot(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", llndkLib2ndPath, variant2nd) snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs") - 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, "") - checkSnapshot(t, ctx, snapshotSingleton, "vndkproduct.libraries.txt", "vndkproduct.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, "") + CheckSnapshot(t, ctx, snapshotSingleton, "vndkproduct.libraries.txt", "vndkproduct.libraries.txt", snapshotConfigsPath, "") checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{ "LLNDK: libc.so", @@ -2643,15 +2599,6 @@ func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[an return modulesInOrder, allDeps } -func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) { - for _, moduleName := range moduleNames { - module := ctx.ModuleForTests(moduleName, variant).Module().(*Module) - output := module.outputFile.Path().RelativeToTop() - paths = append(paths, output) - } - return paths -} - func TestStaticLibDepReordering(t *testing.T) { ctx := testCc(t, ` cc_library { @@ -2679,7 +2626,7 @@ func TestStaticLibDepReordering(t *testing.T) { moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo). TransitiveStaticLibrariesForOrdering.ToList().RelativeToTop() - expected := getOutputPaths(ctx, variant, []string{"a", "c", "b", "d"}) + expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b", "d"}) if !reflect.DeepEqual(actual, expected) { t.Errorf("staticDeps orderings were not propagated correctly"+ @@ -2714,7 +2661,7 @@ func TestStaticLibDepReorderingWithShared(t *testing.T) { moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo). TransitiveStaticLibrariesForOrdering.ToList().RelativeToTop() - expected := getOutputPaths(ctx, variant, []string{"a", "c", "b"}) + expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b"}) if !reflect.DeepEqual(actual, expected) { t.Errorf("staticDeps orderings did not account for shared libs"+ @@ -3357,7 +3304,7 @@ func TestStaticDepsOrderWithStubs(t *testing.T) { mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld") actual := mybin.Implicits[:2] - expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"}) + expected := GetOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"}) if !reflect.DeepEqual(actual, expected) { t.Errorf("staticDeps orderings were not propagated correctly"+ diff --git a/cc/genrule.go b/cc/genrule.go index 82d7205da..b0efc6ca4 100644 --- a/cc/genrule.go +++ b/cc/genrule.go @@ -103,7 +103,7 @@ func (g *GenruleExtraProperties) ExtraImageVariations(ctx android.BaseModuleCont // 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" || !isVendorProprietaryModule(ctx) { + if vndkVersion == "current" || !IsVendorProprietaryModule(ctx) { variants = append(variants, VendorVariationPrefix+ctx.DeviceConfig().PlatformVndkVersion()) } else { variants = append(variants, VendorVariationPrefix+vndkVersion) diff --git a/cc/image.go b/cc/image.go index c6b209f08..9370c40bf 100644 --- a/cc/image.go +++ b/cc/image.go @@ -496,7 +496,7 @@ func MutateImage(mctx android.BaseModuleContext, m ImageMutatableModule) { // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or // PLATFORM_VNDK_VERSION. if m.HasVendorVariant() { - if isVendorProprietaryModule(mctx) { + if IsVendorProprietaryModule(mctx) { vendorVariants = append(vendorVariants, boardVndkVersion) } else { vendorVariants = append(vendorVariants, platformVndkVersion) @@ -525,7 +525,7 @@ func MutateImage(mctx android.BaseModuleContext, m ImageMutatableModule) { platformVndkVersion, boardVndkVersion, ) - } else if isVendorProprietaryModule(mctx) { + } else if IsVendorProprietaryModule(mctx) { vendorVariants = append(vendorVariants, boardVndkVersion) } else { vendorVariants = append(vendorVariants, platformVndkVersion) diff --git a/cc/library.go b/cc/library.go index 5e70c51e9..44be38df4 100644 --- a/cc/library.go +++ b/cc/library.go @@ -606,20 +606,14 @@ func (handler *staticLibraryBazelHandler) generateBazelBuildActions(ctx android. return ok } -// collectHeadersForSnapshot collects all exported headers from library. -// It globs header files in the source tree for exported include directories, -// and tracks generated header files separately. -// -// This is to be called from GenerateAndroidBuildActions, and then collected -// header files can be retrieved by snapshotHeaders(). -func (l *libraryDecorator) collectHeadersForSnapshot(ctx android.ModuleContext) { +func GlobHeadersForSnapshot(ctx android.ModuleContext, paths android.Paths) android.Paths { ret := android.Paths{} // Headers in the source tree should be globbed. On the contrast, generated headers // can't be globbed, and they should be manually collected. // So, we first filter out intermediate directories (which contains generated headers) // from exported directories, and then glob headers under remaining directories. - for _, path := range append(android.CopyOfPaths(l.flagExporter.dirs), l.flagExporter.systemDirs...) { + for _, path := range paths { dir := path.String() // Skip if dir is for generated headers if strings.HasPrefix(dir, android.PathForOutput(ctx).String()) { @@ -635,7 +629,7 @@ func (l *libraryDecorator) collectHeadersForSnapshot(ctx android.ModuleContext) glob, err := ctx.GlobWithDeps("external/eigen/"+subdir+"/**/*", nil) if err != nil { ctx.ModuleErrorf("glob failed: %#v", err) - return + return nil } for _, header := range glob { if strings.HasSuffix(header, "/") { @@ -653,7 +647,7 @@ func (l *libraryDecorator) collectHeadersForSnapshot(ctx android.ModuleContext) glob, err := ctx.GlobWithDeps(dir+"/**/*", nil) if err != nil { ctx.ModuleErrorf("glob failed: %#v", err) - return + return nil } isLibcxx := strings.HasPrefix(dir, "external/libcxx/include") for _, header := range glob { @@ -666,7 +660,7 @@ func (l *libraryDecorator) collectHeadersForSnapshot(ctx android.ModuleContext) } else { // Filter out only the files with extensions that are headers. found := false - for _, ext := range headerExts { + for _, ext := range HeaderExts { if strings.HasSuffix(header, ext) { found = true break @@ -679,15 +673,38 @@ func (l *libraryDecorator) collectHeadersForSnapshot(ctx android.ModuleContext) ret = append(ret, android.PathForSource(ctx, header)) } } + return ret +} - // Collect generated headers - for _, header := range append(android.CopyOfPaths(l.flagExporter.headers), l.flagExporter.deps...) { +func GlobGeneratedHeadersForSnapshot(ctx android.ModuleContext, paths android.Paths) android.Paths { + ret := android.Paths{} + for _, header := range paths { // TODO(b/148123511): remove exportedDeps after cleaning up genrule if strings.HasSuffix(header.Base(), "-phony") { continue } ret = append(ret, header) } + return ret +} + +// collectHeadersForSnapshot collects all exported headers from library. +// It globs header files in the source tree for exported include directories, +// and tracks generated header files separately. +// +// This is to be called from GenerateAndroidBuildActions, and then collected +// header files can be retrieved by snapshotHeaders(). +func (l *libraryDecorator) collectHeadersForSnapshot(ctx android.ModuleContext) { + ret := android.Paths{} + + // Headers in the source tree should be globbed. On the contrast, generated headers + // can't be globbed, and they should be manually collected. + // So, we first filter out intermediate directories (which contains generated headers) + // from exported directories, and then glob headers under remaining directories. + ret = append(ret, GlobHeadersForSnapshot(ctx, append(android.CopyOfPaths(l.flagExporter.dirs), l.flagExporter.systemDirs...))...) + + // Collect generated headers + ret = append(ret, GlobGeneratedHeadersForSnapshot(ctx, append(android.CopyOfPaths(l.flagExporter.headers), l.flagExporter.deps...))...) l.collectedSnapshotHeaders = ret } diff --git a/cc/sanitize.go b/cc/sanitize.go index f486ee470..513730ae9 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -854,7 +854,7 @@ func (m *Module) SanitizableDepTagChecker() SantizableDependencyTagChecker { // as vendor snapshot. Such modules must create both cfi and non-cfi variants, // except for ones which explicitly disable cfi. func needsCfiForVendorSnapshot(mctx android.TopDownMutatorContext) bool { - if isVendorProprietaryModule(mctx) { + if IsVendorProprietaryModule(mctx) { return false } @@ -1192,7 +1192,7 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) { if c.Device() { variations = append(variations, c.ImageVariation()) } - c.addSharedLibDependenciesWithVersions(mctx, variations, depTag, runtimeLibrary, "", true) + AddSharedLibDependenciesWithVersions(mctx, c, variations, depTag, runtimeLibrary, "", true) } // static lib does not have dependency to the runtime library. The // dependency will be added to the executables or shared libs using diff --git a/cc/snapshot_prebuilt.go b/cc/snapshot_prebuilt.go index bf11b11bb..48b7c6952 100644 --- a/cc/snapshot_prebuilt.go +++ b/cc/snapshot_prebuilt.go @@ -108,7 +108,7 @@ var ( } ) -func (vendorSnapshotImage) init(ctx android.RegistrationContext) { +func (vendorSnapshotImage) Init(ctx android.RegistrationContext) { ctx.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton) ctx.RegisterModuleType("vendor_snapshot", vendorSnapshotFactory) ctx.RegisterModuleType("vendor_snapshot_shared", VendorSnapshotSharedFactory) @@ -254,11 +254,11 @@ func (recoverySnapshotImage) moduleNameSuffix() string { return recoverySuffix } -var vendorSnapshotImageSingleton vendorSnapshotImage +var VendorSnapshotImageSingleton vendorSnapshotImage var recoverySnapshotImageSingleton recoverySnapshotImage func init() { - vendorSnapshotImageSingleton.init(android.InitRegistrationContext) + VendorSnapshotImageSingleton.Init(android.InitRegistrationContext) recoverySnapshotImageSingleton.init(android.InitRegistrationContext) } @@ -376,7 +376,7 @@ var SnapshotInfoProvider = blueprint.NewMutatorProvider(SnapshotInfo{}, "deps") var _ android.ImageInterface = (*snapshot)(nil) func vendorSnapshotFactory() android.Module { - return snapshotFactory(vendorSnapshotImageSingleton) + return snapshotFactory(VendorSnapshotImageSingleton) } func recoverySnapshotFactory() android.Module { @@ -475,7 +475,7 @@ func (p *baseSnapshotDecorator) setSnapshotAndroidMkSuffix(ctx android.ModuleCon return } - images := []snapshotImage{vendorSnapshotImageSingleton, recoverySnapshotImageSingleton} + images := []snapshotImage{VendorSnapshotImageSingleton, recoverySnapshotImageSingleton} for _, image := range images { if p.image == image { @@ -724,7 +724,7 @@ func snapshotLibraryFactory(image snapshotImage, moduleSuffix string) (*Module, // overrides the vendor variant of the cc shared library with the same name, if BOARD_VNDK_VERSION // is set. func VendorSnapshotSharedFactory() android.Module { - module, prebuilt := snapshotLibraryFactory(vendorSnapshotImageSingleton, snapshotSharedSuffix) + module, prebuilt := snapshotLibraryFactory(VendorSnapshotImageSingleton, snapshotSharedSuffix) prebuilt.libraryDecorator.BuildOnlyShared() return module.Init() } @@ -744,7 +744,7 @@ func RecoverySnapshotSharedFactory() android.Module { // overrides the vendor variant of the cc static library with the same name, if BOARD_VNDK_VERSION // is set. func VendorSnapshotStaticFactory() android.Module { - module, prebuilt := snapshotLibraryFactory(vendorSnapshotImageSingleton, snapshotStaticSuffix) + module, prebuilt := snapshotLibraryFactory(VendorSnapshotImageSingleton, snapshotStaticSuffix) prebuilt.libraryDecorator.BuildOnlyStatic() return module.Init() } @@ -764,7 +764,7 @@ func RecoverySnapshotStaticFactory() android.Module { // overrides the vendor variant of the cc header library with the same name, if BOARD_VNDK_VERSION // is set. func VendorSnapshotHeaderFactory() android.Module { - module, prebuilt := snapshotLibraryFactory(vendorSnapshotImageSingleton, snapshotHeaderSuffix) + module, prebuilt := snapshotLibraryFactory(VendorSnapshotImageSingleton, snapshotHeaderSuffix) prebuilt.libraryDecorator.HeaderOnly() return module.Init() } @@ -842,7 +842,7 @@ func (p *snapshotBinaryDecorator) nativeCoverage() bool { // development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_binary // overrides the vendor variant of the cc binary with the same name, if BOARD_VNDK_VERSION is set. func VendorSnapshotBinaryFactory() android.Module { - return snapshotBinaryFactory(vendorSnapshotImageSingleton, snapshotBinarySuffix) + return snapshotBinaryFactory(VendorSnapshotImageSingleton, snapshotBinarySuffix) } // recovery_snapshot_binary is a special prebuilt executable binary which is auto-generated by @@ -933,7 +933,7 @@ func VendorSnapshotObjectFactory() android.Module { } module.linker = prebuilt - prebuilt.init(module, vendorSnapshotImageSingleton, snapshotObjectSuffix) + prebuilt.init(module, VendorSnapshotImageSingleton, snapshotObjectSuffix) module.AddProperties(&prebuilt.properties) return module.Init() } diff --git a/cc/snapshot_utils.go b/cc/snapshot_utils.go index 8eb616448..7b62603ef 100644 --- a/cc/snapshot_utils.go +++ b/cc/snapshot_utils.go @@ -20,7 +20,7 @@ import ( ) var ( - headerExts = []string{".h", ".hh", ".hpp", ".hxx", ".h++", ".inl", ".inc", ".ipp", ".h.generic"} + HeaderExts = []string{".h", ".hh", ".hpp", ".hxx", ".h++", ".inl", ".inc", ".ipp", ".h.generic"} ) func (m *Module) IsSnapshotLibrary() bool { @@ -109,7 +109,7 @@ func ShouldCollectHeadersForSnapshot(ctx android.ModuleContext, m LinkableInterf return ctx.Config().VndkSnapshotBuildArtifacts() } - for _, image := range []snapshotImage{vendorSnapshotImageSingleton, recoverySnapshotImageSingleton} { + for _, image := range []snapshotImage{VendorSnapshotImageSingleton, recoverySnapshotImageSingleton} { if isSnapshotAware(ctx.DeviceConfig(), m, image.isProprietaryPath(ctx.ModuleDir(), ctx.DeviceConfig()), apexInfo, image) { return true } diff --git a/cc/testing.go b/cc/testing.go index 15f7ebb0d..f5c5ec5b1 100644 --- a/cc/testing.go +++ b/cc/testing.go @@ -15,6 +15,9 @@ package cc import ( + "path/filepath" + "testing" + "android/soong/android" "android/soong/genrule" ) @@ -625,7 +628,7 @@ var PrepareForTestOnFuchsia = android.GroupFixturePreparers( var PrepareForTestWithCcIncludeVndk = android.GroupFixturePreparers( PrepareForIntegrationTestWithCc, android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { - vendorSnapshotImageSingleton.init(ctx) + VendorSnapshotImageSingleton.Init(ctx) recoverySnapshotImageSingleton.init(ctx) ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton) }), @@ -674,7 +677,7 @@ func CreateTestContext(config android.Config) *android.TestContext { ctx.RegisterModuleType("filegroup", android.FileGroupFactory) ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory) - vendorSnapshotImageSingleton.init(ctx) + VendorSnapshotImageSingleton.Init(ctx) recoverySnapshotImageSingleton.init(ctx) ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton) RegisterVndkLibraryTxtTypes(ctx) @@ -685,3 +688,64 @@ func CreateTestContext(config android.Config) *android.TestContext { return ctx } + +func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) { + t.Helper() + mod := ctx.ModuleForTests(moduleName, variant) + outputFiles := mod.OutputFiles(t, "") + if len(outputFiles) != 1 { + t.Errorf("%q must have single output\n", moduleName) + return + } + snapshotPath := filepath.Join(subDir, snapshotFilename) + + if include { + out := singleton.Output(snapshotPath) + if fake { + if out.Rule == nil { + t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0]) + } + } else { + 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]) + } + } + } else { + out := singleton.MaybeOutput(snapshotPath) + if out.Rule != nil { + t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0]) + } + } +} + +func CheckSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) { + t.Helper() + checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false) +} + +func CheckSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) { + t.Helper() + checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false) +} + +func CheckSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) { + t.Helper() + checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true) +} + +func AssertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) { + t.Helper() + m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface) + if m.ExcludeFromVendorSnapshot() != expected { + t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected) + } +} + +func GetOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) { + for _, moduleName := range moduleNames { + module := ctx.ModuleForTests(moduleName, variant).Module().(*Module) + output := module.outputFile.Path().RelativeToTop() + paths = append(paths, output) + } + return paths +} diff --git a/cc/vendor_public_library_test.go b/cc/vendor_public_library_test.go index 01959b40c..769be0973 100644 --- a/cc/vendor_public_library_test.go +++ b/cc/vendor_public_library_test.go @@ -79,7 +79,7 @@ func TestVendorPublicLibraries(t *testing.T) { // test if libsystem is linked to the stub ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld") libflags := ld.Args["libFlags"] - stubPaths := getOutputPaths(ctx, coreVariant, []string{"libvendorpublic"}) + stubPaths := GetOutputPaths(ctx, coreVariant, []string{"libvendorpublic"}) if !strings.Contains(libflags, stubPaths[0].String()) { t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags) } @@ -87,7 +87,7 @@ func TestVendorPublicLibraries(t *testing.T) { // test if libsystem is linked to the stub ld = ctx.ModuleForTests("libproduct", productVariant).Rule("ld") libflags = ld.Args["libFlags"] - stubPaths = getOutputPaths(ctx, productVariant, []string{"libvendorpublic"}) + stubPaths = GetOutputPaths(ctx, productVariant, []string{"libvendorpublic"}) if !strings.Contains(libflags, stubPaths[0].String()) { t.Errorf("libflags for libproduct must contain %#v, but was %#v", stubPaths[0], libflags) } @@ -95,7 +95,8 @@ func TestVendorPublicLibraries(t *testing.T) { // test if libvendor is linked to the real shared lib ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld") libflags = ld.Args["libFlags"] - stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"}) + stubPaths = GetOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"}) + if !strings.Contains(libflags, stubPaths[0].String()) { t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags) } diff --git a/cc/vendor_snapshot.go b/cc/vendor_snapshot.go index 4e59a95f8..2c29a89aa 100644 --- a/cc/vendor_snapshot.go +++ b/cc/vendor_snapshot.go @@ -31,7 +31,7 @@ var vendorSnapshotSingleton = snapshotSingleton{ "SOONG_VENDOR_SNAPSHOT_ZIP", android.OptionalPath{}, true, - vendorSnapshotImageSingleton, + VendorSnapshotImageSingleton, false, /* fake */ } @@ -40,7 +40,7 @@ var vendorFakeSnapshotSingleton = snapshotSingleton{ "SOONG_VENDOR_FAKE_SNAPSHOT_ZIP", android.OptionalPath{}, true, - vendorSnapshotImageSingleton, + VendorSnapshotImageSingleton, true, /* fake */ } @@ -104,7 +104,7 @@ func isRecoveryProprietaryPath(dir string, deviceConfig android.DeviceConfig) bo return RecoverySnapshotSingleton().(*snapshotSingleton).image.isProprietaryPath(dir, deviceConfig) } -func isVendorProprietaryModule(ctx android.BaseModuleContext) bool { +func IsVendorProprietaryModule(ctx android.BaseModuleContext) bool { // Any module in a vendor proprietary path is a vendor proprietary // module. if isVendorProprietaryPath(ctx.ModuleDir(), ctx.DeviceConfig()) { diff --git a/cc/vendor_snapshot_test.go b/cc/vendor_snapshot_test.go index c3b5e8c20..ceffb29c7 100644 --- a/cc/vendor_snapshot_test.go +++ b/cc/vendor_snapshot_test.go @@ -108,27 +108,27 @@ func TestVendorSnapshotCapture(t *testing.T) { // For shared libraries, only non-VNDK vendor_available modules are captured sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant) sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") - checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant) - checkSnapshot(t, ctx, snapshotSingleton, "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")) // LLNDK modules are not captured - checkSnapshotExclude(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", sharedDir, sharedVariant) + CheckSnapshotExclude(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", sharedDir, sharedVariant) // For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured. // Also cfi variants are captured, except for prebuilts like toolchain_library staticVariant := fmt.Sprintf("android_vendor.29_%s_%s_static", archType, archVariant) staticCfiVariant := fmt.Sprintf("android_vendor.29_%s_%s_static_cfi", archType, archVariant) staticDir := filepath.Join(snapshotVariantPath, archDir, "static") - checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant) - checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.a", staticDir, staticVariant) - checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.cfi.a", staticDir, staticCfiVariant) - checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.a", staticDir, staticVariant) - checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.cfi.a", staticDir, staticCfiVariant) - checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.a", staticDir, staticVariant) - checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.cfi.a", staticDir, staticCfiVariant) + CheckSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant) + CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.a", staticDir, staticVariant) + CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.cfi.a", staticDir, staticCfiVariant) + CheckSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.a", staticDir, staticVariant) + CheckSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.cfi.a", staticDir, staticCfiVariant) + CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.a", staticDir, staticVariant) + CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.cfi.a", staticDir, staticCfiVariant) jsonFiles = append(jsonFiles, filepath.Join(staticDir, "libb.a.json"), filepath.Join(staticDir, "libvndk.a.json"), @@ -142,8 +142,8 @@ func TestVendorSnapshotCapture(t *testing.T) { if archType == "arm64" { binaryVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant) binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary") - checkSnapshot(t, ctx, snapshotSingleton, "vendor_bin", "vendor_bin", binaryDir, binaryVariant) - checkSnapshot(t, ctx, snapshotSingleton, "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")) @@ -156,7 +156,7 @@ func TestVendorSnapshotCapture(t *testing.T) { // For object modules, all vendor:true and vendor_available modules are captured. objectVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant) objectDir := filepath.Join(snapshotVariantPath, archDir, "object") - checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant) + CheckSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant) jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json")) } @@ -239,15 +239,15 @@ func TestVendorSnapshotDirected(t *testing.T) { sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") // Included modules - checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant) + CheckSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant) includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json")) // Check that snapshot captures "prefer: true" prebuilt - checkSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant) + CheckSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant) includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json")) // Excluded modules. Modules not included in the directed vendor snapshot // are still include as fake modules. - checkSnapshotRule(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant) + CheckSnapshotRule(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant) includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libvendor_available.so.json")) } @@ -839,10 +839,11 @@ func TestVendorSnapshotUse(t *testing.T) { []string{staticVariant, "libvendor.vendor_static.31.arm64"}, []string{staticVariant, "libvendor_without_snapshot"}, } { - outputPaths := getOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */) + outputPaths := GetOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */) if !strings.Contains(libclientLdFlags, outputPaths[0].String()) { t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags) } + } libclientAndroidMkSharedLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkSharedLibs @@ -868,7 +869,7 @@ func TestVendorSnapshotUse(t *testing.T) { } libclientCfiLdFlags := ctx.ModuleForTests("libclient_cfi", sharedCfiVariant).Rule("ld").Args["libFlags"] - libvendorCfiOutputPaths := getOutputPaths(ctx, staticCfiVariant, []string{"libvendor.vendor_static.31.arm64"}) + libvendorCfiOutputPaths := GetOutputPaths(ctx, staticCfiVariant, []string{"libvendor.vendor_static.31.arm64"}) if !strings.Contains(libclientCfiLdFlags, libvendorCfiOutputPaths[0].String()) { t.Errorf("libflags for libclientCfi must contain %#v, but was %#v", libvendorCfiOutputPaths[0], libclientCfiLdFlags) } @@ -881,7 +882,7 @@ func TestVendorSnapshotUse(t *testing.T) { } binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("ld").Args["libFlags"] - libVndkStaticOutputPaths := getOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.31.arm64"}) + libVndkStaticOutputPaths := GetOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.31.arm64"}) if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) { t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v", libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags) @@ -1006,14 +1007,6 @@ func TestVendorSnapshotSanitizer(t *testing.T) { assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a") } -func assertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool) { - t.Helper() - m := ctx.ModuleForTests(name, vendorVariant).Module().(*Module) - if m.ExcludeFromVendorSnapshot() != expected { - t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected) - } -} - func assertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool) { t.Helper() m := ctx.ModuleForTests(name, recoveryVariant).Module().(*Module) @@ -1081,13 +1074,13 @@ func TestVendorSnapshotExclude(t *testing.T) { android.FailIfErrored(t, errs) // Test an include and exclude framework module. - assertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false) - assertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true) - assertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true) + AssertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false, vendorVariant) + AssertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true, vendorVariant) + AssertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true, vendorVariant) // A vendor module is excluded, but by its path, not the // exclude_from_vendor_snapshot property. - assertExcludeFromVendorSnapshotIs(t, ctx, "libvendor", false) + AssertExcludeFromVendorSnapshotIs(t, ctx, "libvendor", false, vendorVariant) // Verify the content of the vendor snapshot. @@ -1110,15 +1103,15 @@ func TestVendorSnapshotExclude(t *testing.T) { sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") // Included modules - checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant) + 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) + 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) + CheckSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant) excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json")) - checkSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant) + CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant) excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json")) } @@ -1258,9 +1251,9 @@ func TestRecoverySnapshotCapture(t *testing.T) { // For shared libraries, only recovery_available modules are captured. sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant) sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") - checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant) - checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant) - checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant) + CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant) + CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant) + CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant) jsonFiles = append(jsonFiles, filepath.Join(sharedDir, "libvndk.so.json"), filepath.Join(sharedDir, "librecovery.so.json"), @@ -1269,9 +1262,9 @@ func TestRecoverySnapshotCapture(t *testing.T) { // For static libraries, all recovery:true and recovery_available modules are captured. staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant) staticDir := filepath.Join(snapshotVariantPath, archDir, "static") - checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant) - checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant) - checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant) + CheckSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant) + CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant) + CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant) jsonFiles = append(jsonFiles, filepath.Join(staticDir, "libb.a.json"), filepath.Join(staticDir, "librecovery.a.json"), @@ -1281,8 +1274,8 @@ func TestRecoverySnapshotCapture(t *testing.T) { if archType == "arm64" { binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant) binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary") - checkSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant) - checkSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant) + CheckSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant) + CheckSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant) jsonFiles = append(jsonFiles, filepath.Join(binaryDir, "recovery_bin.json"), filepath.Join(binaryDir, "recovery_available_bin.json")) @@ -1295,7 +1288,7 @@ func TestRecoverySnapshotCapture(t *testing.T) { // For object modules, all vendor:true and vendor_available modules are captured. objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant) objectDir := filepath.Join(snapshotVariantPath, archDir, "object") - checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant) + CheckSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant) jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json")) } @@ -1393,15 +1386,15 @@ func TestRecoverySnapshotExclude(t *testing.T) { sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") // Included modules - checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant) + 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) + CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant) excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json")) - checkSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant) + CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant) excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json")) - checkSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant) + CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant) excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json")) } @@ -1482,15 +1475,15 @@ func TestRecoverySnapshotDirected(t *testing.T) { sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") // Included modules - checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant) + CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant) includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json")) // Check that snapshot captures "prefer: true" prebuilt - checkSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant) + CheckSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant) includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json")) // Excluded modules. Modules not included in the directed recovery snapshot // are still include as fake modules. - checkSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant) + CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant) includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json")) }