Remove bp2build deps mutator
Refactor bp2build to retrieve modules directly by name, instead of via
DirectDeps. This functions properly as bp2build has no need for variant
information of the blueprint graph.
Test: USE_BAZEL_ANALYSIS=1 m fmtlib
Change-Id: Ief4b67bc56f24929871af772f3a742f07085bf8c
diff --git a/android/bazel_paths.go b/android/bazel_paths.go
index f74fed1..26cacdb 100644
--- a/android/bazel_paths.go
+++ b/android/bazel_paths.go
@@ -73,6 +73,7 @@
EarlyModulePathContext
GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
+ ModuleFromName(name string) (blueprint.Module, bool)
Module() Module
ModuleType() string
OtherModuleName(m blueprint.Module) string
@@ -331,11 +332,9 @@
// module. The label will be relative to the current directory if appropriate. The dependency must
// already be resolved by either deps mutator or path deps mutator.
func getOtherModuleLabel(ctx BazelConversionPathContext, dep, tag string, isWholeLibs bool) bazel.Label {
- m, _ := ctx.GetDirectDep(dep)
+ m, _ := ctx.ModuleFromName(dep)
if m == nil {
- panic(fmt.Errorf(`Cannot get direct dep %q of %q.
- This is likely because it was not added via AddDependency().
- This may be due a mutator skipped during bp2build.`, dep, ctx.Module().Name()))
+ panic(fmt.Errorf("No module named %q found, but was a direct dep of %q", dep, ctx.Module().Name()))
}
otherLabel := bazelModuleLabel(ctx, m, tag)
label := bazelModuleLabel(ctx, ctx.Module(), "")
diff --git a/android/module.go b/android/module.go
index 11f63bd..4dd5800 100644
--- a/android/module.go
+++ b/android/module.go
@@ -223,6 +223,8 @@
// the first DependencyTag.
GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
+ ModuleFromName(name string) (blueprint.Module, bool)
+
// VisitDirectDepsBlueprint calls visit for each direct dependency. If there are multiple
// direct dependencies on the same module visit will be called multiple times on that module
// and OtherModuleDependencyTag will return a different tag for each.
@@ -2032,8 +2034,13 @@
tagPath []blueprint.DependencyTag
strictVisitDeps bool // If true, enforce that all dependencies are enabled
+
+ bazelConversionMode bool
}
+func (b *baseModuleContext) BazelConversionMode() bool {
+ return b.bazelConversionMode
+}
func (b *baseModuleContext) OtherModuleName(m blueprint.Module) string {
return b.bp.OtherModuleName(m)
}
@@ -2373,6 +2380,18 @@
return b.getDirectDepFirstTag(name)
}
+func (b *baseModuleContext) ModuleFromName(name string) (blueprint.Module, bool) {
+ if !b.BazelConversionMode() {
+ panic("cannot call ModuleFromName if not in bazel conversion mode")
+ }
+ if len(name) > 1 && (name[0] == ':' || (name[0] == '/' && name[1] == '/')) {
+ moduleName, _ := SrcIsModuleWithTag(name)
+ return b.bp.ModuleFromName(moduleName)
+ } else {
+ return b.bp.ModuleFromName(name)
+ }
+}
+
func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
b.bp.VisitDirectDeps(visit)
}
diff --git a/android/mutator.go b/android/mutator.go
index 819dd0f..d895669 100644
--- a/android/mutator.go
+++ b/android/mutator.go
@@ -35,7 +35,7 @@
// continue on to GenerateAndroidBuildActions
// RegisterMutatorsForBazelConversion is a alternate registration pipeline for bp2build. Exported for testing.
-func RegisterMutatorsForBazelConversion(ctx *Context, preArchMutators, depsMutators, bp2buildMutators []RegisterMutatorFunc) {
+func RegisterMutatorsForBazelConversion(ctx *Context, preArchMutators, bp2buildMutators []RegisterMutatorFunc) {
mctx := ®isterMutatorsContext{
bazelConversionMode: true,
}
@@ -53,16 +53,6 @@
f(mctx)
}
- bp2buildDepsMutators = append([]RegisterMutatorFunc{
- registerDepsMutatorBp2Build,
- registerPathDepsMutator,
- registerBp2buildArchPathDepsMutator,
- }, depsMutators...)
-
- for _, f := range bp2buildDepsMutators {
- f(mctx)
- }
-
// Register bp2build mutators
for _, f := range bp2buildMutators {
f(mctx)
@@ -227,7 +217,6 @@
}
var bp2buildPreArchMutators = []RegisterMutatorFunc{}
-var bp2buildDepsMutators = []RegisterMutatorFunc{}
var bp2buildMutators = map[string]RegisterMutatorFunc{}
// See http://b/192523357
@@ -254,12 +243,6 @@
bp2buildPreArchMutators = append(bp2buildPreArchMutators, f)
}
-// DepsBp2BuildMutators adds mutators to be register for converting Android Blueprint modules into
-// Bazel BUILD targets that should run prior to conversion to resolve dependencies.
-func DepsBp2BuildMutators(f RegisterMutatorFunc) {
- bp2buildDepsMutators = append(bp2buildDepsMutators, f)
-}
-
type BaseMutatorContext interface {
BaseModuleContext
@@ -269,6 +252,9 @@
// 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)
+
+ // BazelConversionMode returns whether this mutator is being run as part of Bazel Conversion.
+ BazelConversionMode() bool
}
type TopDownMutator func(TopDownMutatorContext)
@@ -410,26 +396,24 @@
// variant of the current module. The value should not be modified after being passed to
// SetVariationProvider.
SetVariationProvider(module blueprint.Module, provider blueprint.ProviderKey, value interface{})
-
- // BazelConversionMode returns whether this mutator is being run as part of Bazel Conversion.
- BazelConversionMode() bool
}
type bottomUpMutatorContext struct {
bp blueprint.BottomUpMutatorContext
baseModuleContext
- finalPhase bool
- bazelConversionMode bool
+ finalPhase bool
}
func bottomUpMutatorContextFactory(ctx blueprint.BottomUpMutatorContext, a Module,
finalPhase, bazelConversionMode bool) BottomUpMutatorContext {
+ moduleContext := a.base().baseModuleContextFactory(ctx)
+ moduleContext.bazelConversionMode = bazelConversionMode
+
return &bottomUpMutatorContext{
- bp: ctx,
- baseModuleContext: a.base().baseModuleContextFactory(ctx),
- finalPhase: finalPhase,
- bazelConversionMode: bazelConversionMode,
+ bp: ctx,
+ baseModuleContext: a.base().baseModuleContextFactory(ctx),
+ finalPhase: finalPhase,
}
}
@@ -462,9 +446,11 @@
func (x *registerMutatorsContext) TopDown(name string, m TopDownMutator) MutatorHandle {
f := func(ctx blueprint.TopDownMutatorContext) {
if a, ok := ctx.Module().(Module); ok {
+ moduleContext := a.base().baseModuleContextFactory(ctx)
+ moduleContext.bazelConversionMode = x.bazelConversionMode
actx := &topDownMutatorContext{
bp: ctx,
- baseModuleContext: a.base().baseModuleContextFactory(ctx),
+ baseModuleContext: moduleContext,
}
m(actx)
}
@@ -733,7 +719,3 @@
func (b *bottomUpMutatorContext) SetVariationProvider(module blueprint.Module, provider blueprint.ProviderKey, value interface{}) {
b.bp.SetVariationProvider(module, provider, value)
}
-
-func (b *bottomUpMutatorContext) BazelConversionMode() bool {
- return b.bazelConversionMode
-}
diff --git a/android/register.go b/android/register.go
index 4c8088d..5984862 100644
--- a/android/register.go
+++ b/android/register.go
@@ -180,7 +180,7 @@
bp2buildMutatorList = append(bp2buildMutatorList, f)
}
- RegisterMutatorsForBazelConversion(ctx, bp2buildPreArchMutators, bp2buildDepsMutators, bp2buildMutatorList)
+ RegisterMutatorsForBazelConversion(ctx, bp2buildPreArchMutators, bp2buildMutatorList)
}
// Register the pipeline of singletons, module types, and mutators for
diff --git a/android/testing.go b/android/testing.go
index 17a812e..6ba8e3c 100644
--- a/android/testing.go
+++ b/android/testing.go
@@ -171,9 +171,9 @@
type TestContext struct {
*Context
- preArch, preDeps, postDeps, finalDeps []RegisterMutatorFunc
- bp2buildPreArch, bp2buildDeps, bp2buildMutators []RegisterMutatorFunc
- NameResolver *NameResolver
+ preArch, preDeps, postDeps, finalDeps []RegisterMutatorFunc
+ bp2buildPreArch, bp2buildMutators []RegisterMutatorFunc
+ NameResolver *NameResolver
// The list of pre-singletons and singletons registered for the test.
preSingletons, singletons sortableComponents
@@ -224,12 +224,6 @@
ctx.bp2buildPreArch = append(ctx.bp2buildPreArch, f)
}
-// DepsBp2BuildMutators adds mutators to be register for converting Android Blueprint modules into
-// Bazel BUILD targets that should run prior to conversion to resolve dependencies.
-func (ctx *TestContext) DepsBp2BuildMutators(f RegisterMutatorFunc) {
- ctx.bp2buildDeps = append(ctx.bp2buildDeps, f)
-}
-
// registeredComponentOrder defines the order in which a sortableComponent type is registered at
// runtime and provides support for reordering the components registered for a test in the same
// way.
@@ -464,7 +458,7 @@
// RegisterForBazelConversion prepares a test context for bp2build conversion.
func (ctx *TestContext) RegisterForBazelConversion() {
- RegisterMutatorsForBazelConversion(ctx.Context, ctx.bp2buildPreArch, ctx.bp2buildDeps, ctx.bp2buildMutators)
+ RegisterMutatorsForBazelConversion(ctx.Context, ctx.bp2buildPreArch, ctx.bp2buildMutators)
}
func (ctx *TestContext) ParseFileList(rootDir string, filePaths []string) (deps []string, errs []error) {
diff --git a/bp2build/build_conversion_test.go b/bp2build/build_conversion_test.go
index 0e52f2a..e5dbda6 100644
--- a/bp2build/build_conversion_test.go
+++ b/bp2build/build_conversion_test.go
@@ -556,7 +556,6 @@
moduleTypeUnderTestFactory android.ModuleFactory
moduleTypeUnderTestBp2BuildMutator func(android.TopDownMutatorContext)
preArchMutators []android.RegisterMutatorFunc
- depsMutators []android.RegisterMutatorFunc
bp string
expectedBazelTargets []string
fs map[string]string
@@ -720,7 +719,6 @@
moduleTypeUnderTest: "genrule",
moduleTypeUnderTestFactory: genrule.GenRuleFactory,
moduleTypeUnderTestBp2BuildMutator: genrule.GenruleBp2Build,
- depsMutators: []android.RegisterMutatorFunc{genrule.RegisterGenruleBp2BuildDeps},
bp: `genrule {
name: "foo.tool",
out: ["foo_tool.out"],
@@ -758,7 +756,6 @@
moduleTypeUnderTest: "genrule",
moduleTypeUnderTestFactory: genrule.GenRuleFactory,
moduleTypeUnderTestBp2BuildMutator: genrule.GenruleBp2Build,
- depsMutators: []android.RegisterMutatorFunc{genrule.RegisterGenruleBp2BuildDeps},
bp: `genrule {
name: "foo.tools",
out: ["foo_tool.out", "foo_tool2.out"],
@@ -798,7 +795,6 @@
moduleTypeUnderTest: "genrule",
moduleTypeUnderTestFactory: genrule.GenRuleFactory,
moduleTypeUnderTestBp2BuildMutator: genrule.GenruleBp2Build,
- depsMutators: []android.RegisterMutatorFunc{genrule.RegisterGenruleBp2BuildDeps},
bp: `genrule {
name: "foo",
out: ["foo.out"],
@@ -822,7 +818,6 @@
moduleTypeUnderTest: "genrule",
moduleTypeUnderTestFactory: genrule.GenRuleFactory,
moduleTypeUnderTestBp2BuildMutator: genrule.GenruleBp2Build,
- depsMutators: []android.RegisterMutatorFunc{genrule.RegisterGenruleBp2BuildDeps},
bp: `genrule {
name: "foo",
out: ["foo.out"],
@@ -846,7 +841,6 @@
moduleTypeUnderTest: "genrule",
moduleTypeUnderTestFactory: genrule.GenRuleFactory,
moduleTypeUnderTestBp2BuildMutator: genrule.GenruleBp2Build,
- depsMutators: []android.RegisterMutatorFunc{genrule.RegisterGenruleBp2BuildDeps},
bp: `genrule {
name: "foo",
out: ["foo.out"],
@@ -873,7 +867,6 @@
moduleTypeUnderTest: "genrule",
moduleTypeUnderTestFactory: genrule.GenRuleFactory,
moduleTypeUnderTestBp2BuildMutator: genrule.GenruleBp2Build,
- depsMutators: []android.RegisterMutatorFunc{genrule.RegisterGenruleBp2BuildDeps},
bp: `genrule {
name: "foo",
out: ["foo.out"],
@@ -900,7 +893,6 @@
moduleTypeUnderTest: "genrule",
moduleTypeUnderTestFactory: genrule.GenRuleFactory,
moduleTypeUnderTestBp2BuildMutator: genrule.GenruleBp2Build,
- depsMutators: []android.RegisterMutatorFunc{genrule.RegisterGenruleBp2BuildDeps},
bp: `genrule {
name: "foo",
out: ["foo.out"],
@@ -933,9 +925,6 @@
config := android.TestConfig(buildDir, nil, testCase.bp, fs)
ctx := android.NewTestContext(config)
ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory)
- for _, m := range testCase.depsMutators {
- ctx.DepsBp2BuildMutators(m)
- }
ctx.RegisterBp2BuildMutator(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestBp2BuildMutator)
ctx.RegisterForBazelConversion()
@@ -1370,7 +1359,6 @@
moduleTypeUnderTestFactory android.ModuleFactory
moduleTypeUnderTestBp2BuildMutator func(android.TopDownMutatorContext)
preArchMutators []android.RegisterMutatorFunc
- depsMutators []android.RegisterMutatorFunc
bp string
expectedBazelTargets []string
fs map[string]string
@@ -1487,9 +1475,6 @@
config := android.TestConfig(buildDir, nil, testCase.bp, fs)
ctx := android.NewTestContext(config)
ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory)
- for _, m := range testCase.depsMutators {
- ctx.DepsBp2BuildMutators(m)
- }
ctx.RegisterBp2BuildMutator(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestBp2BuildMutator)
ctx.RegisterForBazelConversion()
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index 662d9d1..8dcba55 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -73,9 +73,6 @@
registerModuleTypes(ctx)
ctx.RegisterModuleType(tc.moduleTypeUnderTest, tc.moduleTypeUnderTestFactory)
ctx.RegisterBp2BuildConfig(bp2buildConfig)
- for _, m := range tc.depsMutators {
- ctx.DepsBp2BuildMutators(m)
- }
ctx.RegisterBp2BuildMutator(tc.moduleTypeUnderTest, tc.moduleTypeUnderTestBp2BuildMutator)
ctx.RegisterForBazelConversion()
@@ -333,7 +330,6 @@
moduleTypeUnderTest: "cc_library",
moduleTypeUnderTestFactory: cc.LibraryFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
dir: "foo/bar",
filesystem: map[string]string{
"foo/bar/both.cpp": "",
@@ -418,7 +414,6 @@
moduleTypeUnderTest: "cc_library",
moduleTypeUnderTestFactory: cc.LibraryFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
dir: "foo/bar",
filesystem: map[string]string{
"foo/bar/Android.bp": `
@@ -465,7 +460,6 @@
moduleTypeUnderTest: "cc_library",
moduleTypeUnderTestFactory: cc.LibraryFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
dir: "foo/bar",
filesystem: map[string]string{
"foo/bar/arm.cpp": "",
@@ -604,7 +598,6 @@
moduleTypeUnderTest: "cc_library",
moduleTypeUnderTestFactory: cc.LibraryFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
dir: "foo/bar",
filesystem: map[string]string{
"foo/bar/both_source.cpp": "",
@@ -745,7 +738,6 @@
moduleTypeUnderTest: "cc_library",
moduleTypeUnderTestFactory: cc.LibraryFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
dir: "foo/bar",
filesystem: map[string]string{
"foo/bar/Android.bp": `
@@ -776,7 +768,6 @@
moduleTypeUnderTest: "cc_library",
moduleTypeUnderTestFactory: cc.LibraryFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
dir: "foo/bar",
filesystem: map[string]string{
"foo/bar/Android.bp": `
@@ -819,7 +810,6 @@
moduleTypeUnderTest: "cc_library",
moduleTypeUnderTestFactory: cc.LibraryFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
dir: "foo/bar",
filesystem: map[string]string{
"foo/bar/Android.bp": `
@@ -859,7 +849,6 @@
moduleTypeUnderTest: "cc_library",
moduleTypeUnderTestFactory: cc.LibraryFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
dir: "foo/bar",
filesystem: map[string]string{
"foo/bar/Android.bp": `
@@ -933,7 +922,6 @@
moduleTypeUnderTest: "cc_library",
moduleTypeUnderTestFactory: cc.LibraryFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
dir: "foo/bar",
filesystem: map[string]string{
"foo/bar/Android.bp": `
@@ -963,7 +951,6 @@
moduleTypeUnderTest: "cc_library",
moduleTypeUnderTestFactory: cc.LibraryFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
dir: "foo/bar",
filesystem: map[string]string{
"foo/bar/Android.bp": `cc_library {
@@ -1019,7 +1006,6 @@
moduleTypeUnderTest: "cc_library",
moduleTypeUnderTestFactory: cc.LibraryFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
dir: "foo/bar",
filesystem: map[string]string{
"foo/bar/Android.bp": `
@@ -1061,7 +1047,6 @@
moduleTypeUnderTest: "cc_library",
moduleTypeUnderTestFactory: cc.LibraryFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
filesystem: map[string]string{},
blueprint: soongCcLibraryStaticPreamble + `
cc_library {
@@ -1308,7 +1293,6 @@
moduleTypeUnderTest: "cc_library",
moduleTypeUnderTestFactory: cc.LibraryFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
dir: "foo/bar",
filesystem: map[string]string{
"foo/bar/Android.bp": `
@@ -1415,7 +1399,6 @@
moduleTypeUnderTest: "cc_library",
moduleTypeUnderTestFactory: cc.LibraryFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
dir: "foo/bar",
filesystem: map[string]string{
"foo/bar/Android.bp": `
diff --git a/bp2build/cc_library_headers_conversion_test.go b/bp2build/cc_library_headers_conversion_test.go
index db344de..d1fd6af 100644
--- a/bp2build/cc_library_headers_conversion_test.go
+++ b/bp2build/cc_library_headers_conversion_test.go
@@ -45,7 +45,6 @@
moduleTypeUnderTest string
moduleTypeUnderTestFactory android.ModuleFactory
moduleTypeUnderTestBp2BuildMutator func(android.TopDownMutatorContext)
- depsMutators []android.RegisterMutatorFunc
blueprint string
expectedBazelTargets []string
filesystem map[string]string
@@ -181,7 +180,6 @@
moduleTypeUnderTest: "cc_library_headers",
moduleTypeUnderTestFactory: cc.LibraryHeaderFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryHeadersBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
filesystem: map[string]string{},
blueprint: soongCcLibraryPreamble + `
cc_library_headers { name: "android-lib" }
@@ -271,7 +269,6 @@
moduleTypeUnderTest: "cc_library_headers",
moduleTypeUnderTestFactory: cc.LibraryHeaderFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryHeadersBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
filesystem: map[string]string{},
blueprint: soongCcLibraryPreamble + `
cc_library_headers { name: "android-lib" }
@@ -318,7 +315,6 @@
moduleTypeUnderTest: "cc_library_headers",
moduleTypeUnderTestFactory: cc.LibraryHeaderFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryHeadersBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
filesystem: map[string]string{},
blueprint: soongCcLibraryPreamble + `cc_library_headers {
name: "foo_headers",
diff --git a/bp2build/cc_library_static_conversion_test.go b/bp2build/cc_library_static_conversion_test.go
index c33889f..1dc6713 100644
--- a/bp2build/cc_library_static_conversion_test.go
+++ b/bp2build/cc_library_static_conversion_test.go
@@ -469,7 +469,6 @@
moduleTypeUnderTest: "cc_library_static",
moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
filesystem: map[string]string{},
blueprint: soongCcLibraryStaticPreamble + `
cc_library_static { name: "static_dep" }
@@ -517,7 +516,6 @@
moduleTypeUnderTest: "cc_library_static",
moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
filesystem: map[string]string{},
blueprint: soongCcLibraryStaticPreamble + `
cc_library_static { name: "static_dep" }
@@ -565,7 +563,6 @@
moduleTypeUnderTest: "cc_library_static",
moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
filesystem: map[string]string{},
blueprint: soongCcLibraryStaticPreamble + `
cc_library_static { name: "static_dep" }
@@ -632,7 +629,6 @@
moduleTypeUnderTest: "cc_library_static",
moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
filesystem: map[string]string{
"common.c": "",
"foo-a.c": "",
@@ -665,7 +661,6 @@
moduleTypeUnderTest: "cc_library_static",
moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
filesystem: map[string]string{
"common.c": "",
"foo-arm.c": "",
@@ -697,7 +692,6 @@
moduleTypeUnderTest: "cc_library_static",
moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
filesystem: map[string]string{
"common.c": "",
"for-arm.c": "",
@@ -734,7 +728,6 @@
moduleTypeUnderTest: "cc_library_static",
moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
filesystem: map[string]string{
"common.c": "",
"for-arm.c": "",
@@ -782,7 +775,6 @@
moduleTypeUnderTest: "cc_library_static",
moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
filesystem: map[string]string{
"common.c": "",
"for-arm.c": "",
@@ -856,7 +848,6 @@
moduleTypeUnderTest: "cc_library_static",
moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
filesystem: map[string]string{
"common.cc": "",
"foo-no-arm.cc": "",
@@ -892,7 +883,6 @@
moduleTypeUnderTest: "cc_library_static",
moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
filesystem: map[string]string{
"common.cc": "",
"foo-no-arm.cc": "",
@@ -934,7 +924,6 @@
moduleTypeUnderTest: "cc_library_static",
moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
filesystem: map[string]string{},
blueprint: soongCcLibraryStaticPreamble + `
cc_library_static { name: "static_dep" }
@@ -967,7 +956,6 @@
moduleTypeUnderTest: "cc_library_static",
moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
filesystem: map[string]string{
"common.c": "",
"for-lib32.c": "",
@@ -1003,7 +991,6 @@
moduleTypeUnderTest: "cc_library_static",
moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
filesystem: map[string]string{
"common.c": "",
"for-lib32.c": "",
@@ -1059,7 +1046,6 @@
moduleTypeUnderTest: "cc_library_static",
moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
filesystem: map[string]string{
"common.c": "",
"for-arm.c": "",
@@ -1151,7 +1137,6 @@
moduleTypeUnderTest: "cc_library_static",
moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
filesystem: map[string]string{
"common.cpp": "",
"for-x86.cpp": "",
@@ -1243,7 +1228,6 @@
moduleTypeUnderTest: "cc_library_static",
moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
blueprint: soongCcLibraryStaticPreamble + `
cc_library_static {
name: "foo_static",
@@ -1300,8 +1284,6 @@
moduleTypeUnderTest: "cc_library_static",
moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
- filesystem: map[string]string{},
blueprint: soongCcLibraryStaticPreamble + `
cc_library_static {
name: "foo_static",
@@ -1345,7 +1327,6 @@
moduleTypeUnderTest: "cc_library_static",
moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
filesystem: map[string]string{},
blueprint: soongCcLibraryStaticPreamble + `
cc_library_static {
@@ -1417,7 +1398,6 @@
moduleTypeUnderTest: "cc_library_static",
moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
filesystem: map[string]string{},
blueprint: soongCcLibraryStaticPreamble + `
cc_library_static {
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 484e922..68afd0d 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -24,122 +24,6 @@
"github.com/google/blueprint/proptools"
)
-// bp2build functions and helpers for converting cc_* modules to Bazel.
-
-func init() {
- android.DepsBp2BuildMutators(RegisterDepsBp2Build)
-}
-
-func RegisterDepsBp2Build(ctx android.RegisterMutatorsContext) {
- ctx.BottomUp("cc_bp2build_deps", depsBp2BuildMutator)
-}
-
-// A naive deps mutator to add deps on all modules across all combinations of
-// target props for cc modules. This is needed to make module -> bazel label
-// resolution work in the bp2build mutator later. This is probably
-// the wrong way to do it, but it works.
-//
-// TODO(jingwen): can we create a custom os mutator in depsBp2BuildMutator to do this?
-func depsBp2BuildMutator(ctx android.BottomUpMutatorContext) {
- module, ok := ctx.Module().(*Module)
- if !ok {
- // Not a cc module
- return
- }
-
- if !module.ConvertWithBp2build(ctx) {
- return
- }
-
- var allDeps []string
-
- for _, configToProps := range module.GetArchVariantProperties(ctx, &BaseCompilerProperties{}) {
- for _, props := range configToProps {
- if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
- allDeps = append(allDeps, baseCompilerProps.Generated_headers...)
- allDeps = append(allDeps, baseCompilerProps.Generated_sources...)
- }
- }
- }
-
- for _, configToProps := range module.GetArchVariantProperties(ctx, &BaseLinkerProperties{}) {
- for _, props := range configToProps {
- if baseLinkerProps, ok := props.(*BaseLinkerProperties); ok {
- allDeps = append(allDeps, baseLinkerProps.Header_libs...)
- allDeps = append(allDeps, baseLinkerProps.Export_header_lib_headers...)
- allDeps = append(allDeps, baseLinkerProps.Static_libs...)
- allDeps = append(allDeps, baseLinkerProps.Exclude_static_libs...)
- allDeps = append(allDeps, baseLinkerProps.Whole_static_libs...)
- allDeps = append(allDeps, baseLinkerProps.Shared_libs...)
- allDeps = append(allDeps, baseLinkerProps.Exclude_shared_libs...)
- allDeps = append(allDeps, baseLinkerProps.System_shared_libs...)
- }
- }
- }
-
- // Deps in the static: { .. } and shared: { .. } props of a cc_library.
- if lib, ok := module.compiler.(*libraryDecorator); ok {
- appendDeps := func(deps []string, p StaticOrSharedProperties, system bool) []string {
- deps = append(deps, p.Static_libs...)
- deps = append(deps, p.Whole_static_libs...)
- deps = append(deps, p.Shared_libs...)
- // TODO(b/186024507, b/186489250): Temporarily exclude adding
- // system_shared_libs deps until libc and libm builds.
- if system {
- allDeps = append(allDeps, p.System_shared_libs...)
- }
- return deps
- }
-
- allDeps = appendDeps(allDeps, lib.SharedProperties.Shared, lib.shared())
- allDeps = appendDeps(allDeps, lib.StaticProperties.Static, lib.static())
-
- // Deps in the target/arch nested static: { .. } and shared: { .. } props of a cc_library.
- // target: { <target>: shared: { ... } }
- for _, configToProps := range module.GetArchVariantProperties(ctx, &SharedProperties{}) {
- for _, props := range configToProps {
- if p, ok := props.(*SharedProperties); ok {
- allDeps = appendDeps(allDeps, p.Shared, lib.shared())
- }
- }
- }
-
- for _, configToProps := range module.GetArchVariantProperties(ctx, &StaticProperties{}) {
- for _, props := range configToProps {
- if p, ok := props.(*StaticProperties); ok {
- allDeps = appendDeps(allDeps, p.Static, lib.static())
- }
- }
- }
- }
-
- // product variables only support a limited set of fields, this is the full list of field names
- // related to cc module dependency management that are supported.
- productVariableDepFields := [4]string{
- "Shared_libs",
- "Static_libs",
- "Exclude_static_libs",
- "Whole_static_libs",
- }
-
- productVariableProps := android.ProductVariableProperties(ctx)
- for _, name := range productVariableDepFields {
- props, exists := productVariableProps[name]
- if !exists {
- continue
- }
- for _, prop := range props {
- if p, ok := prop.Property.([]string); !ok {
- ctx.ModuleErrorf("Could not convert product variable %s property", name)
- } else {
- allDeps = append(allDeps, p...)
- }
- }
- }
-
- ctx.AddDependency(module, nil, android.SortedUniqueStrings(allDeps)...)
-}
-
// staticOrSharedAttributes are the Bazel-ified versions of StaticOrSharedProperties --
// properties which apply to either the shared or static version of a cc_library module.
type staticOrSharedAttributes struct {
@@ -183,30 +67,33 @@
// Convert the filegroup dependencies into the extension-specific filegroups
// filtered in the filegroup.bzl macro.
cppFilegroup := func(label string) string {
- ctx.VisitDirectDeps(func(m android.Module) {
- if isFilegroupNamed(m, label) {
+ m, exists := ctx.ModuleFromName(label)
+ if exists {
+ aModule, _ := m.(android.Module)
+ if isFilegroupNamed(aModule, label) {
label = label + "_cpp_srcs"
- return
}
- })
+ }
return label
}
cFilegroup := func(label string) string {
- ctx.VisitDirectDeps(func(m android.Module) {
- if isFilegroupNamed(m, label) {
+ m, exists := ctx.ModuleFromName(label)
+ if exists {
+ aModule, _ := m.(android.Module)
+ if isFilegroupNamed(aModule, label) {
label = label + "_c_srcs"
- return
}
- })
+ }
return label
}
asFilegroup := func(label string) string {
- ctx.VisitDirectDeps(func(m android.Module) {
- if isFilegroupNamed(m, label) {
+ m, exists := ctx.ModuleFromName(label)
+ if exists {
+ aModule, _ := m.(android.Module)
+ if isFilegroupNamed(aModule, label) {
label = label + "_as_srcs"
- return
}
- })
+ }
return label
}
diff --git a/genrule/genrule.go b/genrule/genrule.go
index 8372a64..c26b20c 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -68,7 +68,6 @@
ctx.BottomUp("genrule_tool_deps", toolDepsMutator).Parallel()
})
- android.DepsBp2BuildMutators(RegisterGenruleBp2BuildDeps)
android.RegisterBp2BuildMutator("genrule", GenruleBp2Build)
}