Move prebuilt mutators earlier
Move the prebuilt mutators from postdeps to predeps mutators. This
ensures that the decisions on whether the source or prebuilt will
be used can be made earlier, which simplifies the apex and dexpreopt
code, allowing it to directly depend on the correct module.
This requires some mutators that previously ran before the prebuilt
mutator and now run after the prebuilt mutator be aware of prebuilts.
In particular, the cc.linkageTransitionMutator and
rust.libraryTransitionMutator now have to manually disable prebuilts
when they don't produce a static or shared variant that the source
module produces, and some mutators have to ignore PrebuiltDepTag
dependencies when propagating transitions.
The apexTransitionMutator also needs to temporarily use an interface
on the dependency tag to correctly resolve some dependencies that
exist before the apex variation is created onto the correct variation.
This will shortly be replaced with depending on the apex itself instead,
and then walking the dependencies of the apex to find the necessary
module.
Bug: 372543712
Test: go test ./...
Change-Id: If125ea981be87673bae3bd0a7e3b2c16c337e8f7
diff --git a/android/apex_contributions.go b/android/apex_contributions.go
index ce34278..fe7a835 100644
--- a/android/apex_contributions.go
+++ b/android/apex_contributions.go
@@ -104,19 +104,8 @@
AcDepTag = apexContributionsDepTag{}
)
-// Creates a dep to each selected apex_contributions
-func (a *allApexContributions) DepsMutator(ctx BottomUpMutatorContext) {
- // Skip apex_contributions if BuildApexContributionContents is true
- // This product config var allows some products in the same family to use mainline modules from source
- // (e.g. shiba and shiba_fullmte)
- // Eventually these product variants will have their own release config maps.
- if !proptools.Bool(ctx.Config().BuildIgnoreApexContributionContents()) {
- ctx.AddDependency(ctx.Module(), AcDepTag, ctx.Config().AllApexContributions()...)
- }
-}
-
// Set PrebuiltSelectionInfoProvider in post deps phase
-func (a *allApexContributions) SetPrebuiltSelectionInfoProvider(ctx BaseModuleContext) {
+func (a *allApexContributions) SetPrebuiltSelectionInfoProvider(ctx BottomUpMutatorContext) {
addContentsToProvider := func(p *PrebuiltSelectionInfoMap, m *apexContributions) {
for _, content := range m.Contents() {
// Verify that the module listed in contents exists in the tree
@@ -135,13 +124,23 @@
}
p := PrebuiltSelectionInfoMap{}
- ctx.VisitDirectDepsWithTag(AcDepTag, func(child Module) {
- if m, ok := child.(*apexContributions); ok {
- addContentsToProvider(&p, m)
- } else {
- ctx.ModuleErrorf("%s is not an apex_contributions module\n", child.Name())
+ // Skip apex_contributions if BuildApexContributionContents is true
+ // This product config var allows some products in the same family to use mainline modules from source
+ // (e.g. shiba and shiba_fullmte)
+ // Eventually these product variants will have their own release config maps.
+ if !proptools.Bool(ctx.Config().BuildIgnoreApexContributionContents()) {
+ deps := ctx.AddDependency(ctx.Module(), AcDepTag, ctx.Config().AllApexContributions()...)
+ for _, child := range deps {
+ if child == nil {
+ continue
+ }
+ if m, ok := child.(*apexContributions); ok {
+ addContentsToProvider(&p, m)
+ } else {
+ ctx.ModuleErrorf("%s is not an apex_contributions module\n", child.Name())
+ }
}
- })
+ }
SetProvider(ctx, PrebuiltSelectionInfoProvider, p)
}
diff --git a/android/mutator.go b/android/mutator.go
index 1b0700a..76487fb 100644
--- a/android/mutator.go
+++ b/android/mutator.go
@@ -159,6 +159,7 @@
var preDeps = []RegisterMutatorFunc{
registerArchMutator,
+ RegisterPrebuiltsPreDepsMutators,
}
var postDeps = []RegisterMutatorFunc{
diff --git a/android/prebuilt.go b/android/prebuilt.go
index bf27178..defec11 100644
--- a/android/prebuilt.go
+++ b/android/prebuilt.go
@@ -28,6 +28,7 @@
func RegisterPrebuiltMutators(ctx RegistrationContext) {
ctx.PreArchMutators(RegisterPrebuiltsPreArchMutators)
+ ctx.PreDepsMutators(RegisterPrebuiltsPreDepsMutators)
ctx.PostDepsMutators(RegisterPrebuiltsPostDepsMutators)
}
@@ -195,6 +196,10 @@
return p.properties.UsePrebuilt
}
+func (p *Prebuilt) SetUsePrebuilt(use bool) {
+ p.properties.UsePrebuilt = use
+}
+
// Called to provide the srcs value for the prebuilt module.
//
// This can be called with a context for any module not just the prebuilt one itself. It can also be
@@ -422,9 +427,12 @@
ctx.BottomUp("prebuilt_rename", PrebuiltRenameMutator).UsesRename()
}
-func RegisterPrebuiltsPostDepsMutators(ctx RegisterMutatorsContext) {
+func RegisterPrebuiltsPreDepsMutators(ctx RegisterMutatorsContext) {
ctx.BottomUp("prebuilt_source", PrebuiltSourceDepsMutator).UsesReverseDependencies()
ctx.BottomUp("prebuilt_select", PrebuiltSelectModuleMutator)
+}
+
+func RegisterPrebuiltsPostDepsMutators(ctx RegisterMutatorsContext) {
ctx.BottomUp("prebuilt_postdeps", PrebuiltPostDepsMutator).UsesReplaceDependencies()
}
@@ -468,7 +476,7 @@
bmn, _ := m.(baseModuleName)
name := bmn.BaseModuleName()
if ctx.OtherModuleReverseDependencyVariantExists(name) {
- ctx.AddReverseDependency(ctx.Module(), PrebuiltDepTag, name)
+ ctx.AddReverseVariationDependency(nil, PrebuiltDepTag, name)
p.properties.SourceExists = true
}
}
diff --git a/android/visibility.go b/android/visibility.go
index cee465e..4837c7d 100644
--- a/android/visibility.go
+++ b/android/visibility.go
@@ -529,7 +529,7 @@
rule := effectiveVisibilityRules(ctx.Config(), depQualified)
if !rule.matches(qualified) {
- ctx.ModuleErrorf("depends on %s which is not visible to this module\nYou may need to add %q to its visibility", depQualified, "//"+ctx.ModuleDir())
+ ctx.ModuleErrorf("depends on %s which is not visible to this module\nYou may need to add %q to its visibility, %#v", depQualified, "//"+ctx.ModuleDir(), ctx.OtherModuleDependencyTag(dep))
}
})
}