diff options
author | 2024-12-20 16:32:37 -0800 | |
---|---|---|
committer | 2025-02-07 16:00:56 -0800 | |
commit | d8d8b85c5666b3ded986f1b5c64df31dea5076ee (patch) | |
tree | f088754b04d70b6a28f3c727b58c370c989cfadc /java/bootclasspath.go | |
parent | 22558312b9c07ddda22fcd00d6a84aa0f73f4d10 (diff) |
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
Diffstat (limited to 'java/bootclasspath.go')
-rw-r--r-- | java/bootclasspath.go | 116 |
1 files changed, 32 insertions, 84 deletions
diff --git a/java/bootclasspath.go b/java/bootclasspath.go index 3413cf350..856f43919 100644 --- a/java/bootclasspath.go +++ b/java/bootclasspath.go @@ -23,36 +23,9 @@ import ( // Contains code that is common to both platform_bootclasspath and bootclasspath_fragment. -func init() { - registerBootclasspathBuildComponents(android.InitRegistrationContext) -} - -func registerBootclasspathBuildComponents(ctx android.RegistrationContext) { - ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) { - ctx.BottomUp("bootclasspath_deps", bootclasspathDepsMutator) - }) -} - -// BootclasspathDepsMutator is the interface that a module must implement if it wants to add -// dependencies onto APEX specific variants of bootclasspath fragments or bootclasspath contents. -type BootclasspathDepsMutator interface { - // BootclasspathDepsMutator implementations should add dependencies using - // addDependencyOntoApexModulePair and addDependencyOntoApexVariants. - BootclasspathDepsMutator(ctx android.BottomUpMutatorContext) -} - -// bootclasspathDepsMutator is called during the final deps phase after all APEX variants have -// been created so can add dependencies onto specific APEX variants of modules. -func bootclasspathDepsMutator(ctx android.BottomUpMutatorContext) { - m := ctx.Module() - if p, ok := m.(BootclasspathDepsMutator); ok { - p.BootclasspathDepsMutator(ctx) - } -} - // addDependencyOntoApexVariants adds dependencies onto the appropriate apex specific variants of // the module as specified in the ApexVariantReference list. -func addDependencyOntoApexVariants(ctx android.BottomUpMutatorContext, propertyName string, refs []ApexVariantReference, tag blueprint.DependencyTag) { +func addDependencyOntoApexVariants(ctx android.BottomUpMutatorContext, propertyName string, refs []ApexVariantReference, tagType bootclasspathDependencyTagType) { for i, ref := range refs { apex := proptools.StringDefault(ref.Apex, "platform") @@ -62,7 +35,7 @@ func addDependencyOntoApexVariants(ctx android.BottomUpMutatorContext, propertyN } name := proptools.String(ref.Module) - addDependencyOntoApexModulePair(ctx, apex, name, tag) + addDependencyOntoApexModulePair(ctx, apex, name, tagType) } } @@ -75,64 +48,26 @@ func addDependencyOntoApexVariants(ctx android.BottomUpMutatorContext, propertyN // module when both source and prebuilt modules are available. // // Use gatherApexModulePairDepsWithTag to retrieve the dependencies. -func addDependencyOntoApexModulePair(ctx android.BottomUpMutatorContext, apex string, name string, tag blueprint.DependencyTag) { - var variations []blueprint.Variation +func addDependencyOntoApexModulePair(ctx android.BottomUpMutatorContext, apex string, name string, tagType bootclasspathDependencyTagType) { + tag := bootclasspathDependencyTag{ + typ: tagType, + } if !android.IsConfiguredJarForPlatform(apex) { - // Pick the correct apex variant. - variations = []blueprint.Variation{ - {Mutator: "apex", Variation: apex}, - } + tag.apex = apex } target := ctx.Module().Target() - variations = append(variations, target.Variations()...) - addedDep := false - if ctx.OtherModuleDependencyVariantExists(variations, name) { - ctx.AddFarVariationDependencies(variations, tag, name) - addedDep = true - } - - // Add a dependency on the prebuilt module if it exists. - prebuiltName := android.PrebuiltNameFromSource(name) - if ctx.OtherModuleDependencyVariantExists(variations, prebuiltName) { - ctx.AddVariationDependencies(variations, tag, prebuiltName) - addedDep = true - } - - // If no appropriate variant existing for this, so no dependency could be added, then it is an - // error, unless missing dependencies are allowed. The simplest way to handle that is to add a - // dependency that will not be satisfied and the default behavior will handle it. - if !addedDep { - // Add dependency on the unprefixed (i.e. source or renamed prebuilt) module which we know does - // not exist. The resulting error message will contain useful information about the available - // variants. - reportMissingVariationDependency(ctx, variations, name) - - // Add dependency on the missing prefixed prebuilt variant too if a module with that name exists - // so that information about its available variants will be reported too. - if ctx.OtherModuleExists(prebuiltName) { - reportMissingVariationDependency(ctx, variations, prebuiltName) - } - } -} - -// reportMissingVariationDependency intentionally adds a dependency on a missing variation in order -// to generate an appropriate error message with information about the available variations. -func reportMissingVariationDependency(ctx android.BottomUpMutatorContext, variations []blueprint.Variation, name string) { - ctx.AddFarVariationDependencies(variations, nil, name) + ctx.AddFarVariationDependencies(target.Variations(), tag, name) } // gatherApexModulePairDepsWithTag returns the list of dependencies with the supplied tag that was // added by addDependencyOntoApexModulePair. -func gatherApexModulePairDepsWithTag(ctx android.BaseModuleContext, tag blueprint.DependencyTag) []android.Module { +func gatherApexModulePairDepsWithTag(ctx android.BaseModuleContext, tagType bootclasspathDependencyTagType) []android.Module { var modules []android.Module - isActiveModulePred := func(module android.Module) bool { - return isActiveModule(ctx, module) - } - ctx.VisitDirectDepsIf(isActiveModulePred, func(module android.Module) { + ctx.VisitDirectDeps(func(module android.Module) { t := ctx.OtherModuleDependencyTag(module) - if t == tag { + if bcpTag, ok := t.(bootclasspathDependencyTag); ok && bcpTag.typ == tagType { modules = append(modules, module) } }) @@ -165,7 +100,7 @@ type BootclasspathFragmentsDepsProperties struct { // addDependenciesOntoFragments adds dependencies to the fragments specified in this properties // structure. func (p *BootclasspathFragmentsDepsProperties) addDependenciesOntoFragments(ctx android.BottomUpMutatorContext) { - addDependencyOntoApexVariants(ctx, "fragments", p.Fragments, bootclasspathFragmentDepTag) + addDependencyOntoApexVariants(ctx, "fragments", p.Fragments, fragment) } // bootclasspathDependencyTag defines dependencies from/to bootclasspath_fragment, @@ -174,23 +109,36 @@ func (p *BootclasspathFragmentsDepsProperties) addDependenciesOntoFragments(ctx type bootclasspathDependencyTag struct { blueprint.BaseDependencyTag - name string + typ bootclasspathDependencyTagType + + apex string } +type bootclasspathDependencyTagType int + +const ( + // The tag used for dependencies onto bootclasspath_fragments. + fragment bootclasspathDependencyTagType = iota + // The tag used for dependencies onto platform_bootclasspath. + platform + dexpreoptBootJar + artBootJar + platformBootJar + apexBootJar +) + func (t bootclasspathDependencyTag) ExcludeFromVisibilityEnforcement() { } +func (t bootclasspathDependencyTag) ApexTransition() string { + return t.apex +} + // Dependencies that use the bootclasspathDependencyTag instances are only added after all the // visibility checking has been done so this has no functional effect. However, it does make it // clear that visibility is not being enforced on these tags. var _ android.ExcludeFromVisibilityEnforcementTag = bootclasspathDependencyTag{} -// The tag used for dependencies onto bootclasspath_fragments. -var bootclasspathFragmentDepTag = bootclasspathDependencyTag{name: "fragment"} - -// The tag used for dependencies onto platform_bootclasspath. -var platformBootclasspathDepTag = bootclasspathDependencyTag{name: "platform"} - // BootclasspathNestedAPIProperties defines properties related to the API provided by parts of the // bootclasspath that are nested within the main BootclasspathAPIProperties. type BootclasspathNestedAPIProperties struct { |