Merge "Remove deapexer and prebuilt apex select mutators"

This commit is contained in:
Paul Duffin
2021-03-02 10:48:29 +00:00
committed by Gerrit Code Review
6 changed files with 35 additions and 46 deletions

View File

@@ -443,6 +443,7 @@ type Module interface {
Disable() Disable()
Enabled() bool Enabled() bool
Target() Target Target() Target
MultiTargets() []Target
Owner() string Owner() string
InstallInData() bool InstallInData() bool
InstallInTestcases() bool InstallInTestcases() bool

View File

@@ -100,7 +100,7 @@ func (p *Prebuilt) Prefer() bool {
// more modules like this. // more modules like this.
func (p *Prebuilt) SingleSourcePath(ctx ModuleContext) Path { func (p *Prebuilt) SingleSourcePath(ctx ModuleContext) Path {
if p.srcsSupplier != nil { if p.srcsSupplier != nil {
srcs := p.srcsSupplier(ctx) srcs := p.srcsSupplier(ctx, ctx.Module())
if len(srcs) == 0 { if len(srcs) == 0 {
ctx.PropertyErrorf(p.srcsPropertyName, "missing prebuilt source file") ctx.PropertyErrorf(p.srcsPropertyName, "missing prebuilt source file")
@@ -128,8 +128,11 @@ func (p *Prebuilt) UsePrebuilt() bool {
// Called to provide the srcs value for the prebuilt module. // 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
// called concurrently.
//
// Return the src value or nil if it is not available. // Return the src value or nil if it is not available.
type PrebuiltSrcsSupplier func(ctx BaseModuleContext) []string type PrebuiltSrcsSupplier func(ctx BaseModuleContext, prebuilt Module) []string
// Initialize the module as a prebuilt module that uses the provided supplier to access the // Initialize the module as a prebuilt module that uses the provided supplier to access the
// prebuilt sources of the module. // prebuilt sources of the module.
@@ -163,7 +166,7 @@ func InitPrebuiltModule(module PrebuiltInterface, srcs *[]string) {
panic(fmt.Errorf("srcs must not be nil")) panic(fmt.Errorf("srcs must not be nil"))
} }
srcsSupplier := func(ctx BaseModuleContext) []string { srcsSupplier := func(ctx BaseModuleContext, _ Module) []string {
return *srcs return *srcs
} }
@@ -184,7 +187,7 @@ func InitSingleSourcePrebuiltModule(module PrebuiltInterface, srcProps interface
srcFieldIndex := srcStructField.Index srcFieldIndex := srcStructField.Index
srcPropertyName := proptools.PropertyNameForField(srcField) srcPropertyName := proptools.PropertyNameForField(srcField)
srcsSupplier := func(ctx BaseModuleContext) []string { srcsSupplier := func(ctx BaseModuleContext, _ Module) []string {
if !module.Enabled() { if !module.Enabled() {
return nil return nil
} }
@@ -256,12 +259,12 @@ func PrebuiltSelectModuleMutator(ctx TopDownMutatorContext) {
panic(fmt.Errorf("prebuilt module did not have InitPrebuiltModule called on it")) panic(fmt.Errorf("prebuilt module did not have InitPrebuiltModule called on it"))
} }
if !p.properties.SourceExists { if !p.properties.SourceExists {
p.properties.UsePrebuilt = p.usePrebuilt(ctx, nil) p.properties.UsePrebuilt = p.usePrebuilt(ctx, nil, m)
} }
} else if s, ok := ctx.Module().(Module); ok { } else if s, ok := ctx.Module().(Module); ok {
ctx.VisitDirectDepsWithTag(PrebuiltDepTag, func(m Module) { ctx.VisitDirectDepsWithTag(PrebuiltDepTag, func(m Module) {
p := m.(PrebuiltInterface).Prebuilt() p := m.(PrebuiltInterface).Prebuilt()
if p.usePrebuilt(ctx, s) { if p.usePrebuilt(ctx, s, m) {
p.properties.UsePrebuilt = true p.properties.UsePrebuilt = true
s.ReplacedByPrebuilt() s.ReplacedByPrebuilt()
} }
@@ -296,8 +299,8 @@ func PrebuiltPostDepsMutator(ctx BottomUpMutatorContext) {
// usePrebuilt returns true if a prebuilt should be used instead of the source module. The prebuilt // usePrebuilt returns true if a prebuilt should be used instead of the source module. The prebuilt
// will be used if it is marked "prefer" or if the source module is disabled. // will be used if it is marked "prefer" or if the source module is disabled.
func (p *Prebuilt) usePrebuilt(ctx TopDownMutatorContext, source Module) bool { func (p *Prebuilt) usePrebuilt(ctx TopDownMutatorContext, source Module, prebuilt Module) bool {
if p.srcsSupplier != nil && len(p.srcsSupplier(ctx)) == 0 { if p.srcsSupplier != nil && len(p.srcsSupplier(ctx, prebuilt)) == 0 {
return false return false
} }

View File

@@ -54,8 +54,6 @@ func init() {
func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) { func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
ctx.TopDown("apex_vndk", apexVndkMutator).Parallel() ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel() ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
ctx.BottomUp("prebuilt_apex_select_source", prebuiltSelectSourceMutator).Parallel()
ctx.BottomUp("deapexer_select_source", deapexerSelectSourceMutator).Parallel()
} }
func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) { func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {

View File

@@ -65,7 +65,7 @@ func privateDeapexerFactory() android.Module {
&module.properties, &module.properties,
&module.apexFileProperties, &module.apexFileProperties,
) )
android.InitSingleSourcePrebuiltModule(module, &module.apexFileProperties, "Source") android.InitPrebuiltModuleWithSrcSupplier(module, module.apexFileProperties.prebuiltApexSelector, "src")
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
return module return module
} }
@@ -78,16 +78,6 @@ func (p *Deapexer) Name() string {
return p.prebuilt.Name(p.ModuleBase.Name()) return p.prebuilt.Name(p.ModuleBase.Name())
} }
func deapexerSelectSourceMutator(ctx android.BottomUpMutatorContext) {
p, ok := ctx.Module().(*Deapexer)
if !ok {
return
}
if err := p.apexFileProperties.selectSource(ctx); err != nil {
ctx.ModuleErrorf("%s", err)
}
}
func (p *Deapexer) DepsMutator(ctx android.BottomUpMutatorContext) { func (p *Deapexer) DepsMutator(ctx android.BottomUpMutatorContext) {
// Add dependencies from the java modules to which this exports files from the `.apex` file onto // Add dependencies from the java modules to which this exports files from the `.apex` file onto
// this module so that they can access the `DeapexerInfo` object that this provides. // this module so that they can access the `DeapexerInfo` object that this provides.

View File

@@ -109,8 +109,10 @@ type Prebuilt struct {
type ApexFileProperties struct { type ApexFileProperties struct {
// the path to the prebuilt .apex file to import. // the path to the prebuilt .apex file to import.
Source string `blueprint:"mutated"` //
// This cannot be marked as `android:"arch_variant"` because the `prebuilt_apex` is only mutated
// for android_common. That is so that it will have the same arch variant as, and so be compatible
// with, the source `apex` module type that it replaces.
Src *string Src *string
Arch struct { Arch struct {
Arm struct { Arm struct {
@@ -128,15 +130,20 @@ type ApexFileProperties struct {
} }
} }
func (p *ApexFileProperties) selectSource(ctx android.BottomUpMutatorContext) error { // prebuiltApexSelector selects the correct prebuilt APEX file for the build target.
// This is called before prebuilt_select and prebuilt_postdeps mutators //
// The mutators requires that src to be set correctly for each arch so that // The ctx parameter can be for any module not just the prebuilt module so care must be taken not
// arch variants are disabled when src is not provided for the arch. // to use methods on it that are specific to the current module.
if len(ctx.MultiTargets()) != 1 { //
return fmt.Errorf("compile_multilib shouldn't be \"both\" for prebuilt_apex") // See the ApexFileProperties.Src property.
func (p *ApexFileProperties) prebuiltApexSelector(ctx android.BaseModuleContext, prebuilt android.Module) []string {
multiTargets := prebuilt.MultiTargets()
if len(multiTargets) != 1 {
ctx.OtherModuleErrorf(prebuilt, "compile_multilib shouldn't be \"both\" for prebuilt_apex")
return nil
} }
var src string var src string
switch ctx.MultiTargets()[0].Arch.ArchType { switch multiTargets[0].Arch.ArchType {
case android.Arm: case android.Arm:
src = String(p.Arch.Arm.Src) src = String(p.Arch.Arm.Src)
case android.Arm64: case android.Arm64:
@@ -146,14 +153,14 @@ func (p *ApexFileProperties) selectSource(ctx android.BottomUpMutatorContext) er
case android.X86_64: case android.X86_64:
src = String(p.Arch.X86_64.Src) src = String(p.Arch.X86_64.Src)
default: default:
return fmt.Errorf("prebuilt_apex does not support %q", ctx.MultiTargets()[0].Arch.String()) ctx.OtherModuleErrorf(prebuilt, "prebuilt_apex does not support %q", multiTargets[0].Arch.String())
return nil
} }
if src == "" { if src == "" {
src = String(p.Src) src = String(p.Src)
} }
p.Source = src
return nil return []string{src}
} }
type PrebuiltProperties struct { type PrebuiltProperties struct {
@@ -217,7 +224,7 @@ func (p *Prebuilt) Name() string {
func PrebuiltFactory() android.Module { func PrebuiltFactory() android.Module {
module := &Prebuilt{} module := &Prebuilt{}
module.AddProperties(&module.properties) module.AddProperties(&module.properties)
android.InitSingleSourcePrebuiltModule(module, &module.properties, "Source") android.InitPrebuiltModuleWithSrcSupplier(module, module.properties.prebuiltApexSelector, "src")
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
android.AddLoadHook(module, func(ctx android.LoadHookContext) { android.AddLoadHook(module, func(ctx android.LoadHookContext) {
@@ -250,16 +257,6 @@ func prebuiltApexExportedModuleName(ctx android.BottomUpMutatorContext, name str
return name return name
} }
func prebuiltSelectSourceMutator(ctx android.BottomUpMutatorContext) {
p, ok := ctx.Module().(*Prebuilt)
if !ok {
return
}
if err := p.properties.selectSource(ctx); err != nil {
ctx.ModuleErrorf("%s", err)
}
}
type exportedDependencyTag struct { type exportedDependencyTag struct {
blueprint.BaseDependencyTag blueprint.BaseDependencyTag
name string name string
@@ -535,7 +532,7 @@ func apexSetFactory() android.Module {
module := &ApexSet{} module := &ApexSet{}
module.AddProperties(&module.properties) module.AddProperties(&module.properties)
srcsSupplier := func(ctx android.BaseModuleContext) []string { srcsSupplier := func(ctx android.BaseModuleContext, _ android.Module) []string {
return module.prebuiltSrcs(ctx) return module.prebuiltSrcs(ctx)
} }

View File

@@ -246,7 +246,7 @@ func NewPrebuiltLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDec
module.AddProperties(&prebuilt.properties) module.AddProperties(&prebuilt.properties)
srcsSupplier := func(ctx android.BaseModuleContext) []string { srcsSupplier := func(ctx android.BaseModuleContext, _ android.Module) []string {
return prebuilt.prebuiltSrcs(ctx) return prebuilt.prebuiltSrcs(ctx)
} }