summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yu Liu <yudiliu@google.com> 2024-11-07 19:19:42 +0000
committer Yu Liu <yudiliu@google.com> 2024-11-07 20:02:43 +0000
commit88ea9ffccd990e6afa8936ea610ab77aa5b464b1 (patch)
treedc54778ce81f1fda234c6898cc16271fc144518b
parentaa83c512685103dd6784dbea14c0894d295e4076 (diff)
Replace FinalModule with IsFinalModule.
Bug: 377723687 Test: Compare generated mk and ninja files. Change-Id: I287b5a56aebf5fed0911bf8fbfc968d7aebc0dea
-rw-r--r--android/apex.go2
-rw-r--r--android/base_module_context.go12
-rw-r--r--android/module.go2
-rw-r--r--android/singleton.go6
-rw-r--r--cc/tidy.go2
-rw-r--r--java/bootclasspath_fragment.go2
6 files changed, 18 insertions, 8 deletions
diff --git a/android/apex.go b/android/apex.go
index 79ab13caf..e73b3e662 100644
--- a/android/apex.go
+++ b/android/apex.go
@@ -833,7 +833,7 @@ func UpdateDirectlyInAnyApex(mctx BottomUpMutatorContext, am ApexModule) {
// If this is the FinalModule (last visited module) copy
// AnyVariantDirectlyInAnyApex to all the other variants
- if am == mctx.FinalModule().(ApexModule) {
+ if mctx.IsFinalModule(am) {
mctx.VisitAllModuleVariants(func(variant Module) {
variant.(ApexModule).apexModuleBase().ApexProperties.AnyVariantDirectlyInAnyApex =
base.ApexProperties.AnyVariantDirectlyInAnyApex
diff --git a/android/base_module_context.go b/android/base_module_context.go
index 02c01586b..060fae5bc 100644
--- a/android/base_module_context.go
+++ b/android/base_module_context.go
@@ -198,9 +198,15 @@ type BaseModuleContext interface {
// singleton actions that are only done once for all variants of a module.
FinalModule() Module
+ // 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 == FinalModule(). Otherwise, care must be taken to not access any
+ // 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))
@@ -592,6 +598,10 @@ func (b *baseModuleContext) FinalModule() Module {
return b.bp.FinalModule().(Module)
}
+func (b *baseModuleContext) IsFinalModule(module Module) bool {
+ return b.bp.IsFinalModule(module)
+}
+
// IsMetaDependencyTag returns true for cross-cutting metadata dependencies.
func IsMetaDependencyTag(tag blueprint.DependencyTag) bool {
if tag == licenseKindTag {
diff --git a/android/module.go b/android/module.go
index 6217833fd..58ae885c8 100644
--- a/android/module.go
+++ b/android/module.go
@@ -2036,7 +2036,7 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext)
ctx.GetMissingDependencies()
}
- if m == ctx.FinalModule().(Module).base() {
+ if ctx.IsFinalModule(m.module) {
m.generateModuleTarget(ctx)
if ctx.Failed() {
return
diff --git a/android/singleton.go b/android/singleton.go
index 64381828a..0754b0ccb 100644
--- a/android/singleton.go
+++ b/android/singleton.go
@@ -81,7 +81,7 @@ type SingletonContext interface {
VisitAllModuleVariantProxies(module Module, visit func(proxy ModuleProxy))
PrimaryModule(module Module) Module
- FinalModule(module Module) Module
+ IsFinalModule(module Module) bool
AddNinjaFileDeps(deps ...string)
@@ -273,8 +273,8 @@ func (s *singletonContextAdaptor) PrimaryModule(module Module) Module {
return s.SingletonContext.PrimaryModule(module).(Module)
}
-func (s *singletonContextAdaptor) FinalModule(module Module) Module {
- return s.SingletonContext.FinalModule(module).(Module)
+func (s *singletonContextAdaptor) IsFinalModule(module Module) bool {
+ return s.SingletonContext.IsFinalModule(module)
}
func (s *singletonContextAdaptor) ModuleVariantsFromName(referer Module, name string) []Module {
diff --git a/cc/tidy.go b/cc/tidy.go
index 89bae1780..5cbf8f076 100644
--- a/cc/tidy.go
+++ b/cc/tidy.go
@@ -254,7 +254,7 @@ func (m *tidyPhonySingleton) GenerateBuildActions(ctx android.SingletonContext)
// Collect tidy/obj targets from the 'final' modules.
ctx.VisitAllModules(func(module android.Module) {
- if module == ctx.FinalModule(module) {
+ if ctx.IsFinalModule(module) {
collectTidyObjModuleTargets(ctx, module, tidyModulesInDirGroup, objModulesInDirGroup)
}
})
diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go
index 1a3368057..7c0f54431 100644
--- a/java/bootclasspath_fragment.go
+++ b/java/bootclasspath_fragment.go
@@ -520,7 +520,7 @@ func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.Mo
// be output to Make but it does not really matter which variant is output. The default/platform
// variant is the first (ctx.PrimaryModule()) and is usually hidden from make so this just picks
// the last variant (ctx.FinalModule()).
- if ctx.Module() != ctx.FinalModule() {
+ if !ctx.IsFinalModule(ctx.Module()) {
b.HideFromMake()
}
}