Have ConvertWBp2build use Bp2buildMutatorContext
This no-op refactoring facilitates some upcoming functional changes for "bp2build allowlist v2". The work requires that the bp2build conversion mutator be changed from a TopDown mutator to a BottomUp mutator. Refactoring all bp2build-related methods so that they use Bp2buildMutatorContext makes it easier to make this functional change without touching tens of files and multiple projects. Bug: 285631638 Test: m bp2build Change-Id: I3d1ef3064146e959c6f0dc315350fc9764bf2bd2
This commit is contained in:
@@ -162,7 +162,7 @@ type Bazelable interface {
|
||||
// Modules must implement this function to be bp2build convertible. The function
|
||||
// must either create at least one Bazel target module (using ctx.CreateBazelTargetModule or
|
||||
// its related functions), or declare itself unconvertible using ctx.MarkBp2buildUnconvertible.
|
||||
ConvertWithBp2build(ctx TopDownMutatorContext)
|
||||
ConvertWithBp2build(ctx Bp2buildMutatorContext)
|
||||
|
||||
// namespacedVariableProps is a map from a soong config variable namespace
|
||||
// (e.g. acme, android) to a map of interfaces{}, which are really
|
||||
|
@@ -585,7 +585,7 @@ func PathsForBazelOut(ctx PathContext, paths []string) Paths {
|
||||
// For the first two cases, they are defined using the label attribute. For the third case,
|
||||
// it's defined with the string attribute.
|
||||
func BazelStringOrLabelFromProp(
|
||||
ctx TopDownMutatorContext,
|
||||
ctx Bp2buildMutatorContext,
|
||||
propToDistinguish *string) (bazel.LabelAttribute, bazel.StringAttribute) {
|
||||
|
||||
var labelAttr bazel.LabelAttribute
|
||||
|
@@ -469,7 +469,7 @@ func mixedBuildModuleFactory() Module {
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *mixedBuildModule) ConvertWithBp2build(ctx TopDownMutatorContext) {
|
||||
func (m *mixedBuildModule) ConvertWithBp2build(ctx Bp2buildMutatorContext) {
|
||||
}
|
||||
|
||||
func (m *mixedBuildModule) DepsMutator(ctx BottomUpMutatorContext) {
|
||||
|
@@ -180,7 +180,7 @@ func (d *DefaultsModuleBase) GenerateAndroidBuildActions(ctx ModuleContext) {}
|
||||
|
||||
// ConvertWithBp2build to fulfill Bazelable interface; however, at this time defaults module are
|
||||
// *NOT* converted with bp2build
|
||||
func (defaultable *DefaultsModuleBase) ConvertWithBp2build(ctx TopDownMutatorContext) {
|
||||
func (defaultable *DefaultsModuleBase) ConvertWithBp2build(ctx Bp2buildMutatorContext) {
|
||||
// Defaults types are never convertible.
|
||||
ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_TYPE_UNSUPPORTED, "")
|
||||
}
|
||||
|
@@ -93,7 +93,7 @@ func (fg *fileGroup) ConvertWithApiBp2build(ctx TopDownMutatorContext) {
|
||||
}
|
||||
|
||||
// ConvertWithBp2build performs bp2build conversion of filegroup
|
||||
func (fg *fileGroup) ConvertWithBp2build(ctx TopDownMutatorContext) {
|
||||
func (fg *fileGroup) ConvertWithBp2build(ctx Bp2buildMutatorContext) {
|
||||
srcs := bazel.MakeLabelListAttribute(
|
||||
BazelLabelForModuleSrcExcludes(ctx, fg.properties.Srcs, fg.properties.Exclude_srcs))
|
||||
|
||||
@@ -209,10 +209,10 @@ func (fg *fileGroup) ConvertWithBp2build(ctx TopDownMutatorContext) {
|
||||
}
|
||||
|
||||
type FileGroupPath interface {
|
||||
GetPath(ctx TopDownMutatorContext) string
|
||||
GetPath(ctx Bp2buildMutatorContext) string
|
||||
}
|
||||
|
||||
func (fg *fileGroup) GetPath(ctx TopDownMutatorContext) string {
|
||||
func (fg *fileGroup) GetPath(ctx Bp2buildMutatorContext) string {
|
||||
if fg.properties.Path != nil {
|
||||
return *fg.properties.Path
|
||||
}
|
||||
|
@@ -71,7 +71,7 @@ type bazelLicenseAttributes struct {
|
||||
Visibility []string
|
||||
}
|
||||
|
||||
func (m *licenseModule) ConvertWithBp2build(ctx TopDownMutatorContext) {
|
||||
func (m *licenseModule) ConvertWithBp2build(ctx Bp2buildMutatorContext) {
|
||||
attrs := &bazelLicenseAttributes{
|
||||
License_kinds: m.properties.License_kinds,
|
||||
Copyright_notice: m.properties.Copyright_notice,
|
||||
|
@@ -50,7 +50,7 @@ type bazelLicenseKindAttributes struct {
|
||||
Visibility []string
|
||||
}
|
||||
|
||||
func (m *licenseKindModule) ConvertWithBp2build(ctx TopDownMutatorContext) {
|
||||
func (m *licenseKindModule) ConvertWithBp2build(ctx Bp2buildMutatorContext) {
|
||||
attrs := &bazelLicenseKindAttributes{
|
||||
Conditions: m.properties.Conditions,
|
||||
Url: m.properties.Url,
|
||||
|
@@ -15,9 +15,10 @@
|
||||
package android
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"android/soong/bazel"
|
||||
"android/soong/ui/metrics/bp2build_metrics_proto"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
)
|
||||
@@ -229,37 +230,8 @@ var bp2buildPreArchMutators = []RegisterMutatorFunc{}
|
||||
// A minimal context for Bp2build conversion
|
||||
type Bp2buildMutatorContext interface {
|
||||
BazelConversionPathContext
|
||||
|
||||
CreateBazelTargetModule(bazel.BazelTargetModuleProperties, CommonAttributes, interface{})
|
||||
CreateBazelTargetModuleWithRestrictions(bazel.BazelTargetModuleProperties, CommonAttributes, interface{}, bazel.BoolAttribute)
|
||||
}
|
||||
|
||||
// PreArchBp2BuildMutators adds mutators to be register for converting Android Blueprint modules
|
||||
// into Bazel BUILD targets that should run prior to deps and conversion.
|
||||
func PreArchBp2BuildMutators(f RegisterMutatorFunc) {
|
||||
bp2buildPreArchMutators = append(bp2buildPreArchMutators, f)
|
||||
}
|
||||
|
||||
type BaseMutatorContext interface {
|
||||
BaseModuleContext
|
||||
|
||||
// MutatorName returns the name that this mutator was registered with.
|
||||
MutatorName() string
|
||||
|
||||
// Rename all variants of a module. The new name is not visible to calls to ModuleName,
|
||||
// AddDependency or OtherModuleName until after this mutator pass is complete.
|
||||
Rename(name string)
|
||||
}
|
||||
|
||||
type TopDownMutator func(TopDownMutatorContext)
|
||||
|
||||
type TopDownMutatorContext interface {
|
||||
BaseMutatorContext
|
||||
|
||||
// CreateModule creates a new module by calling the factory method for the specified moduleType, and applies
|
||||
// the specified property structs to it as if the properties were set in a blueprint file.
|
||||
CreateModule(ModuleFactory, ...interface{}) Module
|
||||
|
||||
// CreateBazelTargetModule creates a BazelTargetModule by calling the
|
||||
// factory method, just like in CreateModule, but also requires
|
||||
// BazelTargetModuleProperties containing additional metadata for the
|
||||
@@ -290,6 +262,34 @@ type TopDownMutatorContext interface {
|
||||
CreateBazelConfigSetting(csa bazel.ConfigSettingAttributes, ca CommonAttributes, dir string)
|
||||
}
|
||||
|
||||
// PreArchBp2BuildMutators adds mutators to be register for converting Android Blueprint modules
|
||||
// into Bazel BUILD targets that should run prior to deps and conversion.
|
||||
func PreArchBp2BuildMutators(f RegisterMutatorFunc) {
|
||||
bp2buildPreArchMutators = append(bp2buildPreArchMutators, f)
|
||||
}
|
||||
|
||||
type BaseMutatorContext interface {
|
||||
BaseModuleContext
|
||||
|
||||
// MutatorName returns the name that this mutator was registered with.
|
||||
MutatorName() string
|
||||
|
||||
// Rename all variants of a module. The new name is not visible to calls to ModuleName,
|
||||
// AddDependency or OtherModuleName until after this mutator pass is complete.
|
||||
Rename(name string)
|
||||
}
|
||||
|
||||
type TopDownMutator func(TopDownMutatorContext)
|
||||
|
||||
type TopDownMutatorContext interface {
|
||||
BaseMutatorContext
|
||||
Bp2buildMutatorContext
|
||||
|
||||
// CreateModule creates a new module by calling the factory method for the specified moduleType, and applies
|
||||
// the specified property structs to it as if the properties were set in a blueprint file.
|
||||
CreateModule(ModuleFactory, ...interface{}) Module
|
||||
}
|
||||
|
||||
type topDownMutatorContext struct {
|
||||
bp blueprint.TopDownMutatorContext
|
||||
baseModuleContext
|
||||
|
@@ -54,7 +54,7 @@ type packageModule struct {
|
||||
|
||||
var _ Bazelable = &packageModule{}
|
||||
|
||||
func (p *packageModule) ConvertWithBp2build(ctx TopDownMutatorContext) {
|
||||
func (p *packageModule) ConvertWithBp2build(ctx Bp2buildMutatorContext) {
|
||||
defaultPackageMetadata := bazel.MakeLabelListAttribute(BazelLabelForModuleDeps(ctx, p.properties.Default_applicable_licenses))
|
||||
// If METADATA file exists in the package, add it to package(default_package_metadata=) using a
|
||||
// filegroup(name="default_metadata_file") which can be accessed later on each module in Bazel
|
||||
|
Reference in New Issue
Block a user