aboutsummaryrefslogtreecommitdiff
path: root/android/base_module_context.go
diff options
context:
space:
mode:
Diffstat (limited to 'android/base_module_context.go')
-rw-r--r--android/base_module_context.go212
1 files changed, 91 insertions, 121 deletions
diff --git a/android/base_module_context.go b/android/base_module_context.go
index 5cb9e71cf..1e8de8198 100644
--- a/android/base_module_context.go
+++ b/android/base_module_context.go
@@ -36,23 +36,23 @@ type BaseModuleContext interface {
// OtherModuleName returns the name of another Module. See BaseModuleContext.ModuleName for more information.
// It is intended for use inside the visit functions of Visit* and WalkDeps.
- OtherModuleName(m blueprint.Module) string
+ OtherModuleName(m ModuleOrProxy) string
// OtherModuleDir returns the directory of another Module. See BaseModuleContext.ModuleDir for more information.
// It is intended for use inside the visit functions of Visit* and WalkDeps.
- OtherModuleDir(m blueprint.Module) string
+ OtherModuleDir(m ModuleOrProxy) string
// OtherModuleErrorf reports an error on another Module. See BaseModuleContext.ModuleErrorf for more information.
// It is intended for use inside the visit functions of Visit* and WalkDeps.
- OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
+ OtherModuleErrorf(m ModuleOrProxy, fmt string, args ...interface{})
// OtherModuleDependencyTag returns the dependency tag used to depend on a module, or nil if there is no dependency
// on the module. When called inside a Visit* method with current module being visited, and there are multiple
// dependencies on the module being visited, it returns the dependency tag used for the current dependency.
- OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
+ OtherModuleDependencyTag(m ModuleOrProxy) blueprint.DependencyTag
// OtherModuleSubDir returns the string representing the variations of a module.
- OtherModuleSubDir(m blueprint.Module) string
+ OtherModuleSubDir(m ModuleOrProxy) string
// OtherModuleExists returns true if a module with the specified name exists, as determined by the NameInterface
// passed to Context.SetNameInterface, or SimpleNameInterface if it was not called.
@@ -80,23 +80,23 @@ type BaseModuleContext interface {
// OtherModuleType returns the type of another Module. See BaseModuleContext.ModuleType for more information.
// It is intended for use inside the visit functions of Visit* and WalkDeps.
- OtherModuleType(m blueprint.Module) string
+ OtherModuleType(m ModuleOrProxy) string
// otherModuleProvider returns the value for a provider for the given module. If the value is
// not set it returns nil and false. The value returned may be a deep copy of the value originally
// passed to SetProvider.
//
// This method shouldn't be used directly, prefer the type-safe android.OtherModuleProvider instead.
- otherModuleProvider(m blueprint.Module, provider blueprint.AnyProviderKey) (any, bool)
+ otherModuleProvider(m ModuleOrProxy, provider blueprint.AnyProviderKey) (any, bool)
// OtherModuleHasProvider returns true if the module has the given provider set. This
// can avoid copying the provider if the caller only cares about the existence of
// the provider.
- OtherModuleHasProvider(m blueprint.Module, provider blueprint.AnyProviderKey) bool
+ OtherModuleHasProvider(m ModuleOrProxy, provider blueprint.AnyProviderKey) bool
// OtherModuleIsAutoGenerated returns true if the module is auto generated by another module
// instead of being defined in Android.bp file.
- OtherModuleIsAutoGenerated(m blueprint.Module) bool
+ OtherModuleIsAutoGenerated(m ModuleOrProxy) bool
// Provider returns the value for a provider for the current module. If the value is
// not set it returns nil and false. It panics if called before the appropriate
@@ -123,7 +123,7 @@ type BaseModuleContext interface {
// dependencies that are not an android.Module.
GetDirectDepWithTag(name string, tag blueprint.DependencyTag) Module
- GetDirectDepProxyWithTag(name string, tag blueprint.DependencyTag) *ModuleProxy
+ GetDirectDepProxyWithTag(name string, tag blueprint.DependencyTag) ModuleProxy
// VisitDirectDeps calls visit for each direct dependency. If there are multiple
// direct dependencies on the same module visit will be called multiple times on that module
@@ -163,10 +163,6 @@ type BaseModuleContext interface {
// The Module passed to the visit function should not be retained outside of the visit function, it may be
// invalidated by future mutators.
VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
- // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
- VisitDepsDepthFirst(visit func(Module))
- // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
- VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
// WalkDeps calls visit for each transitive dependency, traversing the dependency tree in top down order. visit may
// be called multiple times for the same (child, parent) pair if there are multiple direct dependencies between the
@@ -178,11 +174,10 @@ type BaseModuleContext interface {
// invalidated by future mutators.
WalkDeps(visit func(child, parent Module) bool)
- // WalkDeps calls visit for each transitive dependency, traversing the dependency tree in top down order. visit may
+ // WalkDepsProxy calls visit for each transitive dependency, traversing the dependency tree in top down order. visit may
// be called multiple times for the same (child, parent) pair if there are multiple direct dependencies between the
// child and parent with different tags. OtherModuleDependencyTag will return the tag for the currently visited
- // (child, parent) pair. If visit returns false WalkDeps will not continue recursing down to child. It skips
- // any dependencies that are not an android.Module.
+ // (child, parent) pair. If visit returns false WalkDepsProxy will not continue recursing down to child.
//
// The Modules passed to the visit function should not be retained outside of the visit function, they may be
// invalidated by future mutators.
@@ -192,35 +187,27 @@ type BaseModuleContext interface {
// and returns a top-down dependency path from a start module to current child module.
GetWalkPath() []Module
+ // GetProxyWalkPath is supposed to be called in visit function passed in WalkDepsProxy()
+ // and returns a top-down dependency path from a start module to current child module.
+ GetProxyWalkPath() []ModuleProxy
+
// PrimaryModule returns the first variant of the current module. Variants of a module are always visited in
// order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from the
// Module returned by PrimaryModule without data races. This can be used to perform singleton actions that are
// only done once for all variants of a module.
PrimaryModule() Module
- // FinalModule returns the last variant of the current module. Variants of a module are always visited in
- // order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from all
- // variants using VisitAllModuleVariants if the current module == FinalModule(). This can be used to perform
- // singleton actions that are only done once for all variants of a module.
- FinalModule() Module
+ // IsPrimaryModule returns if the current module is the first variant. Variants of a module are always visited in
+ // order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from the
+ // Module returned by PrimaryModule without data races. This can be used to perform singleton actions that are
+ // only done once for all variants of a module.
+ IsPrimaryModule(module ModuleOrProxy) bool
// IsFinalModule returns if the current module is the last variant. Variants of a module are always visited in
// order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from all
// variants using VisitAllModuleVariants if the current module is the last one. This can be used to perform
// singleton actions that are only done once for all variants of a module.
- IsFinalModule(module Module) bool
-
- // VisitAllModuleVariants calls visit for each variant of the current module. Variants of a module are always
- // visited in order by mutators and GenerateBuildActions, so the data created by the current mutator can be read
- // from all variants if the current module is the last one. Otherwise, care must be taken to not access any
- // data modified by the current mutator.
- VisitAllModuleVariants(visit func(Module))
-
- // VisitAllModuleVariantProxies calls visit for each variant of the current module. Variants of a module are always
- // visited in order by mutators and GenerateBuildActions, so the data created by the current mutator can be read
- // from all variants if the current module is the last one. Otherwise, care must be taken to not access any
- // data modified by the current mutator.
- VisitAllModuleVariantProxies(visit func(proxy ModuleProxy))
+ IsFinalModule(module ModuleOrProxy) bool
// GetTagPath is supposed to be called in visit function passed in WalkDeps()
// and returns a top-down dependency tags path from a start module to current child module.
@@ -252,41 +239,32 @@ type baseModuleContext struct {
earlyModuleContext
archModuleContext
- walkPath []Module
- tagPath []blueprint.DependencyTag
+ walkPath []Module
+ proxyWalkPath []ModuleProxy
+ tagPath []blueprint.DependencyTag
strictVisitDeps bool // If true, enforce that all dependencies are enabled
}
-func getWrappedModule(module blueprint.Module) blueprint.Module {
- if mp, isProxy := module.(*ModuleProxy); isProxy {
- return mp.module
- }
- if mp, isProxy := module.(ModuleProxy); isProxy {
- return mp.module
- }
- return module
+func EqualModules(m1, m2 ModuleOrProxy) bool {
+ return blueprint.EqualModules(m1, m2)
}
-func EqualModules(m1, m2 Module) bool {
- return blueprint.EqualModules(getWrappedModule(m1), getWrappedModule(m2))
+func (b *baseModuleContext) OtherModuleName(m ModuleOrProxy) string {
+ return b.bp.OtherModuleName(m)
}
-
-func (b *baseModuleContext) OtherModuleName(m blueprint.Module) string {
- return b.bp.OtherModuleName(getWrappedModule(m))
-}
-func (b *baseModuleContext) OtherModuleDir(m blueprint.Module) string {
- return b.bp.OtherModuleDir(getWrappedModule(m))
+func (b *baseModuleContext) OtherModuleDir(m ModuleOrProxy) string {
+ return b.bp.OtherModuleDir(m)
}
-func (b *baseModuleContext) OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) {
- b.bp.OtherModuleErrorf(getWrappedModule(m), fmt, args...)
+func (b *baseModuleContext) OtherModuleErrorf(m ModuleOrProxy, fmt string, args ...interface{}) {
+ b.bp.OtherModuleErrorf(m, fmt, args...)
}
-func (b *baseModuleContext) OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag {
- return b.bp.OtherModuleDependencyTag(getWrappedModule(m))
+func (b *baseModuleContext) OtherModuleDependencyTag(m ModuleOrProxy) blueprint.DependencyTag {
+ return b.bp.OtherModuleDependencyTag(m)
}
-func (b *baseModuleContext) OtherModuleSubDir(m blueprint.Module) string {
- return b.bp.OtherModuleSubDir(getWrappedModule(m))
+func (b *baseModuleContext) OtherModuleSubDir(m ModuleOrProxy) string {
+ return b.bp.OtherModuleSubDir(m)
}
func (b *baseModuleContext) OtherModuleExists(name string) bool { return b.bp.OtherModuleExists(name) }
func (b *baseModuleContext) OtherModuleDependencyVariantExists(variations []blueprint.Variation, name string) bool {
@@ -298,19 +276,19 @@ func (b *baseModuleContext) OtherModuleFarDependencyVariantExists(variations []b
func (b *baseModuleContext) OtherModuleReverseDependencyVariantExists(name string) bool {
return b.bp.OtherModuleReverseDependencyVariantExists(name)
}
-func (b *baseModuleContext) OtherModuleType(m blueprint.Module) string {
- return b.bp.OtherModuleType(getWrappedModule(m))
+func (b *baseModuleContext) OtherModuleType(m ModuleOrProxy) string {
+ return b.bp.OtherModuleType(m)
}
-func (b *baseModuleContext) otherModuleProvider(m blueprint.Module, provider blueprint.AnyProviderKey) (any, bool) {
- return b.bp.OtherModuleProvider(getWrappedModule(m), provider)
+func (b *baseModuleContext) otherModuleProvider(m ModuleOrProxy, provider blueprint.AnyProviderKey) (any, bool) {
+ return b.bp.OtherModuleProvider(m, provider)
}
-func (b *baseModuleContext) OtherModuleHasProvider(m blueprint.Module, provider blueprint.AnyProviderKey) bool {
- return b.bp.OtherModuleHasProvider(getWrappedModule(m), provider)
+func (b *baseModuleContext) OtherModuleHasProvider(m ModuleOrProxy, provider blueprint.AnyProviderKey) bool {
+ return b.bp.OtherModuleHasProvider(m, provider)
}
-func (b *baseModuleContext) OtherModuleIsAutoGenerated(m blueprint.Module) bool {
+func (b *baseModuleContext) OtherModuleIsAutoGenerated(m ModuleOrProxy) bool {
return b.bp.OtherModuleIsAutoGenerated(m)
}
@@ -329,11 +307,11 @@ func (b *baseModuleContext) GetDirectDepWithTag(name string, tag blueprint.Depen
return nil
}
-func (b *baseModuleContext) GetDirectDepProxyWithTag(name string, tag blueprint.DependencyTag) *ModuleProxy {
- if module := b.bp.GetDirectDepProxyWithTag(name, tag); module != nil {
- return &ModuleProxy{*module}
+func (b *baseModuleContext) GetDirectDepProxyWithTag(name string, tag blueprint.DependencyTag) ModuleProxy {
+ if module := b.bp.GetDirectDepProxyWithTag(name, tag); !module.IsNil() {
+ return ModuleProxy{module}
}
- return nil
+ return ModuleProxy{}
}
func (b *baseModuleContext) blueprintBaseModuleContext() blueprint.BaseModuleContext {
@@ -403,11 +381,11 @@ func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, tag b
}
func (b *baseModuleContext) validateAndroidModuleProxy(
- module blueprint.ModuleProxy, tag blueprint.DependencyTag, strict bool) *ModuleProxy {
- aModule := ModuleProxy{module: module}
+ module blueprint.ModuleProxy, tag blueprint.DependencyTag, strict bool) ModuleProxy {
+ aModule := ModuleProxy{module}
if !strict {
- return &aModule
+ return aModule
}
if !OtherModulePointerProviderOrDefault(b, module, CommonModuleInfoProvider).Enabled {
@@ -418,10 +396,10 @@ func (b *baseModuleContext) validateAndroidModuleProxy(
b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule))
}
}
- return nil
+ return ModuleProxy{}
}
- return &aModule
+ return aModule
}
func (b *baseModuleContext) getDirectDepsInternal(name string, tag blueprint.DependencyTag) []Module {
@@ -480,8 +458,8 @@ func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
func (b *baseModuleContext) VisitDirectDepsProxy(visit func(ModuleProxy)) {
b.bp.VisitDirectDepsProxy(func(module blueprint.ModuleProxy) {
- if aModule := b.validateAndroidModuleProxy(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
- visit(*aModule)
+ if aModule := b.validateAndroidModuleProxy(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); !aModule.IsNil() {
+ visit(aModule)
}
})
}
@@ -503,8 +481,8 @@ func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag,
func (b *baseModuleContext) VisitDirectDepsProxyWithTag(tag blueprint.DependencyTag, visit func(proxy ModuleProxy)) {
b.bp.VisitDirectDepsProxy(func(module blueprint.ModuleProxy) {
if b.bp.OtherModuleDependencyTag(module) == tag {
- if aModule := b.validateAndroidModuleProxy(module, tag, b.strictVisitDeps); aModule != nil {
- visit(*aModule)
+ if aModule := b.validateAndroidModuleProxy(module, tag, b.strictVisitDeps); !aModule.IsNil() {
+ visit(aModule)
}
}
})
@@ -526,32 +504,9 @@ func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func
})
}
-func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
- b.bp.VisitDepsDepthFirst(func(module blueprint.Module) {
- if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
- visit(aModule)
- }
- })
-}
-
-func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
- b.bp.VisitDepsDepthFirstIf(
- // pred
- func(module blueprint.Module) bool {
- if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
- return pred(aModule)
- } else {
- return false
- }
- },
- // visit
- func(module blueprint.Module) {
- visit(module.(Module))
- })
-}
-
func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
b.walkPath = []Module{b.Module()}
+ b.proxyWalkPath = nil
b.tagPath = []blueprint.DependencyTag{}
b.bp.WalkDeps(func(child, parent blueprint.Module) bool {
childAndroidModule, _ := child.(Module)
@@ -569,52 +524,56 @@ func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
return false
}
})
+ b.walkPath = nil
}
func (b *baseModuleContext) WalkDepsProxy(visit func(ModuleProxy, ModuleProxy) bool) {
- b.walkPath = []Module{ModuleProxy{blueprint.CreateModuleProxy(b.Module())}}
+ startProxy := blueprint.CreateModuleProxy(b.Module())
+ b.proxyWalkPath = []ModuleProxy{{startProxy}}
+ b.walkPath = nil
b.tagPath = []blueprint.DependencyTag{}
b.bp.WalkDepsProxy(func(child, parent blueprint.ModuleProxy) bool {
childAndroidModule := ModuleProxy{child}
parentAndroidModule := ModuleProxy{parent}
// record walkPath before visit
- for b.walkPath[len(b.walkPath)-1] != parentAndroidModule {
- b.walkPath = b.walkPath[0 : len(b.walkPath)-1]
+ for b.proxyWalkPath[len(b.proxyWalkPath)-1] != parentAndroidModule {
+ b.proxyWalkPath = b.proxyWalkPath[0 : len(b.proxyWalkPath)-1]
b.tagPath = b.tagPath[0 : len(b.tagPath)-1]
}
- b.walkPath = append(b.walkPath, childAndroidModule)
+ b.proxyWalkPath = append(b.proxyWalkPath, childAndroidModule)
b.tagPath = append(b.tagPath, b.OtherModuleDependencyTag(childAndroidModule))
return visit(childAndroidModule, parentAndroidModule)
})
+ b.proxyWalkPath = nil
}
func (b *baseModuleContext) GetWalkPath() []Module {
+ if b.walkPath == nil {
+ panic("GetWalkPath called from outside WalkDeps, did you mean GetProxyWalkPath?")
+ }
return slices.Clone(b.walkPath)
}
-func (b *baseModuleContext) GetTagPath() []blueprint.DependencyTag {
- return b.tagPath
-}
-
-func (b *baseModuleContext) VisitAllModuleVariants(visit func(Module)) {
- b.bp.VisitAllModuleVariants(func(module blueprint.Module) {
- visit(module.(Module))
- })
+func (b *baseModuleContext) GetProxyWalkPath() []ModuleProxy {
+ if b.proxyWalkPath == nil {
+ panic("GetProxyWalkPath called from outside WalkDeps, did you mean GetWalkPath?")
+ }
+ return slices.Clone(b.proxyWalkPath)
}
-func (b *baseModuleContext) VisitAllModuleVariantProxies(visit func(ModuleProxy)) {
- b.bp.VisitAllModuleVariantProxies(visitProxyAdaptor(visit))
+func (b *baseModuleContext) GetTagPath() []blueprint.DependencyTag {
+ return b.tagPath
}
func (b *baseModuleContext) PrimaryModule() Module {
return b.bp.PrimaryModule().(Module)
}
-func (b *baseModuleContext) FinalModule() Module {
- return b.bp.FinalModule().(Module)
+func (b *baseModuleContext) IsPrimaryModule(module ModuleOrProxy) bool {
+ return b.bp.IsPrimaryModule(module)
}
-func (b *baseModuleContext) IsFinalModule(module Module) bool {
+func (b *baseModuleContext) IsFinalModule(module ModuleOrProxy) bool {
return b.bp.IsFinalModule(module)
}
@@ -653,7 +612,18 @@ func PrettyPrintTag(tag blueprint.DependencyTag) string {
func (b *baseModuleContext) GetPathString(skipFirst bool) string {
sb := strings.Builder{}
tagPath := b.GetTagPath()
- walkPath := b.GetWalkPath()
+ var walkPath []ModuleOrProxy
+ if b.walkPath != nil {
+ for _, w := range b.walkPath {
+ walkPath = append(walkPath, w)
+ }
+ } else if b.proxyWalkPath != nil {
+ for _, w := range b.proxyWalkPath {
+ walkPath = append(walkPath, w)
+ }
+ } else {
+ panic(fmt.Errorf("GetPathString must be called inside WalkDeps or WalkDepsProxy"))
+ }
if !skipFirst {
sb.WriteString(walkPath[0].String())
}