Convert orderfile mutators to TransitionMutator

Convert orderfileDepsMutator and orderfileMutator to a TransitionMutator
as a step towards variants-on-demand.

Bug: 319288033
Test: orderfile_test.go

Change-Id: I27df65b7264a5b059a900e7ea04c18dfb2787a84
This commit is contained in:
Colin Cross
2024-01-23 16:36:07 -08:00
parent 6ac83a8f85
commit 33e0c81093
2 changed files with 51 additions and 55 deletions

View File

@@ -73,8 +73,7 @@ func RegisterCCBuildComponents(ctx android.RegistrationContext) {
ctx.TopDown("afdo_deps", afdoDepsMutator) ctx.TopDown("afdo_deps", afdoDepsMutator)
ctx.BottomUp("afdo", afdoMutator).Parallel() ctx.BottomUp("afdo", afdoMutator).Parallel()
ctx.TopDown("orderfile_deps", orderfileDepsMutator) ctx.Transition("orderfile", &orderfileTransitionMutator{})
ctx.BottomUp("orderfile", orderfileMutator).Parallel()
ctx.Transition("lto", &ltoTransitionMutator{}) ctx.Transition("lto", &ltoTransitionMutator{})

View File

@@ -20,6 +20,8 @@ package cc
import ( import (
"fmt" "fmt"
"github.com/google/blueprint"
"android/soong/android" "android/soong/android"
) )
@@ -190,66 +192,61 @@ func (orderfile *orderfile) flags(ctx ModuleContext, flags Flags) Flags {
return flags return flags
} }
// Propagate profile orderfile flags down from binaries and shared libraries func orderfilePropagateViaDepTag(tag blueprint.DependencyTag) bool {
// We do not allow propagation for load flags because the orderfile is specific libTag, isLibTag := tag.(libraryDependencyTag)
// to the module (binary / shared library) // Do not recurse down non-static dependencies
func orderfileDepsMutator(mctx android.TopDownMutatorContext) { if isLibTag {
if m, ok := mctx.Module().(*Module); ok { return libTag.static()
if !m.orderfile.orderfileLinkEnabled() { } else {
return return tag == objDepTag || tag == reuseObjTag || tag == staticVariantTag
}
mctx.WalkDeps(func(dep android.
Module, parent android.Module) bool {
tag := mctx.OtherModuleDependencyTag(dep)
libTag, isLibTag := tag.(libraryDependencyTag)
// Do not recurse down non-static dependencies
if isLibTag {
if !libTag.static() {
return false
}
} else {
if tag != objDepTag && tag != reuseObjTag {
return false
}
}
if dep, ok := dep.(*Module); ok {
if m.orderfile.Properties.OrderfileInstrLink {
dep.orderfile.Properties.OrderfileInstrLink = true
}
}
return true
})
} }
} }
// Create orderfile variants for modules that need them // orderfileTransitionMutator creates orderfile variants of cc modules.
func orderfileMutator(mctx android.BottomUpMutatorContext) { type orderfileTransitionMutator struct{}
if m, ok := mctx.Module().(*Module); ok && m.orderfile != nil {
if !m.static() && m.orderfile.orderfileEnabled() { const ORDERFILE_VARIATION = "orderfile"
mctx.SetDependencyVariation("orderfile")
return func (o *orderfileTransitionMutator) Split(ctx android.BaseModuleContext) []string {
return []string{""}
}
func (o *orderfileTransitionMutator) OutgoingTransition(ctx android.OutgoingTransitionContext, sourceVariation string) string {
if m, ok := ctx.Module().(*Module); ok && m.orderfile != nil {
if !orderfilePropagateViaDepTag(ctx.DepTag()) {
return ""
} }
variationNames := []string{""} if sourceVariation != "" {
if m.orderfile.Properties.OrderfileInstrLink { return sourceVariation
variationNames = append(variationNames, "orderfile")
} }
if len(variationNames) > 1 { // Propagate profile orderfile flags down from binaries and shared libraries
modules := mctx.CreateVariations(variationNames...) if m.orderfile.orderfileLinkEnabled() {
for i, name := range variationNames { return ORDERFILE_VARIATION
if name == "" {
continue
}
variation := modules[i].(*Module)
variation.Properties.PreventInstall = true
variation.Properties.HideFromMake = true
variation.orderfile.Properties.ShouldProfileModule = true
variation.orderfile.Properties.OrderfileLoad = false
}
} }
} }
return ""
}
func (o *orderfileTransitionMutator) IncomingTransition(ctx android.IncomingTransitionContext, incomingVariation string) string {
if m, ok := ctx.Module().(*Module); ok && m.orderfile != nil {
return incomingVariation
}
return ""
}
func (o *orderfileTransitionMutator) Mutate(ctx android.BottomUpMutatorContext, variation string) {
if variation == "" {
return
}
if m, ok := ctx.Module().(*Module); ok && m.orderfile != nil {
m.Properties.PreventInstall = true
m.Properties.HideFromMake = true
m.orderfile.Properties.ShouldProfileModule = true
// We do not allow propagation for load flags because the orderfile is specific
// to the module (binary / shared library)
m.orderfile.Properties.OrderfileLoad = false
}
} }