Change GetModuleFromPathDep to use ModuleProxy.
Bug: 377723687
Test: Compare ninja and mk files generated.
Change-Id: I428b0965b217adb20a792ebde88374e0c6fae9d6
diff --git a/android/module.go b/android/module.go
index 3b30c11..fba989f 100644
--- a/android/module.go
+++ b/android/module.go
@@ -1834,6 +1834,12 @@
var InstallFilesProvider = blueprint.NewProvider[InstallFilesInfo]()
+type SourceFilesInfo struct {
+ Srcs Paths
+}
+
+var SourceFilesInfoKey = blueprint.NewProvider[SourceFilesInfo]()
+
type FinalModuleBuildTargetsInfo struct {
// Used by buildTargetSingleton to create checkbuild and per-directory build targets
// Only set on the final variant of each module
@@ -2038,6 +2044,10 @@
ctx.GetMissingDependencies()
}
+ if sourceFileProducer, ok := m.module.(SourceFileProducer); ok {
+ SetProvider(ctx, SourceFilesInfoKey, SourceFilesInfo{Srcs: sourceFileProducer.Srcs()})
+ }
+
if ctx.IsFinalModule(m.module) {
m.generateModuleTarget(ctx)
if ctx.Failed() {
@@ -2634,7 +2644,7 @@
// OutputFilesForModule returns the output file paths with the given tag. On error, including if the
// module produced zero paths, it reports errors to the ctx and returns nil.
-func OutputFilesForModule(ctx PathContext, module blueprint.Module, tag string) Paths {
+func OutputFilesForModule(ctx PathContext, module Module, tag string) Paths {
paths, err := outputFilesForModule(ctx, module, tag)
if err != nil {
reportPathError(ctx, err)
@@ -2645,7 +2655,7 @@
// OutputFileForModule returns the output file paths with the given tag. On error, including if the
// module produced zero or multiple paths, it reports errors to the ctx and returns nil.
-func OutputFileForModule(ctx PathContext, module blueprint.Module, tag string) Path {
+func OutputFileForModule(ctx PathContext, module Module, tag string) Path {
paths, err := outputFilesForModule(ctx, module, tag)
if err != nil {
reportPathError(ctx, err)
@@ -2678,20 +2688,34 @@
return paths[0]
}
-func outputFilesForModule(ctx PathContext, module blueprint.Module, tag string) (Paths, error) {
+type OutputFilesProviderModuleContext interface {
+ OtherModuleProviderContext
+ Module() Module
+ GetOutputFiles() OutputFilesInfo
+ EqualModules(m1, m2 Module) bool
+}
+
+func outputFilesForModule(ctx PathContext, module Module, tag string) (Paths, error) {
outputFilesFromProvider, err := outputFilesForModuleFromProvider(ctx, module, tag)
if outputFilesFromProvider != nil || err != OutputFilesProviderNotSet {
return outputFilesFromProvider, err
}
- if sourceFileProducer, ok := module.(SourceFileProducer); ok {
- if tag != "" {
- return nil, fmt.Errorf("module %q is a SourceFileProducer, which does not support tag %q", pathContextName(ctx, module), tag)
+
+ if octx, ok := ctx.(OutputFilesProviderModuleContext); ok {
+ if octx.EqualModules(octx.Module(), module) {
+ if sourceFileProducer, ok := module.(SourceFileProducer); ok {
+ return sourceFileProducer.Srcs(), nil
+ }
+ } else if sourceFiles, ok := OtherModuleProvider(octx, module, SourceFilesInfoKey); ok {
+ if tag != "" {
+ return nil, fmt.Errorf("module %q is a SourceFileProducer, which does not support tag %q", pathContextName(ctx, module), tag)
+ }
+ paths := sourceFiles.Srcs
+ return paths, nil
}
- paths := sourceFileProducer.Srcs()
- return paths, nil
- } else {
- return nil, fmt.Errorf("module %q is not a SourceFileProducer or having valid output file for tag %q", pathContextName(ctx, module), tag)
}
+
+ return nil, fmt.Errorf("module %q is not a SourceFileProducer or having valid output file for tag %q", pathContextName(ctx, module), tag)
}
// This method uses OutputFilesProvider for output files
@@ -2700,26 +2724,19 @@
// from outputFiles property of module base, to avoid both setting and
// reading OutputFilesProvider before GenerateBuildActions is finished.
// If a module doesn't have the OutputFilesProvider, nil is returned.
-func outputFilesForModuleFromProvider(ctx PathContext, module blueprint.Module, tag string) (Paths, error) {
+func outputFilesForModuleFromProvider(ctx PathContext, module Module, tag string) (Paths, error) {
var outputFiles OutputFilesInfo
fromProperty := false
- type OutputFilesProviderModuleContext interface {
- OtherModuleProviderContext
- Module() Module
- GetOutputFiles() OutputFilesInfo
- }
-
if mctx, isMctx := ctx.(OutputFilesProviderModuleContext); isMctx {
- if mctx.Module() != module {
+ if !mctx.EqualModules(mctx.Module(), module) {
outputFiles, _ = OtherModuleProvider(mctx, module, OutputFilesProvider)
} else {
outputFiles = mctx.GetOutputFiles()
fromProperty = true
}
} else if cta, isCta := ctx.(*singletonContextAdaptor); isCta {
- providerData, _ := cta.otherModuleProvider(module, OutputFilesProvider)
- outputFiles, _ = providerData.(OutputFilesInfo)
+ outputFiles, _ = OtherModuleProvider(cta, module, OutputFilesProvider)
} else {
return nil, fmt.Errorf("unsupported context %q in method outputFilesForModuleFromProvider", reflect.TypeOf(ctx))
}