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/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
}