diff options
author | 2025-01-07 00:48:08 +0000 | |
---|---|---|
committer | 2025-01-08 23:28:12 +0000 | |
commit | 8a8d5b4b1c714707faf2b9456099ac95fad74b7a (patch) | |
tree | eb429d4c1149643271157f8ef4131b4bca0a981c | |
parent | 8024b92aa2edf9a2c0dcab4dc40a081b002146da (diff) |
Convert CollectAllSharedDependencies to use ModuleProxy.
Bug: 377723687
Test: Unit tests and compare the ninja and mk files generated.
Change-Id: Ie3b6d1f8fa684ab191123bd57645b86f3bfa97b4
-rw-r--r-- | android/module.go | 10 | ||||
-rw-r--r-- | android/prebuilt.go | 2 | ||||
-rw-r--r-- | cc/cc.go | 21 | ||||
-rw-r--r-- | cc/fuzz.go | 45 |
4 files changed, 52 insertions, 26 deletions
diff --git a/android/module.go b/android/module.go index 287ac599e..8faaa9f3a 100644 --- a/android/module.go +++ b/android/module.go @@ -1887,11 +1887,11 @@ type CommonModuleInfo struct { var CommonModuleInfoKey = blueprint.NewProvider[CommonModuleInfo]() -type PrebuiltModuleProviderData struct { - // Empty for now +type PrebuiltModuleInfo struct { + SourceExists bool } -var PrebuiltModuleProviderKey = blueprint.NewProvider[PrebuiltModuleProviderData]() +var PrebuiltModuleInfoProvider = blueprint.NewProvider[PrebuiltModuleInfo]() type HostToolProviderData struct { HostToolPath OptionalPath @@ -2193,7 +2193,9 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) } SetProvider(ctx, CommonModuleInfoKey, commonData) if p, ok := m.module.(PrebuiltInterface); ok && p.Prebuilt() != nil { - SetProvider(ctx, PrebuiltModuleProviderKey, PrebuiltModuleProviderData{}) + SetProvider(ctx, PrebuiltModuleInfoProvider, PrebuiltModuleInfo{ + SourceExists: p.Prebuilt().SourceExists(), + }) } if h, ok := m.module.(HostToolProvider); ok { SetProvider(ctx, HostToolProviderKey, HostToolProviderData{ diff --git a/android/prebuilt.go b/android/prebuilt.go index 0ac67b3f4..bf2717865 100644 --- a/android/prebuilt.go +++ b/android/prebuilt.go @@ -384,7 +384,7 @@ func PrebuiltGetPreferred(ctx BaseModuleContext, module Module) Module { if !OtherModuleProviderOrDefault(ctx, module, CommonModuleInfoKey).ReplacedByPrebuilt { return module } - if _, ok := OtherModuleProvider(ctx, module, PrebuiltModuleProviderKey); ok { + if _, ok := OtherModuleProvider(ctx, module, PrebuiltModuleInfoProvider); ok { // If we're given a prebuilt then assume there's no source module around. return module } @@ -85,6 +85,7 @@ type LinkerInfo struct { TestBinaryInfo *TestBinaryInfo BenchmarkDecoratorInfo *BenchmarkDecoratorInfo ObjectLinkerInfo *ObjectLinkerInfo + StubDecoratorInfo *StubDecoratorInfo } type BinaryDecoratorInfo struct{} @@ -101,8 +102,15 @@ type TestBinaryInfo struct { Gtest bool } type BenchmarkDecoratorInfo struct{} + +type StubDecoratorInfo struct{} + type ObjectLinkerInfo struct{} +type LibraryInfo struct { + BuildStubs bool +} + // Common info about the cc module. type CcInfo struct { IsPrebuilt bool @@ -110,6 +118,7 @@ type CcInfo struct { CompilerInfo *CompilerInfo LinkerInfo *LinkerInfo SnapshotInfo *SnapshotInfo + LibraryInfo *LibraryInfo } var CcInfoProvider = blueprint.NewProvider[*CcInfo]() @@ -126,6 +135,7 @@ type LinkableInfo struct { OutputFile android.OptionalPath CoverageFiles android.Paths SAbiDumpFiles android.Paths + CcLibrary bool CcLibraryInterface bool RustLibraryInterface bool // CrateName returns the crateName for a Rust library @@ -145,6 +155,7 @@ type LinkableInfo struct { OnlyInVendorRamdisk bool InRecovery bool OnlyInRecovery bool + Installable *bool } var LinkableInfoProvider = blueprint.NewProvider[*LinkableInfo]() @@ -2214,6 +2225,7 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { if c.linker != nil { if library, ok := c.linker.(libraryInterface); ok { linkableInfo.Static = library.static() + linkableInfo.Shared = library.shared() linkableInfo.CoverageFiles = library.objs().coverageFiles linkableInfo.SAbiDumpFiles = library.objs().sAbiDumpFiles } @@ -2264,6 +2276,8 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { ccInfo.LinkerInfo.BenchmarkDecoratorInfo = &BenchmarkDecoratorInfo{} case *objectLinker: ccInfo.LinkerInfo.ObjectLinkerInfo = &ObjectLinkerInfo{} + case *stubDecorator: + ccInfo.LinkerInfo.StubDecoratorInfo = &StubDecoratorInfo{} } if s, ok := c.linker.(SnapshotInterface); ok { @@ -2272,6 +2286,11 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { } } } + if c.library != nil { + ccInfo.LibraryInfo = &LibraryInfo{ + BuildStubs: c.library.buildStubs(), + } + } android.SetProvider(ctx, CcInfoProvider, &ccInfo) c.setOutputFiles(ctx) @@ -2288,6 +2307,7 @@ func CreateCommonLinkableInfo(mod LinkableInterface) *LinkableInfo { OutputFile: mod.OutputFile(), UnstrippedOutputFile: mod.UnstrippedOutputFile(), IsStubs: mod.IsStubs(), + CcLibrary: mod.CcLibrary(), CcLibraryInterface: mod.CcLibraryInterface(), RustLibraryInterface: mod.RustLibraryInterface(), BaseModuleName: mod.BaseModuleName(), @@ -2301,6 +2321,7 @@ func CreateCommonLinkableInfo(mod LinkableInterface) *LinkableInfo { OnlyInVendorRamdisk: mod.OnlyInVendorRamdisk(), InRecovery: mod.InRecovery(), OnlyInRecovery: mod.OnlyInRecovery(), + Installable: mod.Installable(), } } diff --git a/cc/fuzz.go b/cc/fuzz.go index 911a81c18..056b0dafe 100644 --- a/cc/fuzz.go +++ b/cc/fuzz.go @@ -211,29 +211,30 @@ func (fuzz *fuzzBinary) moduleInfoJSON(ctx ModuleContext, moduleInfoJSON *androi moduleInfoJSON.Class = []string{"EXECUTABLES"} } -// IsValidSharedDependency takes a module and determines if it is a unique shared library +// isValidSharedDependency takes a module and determines if it is a unique shared library // that should be installed in the fuzz target output directories. This function // returns true, unless: // - The module is not an installable shared library, or // - The module is a header or stub, or // - The module is a prebuilt and its source is available, or // - The module is a versioned member of an SDK snapshot. -func IsValidSharedDependency(dependency android.Module) bool { +func isValidSharedDependency(ctx android.ModuleContext, dependency android.ModuleProxy) bool { // TODO(b/144090547): We should be parsing these modules using // ModuleDependencyTag instead of the current brute-force checking. - linkable, ok := dependency.(LinkableInterface) - if !ok || !linkable.CcLibraryInterface() { + linkable, ok := android.OtherModuleProvider(ctx, dependency, LinkableInfoProvider) + if !ok || !linkable.CcLibraryInterface { // Discard non-linkables. return false } - if !linkable.Shared() { + if !linkable.Shared { // Discard static libs. return false } - if lib := moduleLibraryInterface(dependency); lib != nil && lib.buildStubs() && linkable.CcLibrary() { + ccInfo, hasCcInfo := android.OtherModuleProvider(ctx, dependency, CcInfoProvider) + if hasCcInfo && ccInfo.LibraryInfo != nil && ccInfo.LibraryInfo.BuildStubs && linkable.CcLibrary { // Discard stubs libs (only CCLibrary variants). Prebuilt libraries should not // be excluded on the basis of they're not CCLibrary()'s. return false @@ -242,13 +243,13 @@ func IsValidSharedDependency(dependency android.Module) bool { // We discarded module stubs libraries above, but the LLNDK prebuilts stubs // libraries must be handled differently - by looking for the stubDecorator. // Discard LLNDK prebuilts stubs as well. - if ccLibrary, isCcLibrary := dependency.(*Module); isCcLibrary { - if _, isLLndkStubLibrary := ccLibrary.linker.(*stubDecorator); isLLndkStubLibrary { + if hasCcInfo { + if ccInfo.LinkerInfo.StubDecoratorInfo != nil { return false } // Discard installable:false libraries because they are expected to be absent // in runtime. - if !proptools.BoolDefault(ccLibrary.Installable(), true) { + if !proptools.BoolDefault(linkable.Installable, true) { return false } } @@ -256,7 +257,7 @@ func IsValidSharedDependency(dependency android.Module) bool { // If the same library is present both as source and a prebuilt we must pick // only one to avoid a conflict. Always prefer the source since the prebuilt // probably won't be built with sanitizers enabled. - if prebuilt := android.GetEmbeddedPrebuilt(dependency); prebuilt != nil && prebuilt.SourceExists() { + if prebuilt, ok := android.OtherModuleProvider(ctx, dependency, android.PrebuiltModuleInfoProvider); ok && prebuilt.SourceExists { return false } @@ -607,17 +608,17 @@ func GetSharedLibsToZip(sharedLibraries android.RuleBuilderInstalls, module Link // VisitDirectDeps is used first to avoid incorrectly using the core libraries (sanitizer // runtimes, libc, libdl, etc.) from a dependency. This may cause issues when dependencies // have explicit sanitizer tags, as we may get a dependency on an unsanitized libc, etc. -func CollectAllSharedDependencies(ctx android.ModuleContext) (android.RuleBuilderInstalls, []android.Module) { +func CollectAllSharedDependencies(ctx android.ModuleContext) (android.RuleBuilderInstalls, []android.ModuleProxy) { seen := make(map[string]bool) recursed := make(map[string]bool) - deps := []android.Module{} + deps := []android.ModuleProxy{} var sharedLibraries android.RuleBuilderInstalls // Enumerate the first level of dependencies, as we discard all non-library // modules in the BFS loop below. - ctx.VisitDirectDeps(func(dep android.Module) { - if !IsValidSharedDependency(dep) { + ctx.VisitDirectDepsProxy(func(dep android.ModuleProxy) { + if !isValidSharedDependency(ctx, dep) { return } sharedLibraryInfo, hasSharedLibraryInfo := android.OtherModuleProvider(ctx, dep, SharedLibraryInfoProvider) @@ -635,19 +636,21 @@ func CollectAllSharedDependencies(ctx android.ModuleContext) (android.RuleBuilde sharedLibraries = append(sharedLibraries, ruleBuilderInstall) }) - ctx.WalkDeps(func(child, parent android.Module) bool { + ctx.WalkDepsProxy(func(child, _ android.ModuleProxy) bool { // If this is a Rust module which is not rust_ffi_shared, we still want to bundle any transitive // shared dependencies (even for rust_ffi_static) - if rustmod, ok := child.(LinkableInterface); ok && rustmod.RustLibraryInterface() && !rustmod.Shared() { - if recursed[ctx.OtherModuleName(child)] { - return false + if info, ok := android.OtherModuleProvider(ctx, child, LinkableInfoProvider); ok { + if info.RustLibraryInterface && !info.Shared { + if recursed[ctx.OtherModuleName(child)] { + return false + } + recursed[ctx.OtherModuleName(child)] = true + return true } - recursed[ctx.OtherModuleName(child)] = true - return true } - if !IsValidSharedDependency(child) { + if !isValidSharedDependency(ctx, child) { return false } sharedLibraryInfo, hasSharedLibraryInfo := android.OtherModuleProvider(ctx, child, SharedLibraryInfoProvider) |