summaryrefslogtreecommitdiff
path: root/android/module.go
diff options
context:
space:
mode:
author Yu Liu <yudiliu@google.com> 2024-11-08 23:11:47 +0000
committer Yu Liu <yudiliu@google.com> 2024-11-12 03:48:18 +0000
commitd3228acdc8658e7bd9ef9662c425822ae55fdebf (patch)
treee44aabb46fe66af9168e07d91792d7dd6a724e04 /android/module.go
parent48a943f674de35fb78e1e8d7f36b823798c96233 (diff)
Change GetModuleFromPathDep to use ModuleProxy.
Bug: 377723687 Test: Compare ninja and mk files generated. Change-Id: I428b0965b217adb20a792ebde88374e0c6fae9d6
Diffstat (limited to 'android/module.go')
-rw-r--r--android/module.go57
1 files changed, 37 insertions, 20 deletions
diff --git a/android/module.go b/android/module.go
index 3b30c11ef..fba989f69 100644
--- a/android/module.go
+++ b/android/module.go
@@ -1834,6 +1834,12 @@ type InstallFilesInfo struct {
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 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext)
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 @@ type SourceFileProducer interface {
// 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 @@ func OutputFilesForModule(ctx PathContext, module blueprint.Module, tag string)
// 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 @@ func OutputFileForModule(ctx PathContext, module blueprint.Module, tag string) P
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 @@ func outputFilesForModule(ctx PathContext, module blueprint.Module, tag string)
// 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))
}