Convert CollectAllSharedDependencies to use ModuleProxy.
Bug: 377723687
Test: Unit tests and compare the ninja and mk files generated.
Change-Id: Ie3b6d1f8fa684ab191123bd57645b86f3bfa97b4
diff --git a/android/module.go b/android/module.go
index 287ac59..8faaa9f 100644
--- a/android/module.go
+++ b/android/module.go
@@ -1887,11 +1887,11 @@
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 @@
}
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 0ac67b3..bf27178 100644
--- a/android/prebuilt.go
+++ b/android/prebuilt.go
@@ -384,7 +384,7 @@
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
}
diff --git a/cc/cc.go b/cc/cc.go
index 16471c9..21fd216 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -85,6 +85,7 @@
TestBinaryInfo *TestBinaryInfo
BenchmarkDecoratorInfo *BenchmarkDecoratorInfo
ObjectLinkerInfo *ObjectLinkerInfo
+ StubDecoratorInfo *StubDecoratorInfo
}
type BinaryDecoratorInfo struct{}
@@ -101,8 +102,15 @@
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 @@
CompilerInfo *CompilerInfo
LinkerInfo *LinkerInfo
SnapshotInfo *SnapshotInfo
+ LibraryInfo *LibraryInfo
}
var CcInfoProvider = blueprint.NewProvider[*CcInfo]()
@@ -126,6 +135,7 @@
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 @@
OnlyInVendorRamdisk bool
InRecovery bool
OnlyInRecovery bool
+ Installable *bool
}
var LinkableInfoProvider = blueprint.NewProvider[*LinkableInfo]()
@@ -2214,6 +2225,7 @@
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 @@
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 @@
}
}
}
+ if c.library != nil {
+ ccInfo.LibraryInfo = &LibraryInfo{
+ BuildStubs: c.library.buildStubs(),
+ }
+ }
android.SetProvider(ctx, CcInfoProvider, &ccInfo)
c.setOutputFiles(ctx)
@@ -2288,6 +2307,7 @@
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 @@
OnlyInVendorRamdisk: mod.OnlyInVendorRamdisk(),
InRecovery: mod.InRecovery(),
OnlyInRecovery: mod.OnlyInRecovery(),
+ Installable: mod.Installable(),
}
}
diff --git a/cc/fuzz.go b/cc/fuzz.go
index 911a81c..056b0da 100644
--- a/cc/fuzz.go
+++ b/cc/fuzz.go
@@ -211,29 +211,30 @@
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 @@
// 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 @@
// 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 @@
// 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 @@
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)