Use one mutator for all bp2build conversion.
Each conversion required defining a separate mutator, which will each
operate on _all_ modules and requires each to repeat checks whether the
mutator should operator. Instead, we introduce a single mutator and
modules can define a ConvertWithBp2build to implement bp2build
conversion for that module.
Test: bp2build.sh
Bug: 183079158
Change-Id: I99d4b51f441c2903879092c5b56313d606d4338d
diff --git a/android/bazel.go b/android/bazel.go
index 0ee65ef..fd3f23e 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -39,6 +39,10 @@
// To opt-out a module, set bazel_module: { bp2build_available: false }
// To defer the default setting for the directory, do not set the value.
Bp2build_available *bool
+
+ // CanConvertToBazel is set via InitBazelModule to indicate that a module type can be converted to
+ // Bazel with Bp2build.
+ CanConvertToBazel bool `blueprint:"mutated"`
}
// Properties contains common module properties for Bazel migration purposes.
@@ -80,9 +84,10 @@
HasHandcraftedLabel() bool
HandcraftedLabel() string
GetBazelLabel(ctx BazelConversionPathContext, module blueprint.Module) string
- ConvertWithBp2build(ctx BazelConversionContext) bool
- convertWithBp2build(ctx BazelConversionContext, module blueprint.Module) bool
+ ShouldConvertWithBp2build(ctx BazelConversionContext) bool
+ shouldConvertWithBp2build(ctx BazelConversionContext, module blueprint.Module) bool
GetBazelBuildFileContents(c Config, path, name string) (string, error)
+ ConvertWithBp2build(ctx TopDownMutatorContext)
// namespacedVariableProps is a map from a soong config variable namespace
// (e.g. acme, android) to a map of interfaces{}, which are really
@@ -109,6 +114,7 @@
// properties.
func InitBazelModule(module BazelModule) {
module.AddProperties(module.bazelProps())
+ module.bazelProps().Bazel_module.CanConvertToBazel = true
}
// bazelProps returns the Bazel properties for the given BazelModuleBase.
@@ -147,7 +153,7 @@
if b.HasHandcraftedLabel() {
return b.HandcraftedLabel()
}
- if b.ConvertWithBp2build(ctx) {
+ if b.ShouldConvertWithBp2build(ctx) {
return bp2buildModuleLabel(ctx, module)
}
return "" // no label for unconverted module
@@ -436,6 +442,9 @@
"acvp_modulewrapper", // disabled for android x86/x86_64
"CarHTMLViewer", // depends on unconverted modules android.car-stubs, car-ui-lib
+
+ "libdexfile", // depends on unconverted modules: dexfile_operator_srcs, libartbase, libartpalette,
+ "libdexfiled", // depends on unconverted modules: dexfile_operator_srcs, libartbased, libartpalette
}
// Per-module denylist of cc_library modules to only generate the static
@@ -530,32 +539,21 @@
if !ok {
return false
}
- return b.convertWithBp2build(ctx, module) || b.HasHandcraftedLabel()
+ return b.shouldConvertWithBp2build(ctx, module) || b.HasHandcraftedLabel()
}
-// ConvertWithBp2build returns whether the given BazelModuleBase should be converted with bp2build.
-func (b *BazelModuleBase) ConvertWithBp2build(ctx BazelConversionContext) bool {
- return b.convertWithBp2build(ctx, ctx.Module())
+// ShouldConvertWithBp2build returns whether the given BazelModuleBase should be converted with bp2build.
+func (b *BazelModuleBase) ShouldConvertWithBp2build(ctx BazelConversionContext) bool {
+ return b.shouldConvertWithBp2build(ctx, ctx.Module())
}
-func (b *BazelModuleBase) convertWithBp2build(ctx BazelConversionContext, module blueprint.Module) bool {
+func (b *BazelModuleBase) shouldConvertWithBp2build(ctx BazelConversionContext, module blueprint.Module) bool {
if bp2buildModuleDoNotConvert[module.Name()] {
return false
}
- // Ensure that the module type of this module has a bp2build converter. This
- // prevents mixed builds from using auto-converted modules just by matching
- // the package dir; it also has to have a bp2build mutator as well.
- if ctx.Config().bp2buildModuleTypeConfig[ctx.OtherModuleType(module)] == false {
- if b, ok := module.(Bazelable); ok && b.BaseModuleType() != "" {
- // For modules with custom types from soong_config_module_types,
- // check that their _base module type_ has a bp2build mutator.
- if ctx.Config().bp2buildModuleTypeConfig[b.BaseModuleType()] == false {
- return false
- }
- } else {
- return false
- }
+ if !b.bazelProps().Bazel_module.CanConvertToBazel {
+ return false
}
packagePath := ctx.OtherModuleDir(module)
@@ -629,3 +627,16 @@
}
return string(data[:]), nil
}
+
+func registerBp2buildConversionMutator(ctx RegisterMutatorsContext) {
+ ctx.TopDown("bp2build_conversion", convertWithBp2build).Parallel()
+}
+
+func convertWithBp2build(ctx TopDownMutatorContext) {
+ bModule, ok := ctx.Module().(Bazelable)
+ if !ok || !bModule.shouldConvertWithBp2build(ctx, ctx.Module()) {
+ return
+ }
+
+ bModule.ConvertWithBp2build(ctx)
+}
diff --git a/android/config.go b/android/config.go
index 3ce59b2..5d90fd2 100644
--- a/android/config.go
+++ b/android/config.go
@@ -157,7 +157,6 @@
runningAsBp2Build bool
bp2buildPackageConfig Bp2BuildConfig
- bp2buildModuleTypeConfig map[string]bool
Bp2buildSoongConfigDefinitions soongconfig.Bp2BuildSoongConfigDefinitions
// If testAllowNonExistentPaths is true then PathForSource and PathForModuleSrc won't error
@@ -353,8 +352,6 @@
config.mockFileSystem(bp, fs)
- config.bp2buildModuleTypeConfig = map[string]bool{}
-
determineBuildOS(config)
return Config{config}
@@ -522,7 +519,6 @@
config.BazelContext, err = NewBazelContext(config)
config.bp2buildPackageConfig = bp2buildDefaultConfig
- config.bp2buildModuleTypeConfig = make(map[string]bool)
return Config{config}, err
}
diff --git a/android/defaults.go b/android/defaults.go
index d2b351d..7b3d38c 100644
--- a/android/defaults.go
+++ b/android/defaults.go
@@ -173,6 +173,10 @@
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 InitDefaultsModule(module DefaultsModule) {
commonProperties := &commonProperties{}
diff --git a/android/filegroup.go b/android/filegroup.go
index a79374d..c932ffa 100644
--- a/android/filegroup.go
+++ b/android/filegroup.go
@@ -22,7 +22,6 @@
func init() {
RegisterModuleType("filegroup", FileGroupFactory)
- RegisterBp2BuildMutator("filegroup", FilegroupBp2Build)
}
var PrepareForTestWithFilegroup = FixtureRegisterWithContext(func(ctx RegistrationContext) {
@@ -34,12 +33,8 @@
Srcs bazel.LabelListAttribute
}
-func FilegroupBp2Build(ctx TopDownMutatorContext) {
- fg, ok := ctx.Module().(*fileGroup)
- if !ok || !fg.ConvertWithBp2build(ctx) {
- return
- }
-
+// ConvertWithBp2build performs bp2build conversion of filegroup
+func (fg *fileGroup) ConvertWithBp2build(ctx TopDownMutatorContext) {
srcs := bazel.MakeLabelListAttribute(
BazelLabelForModuleSrcExcludes(ctx, fg.properties.Srcs, fg.properties.Exclude_srcs))
diff --git a/android/mutator.go b/android/mutator.go
index bf1cf80..dbd8c04 100644
--- a/android/mutator.go
+++ b/android/mutator.go
@@ -16,7 +16,6 @@
import (
"reflect"
- "sync"
"android/soong/bazel"
@@ -34,12 +33,12 @@
// continue on to GenerateAndroidBuildActions
// RegisterMutatorsForBazelConversion is a alternate registration pipeline for bp2build. Exported for testing.
-func RegisterMutatorsForBazelConversion(ctx *Context, preArchMutators, bp2buildMutators []RegisterMutatorFunc) {
+func RegisterMutatorsForBazelConversion(ctx *Context, preArchMutators []RegisterMutatorFunc) {
mctx := ®isterMutatorsContext{
bazelConversionMode: true,
}
- bp2buildPreArchMutators = append([]RegisterMutatorFunc{
+ bp2buildMutators := append([]RegisterMutatorFunc{
RegisterNamespaceMutator,
RegisterDefaultsPreArchMutators,
// TODO(b/165114590): this is required to resolve deps that are only prebuilts, but we should
@@ -47,10 +46,7 @@
RegisterPrebuiltsPreArchMutators,
},
preArchMutators...)
-
- for _, f := range bp2buildPreArchMutators {
- f(mctx)
- }
+ bp2buildMutators = append(bp2buildMutators, registerBp2buildConversionMutator)
// Register bp2build mutators
for _, f := range bp2buildMutators {
@@ -216,10 +212,6 @@
}
var bp2buildPreArchMutators = []RegisterMutatorFunc{}
-var bp2buildMutators = map[string]RegisterMutatorFunc{}
-
-// See http://b/192523357
-var bp2buildLock sync.Mutex
// A minimal context for Bp2build conversion
type Bp2buildMutatorContext interface {
@@ -228,21 +220,6 @@
CreateBazelTargetModule(bazel.BazelTargetModuleProperties, CommonAttributes, interface{})
}
-// RegisterBp2BuildMutator registers specially crafted mutators for
-// converting Blueprint/Android modules into special modules that can
-// be code-generated into Bazel BUILD targets.
-//
-// TODO(b/178068862): bring this into TestContext.
-func RegisterBp2BuildMutator(moduleType string, m func(TopDownMutatorContext)) {
- f := func(ctx RegisterMutatorsContext) {
- ctx.TopDown(moduleType, m)
- }
- // Use a lock to avoid a concurrent map write if RegisterBp2BuildMutator is called in parallel
- bp2buildLock.Lock()
- defer bp2buildLock.Unlock()
- bp2buildMutators[moduleType] = f
-}
-
// 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) {
diff --git a/android/register.go b/android/register.go
index 4244398..1ac4440 100644
--- a/android/register.go
+++ b/android/register.go
@@ -178,13 +178,7 @@
t.register(ctx)
}
- bp2buildMutatorList := []RegisterMutatorFunc{}
- for t, f := range bp2buildMutators {
- ctx.config.bp2buildModuleTypeConfig[t] = true
- bp2buildMutatorList = append(bp2buildMutatorList, f)
- }
-
- RegisterMutatorsForBazelConversion(ctx, bp2buildPreArchMutators, bp2buildMutatorList)
+ RegisterMutatorsForBazelConversion(ctx, bp2buildPreArchMutators)
}
// Register the pipeline of singletons, module types, and mutators for
@@ -196,15 +190,6 @@
t.register(ctx)
}
- if ctx.config.BazelContext.BazelEnabled() {
- // Hydrate the configuration of bp2build-enabled module types. This is
- // required as a signal to identify which modules should be deferred to
- // Bazel in mixed builds, if it is enabled.
- for t, _ := range bp2buildMutators {
- ctx.config.bp2buildModuleTypeConfig[t] = true
- }
- }
-
mutators := collateGloballyRegisteredMutators()
mutators.registerAll(ctx)
diff --git a/android/testing.go b/android/testing.go
index 6290d43..8daf6b7 100644
--- a/android/testing.go
+++ b/android/testing.go
@@ -208,16 +208,6 @@
ctx.config.bp2buildPackageConfig = config
}
-// RegisterBp2BuildMutator registers a BazelTargetModule mutator for converting a module
-// type to the equivalent Bazel target.
-func (ctx *TestContext) RegisterBp2BuildMutator(moduleType string, m func(TopDownMutatorContext)) {
- f := func(ctx RegisterMutatorsContext) {
- ctx.TopDown(moduleType, m)
- }
- ctx.config.bp2buildModuleTypeConfig[moduleType] = true
- ctx.bp2buildMutators = append(ctx.bp2buildMutators, f)
-}
-
// PreArchBp2BuildMutators adds mutators to be register for converting Android Blueprint modules
// into Bazel BUILD targets that should run prior to deps and conversion.
func (ctx *TestContext) PreArchBp2BuildMutators(f RegisterMutatorFunc) {
@@ -459,7 +449,7 @@
// RegisterForBazelConversion prepares a test context for bp2build conversion.
func (ctx *TestContext) RegisterForBazelConversion() {
ctx.SetRunningAsBp2build()
- RegisterMutatorsForBazelConversion(ctx.Context, ctx.bp2buildPreArch, ctx.bp2buildMutators)
+ RegisterMutatorsForBazelConversion(ctx.Context, ctx.bp2buildPreArch)
}
func (ctx *TestContext) ParseFileList(rootDir string, filePaths []string) (deps []string, errs []error) {
diff --git a/apex/apex.go b/apex/apex.go
index e5cee72..a28cd72 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -54,8 +54,6 @@
ctx.PreArchMutators(registerPreArchMutators)
ctx.PreDepsMutators(RegisterPreDepsMutators)
ctx.PostDepsMutators(RegisterPostDepsMutators)
-
- android.RegisterBp2BuildMutator("apex", ApexBundleBp2Build)
}
func registerPreArchMutators(ctx android.RegisterMutatorsContext) {
@@ -3274,72 +3272,62 @@
Prebuilts bazel.LabelListAttribute
}
-func ApexBundleBp2Build(ctx android.TopDownMutatorContext) {
- module, ok := ctx.Module().(*apexBundle)
- if !ok {
- // Not an APEX bundle
- return
- }
- if !module.ConvertWithBp2build(ctx) {
- return
- }
+// ConvertWithBp2build performs bp2build conversion of an apex
+func (a *apexBundle) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
+ // We do not convert apex_test modules at this time
if ctx.ModuleType() != "apex" {
return
}
- apexBundleBp2BuildInternal(ctx, module)
-}
-
-func apexBundleBp2BuildInternal(ctx android.TopDownMutatorContext, module *apexBundle) {
var manifestLabelAttribute bazel.LabelAttribute
- if module.properties.Manifest != nil {
- manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *module.properties.Manifest))
+ if a.properties.Manifest != nil {
+ manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.Manifest))
}
var androidManifestLabelAttribute bazel.LabelAttribute
- if module.properties.AndroidManifest != nil {
- androidManifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *module.properties.AndroidManifest))
+ if a.properties.AndroidManifest != nil {
+ androidManifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.AndroidManifest))
}
var fileContextsLabelAttribute bazel.LabelAttribute
- if module.properties.File_contexts != nil {
- fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *module.properties.File_contexts))
+ if a.properties.File_contexts != nil {
+ fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.properties.File_contexts))
}
var minSdkVersion *string
- if module.properties.Min_sdk_version != nil {
- minSdkVersion = module.properties.Min_sdk_version
+ if a.properties.Min_sdk_version != nil {
+ minSdkVersion = a.properties.Min_sdk_version
}
var keyLabelAttribute bazel.LabelAttribute
- if module.overridableProperties.Key != nil {
- keyLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *module.overridableProperties.Key))
+ if a.overridableProperties.Key != nil {
+ keyLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Key))
}
var certificateLabelAttribute bazel.LabelAttribute
- if module.overridableProperties.Certificate != nil {
- certificateLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *module.overridableProperties.Certificate))
+ if a.overridableProperties.Certificate != nil {
+ certificateLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Certificate))
}
- nativeSharedLibs := module.properties.ApexNativeDependencies.Native_shared_libs
+ nativeSharedLibs := a.properties.ApexNativeDependencies.Native_shared_libs
nativeSharedLibsLabelList := android.BazelLabelForModuleDeps(ctx, nativeSharedLibs)
nativeSharedLibsLabelListAttribute := bazel.MakeLabelListAttribute(nativeSharedLibsLabelList)
- prebuilts := module.overridableProperties.Prebuilts
+ prebuilts := a.overridableProperties.Prebuilts
prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, prebuilts)
prebuiltsLabelListAttribute := bazel.MakeLabelListAttribute(prebuiltsLabelList)
- binaries := android.BazelLabelForModuleDeps(ctx, module.properties.ApexNativeDependencies.Binaries)
+ binaries := android.BazelLabelForModuleDeps(ctx, a.properties.ApexNativeDependencies.Binaries)
binariesLabelListAttribute := bazel.MakeLabelListAttribute(binaries)
var updatableAttribute bazel.BoolAttribute
- if module.properties.Updatable != nil {
- updatableAttribute.Value = module.properties.Updatable
+ if a.properties.Updatable != nil {
+ updatableAttribute.Value = a.properties.Updatable
}
var installableAttribute bazel.BoolAttribute
- if module.properties.Installable != nil {
- installableAttribute.Value = module.properties.Installable
+ if a.properties.Installable != nil {
+ installableAttribute.Value = a.properties.Installable
}
attrs := &bazelApexBundleAttributes{
@@ -3361,5 +3349,5 @@
Bzl_load_location: "//build/bazel/rules:apex.bzl",
}
- ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, attrs)
+ ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: a.Name()}, attrs)
}
diff --git a/apex/key.go b/apex/key.go
index 259060f..829410e 100644
--- a/apex/key.go
+++ b/apex/key.go
@@ -34,8 +34,6 @@
func registerApexKeyBuildComponents(ctx android.RegistrationContext) {
ctx.RegisterModuleType("apex_key", ApexKeyFactory)
ctx.RegisterSingletonType("apex_keys_text", apexKeysTextFactory)
-
- android.RegisterBp2BuildMutator("apex_key", ApexKeyBp2Build)
}
type apexKey struct {
@@ -209,20 +207,9 @@
Private_key bazel.LabelAttribute
}
-func ApexKeyBp2Build(ctx android.TopDownMutatorContext) {
- module, ok := ctx.Module().(*apexKey)
- if !ok {
- // Not an APEX key
- return
- }
- if !module.ConvertWithBp2build(ctx) {
- return
- }
- if ctx.ModuleType() != "apex_key" {
- return
- }
-
- apexKeyBp2BuildInternal(ctx, module)
+// ConvertWithBp2build performs conversion apexKey for bp2build
+func (m *apexKey) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
+ apexKeyBp2BuildInternal(ctx, m)
}
func apexKeyBp2BuildInternal(ctx android.TopDownMutatorContext, module *apexKey) {
diff --git a/bp2build/android_app_certificate_conversion_test.go b/bp2build/android_app_certificate_conversion_test.go
index 6a53b00..035a352 100644
--- a/bp2build/android_app_certificate_conversion_test.go
+++ b/bp2build/android_app_certificate_conversion_test.go
@@ -31,11 +31,10 @@
func TestAndroidAppCertificateSimple(t *testing.T) {
runAndroidAppCertificateTestCase(t, bp2buildTestCase{
- description: "Android app certificate - simple example",
- moduleTypeUnderTest: "android_app_certificate",
- moduleTypeUnderTestFactory: java.AndroidAppCertificateFactory,
- moduleTypeUnderTestBp2BuildMutator: java.AndroidAppCertificateBp2Build,
- filesystem: map[string]string{},
+ description: "Android app certificate - simple example",
+ moduleTypeUnderTest: "android_app_certificate",
+ moduleTypeUnderTestFactory: java.AndroidAppCertificateFactory,
+ filesystem: map[string]string{},
blueprint: `
android_app_certificate {
name: "com.android.apogee.cert",
diff --git a/bp2build/android_app_conversion_test.go b/bp2build/android_app_conversion_test.go
index b12b567..153817b 100644
--- a/bp2build/android_app_conversion_test.go
+++ b/bp2build/android_app_conversion_test.go
@@ -31,10 +31,9 @@
func TestMinimalAndroidApp(t *testing.T) {
runAndroidAppTestCase(t, bp2buildTestCase{
- description: "Android app - simple example",
- moduleTypeUnderTest: "android_app",
- moduleTypeUnderTestFactory: java.AndroidAppFactory,
- moduleTypeUnderTestBp2BuildMutator: java.AppBp2Build,
+ description: "Android app - simple example",
+ moduleTypeUnderTest: "android_app",
+ moduleTypeUnderTestFactory: java.AndroidAppFactory,
filesystem: map[string]string{
"app.java": "",
"res/res.png": "",
@@ -58,10 +57,9 @@
func TestAndroidAppAllSupportedFields(t *testing.T) {
runAndroidAppTestCase(t, bp2buildTestCase{
- description: "Android app - all supported fields",
- moduleTypeUnderTest: "android_app",
- moduleTypeUnderTestFactory: java.AndroidAppFactory,
- moduleTypeUnderTestBp2BuildMutator: java.AppBp2Build,
+ description: "Android app - all supported fields",
+ moduleTypeUnderTest: "android_app",
+ moduleTypeUnderTestFactory: java.AndroidAppFactory,
filesystem: map[string]string{
"app.java": "",
"resa/res.png": "",
diff --git a/bp2build/apex_conversion_test.go b/bp2build/apex_conversion_test.go
index 64440df..a3825e6 100644
--- a/bp2build/apex_conversion_test.go
+++ b/bp2build/apex_conversion_test.go
@@ -43,11 +43,10 @@
func TestApexBundleSimple(t *testing.T) {
runApexTestCase(t, bp2buildTestCase{
- description: "apex - example with all props",
- moduleTypeUnderTest: "apex",
- moduleTypeUnderTestFactory: apex.BundleFactory,
- moduleTypeUnderTestBp2BuildMutator: apex.ApexBundleBp2Build,
- filesystem: map[string]string{},
+ description: "apex - example with all props",
+ moduleTypeUnderTest: "apex",
+ moduleTypeUnderTestFactory: apex.BundleFactory,
+ filesystem: map[string]string{},
blueprint: `
apex_key {
name: "com.android.apogee.key",
@@ -147,11 +146,10 @@
func TestApexBundleDefaultPropertyValues(t *testing.T) {
runApexTestCase(t, bp2buildTestCase{
- description: "apex - default property values",
- moduleTypeUnderTest: "apex",
- moduleTypeUnderTestFactory: apex.BundleFactory,
- moduleTypeUnderTestBp2BuildMutator: apex.ApexBundleBp2Build,
- filesystem: map[string]string{},
+ description: "apex - default property values",
+ moduleTypeUnderTest: "apex",
+ moduleTypeUnderTestFactory: apex.BundleFactory,
+ filesystem: map[string]string{},
blueprint: `
apex {
name: "com.android.apogee",
@@ -166,11 +164,10 @@
func TestApexBundleHasBazelModuleProps(t *testing.T) {
runApexTestCase(t, bp2buildTestCase{
- description: "apex - has bazel module props",
- moduleTypeUnderTest: "apex",
- moduleTypeUnderTestFactory: apex.BundleFactory,
- moduleTypeUnderTestBp2BuildMutator: apex.ApexBundleBp2Build,
- filesystem: map[string]string{},
+ description: "apex - has bazel module props",
+ moduleTypeUnderTest: "apex",
+ moduleTypeUnderTestFactory: apex.BundleFactory,
+ filesystem: map[string]string{},
blueprint: `
apex {
name: "apogee",
diff --git a/bp2build/apex_key_conversion_test.go b/bp2build/apex_key_conversion_test.go
index 17f79a6..1d949901 100644
--- a/bp2build/apex_key_conversion_test.go
+++ b/bp2build/apex_key_conversion_test.go
@@ -31,11 +31,10 @@
func TestApexKeySimple(t *testing.T) {
runApexKeyTestCase(t, bp2buildTestCase{
- description: "apex key - simple example",
- moduleTypeUnderTest: "apex_key",
- moduleTypeUnderTestFactory: apex.ApexKeyFactory,
- moduleTypeUnderTestBp2BuildMutator: apex.ApexKeyBp2Build,
- filesystem: map[string]string{},
+ description: "apex key - simple example",
+ moduleTypeUnderTest: "apex_key",
+ moduleTypeUnderTestFactory: apex.ApexKeyFactory,
+ filesystem: map[string]string{},
blueprint: `
apex_key {
name: "com.android.apogee.key",
diff --git a/bp2build/build_conversion_test.go b/bp2build/build_conversion_test.go
index 95a26a9..1440b6f 100644
--- a/bp2build/build_conversion_test.go
+++ b/bp2build/build_conversion_test.go
@@ -245,7 +245,7 @@
{
description: "string props",
blueprint: `custom {
- name: "foo",
+ name: "foo",
string_list_prop: ["a", "b"],
string_ptr_prop: "a",
bazel_module: { bp2build_available: true },
@@ -470,7 +470,7 @@
android.FailIfErrored(t, err)
if actualCount, expectedCount := len(bazelTargets), len(testCase.expectedBazelTargets); actualCount != expectedCount {
- t.Errorf("Expected %d bazel target, got %d", expectedCount, actualCount)
+ t.Errorf("Expected %d bazel target (%s),\ngot %d (%s)", expectedCount, testCase.expectedBazelTargets, actualCount, bazelTargets)
} else {
for i, expectedBazelTarget := range testCase.expectedBazelTargets {
actualBazelTarget := bazelTargets[i]
@@ -596,6 +596,7 @@
{
bp: `custom {
name: "bar",
+ one_to_many_prop: true,
bazel_module: { bp2build_available: true },
}`,
expectedBazelTarget: `my_library(
@@ -620,7 +621,6 @@
config := android.TestConfig(buildDir, nil, testCase.bp, nil)
ctx := android.NewTestContext(config)
ctx.RegisterModuleType("custom", customModuleFactory)
- ctx.RegisterBp2BuildMutator("custom", customBp2BuildMutatorFromStarlark)
ctx.RegisterForBazelConversion()
_, errs := ctx.ParseFileList(dir, []string{"Android.bp"})
@@ -658,10 +658,9 @@
func TestModuleTypeBp2Build(t *testing.T) {
testCases := []bp2buildTestCase{
{
- description: "filegroup with does not specify srcs",
- moduleTypeUnderTest: "filegroup",
- moduleTypeUnderTestFactory: android.FileGroupFactory,
- moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
+ description: "filegroup with does not specify srcs",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
blueprint: `filegroup {
name: "fg_foo",
bazel_module: { bp2build_available: true },
@@ -671,10 +670,9 @@
},
},
{
- description: "filegroup with no srcs",
- moduleTypeUnderTest: "filegroup",
- moduleTypeUnderTestFactory: android.FileGroupFactory,
- moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
+ description: "filegroup with no srcs",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
blueprint: `filegroup {
name: "fg_foo",
srcs: [],
@@ -685,10 +683,9 @@
},
},
{
- description: "filegroup with srcs",
- moduleTypeUnderTest: "filegroup",
- moduleTypeUnderTestFactory: android.FileGroupFactory,
- moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
+ description: "filegroup with srcs",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
blueprint: `filegroup {
name: "fg_foo",
srcs: ["a", "b"],
@@ -704,10 +701,9 @@
},
},
{
- description: "filegroup with excludes srcs",
- moduleTypeUnderTest: "filegroup",
- moduleTypeUnderTestFactory: android.FileGroupFactory,
- moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
+ description: "filegroup with excludes srcs",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
blueprint: `filegroup {
name: "fg_foo",
srcs: ["a", "b"],
@@ -721,10 +717,9 @@
},
},
{
- description: "filegroup with glob",
- moduleTypeUnderTest: "filegroup",
- moduleTypeUnderTestFactory: android.FileGroupFactory,
- moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
+ description: "filegroup with glob",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
blueprint: `filegroup {
name: "fg_foo",
srcs: ["**/*.txt"],
@@ -747,12 +742,10 @@
},
},
{
- description: "filegroup with glob in subdir",
- moduleTypeUnderTest: "filegroup",
- moduleTypeUnderTestFactory: android.FileGroupFactory,
- moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
- blueprint: ``,
- dir: "other",
+ description: "filegroup with glob in subdir",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
+ dir: "other",
filesystem: map[string]string{
"other/Android.bp": `filegroup {
name: "fg_foo",
@@ -775,10 +768,9 @@
},
},
{
- description: "depends_on_other_dir_module",
- moduleTypeUnderTest: "filegroup",
- moduleTypeUnderTestFactory: android.FileGroupFactory,
- moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
+ description: "depends_on_other_dir_module",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
blueprint: `filegroup {
name: "fg_foo",
srcs: [
@@ -804,26 +796,25 @@
},
},
{
- description: "depends_on_other_unconverted_module_error",
- moduleTypeUnderTest: "filegroup",
- moduleTypeUnderTestFactory: android.FileGroupFactory,
- moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
- unconvertedDepsMode: errorModulesUnconvertedDeps,
- filesystem: map[string]string{
- "other/Android.bp": `filegroup {
- name: "foo",
- srcs: ["a", "b"],
-}`,
- },
+ description: "depends_on_other_unconverted_module_error",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
+ unconvertedDepsMode: errorModulesUnconvertedDeps,
blueprint: `filegroup {
- name: "fg_foo",
+ name: "foobar",
srcs: [
":foo",
"c",
],
bazel_module: { bp2build_available: true },
}`,
- expectedErr: fmt.Errorf(`"fg_foo" depends on unconverted modules: foo`),
+ expectedErr: fmt.Errorf(`"foobar" depends on unconverted modules: foo`),
+ filesystem: map[string]string{
+ "other/Android.bp": `filegroup {
+ name: "foo",
+ srcs: ["a", "b"],
+}`,
+ },
},
}
@@ -838,18 +829,16 @@
func TestAllowlistingBp2buildTargetsExplicitly(t *testing.T) {
testCases := []struct {
- moduleTypeUnderTest string
- moduleTypeUnderTestFactory android.ModuleFactory
- moduleTypeUnderTestBp2BuildMutator bp2buildMutator
- bp string
- expectedCount int
- description string
+ moduleTypeUnderTest string
+ moduleTypeUnderTestFactory android.ModuleFactory
+ bp string
+ expectedCount int
+ description string
}{
{
- description: "explicitly unavailable",
- moduleTypeUnderTest: "filegroup",
- moduleTypeUnderTestFactory: android.FileGroupFactory,
- moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
+ description: "explicitly unavailable",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
bp: `filegroup {
name: "foo",
srcs: ["a", "b"],
@@ -858,10 +847,9 @@
expectedCount: 0,
},
{
- description: "implicitly unavailable",
- moduleTypeUnderTest: "filegroup",
- moduleTypeUnderTestFactory: android.FileGroupFactory,
- moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
+ description: "implicitly unavailable",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
bp: `filegroup {
name: "foo",
srcs: ["a", "b"],
@@ -869,10 +857,9 @@
expectedCount: 0,
},
{
- description: "explicitly available",
- moduleTypeUnderTest: "filegroup",
- moduleTypeUnderTestFactory: android.FileGroupFactory,
- moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
+ description: "explicitly available",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
bp: `filegroup {
name: "foo",
srcs: ["a", "b"],
@@ -881,12 +868,12 @@
expectedCount: 1,
},
{
- description: "generates more than 1 target if needed",
- moduleTypeUnderTest: "custom",
- moduleTypeUnderTestFactory: customModuleFactory,
- moduleTypeUnderTestBp2BuildMutator: customBp2BuildMutatorFromStarlark,
+ description: "generates more than 1 target if needed",
+ moduleTypeUnderTest: "custom",
+ moduleTypeUnderTestFactory: customModuleFactory,
bp: `custom {
name: "foo",
+ one_to_many_prop: true,
bazel_module: { bp2build_available: true },
}`,
expectedCount: 3,
@@ -899,7 +886,6 @@
config := android.TestConfig(buildDir, nil, testCase.bp, nil)
ctx := android.NewTestContext(config)
ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory)
- ctx.RegisterBp2BuildMutator(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestBp2BuildMutator)
ctx.RegisterForBazelConversion()
_, errs := ctx.ParseFileList(dir, []string{"Android.bp"})
@@ -919,20 +905,18 @@
func TestAllowlistingBp2buildTargetsWithConfig(t *testing.T) {
testCases := []struct {
- moduleTypeUnderTest string
- moduleTypeUnderTestFactory android.ModuleFactory
- moduleTypeUnderTestBp2BuildMutator bp2buildMutator
- expectedCount map[string]int
- description string
- bp2buildConfig android.Bp2BuildConfig
- checkDir string
- fs map[string]string
+ moduleTypeUnderTest string
+ moduleTypeUnderTestFactory android.ModuleFactory
+ expectedCount map[string]int
+ description string
+ bp2buildConfig android.Bp2BuildConfig
+ checkDir string
+ fs map[string]string
}{
{
- description: "test bp2build config package and subpackages config",
- moduleTypeUnderTest: "filegroup",
- moduleTypeUnderTestFactory: android.FileGroupFactory,
- moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
+ description: "test bp2build config package and subpackages config",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
expectedCount: map[string]int{
"migrated": 1,
"migrated/but_not_really": 0,
@@ -954,10 +938,9 @@
},
},
{
- description: "test bp2build config opt-in and opt-out",
- moduleTypeUnderTest: "filegroup",
- moduleTypeUnderTestFactory: android.FileGroupFactory,
- moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
+ description: "test bp2build config opt-in and opt-out",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
expectedCount: map[string]int{
"package-opt-in": 2,
"package-opt-in/subpackage": 0,
@@ -1008,7 +991,6 @@
config := android.TestConfig(buildDir, nil, "", fs)
ctx := android.NewTestContext(config)
ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory)
- ctx.RegisterBp2BuildMutator(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestBp2BuildMutator)
ctx.RegisterBp2BuildConfig(testCase.bp2buildConfig)
ctx.RegisterForBazelConversion()
@@ -1039,10 +1021,9 @@
func TestCombineBuildFilesBp2buildTargets(t *testing.T) {
testCases := []bp2buildTestCase{
{
- description: "filegroup bazel_module.label",
- moduleTypeUnderTest: "filegroup",
- moduleTypeUnderTestFactory: android.FileGroupFactory,
- moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
+ description: "filegroup bazel_module.label",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
blueprint: `filegroup {
name: "fg_foo",
bazel_module: { label: "//other:fg_foo" },
@@ -1055,19 +1036,18 @@
},
},
{
- description: "multiple bazel_module.label same BUILD",
- moduleTypeUnderTest: "filegroup",
- moduleTypeUnderTestFactory: android.FileGroupFactory,
- moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
+ description: "multiple bazel_module.label same BUILD",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
blueprint: `filegroup {
- name: "fg_foo",
- bazel_module: { label: "//other:fg_foo" },
- }
+ name: "fg_foo",
+ bazel_module: { label: "//other:fg_foo" },
+ }
- filegroup {
- name: "foo",
- bazel_module: { label: "//other:foo" },
- }`,
+ filegroup {
+ name: "foo",
+ bazel_module: { label: "//other:foo" },
+ }`,
expectedBazelTargets: []string{
`// BUILD file`,
},
@@ -1076,25 +1056,24 @@
},
},
{
- description: "filegroup bazel_module.label and bp2build in subdir",
- moduleTypeUnderTest: "filegroup",
- moduleTypeUnderTestFactory: android.FileGroupFactory,
- moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
- dir: "other",
- blueprint: ``,
+ description: "filegroup bazel_module.label and bp2build in subdir",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
+ dir: "other",
+ blueprint: ``,
filesystem: map[string]string{
"other/Android.bp": `filegroup {
- name: "fg_foo",
- bazel_module: {
- bp2build_available: true,
- },
- }
- filegroup {
- name: "fg_bar",
- bazel_module: {
- label: "//other:fg_bar"
- },
- }`,
+ name: "fg_foo",
+ bazel_module: {
+ bp2build_available: true,
+ },
+ }
+ filegroup {
+ name: "fg_bar",
+ bazel_module: {
+ label: "//other:fg_bar"
+ },
+ }`,
"other/BUILD.bazel": `// definition for fg_bar`,
},
expectedBazelTargets: []string{
@@ -1103,26 +1082,26 @@
},
},
{
- description: "filegroup bazel_module.label and filegroup bp2build",
- moduleTypeUnderTest: "filegroup",
- moduleTypeUnderTestFactory: android.FileGroupFactory,
- moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
+ description: "filegroup bazel_module.label and filegroup bp2build",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
+
filesystem: map[string]string{
"other/BUILD.bazel": `// BUILD file`,
},
blueprint: `filegroup {
- name: "fg_foo",
- bazel_module: {
- label: "//other:fg_foo",
- },
- }
+ name: "fg_foo",
+ bazel_module: {
+ label: "//other:fg_foo",
+ },
+ }
- filegroup {
- name: "fg_bar",
- bazel_module: {
- bp2build_available: true,
- },
- }`,
+ filegroup {
+ name: "fg_bar",
+ bazel_module: {
+ bp2build_available: true,
+ },
+ }`,
expectedBazelTargets: []string{
makeBazelTarget("filegroup", "fg_bar", map[string]string{}),
`// BUILD file`,
@@ -1146,7 +1125,6 @@
config := android.TestConfig(buildDir, nil, testCase.blueprint, fs)
ctx := android.NewTestContext(config)
ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory)
- ctx.RegisterBp2BuildMutator(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestBp2BuildMutator)
ctx.RegisterForBazelConversion()
_, errs := ctx.ParseFileList(dir, toParse)
@@ -1192,10 +1170,9 @@
func TestGlobExcludeSrcs(t *testing.T) {
testCases := []bp2buildTestCase{
{
- description: "filegroup top level exclude_srcs",
- moduleTypeUnderTest: "filegroup",
- moduleTypeUnderTestFactory: android.FileGroupFactory,
- moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
+ description: "filegroup top level exclude_srcs",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
blueprint: `filegroup {
name: "fg_foo",
srcs: ["**/*.txt"],
@@ -1222,12 +1199,11 @@
},
},
{
- description: "filegroup in subdir exclude_srcs",
- moduleTypeUnderTest: "filegroup",
- moduleTypeUnderTestFactory: android.FileGroupFactory,
- moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
- blueprint: "",
- dir: "dir",
+ description: "filegroup in subdir exclude_srcs",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
+ blueprint: "",
+ dir: "dir",
filesystem: map[string]string{
"dir/Android.bp": `filegroup {
name: "fg_foo",
@@ -1264,10 +1240,9 @@
func TestCommonBp2BuildModuleAttrs(t *testing.T) {
testCases := []bp2buildTestCase{
{
- description: "Required into data test",
- moduleTypeUnderTest: "filegroup",
- moduleTypeUnderTestFactory: android.FileGroupFactory,
- moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
+ description: "Required into data test",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
blueprint: simpleModuleDoNotConvertBp2build("filegroup", "reqd") + `
filegroup {
name: "fg_foo",
@@ -1281,21 +1256,20 @@
},
},
{
- description: "Required via arch into data test",
- moduleTypeUnderTest: "python_library",
- moduleTypeUnderTestFactory: python.PythonLibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: python.PythonLibraryBp2Build,
+ description: "Required via arch into data test",
+ moduleTypeUnderTest: "python_library",
+ moduleTypeUnderTestFactory: python.PythonLibraryFactory,
blueprint: simpleModuleDoNotConvertBp2build("python_library", "reqdx86") +
simpleModuleDoNotConvertBp2build("python_library", "reqdarm") + `
python_library {
name: "fg_foo",
arch: {
- arm: {
- required: ["reqdarm"],
- },
- x86: {
- required: ["reqdx86"],
- },
+ arm: {
+ required: ["reqdarm"],
+ },
+ x86: {
+ required: ["reqdx86"],
+ },
},
bazel_module: { bp2build_available: true },
}`,
@@ -1311,10 +1285,9 @@
},
},
{
- description: "Required appended to data test",
- moduleTypeUnderTest: "python_library",
- moduleTypeUnderTestFactory: python.PythonLibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: python.PythonLibraryBp2Build,
+ description: "Required appended to data test",
+ moduleTypeUnderTest: "python_library",
+ moduleTypeUnderTestFactory: python.PythonLibraryFactory,
filesystem: map[string]string{
"data.bin": "",
"src.py": "",
@@ -1337,10 +1310,9 @@
},
},
{
- description: "All props-to-attrs at once together test",
- moduleTypeUnderTest: "filegroup",
- moduleTypeUnderTestFactory: android.FileGroupFactory,
- moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
+ description: "All props-to-attrs at once together test",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
blueprint: simpleModuleDoNotConvertBp2build("filegroup", "reqd") + `
filegroup {
name: "fg_foo",
diff --git a/bp2build/bzl_conversion_test.go b/bp2build/bzl_conversion_test.go
index 1e78c0e..f3345a6 100644
--- a/bp2build/bzl_conversion_test.go
+++ b/bp2build/bzl_conversion_test.go
@@ -100,6 +100,7 @@
# nested_props_ptr start
# "nested_prop": attr.string(),
# nested_props_ptr end
+ "one_to_many_prop": attr.bool(),
"other_embedded_prop": attr.string(),
"string_list_prop": attr.string_list(),
"string_prop": attr.string(),
@@ -128,6 +129,7 @@
# nested_props_ptr start
# "nested_prop": attr.string(),
# nested_props_ptr end
+ "one_to_many_prop": attr.bool(),
"other_embedded_prop": attr.string(),
"string_list_prop": attr.string_list(),
"string_prop": attr.string(),
@@ -156,6 +158,7 @@
# nested_props_ptr start
# "nested_prop": attr.string(),
# nested_props_ptr end
+ "one_to_many_prop": attr.bool(),
"other_embedded_prop": attr.string(),
"string_list_prop": attr.string_list(),
"string_prop": attr.string(),
diff --git a/bp2build/cc_binary_conversion_test.go b/bp2build/cc_binary_conversion_test.go
index b46248f..a156480 100644
--- a/bp2build/cc_binary_conversion_test.go
+++ b/bp2build/cc_binary_conversion_test.go
@@ -68,14 +68,14 @@
t.Helper()
moduleTypeUnderTest := "cc_binary"
testCase := bp2buildTestCase{
- expectedBazelTargets: generateBazelTargetsForTest(tc.targets),
- moduleTypeUnderTest: moduleTypeUnderTest,
- moduleTypeUnderTestFactory: cc.BinaryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.BinaryBp2build,
- description: fmt.Sprintf("%s %s", moduleTypeUnderTest, tc.description),
- blueprint: binaryReplacer.Replace(tc.blueprint),
+ expectedBazelTargets: generateBazelTargetsForTest(tc.targets),
+ moduleTypeUnderTest: moduleTypeUnderTest,
+ moduleTypeUnderTestFactory: cc.BinaryFactory,
+ description: fmt.Sprintf("%s %s", moduleTypeUnderTest, tc.description),
+ blueprint: binaryReplacer.Replace(tc.blueprint),
}
t.Run(testCase.description, func(t *testing.T) {
+ t.Helper()
runBp2BuildTestCase(t, registerCcBinaryModuleTypes, testCase)
})
}
@@ -96,12 +96,11 @@
moduleTypeUnderTest := "cc_binary_host"
t.Run(testCase.description, func(t *testing.T) {
runBp2BuildTestCase(t, registerCcBinaryModuleTypes, bp2buildTestCase{
- expectedBazelTargets: generateBazelTargetsForTest(testCase.targets),
- moduleTypeUnderTest: moduleTypeUnderTest,
- moduleTypeUnderTestFactory: cc.BinaryHostFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.BinaryHostBp2build,
- description: fmt.Sprintf("%s %s", moduleTypeUnderTest, tc.description),
- blueprint: hostBinaryReplacer.Replace(testCase.blueprint),
+ expectedBazelTargets: generateBazelTargetsForTest(testCase.targets),
+ moduleTypeUnderTest: moduleTypeUnderTest,
+ moduleTypeUnderTestFactory: cc.BinaryHostFactory,
+ description: fmt.Sprintf("%s %s", moduleTypeUnderTest, tc.description),
+ blueprint: hostBinaryReplacer.Replace(testCase.blueprint),
})
})
}
@@ -258,11 +257,13 @@
genrule {
name: "generated_hdr",
cmd: "nothing to see here",
+ bazel_module: { bp2build_available: false },
}
genrule {
name: "export_generated_hdr",
cmd: "nothing to see here",
+ bazel_module: { bp2build_available: false },
}
{rule_name} {
diff --git a/bp2build/cc_genrule_conversion_test.go b/bp2build/cc_genrule_conversion_test.go
index b3624dd..440b462 100644
--- a/bp2build/cc_genrule_conversion_test.go
+++ b/bp2build/cc_genrule_conversion_test.go
@@ -19,7 +19,6 @@
"android/soong/android"
"android/soong/cc"
- "android/soong/genrule"
)
var otherCcGenruleBp = map[string]string{
@@ -41,7 +40,6 @@
t.Helper()
(&tc).moduleTypeUnderTest = "cc_genrule"
(&tc).moduleTypeUnderTestFactory = cc.GenRuleFactory
- (&tc).moduleTypeUnderTestBp2BuildMutator = genrule.CcGenruleBp2Build
runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
}
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index dcbe326..b4eb28f 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -70,10 +70,9 @@
func TestCcLibrarySimple(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library - simple example",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ description: "cc_library - simple example",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
filesystem: map[string]string{
"android.cpp": "",
"bionic.cpp": "",
@@ -159,10 +158,9 @@
func TestCcLibraryTrimmedLdAndroid(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library - trimmed example of //bionic/linker:ld-android",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ description: "cc_library - trimmed example of //bionic/linker:ld-android",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
filesystem: map[string]string{
"ld-android.cpp": "",
"linked_list.h": "",
@@ -170,8 +168,8 @@
"linker_block_allocator.h": "",
"linker_cfi.h": "",
},
- blueprint: soongCcLibraryPreamble + `
-cc_library_headers { name: "libc_headers" }
+ blueprint: soongCcLibraryPreamble +
+ simpleModuleDoNotConvertBp2build("cc_library_headers", "libc_headers") + `
cc_library {
name: "fake-ld-android",
srcs: ["ld_android.cpp"],
@@ -228,11 +226,10 @@
func TestCcLibraryExcludeSrcs(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library exclude_srcs - trimmed example of //external/arm-optimized-routines:libarm-optimized-routines-math",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
- dir: "external",
+ description: "cc_library exclude_srcs - trimmed example of //external/arm-optimized-routines:libarm-optimized-routines-math",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ dir: "external",
filesystem: map[string]string{
"external/math/cosf.c": "",
"external/math/erf.c": "",
@@ -280,10 +277,9 @@
func TestCcLibrarySharedStaticProps(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library shared/static props",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ description: "cc_library shared/static props",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
filesystem: map[string]string{
"both.cpp": "",
"sharedonly.cpp": "",
@@ -409,10 +405,9 @@
func TestCcLibraryDeps(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library shared/static props",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ description: "cc_library shared/static props",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
filesystem: map[string]string{
"both.cpp": "",
"sharedonly.cpp": "",
@@ -537,10 +532,9 @@
func TestCcLibraryWholeStaticLibsAlwaysLink(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
- dir: "foo/bar",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ dir: "foo/bar",
filesystem: map[string]string{
"foo/bar/Android.bp": `
cc_library {
@@ -584,11 +578,10 @@
func TestCcLibrarySharedStaticPropsInArch(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library shared/static props in arch",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
- dir: "foo/bar",
+ description: "cc_library shared/static props in arch",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ dir: "foo/bar",
filesystem: map[string]string{
"foo/bar/arm.cpp": "",
"foo/bar/x86.cpp": "",
@@ -735,11 +728,10 @@
func TestCcLibrarySharedStaticPropsWithMixedSources(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library shared/static props with c/cpp/s mixed sources",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
- dir: "foo/bar",
+ description: "cc_library shared/static props with c/cpp/s mixed sources",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ dir: "foo/bar",
filesystem: map[string]string{
"foo/bar/both_source.cpp": "",
"foo/bar/both_source.cc": "",
@@ -868,11 +860,10 @@
func TestCcLibraryNonConfiguredVersionScript(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library non-configured version script",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
- dir: "foo/bar",
+ description: "cc_library non-configured version script",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ dir: "foo/bar",
filesystem: map[string]string{
"foo/bar/Android.bp": `
cc_library {
@@ -896,11 +887,10 @@
func TestCcLibraryConfiguredVersionScript(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library configured version script",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
- dir: "foo/bar",
+ description: "cc_library configured version script",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ dir: "foo/bar",
filesystem: map[string]string{
"foo/bar/Android.bp": `
cc_library {
@@ -940,10 +930,9 @@
func TestCcLibrarySharedLibs(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library shared_libs",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ description: "cc_library shared_libs",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
blueprint: soongCcLibraryPreamble + `
cc_library {
name: "mylib",
@@ -994,10 +983,9 @@
})...)
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library pack_relocations test",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ description: "cc_library pack_relocations test",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
blueprint: soongCcLibraryPreamble + `
cc_library {
name: "a",
@@ -1036,10 +1024,9 @@
func TestCcLibrarySpacesInCopts(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library spaces in copts",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ description: "cc_library spaces in copts",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
blueprint: soongCcLibraryPreamble + `
cc_library {
name: "a",
@@ -1059,10 +1046,9 @@
func TestCcLibraryCppFlagsGoesIntoCopts(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library cppflags usage",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ description: "cc_library cppflags usage",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
blueprint: soongCcLibraryPreamble + `cc_library {
name: "a",
srcs: ["a.cpp"],
@@ -1104,10 +1090,9 @@
func TestCcLibraryExcludeLibs(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
- filesystem: map[string]string{},
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ filesystem: map[string]string{},
blueprint: soongCcLibraryStaticPreamble + `
cc_library {
name: "foo_static",
@@ -1212,10 +1197,9 @@
func TestCCLibraryNoCrtTrue(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library - nocrt: true emits attribute",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ description: "cc_library - nocrt: true emits attribute",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
filesystem: map[string]string{
"impl.cpp": "",
},
@@ -1237,10 +1221,9 @@
func TestCCLibraryNoCrtFalse(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library - nocrt: false - does not emit attribute",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ description: "cc_library - nocrt: false - does not emit attribute",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
filesystem: map[string]string{
"impl.cpp": "",
},
@@ -1260,10 +1243,9 @@
func TestCCLibraryNoCrtArchVariant(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library - nocrt in select",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ description: "cc_library - nocrt in select",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
filesystem: map[string]string{
"impl.cpp": "",
},
@@ -1288,15 +1270,12 @@
func TestCCLibraryNoLibCrtTrue(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library - simple example",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
filesystem: map[string]string{
"impl.cpp": "",
},
blueprint: soongCcLibraryPreamble + `
-cc_library_headers { name: "some-headers" }
cc_library {
name: "foo-lib",
srcs: ["impl.cpp"],
@@ -1337,14 +1316,12 @@
func TestCCLibraryNoLibCrtFalse(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
filesystem: map[string]string{
"impl.cpp": "",
},
blueprint: soongCcLibraryPreamble + `
-cc_library_headers { name: "some-headers" }
cc_library {
name: "foo-lib",
srcs: ["impl.cpp"],
@@ -1361,9 +1338,8 @@
func TestCCLibraryNoLibCrtArchVariant(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
filesystem: map[string]string{
"impl.cpp": "",
},
@@ -1423,10 +1399,9 @@
expectedTargets = append(expectedTargets, makeCcLibraryTargets("nothing", attrNameToString{})...)
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library strip args",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ description: "cc_library strip args",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
blueprint: soongCcLibraryPreamble + `
cc_library {
name: "nothing",
@@ -1474,10 +1449,9 @@
func TestCcLibraryStripWithArch(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library strip args",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ description: "cc_library strip args",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
blueprint: soongCcLibraryPreamble + `
cc_library {
name: "multi-arch",
@@ -1528,10 +1502,9 @@
func TestCcLibrary_SystemSharedLibsRootEmpty(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library system_shared_libs empty at root",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ description: "cc_library system_shared_libs empty at root",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
blueprint: soongCcLibraryPreamble + `
cc_library {
name: "root_empty",
@@ -1548,10 +1521,9 @@
func TestCcLibrary_SystemSharedLibsStaticEmpty(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library system_shared_libs empty for static variant",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ description: "cc_library system_shared_libs empty for static variant",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
blueprint: soongCcLibraryPreamble + `
cc_library {
name: "static_empty",
@@ -1572,10 +1544,9 @@
func TestCcLibrary_SystemSharedLibsSharedEmpty(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library system_shared_libs empty for shared variant",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ description: "cc_library system_shared_libs empty for shared variant",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
blueprint: soongCcLibraryPreamble + `
cc_library {
name: "shared_empty",
@@ -1596,10 +1567,9 @@
func TestCcLibrary_SystemSharedLibsSharedBionicEmpty(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library system_shared_libs empty for shared, bionic variant",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ description: "cc_library system_shared_libs empty for shared, bionic variant",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
blueprint: soongCcLibraryPreamble + `
cc_library {
name: "shared_empty",
@@ -1628,10 +1598,9 @@
// only for linux_bionic, but `android` had `["libc", "libdl", "libm"].
// b/195791252 tracks the fix.
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library system_shared_libs empty for linux_bionic variant",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ description: "cc_library system_shared_libs empty for linux_bionic variant",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
blueprint: soongCcLibraryPreamble + `
cc_library {
name: "target_linux_bionic_empty",
@@ -1652,10 +1621,9 @@
func TestCcLibrary_SystemSharedLibsBionicEmpty(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library system_shared_libs empty for bionic variant",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ description: "cc_library system_shared_libs empty for bionic variant",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
blueprint: soongCcLibraryPreamble + `
cc_library {
name: "target_bionic_empty",
@@ -1676,10 +1644,9 @@
func TestCcLibrary_SystemSharedLibsSharedAndRoot(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library system_shared_libs set for shared and root",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ description: "cc_library system_shared_libs set for shared and root",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
blueprint: soongCcLibraryPreamble + `
cc_library {
name: "libc",
@@ -1715,13 +1682,11 @@
func TestCcLibraryOsSelects(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library - selects for all os targets",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
- filesystem: map[string]string{},
+ description: "cc_library - selects for all os targets",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ filesystem: map[string]string{},
blueprint: soongCcLibraryPreamble + `
-cc_library_headers { name: "some-headers" }
cc_library {
name: "foo-lib",
srcs: ["base.cpp"],
@@ -1861,10 +1826,9 @@
runCcLibraryTestCase(t, bp2buildTestCase{
description: fmt.Sprintf(
- "cc_library with c_std: %s, cpp_std: %s and gnu_extensions: %s", tc.c_std, tc.cpp_std, tc.gnu_extensions),
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ "cc_library with cpp_std: %s and gnu_extensions: %s", tc.cpp_std, tc.gnu_extensions),
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
blueprint: soongCcLibraryPreamble + fmt.Sprintf(`
cc_library {
name: "%s_full",
@@ -1879,10 +1843,9 @@
runCcLibraryStaticTestCase(t, bp2buildTestCase{
description: fmt.Sprintf(
- "cc_library_static with c_std: %s, cpp_std: %s and gnu_extensions: %s", tc.c_std, tc.cpp_std, tc.gnu_extensions),
- moduleTypeUnderTest: "cc_library_static",
- moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
+ "cc_library_static with cpp_std: %s and gnu_extensions: %s", tc.cpp_std, tc.gnu_extensions),
+ moduleTypeUnderTest: "cc_library_static",
+ moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
blueprint: soongCcLibraryPreamble + fmt.Sprintf(`
cc_library_static {
name: "%s_static",
@@ -1899,10 +1862,9 @@
runCcLibrarySharedTestCase(t, bp2buildTestCase{
description: fmt.Sprintf(
- "cc_library_shared with c_std: %s, cpp_std: %s and gnu_extensions: %s", tc.c_std, tc.cpp_std, tc.gnu_extensions),
- moduleTypeUnderTest: "cc_library_shared",
- moduleTypeUnderTestFactory: cc.LibrarySharedFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibrarySharedBp2Build,
+ "cc_library_shared with cpp_std: %s and gnu_extensions: %s", tc.cpp_std, tc.gnu_extensions),
+ moduleTypeUnderTest: "cc_library_shared",
+ moduleTypeUnderTestFactory: cc.LibrarySharedFactory,
blueprint: soongCcLibraryPreamble + fmt.Sprintf(`
cc_library_shared {
name: "%s_shared",
@@ -1921,9 +1883,8 @@
func TestCcLibraryProtoSimple(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
blueprint: soongCcProtoPreamble + `cc_library {
name: "foo",
srcs: ["foo.proto"],
@@ -1947,9 +1908,8 @@
func TestCcLibraryProtoNoCanonicalPathFromRoot(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
blueprint: soongCcProtoPreamble + `cc_library {
name: "foo",
srcs: ["foo.proto"],
@@ -1973,9 +1933,8 @@
func TestCcLibraryProtoExplicitCanonicalPathFromRoot(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
blueprint: soongCcProtoPreamble + `cc_library {
name: "foo",
srcs: ["foo.proto"],
@@ -2000,9 +1959,8 @@
func TestCcLibraryProtoFull(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
blueprint: soongCcProtoPreamble + `cc_library {
name: "foo",
srcs: ["foo.proto"],
@@ -2029,9 +1987,8 @@
func TestCcLibraryProtoLite(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
blueprint: soongCcProtoPreamble + `cc_library {
name: "foo",
srcs: ["foo.proto"],
@@ -2058,9 +2015,8 @@
func TestCcLibraryProtoExportHeaders(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
blueprint: soongCcProtoPreamble + `cc_library {
name: "foo",
srcs: ["foo.proto"],
diff --git a/bp2build/cc_library_headers_conversion_test.go b/bp2build/cc_library_headers_conversion_test.go
index 76fdab2..594c050 100644
--- a/bp2build/cc_library_headers_conversion_test.go
+++ b/bp2build/cc_library_headers_conversion_test.go
@@ -78,10 +78,9 @@
func TestCcLibraryHeadersSimple(t *testing.T) {
runCcLibraryHeadersTestCase(t, bp2buildTestCase{
- description: "cc_library_headers test",
- moduleTypeUnderTest: "cc_library_headers",
- moduleTypeUnderTestFactory: cc.LibraryHeaderFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryHeadersBp2Build,
+ description: "cc_library_headers test",
+ moduleTypeUnderTest: "cc_library_headers",
+ moduleTypeUnderTestFactory: cc.LibraryHeaderFactory,
filesystem: map[string]string{
"lib-1/lib1a.h": "",
"lib-1/lib1b.h": "",
@@ -150,11 +149,10 @@
func TestCcLibraryHeadersOsSpecificHeader(t *testing.T) {
runCcLibraryHeadersTestCase(t, bp2buildTestCase{
- description: "cc_library_headers test with os-specific header_libs props",
- moduleTypeUnderTest: "cc_library_headers",
- moduleTypeUnderTestFactory: cc.LibraryHeaderFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryHeadersBp2Build,
- filesystem: map[string]string{},
+ description: "cc_library_headers test with os-specific header_libs props",
+ moduleTypeUnderTest: "cc_library_headers",
+ moduleTypeUnderTestFactory: cc.LibraryHeaderFactory,
+ filesystem: map[string]string{},
blueprint: soongCcLibraryPreamble + `
cc_library_headers {
name: "android-lib",
@@ -209,11 +207,10 @@
func TestCcLibraryHeadersOsSpecficHeaderLibsExportHeaderLibHeaders(t *testing.T) {
runCcLibraryHeadersTestCase(t, bp2buildTestCase{
- description: "cc_library_headers test with os-specific header_libs and export_header_lib_headers props",
- moduleTypeUnderTest: "cc_library_headers",
- moduleTypeUnderTestFactory: cc.LibraryHeaderFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryHeadersBp2Build,
- filesystem: map[string]string{},
+ description: "cc_library_headers test with os-specific header_libs and export_header_lib_headers props",
+ moduleTypeUnderTest: "cc_library_headers",
+ moduleTypeUnderTestFactory: cc.LibraryHeaderFactory,
+ filesystem: map[string]string{},
blueprint: soongCcLibraryPreamble + `
cc_library_headers {
name: "android-lib",
@@ -250,11 +247,10 @@
func TestCcLibraryHeadersArchAndTargetExportSystemIncludes(t *testing.T) {
runCcLibraryHeadersTestCase(t, bp2buildTestCase{
- description: "cc_library_headers test with arch-specific and target-specific export_system_include_dirs props",
- moduleTypeUnderTest: "cc_library_headers",
- moduleTypeUnderTestFactory: cc.LibraryHeaderFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryHeadersBp2Build,
- filesystem: map[string]string{},
+ description: "cc_library_headers test with arch-specific and target-specific export_system_include_dirs props",
+ moduleTypeUnderTest: "cc_library_headers",
+ moduleTypeUnderTestFactory: cc.LibraryHeaderFactory,
+ filesystem: map[string]string{},
blueprint: soongCcLibraryPreamble + `cc_library_headers {
name: "foo_headers",
export_system_include_dirs: [
@@ -310,10 +306,9 @@
func TestCcLibraryHeadersNoCrtIgnored(t *testing.T) {
runCcLibraryHeadersTestCase(t, bp2buildTestCase{
- description: "cc_library_headers test",
- moduleTypeUnderTest: "cc_library_headers",
- moduleTypeUnderTestFactory: cc.LibraryHeaderFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryHeadersBp2Build,
+ description: "cc_library_headers test",
+ moduleTypeUnderTest: "cc_library_headers",
+ moduleTypeUnderTestFactory: cc.LibraryHeaderFactory,
filesystem: map[string]string{
"lib-1/lib1a.h": "",
"lib-1/lib1b.h": "",
diff --git a/bp2build/cc_library_shared_conversion_test.go b/bp2build/cc_library_shared_conversion_test.go
index 64f368e..97a600a 100644
--- a/bp2build/cc_library_shared_conversion_test.go
+++ b/bp2build/cc_library_shared_conversion_test.go
@@ -40,7 +40,6 @@
t.Helper()
(&tc).moduleTypeUnderTest = "cc_library_shared"
(&tc).moduleTypeUnderTestFactory = cc.LibrarySharedFactory
- (&tc).moduleTypeUnderTestBp2BuildMutator = cc.CcLibrarySharedBp2Build
runBp2BuildTestCase(t, registerCcLibrarySharedModuleTypes, tc)
}
diff --git a/bp2build/cc_library_static_conversion_test.go b/bp2build/cc_library_static_conversion_test.go
index fff0b4e..e2e55dd 100644
--- a/bp2build/cc_library_static_conversion_test.go
+++ b/bp2build/cc_library_static_conversion_test.go
@@ -82,7 +82,6 @@
(&tc).moduleTypeUnderTest = "cc_library_static"
(&tc).moduleTypeUnderTestFactory = cc.LibraryStaticFactory
- (&tc).moduleTypeUnderTestBp2BuildMutator = cc.CcLibraryStaticBp2Build
runBp2BuildTestCase(t, registerCcLibraryStaticModuleTypes, tc)
}
@@ -954,11 +953,13 @@
genrule {
name: "generated_hdr",
cmd: "nothing to see here",
+ bazel_module: { bp2build_available: false },
}
genrule {
name: "export_generated_hdr",
cmd: "nothing to see here",
+ bazel_module: { bp2build_available: false },
}
cc_library_static {
@@ -998,48 +999,17 @@
"for-x86.cpp": "",
"not-for-x86.cpp": "",
"not-for-everything.cpp": "",
- "dep/Android.bp": `
-genrule {
- name: "generated_src_other_pkg",
- cmd: "nothing to see here",
-}
-
-genrule {
- name: "generated_hdr_other_pkg",
- cmd: "nothing to see here",
-}
-
-genrule {
- name: "generated_hdr_other_pkg_x86",
- cmd: "nothing to see here",
-}
-
-genrule {
- name: "generated_hdr_other_pkg_android",
- cmd: "nothing to see here",
-}`,
+ "dep/Android.bp": simpleModuleDoNotConvertBp2build("genrule", "generated_src_other_pkg") +
+ simpleModuleDoNotConvertBp2build("genrule", "generated_hdr_other_pkg") +
+ simpleModuleDoNotConvertBp2build("genrule", "generated_src_other_pkg_x86") +
+ simpleModuleDoNotConvertBp2build("genrule", "generated_hdr_other_pkg_x86") +
+ simpleModuleDoNotConvertBp2build("genrule", "generated_hdr_other_pkg_android"),
},
- blueprint: soongCcLibraryStaticPreamble + `
-genrule {
- name: "generated_src",
- cmd: "nothing to see here",
-}
-
-genrule {
- name: "generated_src_not_x86",
- cmd: "nothing to see here",
-}
-
-genrule {
- name: "generated_src_android",
- cmd: "nothing to see here",
-}
-
-genrule {
- name: "generated_hdr",
- cmd: "nothing to see here",
-}
-
+ blueprint: soongCcLibraryStaticPreamble +
+ simpleModuleDoNotConvertBp2build("genrule", "generated_src") +
+ simpleModuleDoNotConvertBp2build("genrule", "generated_src_not_x86") +
+ simpleModuleDoNotConvertBp2build("genrule", "generated_src_android") +
+ simpleModuleDoNotConvertBp2build("genrule", "generated_hdr") + `
cc_library_static {
name: "foo_static",
srcs: ["common.cpp", "not-for-*.cpp"],
@@ -1373,9 +1343,8 @@
func TestStaticLibrary_SystemSharedLibsBionic(t *testing.T) {
runCcLibraryStaticTestCase(t, bp2buildTestCase{
description: "cc_library_static system_shared_libs set for bionic variant",
- blueprint: soongCcLibraryStaticPreamble + `
-cc_library{name: "libc"}
-
+ blueprint: soongCcLibraryStaticPreamble +
+ simpleModuleDoNotConvertBp2build("cc_library", "libc") + `
cc_library_static {
name: "target_bionic",
target: {
@@ -1401,10 +1370,9 @@
func TestStaticLibrary_SystemSharedLibsLinuxRootAndLinuxBionic(t *testing.T) {
runCcLibraryStaticTestCase(t, bp2buildTestCase{
description: "cc_library_static system_shared_libs set for root and linux_bionic variant",
- blueprint: soongCcLibraryStaticPreamble + `
-cc_library{name: "libc"}
-cc_library{name: "libm"}
-
+ blueprint: soongCcLibraryStaticPreamble +
+ simpleModuleDoNotConvertBp2build("cc_library", "libc") +
+ simpleModuleDoNotConvertBp2build("cc_library", "libm") + `
cc_library_static {
name: "target_linux_bionic",
system_shared_libs: ["libc"],
diff --git a/bp2build/cc_object_conversion_test.go b/bp2build/cc_object_conversion_test.go
index 5ab9129..0a6c317 100644
--- a/bp2build/cc_object_conversion_test.go
+++ b/bp2build/cc_object_conversion_test.go
@@ -30,7 +30,6 @@
t.Helper()
(&tc).moduleTypeUnderTest = "cc_object"
(&tc).moduleTypeUnderTestFactory = cc.ObjectFactory
- (&tc).moduleTypeUnderTestBp2BuildMutator = cc.ObjectBp2Build
runBp2BuildTestCase(t, registerCcObjectModuleTypes, tc)
}
diff --git a/bp2build/cc_prebuilt_library_shared_test.go b/bp2build/cc_prebuilt_library_shared_test.go
index bac3908..ef2fddc 100644
--- a/bp2build/cc_prebuilt_library_shared_test.go
+++ b/bp2build/cc_prebuilt_library_shared_test.go
@@ -9,10 +9,9 @@
func TestSharedPrebuiltLibrary(t *testing.T) {
runBp2BuildTestCaseSimple(t,
bp2buildTestCase{
- description: "prebuilt library shared simple",
- moduleTypeUnderTest: "cc_prebuilt_library_shared",
- moduleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.PrebuiltLibrarySharedBp2Build,
+ description: "prebuilt library shared simple",
+ moduleTypeUnderTest: "cc_prebuilt_library_shared",
+ moduleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory,
filesystem: map[string]string{
"libf.so": "",
},
@@ -33,10 +32,9 @@
func TestSharedPrebuiltLibraryWithArchVariance(t *testing.T) {
runBp2BuildTestCaseSimple(t,
bp2buildTestCase{
- description: "prebuilt library shared with arch variance",
- moduleTypeUnderTest: "cc_prebuilt_library_shared",
- moduleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.PrebuiltLibrarySharedBp2Build,
+ description: "prebuilt library shared with arch variance",
+ moduleTypeUnderTest: "cc_prebuilt_library_shared",
+ moduleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory,
filesystem: map[string]string{
"libf.so": "",
"libg.so": "",
diff --git a/bp2build/filegroup_conversion_test.go b/bp2build/filegroup_conversion_test.go
index 9f4add2..b43cf53 100644
--- a/bp2build/filegroup_conversion_test.go
+++ b/bp2build/filegroup_conversion_test.go
@@ -25,7 +25,6 @@
t.Helper()
(&tc).moduleTypeUnderTest = "filegroup"
(&tc).moduleTypeUnderTestFactory = android.FileGroupFactory
- (&tc).moduleTypeUnderTestBp2BuildMutator = android.FilegroupBp2Build
runBp2BuildTestCase(t, registerFilegroupModuleTypes, tc)
}
diff --git a/bp2build/genrule_conversion_test.go b/bp2build/genrule_conversion_test.go
index 5976666..fd631a5 100644
--- a/bp2build/genrule_conversion_test.go
+++ b/bp2build/genrule_conversion_test.go
@@ -28,7 +28,6 @@
t.Helper()
(&tc).moduleTypeUnderTest = "genrule"
(&tc).moduleTypeUnderTestFactory = genrule.GenRuleFactory
- (&tc).moduleTypeUnderTestBp2BuildMutator = genrule.GenruleBp2Build
runBp2BuildTestCase(t, registerGenruleModuleTypes, tc)
}
diff --git a/bp2build/prebuilt_etc_conversion_test.go b/bp2build/prebuilt_etc_conversion_test.go
index 1189309..5065893 100644
--- a/bp2build/prebuilt_etc_conversion_test.go
+++ b/bp2build/prebuilt_etc_conversion_test.go
@@ -25,7 +25,6 @@
t.Helper()
(&tc).moduleTypeUnderTest = "prebuilt_etc"
(&tc).moduleTypeUnderTestFactory = etc.PrebuiltEtcFactory
- (&tc).moduleTypeUnderTestBp2BuildMutator = etc.PrebuiltEtcBp2Build
runBp2BuildTestCase(t, registerPrebuiltEtcModuleTypes, tc)
}
diff --git a/bp2build/python_binary_conversion_test.go b/bp2build/python_binary_conversion_test.go
index 01b6aa2..40c8ba1 100644
--- a/bp2build/python_binary_conversion_test.go
+++ b/bp2build/python_binary_conversion_test.go
@@ -17,10 +17,9 @@
func TestPythonBinaryHostSimple(t *testing.T) {
runBp2BuildTestCaseWithPythonLibraries(t, bp2buildTestCase{
- description: "simple python_binary_host converts to a native py_binary",
- moduleTypeUnderTest: "python_binary_host",
- moduleTypeUnderTestFactory: python.PythonBinaryHostFactory,
- moduleTypeUnderTestBp2BuildMutator: python.PythonBinaryBp2Build,
+ description: "simple python_binary_host converts to a native py_binary",
+ moduleTypeUnderTest: "python_binary_host",
+ moduleTypeUnderTestFactory: python.PythonBinaryHostFactory,
filesystem: map[string]string{
"a.py": "",
"b/c.py": "",
@@ -40,7 +39,7 @@
python_library_host {
name: "bar",
srcs: ["b/e.py"],
- bazel_module: { bp2build_available: true },
+ bazel_module: { bp2build_available: false },
}`,
expectedBazelTargets: []string{
makeBazelTarget("py_binary", "foo", attrNameToString{
@@ -59,10 +58,9 @@
func TestPythonBinaryHostPy2(t *testing.T) {
runBp2BuildTestCaseSimple(t, bp2buildTestCase{
- description: "py2 python_binary_host",
- moduleTypeUnderTest: "python_binary_host",
- moduleTypeUnderTestFactory: python.PythonBinaryHostFactory,
- moduleTypeUnderTestBp2BuildMutator: python.PythonBinaryBp2Build,
+ description: "py2 python_binary_host",
+ moduleTypeUnderTest: "python_binary_host",
+ moduleTypeUnderTestFactory: python.PythonBinaryHostFactory,
blueprint: `python_binary_host {
name: "foo",
srcs: ["a.py"],
@@ -89,10 +87,9 @@
func TestPythonBinaryHostPy3(t *testing.T) {
runBp2BuildTestCaseSimple(t, bp2buildTestCase{
- description: "py3 python_binary_host",
- moduleTypeUnderTest: "python_binary_host",
- moduleTypeUnderTestFactory: python.PythonBinaryHostFactory,
- moduleTypeUnderTestBp2BuildMutator: python.PythonBinaryBp2Build,
+ description: "py3 python_binary_host",
+ moduleTypeUnderTest: "python_binary_host",
+ moduleTypeUnderTestFactory: python.PythonBinaryHostFactory,
blueprint: `python_binary_host {
name: "foo",
srcs: ["a.py"],
@@ -119,10 +116,9 @@
func TestPythonBinaryHostArchVariance(t *testing.T) {
runBp2BuildTestCaseSimple(t, bp2buildTestCase{
- description: "test arch variants",
- moduleTypeUnderTest: "python_binary_host",
- moduleTypeUnderTestFactory: python.PythonBinaryHostFactory,
- moduleTypeUnderTestBp2BuildMutator: python.PythonBinaryBp2Build,
+ description: "test arch variants",
+ moduleTypeUnderTest: "python_binary_host",
+ moduleTypeUnderTestFactory: python.PythonBinaryHostFactory,
filesystem: map[string]string{
"dir/arm.py": "",
"dir/x86.py": "",
diff --git a/bp2build/python_library_conversion_test.go b/bp2build/python_library_conversion_test.go
index e334592..6b26105 100644
--- a/bp2build/python_library_conversion_test.go
+++ b/bp2build/python_library_conversion_test.go
@@ -18,7 +18,6 @@
testCase.blueprint = fmt.Sprintf(testCase.blueprint, "python_library")
testCase.moduleTypeUnderTest = "python_library"
testCase.moduleTypeUnderTestFactory = python.PythonLibraryFactory
- testCase.moduleTypeUnderTestBp2BuildMutator = python.PythonLibraryBp2Build
runBp2BuildTestCaseSimple(t, testCase)
}
@@ -29,7 +28,6 @@
testCase.blueprint = fmt.Sprintf(testCase.blueprint, "python_library_host")
testCase.moduleTypeUnderTest = "python_library_host"
testCase.moduleTypeUnderTestFactory = python.PythonLibraryHostFactory
- testCase.moduleTypeUnderTestBp2BuildMutator = python.PythonLibraryHostBp2Build
runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("python_library", python.PythonLibraryFactory)
},
diff --git a/bp2build/sh_conversion_test.go b/bp2build/sh_conversion_test.go
index 0d87c8d..f6d2a20 100644
--- a/bp2build/sh_conversion_test.go
+++ b/bp2build/sh_conversion_test.go
@@ -55,10 +55,9 @@
func TestShBinarySimple(t *testing.T) {
runShBinaryTestCase(t, bp2buildTestCase{
- description: "sh_binary test",
- moduleTypeUnderTest: "sh_binary",
- moduleTypeUnderTestFactory: sh.ShBinaryFactory,
- moduleTypeUnderTestBp2BuildMutator: sh.ShBinaryBp2Build,
+ description: "sh_binary test",
+ moduleTypeUnderTest: "sh_binary",
+ moduleTypeUnderTestFactory: sh.ShBinaryFactory,
blueprint: `sh_binary {
name: "foo",
src: "foo.sh",
diff --git a/bp2build/soong_config_module_type_conversion_test.go b/bp2build/soong_config_module_type_conversion_test.go
index d21db04..f1489aa 100644
--- a/bp2build/soong_config_module_type_conversion_test.go
+++ b/bp2build/soong_config_module_type_conversion_test.go
@@ -61,11 +61,10 @@
`
runSoongConfigModuleTypeTest(t, bp2buildTestCase{
- description: "soong config variables - soong_config_module_type is supported in bp2build",
- moduleTypeUnderTest: "cc_library_static",
- moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- blueprint: bp,
+ description: "soong config variables - soong_config_module_type is supported in bp2build",
+ moduleTypeUnderTest: "cc_library_static",
+ moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
+ blueprint: bp,
expectedBazelTargets: []string{`cc_library_static(
name = "foo",
copts = select({
@@ -107,10 +106,9 @@
`
runSoongConfigModuleTypeTest(t, bp2buildTestCase{
- description: "soong config variables - soong_config_module_type_import is supported in bp2build",
- moduleTypeUnderTest: "cc_library_static",
- moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
+ description: "soong config variables - soong_config_module_type_import is supported in bp2build",
+ moduleTypeUnderTest: "cc_library_static",
+ moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
filesystem: map[string]string{
"foo/bar/SoongConfig.bp": configBp,
},
@@ -161,11 +159,10 @@
`
runSoongConfigModuleTypeTest(t, bp2buildTestCase{
- description: "soong config variables - generates selects for string vars",
- moduleTypeUnderTest: "cc_library_static",
- moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- blueprint: bp,
+ description: "soong config variables - generates selects for string vars",
+ moduleTypeUnderTest: "cc_library_static",
+ moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
+ blueprint: bp,
expectedBazelTargets: []string{`cc_library_static(
name = "foo",
copts = select({
@@ -232,11 +229,10 @@
}`
runSoongConfigModuleTypeTest(t, bp2buildTestCase{
- description: "soong config variables - generates selects for multiple variable types",
- moduleTypeUnderTest: "cc_library_static",
- moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- blueprint: bp,
+ description: "soong config variables - generates selects for multiple variable types",
+ moduleTypeUnderTest: "cc_library_static",
+ moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
+ blueprint: bp,
expectedBazelTargets: []string{`cc_library_static(
name = "foo",
copts = select({
@@ -298,11 +294,10 @@
`
runSoongConfigModuleTypeTest(t, bp2buildTestCase{
- description: "soong config variables - generates selects for label list attributes",
- moduleTypeUnderTest: "cc_library_static",
- moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- blueprint: bp,
+ description: "soong config variables - generates selects for label list attributes",
+ moduleTypeUnderTest: "cc_library_static",
+ moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
+ blueprint: bp,
filesystem: map[string]string{
"foo/bar/Android.bp": otherDeps,
},
@@ -365,11 +360,10 @@
`
runSoongConfigModuleTypeTest(t, bp2buildTestCase{
- description: "soong config variables - defaults with a single namespace",
- moduleTypeUnderTest: "cc_library_static",
- moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- blueprint: bp,
+ description: "soong config variables - defaults with a single namespace",
+ moduleTypeUnderTest: "cc_library_static",
+ moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
+ blueprint: bp,
expectedBazelTargets: []string{`cc_library_static(
name = "lib",
copts = select({
@@ -445,11 +439,10 @@
`
runSoongConfigModuleTypeTest(t, bp2buildTestCase{
- description: "soong config variables - multiple defaults with a single namespace",
- moduleTypeUnderTest: "cc_library_static",
- moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- blueprint: bp,
+ description: "soong config variables - multiple defaults with a single namespace",
+ moduleTypeUnderTest: "cc_library_static",
+ moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
+ blueprint: bp,
expectedBazelTargets: []string{`cc_library_static(
name = "lib",
asflags = select({
@@ -561,11 +554,10 @@
`
runSoongConfigModuleTypeTest(t, bp2buildTestCase{
- description: "soong config variables - defaults with multiple namespaces",
- moduleTypeUnderTest: "cc_library_static",
- moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
- blueprint: bp,
+ description: "soong config variables - defaults with multiple namespaces",
+ moduleTypeUnderTest: "cc_library_static",
+ moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
+ blueprint: bp,
expectedBazelTargets: []string{`cc_library_static(
name = "lib",
copts = select({
@@ -652,11 +644,10 @@
`
runSoongConfigModuleTypeTest(t, bp2buildTestCase{
- description: "soong config variables - generates selects for library_linking_strategy",
- moduleTypeUnderTest: "cc_binary",
- moduleTypeUnderTestFactory: cc.BinaryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.BinaryBp2build,
- blueprint: bp,
+ description: "soong config variables - generates selects for library_linking_strategy",
+ moduleTypeUnderTest: "cc_binary",
+ moduleTypeUnderTestFactory: cc.BinaryFactory,
+ blueprint: bp,
filesystem: map[string]string{
"foo/bar/Android.bp": otherDeps,
},
@@ -733,11 +724,10 @@
`
runSoongConfigModuleTypeTest(t, bp2buildTestCase{
- description: "soong config variables - generates selects for library_linking_strategy",
- moduleTypeUnderTest: "cc_binary",
- moduleTypeUnderTestFactory: cc.BinaryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.BinaryBp2build,
- blueprint: bp,
+ description: "soong config variables - generates selects for library_linking_strategy",
+ moduleTypeUnderTest: "cc_binary",
+ moduleTypeUnderTestFactory: cc.BinaryFactory,
+ blueprint: bp,
filesystem: map[string]string{
"foo/bar/Android.bp": otherDeps,
},
@@ -821,11 +811,10 @@
`
runSoongConfigModuleTypeTest(t, bp2buildTestCase{
- description: "soong config variables - generates selects for library_linking_strategy",
- moduleTypeUnderTest: "cc_binary",
- moduleTypeUnderTestFactory: cc.BinaryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.BinaryBp2build,
- blueprint: bp,
+ description: "soong config variables - generates selects for library_linking_strategy",
+ moduleTypeUnderTest: "cc_binary",
+ moduleTypeUnderTestFactory: cc.BinaryFactory,
+ blueprint: bp,
filesystem: map[string]string{
"foo/bar/Android.bp": otherDeps,
},
diff --git a/bp2build/testing.go b/bp2build/testing.go
index cd84519..15cf486 100644
--- a/bp2build/testing.go
+++ b/bp2build/testing.go
@@ -74,16 +74,15 @@
}
type bp2buildTestCase struct {
- description string
- moduleTypeUnderTest string
- moduleTypeUnderTestFactory android.ModuleFactory
- moduleTypeUnderTestBp2BuildMutator func(android.TopDownMutatorContext)
- blueprint string
- expectedBazelTargets []string
- filesystem map[string]string
- dir string
- expectedErr error
- unconvertedDepsMode unconvertedDepsMode
+ description string
+ moduleTypeUnderTest string
+ moduleTypeUnderTestFactory android.ModuleFactory
+ blueprint string
+ expectedBazelTargets []string
+ filesystem map[string]string
+ dir string
+ expectedErr error
+ unconvertedDepsMode unconvertedDepsMode
}
func runBp2BuildTestCase(t *testing.T, registerModuleTypes func(ctx android.RegistrationContext), tc bp2buildTestCase) {
@@ -105,7 +104,6 @@
registerModuleTypes(ctx)
ctx.RegisterModuleType(tc.moduleTypeUnderTest, tc.moduleTypeUnderTestFactory)
ctx.RegisterBp2BuildConfig(bp2buildConfig)
- ctx.RegisterBp2BuildMutator(tc.moduleTypeUnderTest, tc.moduleTypeUnderTestBp2BuildMutator)
ctx.RegisterForBazelConversion()
_, parseErrs := ctx.ParseFileList(dir, toParse)
@@ -178,6 +176,9 @@
Arch_paths []string `android:"path,arch_variant"`
Arch_paths_exclude []string `android:"path,arch_variant"`
+
+ // Prop used to indicate this conversion should be 1 module -> multiple targets
+ One_to_many_prop *bool
}
type customModule struct {
@@ -277,71 +278,65 @@
Arch_paths bazel.LabelListAttribute
}
-func customBp2BuildMutator(ctx android.TopDownMutatorContext) {
- if m, ok := ctx.Module().(*customModule); ok {
- if !m.ConvertWithBp2build(ctx) {
- return
- }
+func (m *customModule) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
+ paths := bazel.LabelListAttribute{}
- paths := bazel.LabelListAttribute{}
+ if p := m.props.One_to_many_prop; p != nil && *p {
+ customBp2buildOneToMany(ctx, m)
+ return
+ }
- for axis, configToProps := range m.GetArchVariantProperties(ctx, &customProps{}) {
- for config, props := range configToProps {
- if archProps, ok := props.(*customProps); ok && archProps.Arch_paths != nil {
- paths.SetSelectValue(axis, config, android.BazelLabelForModuleSrcExcludes(ctx, archProps.Arch_paths, archProps.Arch_paths_exclude))
- }
+ for axis, configToProps := range m.GetArchVariantProperties(ctx, &customProps{}) {
+ for config, props := range configToProps {
+ if archProps, ok := props.(*customProps); ok && archProps.Arch_paths != nil {
+ paths.SetSelectValue(axis, config, android.BazelLabelForModuleSrcExcludes(ctx, archProps.Arch_paths, archProps.Arch_paths_exclude))
}
}
-
- paths.ResolveExcludes()
-
- attrs := &customBazelModuleAttributes{
- String_ptr_prop: m.props.String_ptr_prop,
- String_list_prop: m.props.String_list_prop,
- Arch_paths: paths,
- }
- attrs.Embedded_attr = m.props.Embedded_prop
- if m.props.OtherEmbeddedProps != nil {
- attrs.OtherEmbeddedAttr = &OtherEmbeddedAttr{Other_embedded_attr: m.props.OtherEmbeddedProps.Other_embedded_prop}
- }
-
- props := bazel.BazelTargetModuleProperties{
- Rule_class: "custom",
- }
-
- ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs)
}
+
+ paths.ResolveExcludes()
+
+ attrs := &customBazelModuleAttributes{
+ String_ptr_prop: m.props.String_ptr_prop,
+ String_list_prop: m.props.String_list_prop,
+ Arch_paths: paths,
+ }
+ attrs.Embedded_attr = m.props.Embedded_prop
+ if m.props.OtherEmbeddedProps != nil {
+ attrs.OtherEmbeddedAttr = &OtherEmbeddedAttr{Other_embedded_attr: m.props.OtherEmbeddedProps.Other_embedded_prop}
+ }
+
+ props := bazel.BazelTargetModuleProperties{
+ Rule_class: "custom",
+ }
+
+ ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs)
}
// A bp2build mutator that uses load statements and creates a 1:M mapping from
// module to target.
-func customBp2BuildMutatorFromStarlark(ctx android.TopDownMutatorContext) {
- if m, ok := ctx.Module().(*customModule); ok {
- if !m.ConvertWithBp2build(ctx) {
- return
- }
+func customBp2buildOneToMany(ctx android.TopDownMutatorContext, m *customModule) {
- baseName := m.Name()
- attrs := &customBazelModuleAttributes{}
+ baseName := m.Name()
+ attrs := &customBazelModuleAttributes{}
- myLibraryProps := bazel.BazelTargetModuleProperties{
- Rule_class: "my_library",
- Bzl_load_location: "//build/bazel/rules:rules.bzl",
- }
- ctx.CreateBazelTargetModule(myLibraryProps, android.CommonAttributes{Name: baseName}, attrs)
-
- protoLibraryProps := bazel.BazelTargetModuleProperties{
- Rule_class: "proto_library",
- Bzl_load_location: "//build/bazel/rules:proto.bzl",
- }
- ctx.CreateBazelTargetModule(protoLibraryProps, android.CommonAttributes{Name: baseName + "_proto_library_deps"}, attrs)
-
- myProtoLibraryProps := bazel.BazelTargetModuleProperties{
- Rule_class: "my_proto_library",
- Bzl_load_location: "//build/bazel/rules:proto.bzl",
- }
- ctx.CreateBazelTargetModule(myProtoLibraryProps, android.CommonAttributes{Name: baseName + "_my_proto_library_deps"}, attrs)
+ myLibraryProps := bazel.BazelTargetModuleProperties{
+ Rule_class: "my_library",
+ Bzl_load_location: "//build/bazel/rules:rules.bzl",
}
+ ctx.CreateBazelTargetModule(myLibraryProps, android.CommonAttributes{Name: baseName}, attrs)
+
+ protoLibraryProps := bazel.BazelTargetModuleProperties{
+ Rule_class: "proto_library",
+ Bzl_load_location: "//build/bazel/rules:proto.bzl",
+ }
+ ctx.CreateBazelTargetModule(protoLibraryProps, android.CommonAttributes{Name: baseName + "_proto_library_deps"}, attrs)
+
+ myProtoLibraryProps := bazel.BazelTargetModuleProperties{
+ Rule_class: "my_proto_library",
+ Bzl_load_location: "//build/bazel/rules:proto.bzl",
+ }
+ ctx.CreateBazelTargetModule(myProtoLibraryProps, android.CommonAttributes{Name: baseName + "_my_proto_library_deps"}, attrs)
}
// Helper method for tests to easily access the targets in a dir.
@@ -353,7 +348,6 @@
func registerCustomModuleForBp2buildConversion(ctx *android.TestContext) {
ctx.RegisterModuleType("custom", customModuleFactory)
- ctx.RegisterBp2BuildMutator("custom", customBp2BuildMutator)
ctx.RegisterForBazelConversion()
}
diff --git a/cc/binary.go b/cc/binary.go
index e839122..50175d9 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -69,13 +69,14 @@
// cc_binary produces a binary that is runnable on a device.
func BinaryFactory() android.Module {
- module, _ := NewBinary(android.HostAndDeviceSupported)
+ module, _ := newBinary(android.HostAndDeviceSupported, true)
return module.Init()
}
// cc_binary_host produces a binary that is runnable on a host.
func BinaryHostFactory() android.Module {
- module, _ := NewBinary(android.HostSupported)
+ module, _ := newBinary(android.HostSupported, true)
+ module.bazelable = true
return module.Init()
}
@@ -193,6 +194,10 @@
// Individual module implementations which comprise a C++ binary should call this function,
// set some fields on the result, and then call the Init function.
func NewBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) {
+ return newBinary(hod, true)
+}
+
+func newBinary(hod android.HostOrDeviceSupported, bazelable bool) (*Module, *binaryDecorator) {
module := newModule(hod, android.MultilibFirst)
binary := &binaryDecorator{
baseLinker: NewBaseLinker(module.sanitize),
@@ -201,6 +206,7 @@
module.compiler = NewBaseCompiler()
module.linker = binary
module.installer = binary
+ module.bazelable = bazelable
// Allow module to be added as member of an sdk/module_exports.
module.sdkMemberTypes = []android.SdkMemberType{
@@ -551,33 +557,7 @@
})
}
-func init() {
- android.RegisterBp2BuildMutator("cc_binary", BinaryBp2build)
- android.RegisterBp2BuildMutator("cc_binary_host", BinaryHostBp2build)
-}
-
-func BinaryBp2build(ctx android.TopDownMutatorContext) {
- binaryBp2build(ctx, "cc_binary")
-}
-
-func BinaryHostBp2build(ctx android.TopDownMutatorContext) {
- binaryBp2build(ctx, "cc_binary_host")
-}
-
-func binaryBp2build(ctx android.TopDownMutatorContext, typ string) {
- m, ok := ctx.Module().(*Module)
- if !ok {
- // Not a cc module
- return
- }
- if !m.ConvertWithBp2build(ctx) {
- return
- }
-
- if ctx.ModuleType() != typ {
- return
- }
-
+func binaryBp2build(ctx android.TopDownMutatorContext, m *Module, typ string) {
var compatibleWith bazel.StringListAttribute
if typ == "cc_binary_host" {
//incompatible with android OS
diff --git a/cc/cc.go b/cc/cc.go
index 39fdcb7..0904bd9 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -786,8 +786,9 @@
Properties BaseProperties
// initialize before calling Init
- hod android.HostOrDeviceSupported
- multilib android.Multilib
+ hod android.HostOrDeviceSupported
+ multilib android.Multilib
+ bazelable bool
// Allowable SdkMemberTypes of this module type.
sdkMemberTypes []android.SdkMemberType
@@ -1150,7 +1151,9 @@
}
android.InitAndroidArchModule(c, c.hod, c.multilib)
- android.InitBazelModule(c)
+ if c.bazelable {
+ android.InitBazelModule(c)
+ }
android.InitApexModule(c)
android.InitSdkAwareModule(c)
android.InitDefaultableModule(c)
@@ -3185,6 +3188,24 @@
return false
}
+func (c *Module) benchmarkBinary() bool {
+ if b, ok := c.linker.(interface {
+ benchmarkBinary() bool
+ }); ok {
+ return b.benchmarkBinary()
+ }
+ return false
+}
+
+func (c *Module) fuzzBinary() bool {
+ if f, ok := c.linker.(interface {
+ fuzzBinary() bool
+ }); ok {
+ return f.fuzzBinary()
+ }
+ return false
+}
+
// Header returns true if the module is a header-only variant. (See cc/library.go header()).
func (c *Module) Header() bool {
if h, ok := c.linker.(interface {
@@ -3430,6 +3451,41 @@
var _ snapshot.RelativeInstallPath = (*Module)(nil)
+// ConvertWithBp2build converts Module to Bazel for bp2build.
+func (c *Module) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
+ if c.Binary() {
+ binaryBp2build(ctx, c, ctx.ModuleType())
+ } else if c.Object() {
+ objectBp2Build(ctx, c)
+ } else if c.CcLibrary() {
+ if c.hod == android.HostSupported {
+ return
+ }
+
+ static := c.BuildStaticVariant()
+ shared := c.BuildSharedVariant()
+ prebuilt := c.IsPrebuilt()
+
+ if static && shared {
+ libraryBp2Build(ctx, c)
+ } else if !static && !shared {
+ libraryHeadersBp2Build(ctx, c)
+ } else if static {
+ if prebuilt {
+ prebuiltLibraryStaticBp2Build(ctx, c)
+ } else {
+ sharedOrStaticLibraryBp2Build(ctx, c, true)
+ }
+ } else if shared {
+ if prebuilt {
+ prebuiltLibrarySharedBp2Build(ctx, c)
+ } else {
+ sharedOrStaticLibraryBp2Build(ctx, c, false)
+ }
+ }
+ }
+}
+
//
// Defaults
//
diff --git a/cc/fuzz.go b/cc/fuzz.go
index e987fe4..23d81d6 100644
--- a/cc/fuzz.go
+++ b/cc/fuzz.go
@@ -52,6 +52,10 @@
installedSharedDeps []string
}
+func (fuzz *fuzzBinary) fuzzBinary() bool {
+ return true
+}
+
func (fuzz *fuzzBinary) linkerProps() []interface{} {
props := fuzz.binaryDecorator.linkerProps()
props = append(props, &fuzz.fuzzPackagedModule.FuzzProperties)
@@ -234,7 +238,7 @@
}
func NewFuzz(hod android.HostOrDeviceSupported) *Module {
- module, binary := NewBinary(hod)
+ module, binary := newBinary(hod, false)
binary.baseInstaller = NewFuzzInstaller()
module.sanitize.SetSanitizer(Fuzzer, true)
diff --git a/cc/library.go b/cc/library.go
index 15c4ec3..aec699c 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -207,10 +207,6 @@
func init() {
RegisterLibraryBuildComponents(android.InitRegistrationContext)
-
- android.RegisterBp2BuildMutator("cc_library_static", CcLibraryStaticBp2Build)
- android.RegisterBp2BuildMutator("cc_library_shared", CcLibrarySharedBp2Build)
- android.RegisterBp2BuildMutator("cc_library", CcLibraryBp2Build)
}
func RegisterLibraryBuildComponents(ctx android.RegistrationContext) {
@@ -277,21 +273,12 @@
None bazel.BoolAttribute
}
-func CcLibraryBp2Build(ctx android.TopDownMutatorContext) {
- m, ok := ctx.Module().(*Module)
- if !ok || !m.ConvertWithBp2build(ctx) {
- return
- }
-
- if ctx.ModuleType() != "cc_library" {
- return
- }
-
+func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) {
// For some cc_library modules, their static variants are ready to be
// converted, but not their shared variants. For these modules, delegate to
// the cc_library_static bp2build converter temporarily instead.
if android.GenerateCcLibraryStaticOnly(ctx.Module().Name()) {
- ccSharedOrStaticBp2BuildMutatorInternal(ctx, m, "cc_library_static")
+ sharedOrStaticLibraryBp2Build(ctx, m, true)
return
}
@@ -421,6 +408,7 @@
staticLibrarySdkMemberType,
staticAndSharedLibrarySdkMemberType,
}
+ module.bazelable = true
module.bazelHandler = &ccLibraryBazelHandler{module: module}
return module.Init()
}
@@ -430,6 +418,7 @@
module, library := NewLibrary(android.HostAndDeviceSupported)
library.BuildOnlyStatic()
module.sdkMemberTypes = []android.SdkMemberType{staticLibrarySdkMemberType}
+ module.bazelable = true
module.bazelHandler = &ccLibraryBazelHandler{module: module}
return module.Init()
}
@@ -439,6 +428,7 @@
module, library := NewLibrary(android.HostAndDeviceSupported)
library.BuildOnlyShared()
module.sdkMemberTypes = []android.SdkMemberType{sharedLibrarySdkMemberType}
+ module.bazelable = true
module.bazelHandler = &ccLibraryBazelHandler{module: module}
return module.Init()
}
@@ -2413,25 +2403,7 @@
return outputFile
}
-func ccSharedOrStaticBp2BuildMutator(ctx android.TopDownMutatorContext, modType string) {
- module, ok := ctx.Module().(*Module)
- if !ok {
- // Not a cc module
- return
- }
- if !module.ConvertWithBp2build(ctx) {
- return
- }
-
- ccSharedOrStaticBp2BuildMutatorInternal(ctx, module, modType)
-}
-
-func ccSharedOrStaticBp2BuildMutatorInternal(ctx android.TopDownMutatorContext, module *Module, modType string) {
- if modType != "cc_library_static" && modType != "cc_library_shared" {
- panic("ccSharedOrStaticBp2BuildMutatorInternal only supports cc_library_{static,shared}")
- }
- isStatic := modType == "cc_library_static"
-
+func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Module, isStatic bool) {
baseAttributes := bp2BuildParseBaseProps(ctx, module)
compilerAttrs := baseAttributes.compilerAttributes
linkerAttrs := baseAttributes.linkerAttributes
@@ -2541,6 +2513,12 @@
}
}
+ var modType string
+ if isStatic {
+ modType = "cc_library_static"
+ } else {
+ modType = "cc_library_shared"
+ }
props := bazel.BazelTargetModuleProperties{
Rule_class: modType,
Bzl_load_location: fmt.Sprintf("//build/bazel/rules:%s.bzl", modType),
@@ -2575,18 +2553,6 @@
Features bazel.StringListAttribute
}
-func CcLibraryStaticBp2Build(ctx android.TopDownMutatorContext) {
- isLibraryStatic := ctx.ModuleType() == "cc_library_static"
- if b, ok := ctx.Module().(android.Bazelable); ok {
- // This is created by a custom soong config module type, so its ctx.ModuleType() is not
- // cc_library_static. Check its BaseModuleType.
- isLibraryStatic = isLibraryStatic || b.BaseModuleType() == "cc_library_static"
- }
- if isLibraryStatic {
- ccSharedOrStaticBp2BuildMutator(ctx, "cc_library_static")
- }
-}
-
// TODO(b/199902614): Can this be factored to share with the other Attributes?
type bazelCcLibrarySharedAttributes struct {
staticOrSharedAttributes
@@ -2618,15 +2584,3 @@
Features bazel.StringListAttribute
}
-
-func CcLibrarySharedBp2Build(ctx android.TopDownMutatorContext) {
- isLibraryShared := ctx.ModuleType() == "cc_library_shared"
- if b, ok := ctx.Module().(android.Bazelable); ok {
- // This is created by a custom soong config module type, so its ctx.ModuleType() is not
- // cc_library_shared. Check its BaseModuleType.
- isLibraryShared = isLibraryShared || b.BaseModuleType() == "cc_library_shared"
- }
- if isLibraryShared {
- ccSharedOrStaticBp2BuildMutator(ctx, "cc_library_shared")
- }
-}
diff --git a/cc/library_headers.go b/cc/library_headers.go
index ce8c391..70e4715 100644
--- a/cc/library_headers.go
+++ b/cc/library_headers.go
@@ -25,7 +25,6 @@
// Register sdk member types.
android.RegisterSdkMemberType(headersLibrarySdkMemberType)
- android.RegisterBp2BuildMutator("cc_library_headers", CcLibraryHeadersBp2Build)
}
var headersLibrarySdkMemberType = &librarySdkMemberType{
@@ -96,6 +95,7 @@
module, library := NewLibrary(android.HostAndDeviceSupported)
library.HeaderOnly()
module.sdkMemberTypes = []android.SdkMemberType{headersLibrarySdkMemberType}
+ module.bazelable = true
module.bazelHandler = &libraryHeaderBazelHander{module: module, library: library}
return module.Init()
}
@@ -117,21 +117,7 @@
System_dynamic_deps bazel.LabelListAttribute
}
-func CcLibraryHeadersBp2Build(ctx android.TopDownMutatorContext) {
- module, ok := ctx.Module().(*Module)
- if !ok {
- // Not a cc module
- return
- }
-
- if !module.ConvertWithBp2build(ctx) {
- return
- }
-
- if ctx.ModuleType() != "cc_library_headers" {
- return
- }
-
+func libraryHeadersBp2Build(ctx android.TopDownMutatorContext, module *Module) {
baseAttributes := bp2BuildParseBaseProps(ctx, module)
exportedIncludes := bp2BuildParseExportedIncludes(ctx, module, baseAttributes.includes)
linkerAttrs := baseAttributes.linkerAttributes
diff --git a/cc/object.go b/cc/object.go
index 0327a45..bd43e36 100644
--- a/cc/object.go
+++ b/cc/object.go
@@ -29,7 +29,6 @@
android.RegisterModuleType("cc_object", ObjectFactory)
android.RegisterSdkMemberType(ccObjectSdkMemberType)
- android.RegisterBp2BuildMutator("cc_object", ObjectBp2Build)
}
var ccObjectSdkMemberType = &librarySdkMemberType{
@@ -117,6 +116,7 @@
module.sdkMemberTypes = []android.SdkMemberType{ccObjectSdkMemberType}
+ module.bazelable = true
return module.Init()
}
@@ -135,19 +135,9 @@
Linker_script bazel.LabelAttribute
}
-// ObjectBp2Build is the bp2build converter from cc_object modules to the
+// objectBp2Build is the bp2build converter from cc_object modules to the
// Bazel equivalent target, plus any necessary include deps for the cc_object.
-func ObjectBp2Build(ctx android.TopDownMutatorContext) {
- m, ok := ctx.Module().(*Module)
- if !ok || !m.ConvertWithBp2build(ctx) {
- return
- }
-
- // a Module can be something other than a cc_object.
- if ctx.ModuleType() != "cc_object" {
- return
- }
-
+func objectBp2Build(ctx android.TopDownMutatorContext, m *Module) {
if m.compiler == nil {
// a cc_object must have access to the compiler decorator for its props.
ctx.ModuleErrorf("compiler must not be nil for a cc_object module")
diff --git a/cc/prebuilt.go b/cc/prebuilt.go
index c303fda..4c3c7b4 100644
--- a/cc/prebuilt.go
+++ b/cc/prebuilt.go
@@ -32,8 +32,6 @@
ctx.RegisterModuleType("cc_prebuilt_test_library_shared", PrebuiltSharedTestLibraryFactory)
ctx.RegisterModuleType("cc_prebuilt_object", prebuiltObjectFactory)
ctx.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory)
-
- android.RegisterBp2BuildMutator("cc_prebuilt_library_shared", PrebuiltLibrarySharedBp2Build)
}
type prebuiltLinkerInterface interface {
@@ -299,6 +297,7 @@
func NewPrebuiltSharedLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
module, library := NewPrebuiltLibrary(hod, "srcs")
library.BuildOnlyShared()
+ module.bazelable = true
// Prebuilt shared libraries can be included in APEXes
android.InitApexModule(module)
@@ -316,31 +315,41 @@
func NewPrebuiltStaticLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
module, library := NewPrebuiltLibrary(hod, "srcs")
library.BuildOnlyStatic()
+ module.bazelable = true
module.bazelHandler = &prebuiltStaticLibraryBazelHandler{module: module, library: library}
return module, library
}
+type bazelPrebuiltLibraryStaticAttributes struct {
+ Static_library bazel.LabelAttribute
+ Export_includes bazel.StringListAttribute
+ Export_system_includes bazel.StringListAttribute
+}
+
+func prebuiltLibraryStaticBp2Build(ctx android.TopDownMutatorContext, module *Module) {
+ prebuiltAttrs := Bp2BuildParsePrebuiltLibraryProps(ctx, module)
+ exportedIncludes := Bp2BuildParseExportedIncludesForPrebuiltLibrary(ctx, module)
+
+ attrs := &bazelPrebuiltLibraryStaticAttributes{
+ Static_library: prebuiltAttrs.Src,
+ Export_includes: exportedIncludes.Includes,
+ Export_system_includes: exportedIncludes.SystemIncludes,
+ }
+
+ props := bazel.BazelTargetModuleProperties{
+ Rule_class: "prebuilt_library_static",
+ Bzl_load_location: "//build/bazel/rules:prebuilt_library_static.bzl",
+ }
+
+ name := android.RemoveOptionalPrebuiltPrefix(module.Name())
+ ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, attrs)
+}
+
type bazelPrebuiltLibrarySharedAttributes struct {
Shared_library bazel.LabelAttribute
}
-func PrebuiltLibrarySharedBp2Build(ctx android.TopDownMutatorContext) {
- module, ok := ctx.Module().(*Module)
- if !ok {
- // Not a cc module
- return
- }
- if !module.ConvertWithBp2build(ctx) {
- return
- }
- if ctx.ModuleType() != "cc_prebuilt_library_shared" {
- return
- }
-
- prebuiltLibrarySharedBp2BuildInternal(ctx, module)
-}
-
-func prebuiltLibrarySharedBp2BuildInternal(ctx android.TopDownMutatorContext, module *Module) {
+func prebuiltLibrarySharedBp2Build(ctx android.TopDownMutatorContext, module *Module) {
prebuiltAttrs := Bp2BuildParsePrebuiltLibraryProps(ctx, module)
attrs := &bazelPrebuiltLibrarySharedAttributes{
diff --git a/cc/test.go b/cc/test.go
index 0ca96f7..d8b7833 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -461,7 +461,7 @@
}
func NewTest(hod android.HostOrDeviceSupported) *Module {
- module, binary := NewBinary(hod)
+ module, binary := newBinary(hod, false)
module.multilib = android.MultilibBoth
binary.baseInstaller = NewTestInstaller()
@@ -551,6 +551,10 @@
testConfig android.Path
}
+func (benchmark *benchmarkDecorator) benchmarkBinary() bool {
+ return true
+}
+
func (benchmark *benchmarkDecorator) linkerInit(ctx BaseModuleContext) {
runpath := "../../lib"
if ctx.toolchain().Is64Bit() {
@@ -588,7 +592,7 @@
}
func NewBenchmark(hod android.HostOrDeviceSupported) *Module {
- module, binary := NewBinary(hod)
+ module, binary := newBinary(hod, false)
module.multilib = android.MultilibBoth
binary.baseInstaller = NewBaseInstaller("benchmarktest", "benchmarktest64", InstallInData)
diff --git a/etc/prebuilt_etc.go b/etc/prebuilt_etc.go
index 2865ffa..80ab41b 100644
--- a/etc/prebuilt_etc.go
+++ b/etc/prebuilt_etc.go
@@ -63,7 +63,6 @@
ctx.RegisterModuleType("prebuilt_defaults", defaultsFactory)
- android.RegisterBp2BuildMutator("prebuilt_etc", PrebuiltEtcBp2Build)
}
var PrepareForTestWithPrebuiltEtc = android.FixtureRegisterWithContext(RegisterPrebuiltEtcBuildComponents)
@@ -663,20 +662,14 @@
Installable bazel.BoolAttribute
}
-func PrebuiltEtcBp2Build(ctx android.TopDownMutatorContext) {
- module, ok := ctx.Module().(*PrebuiltEtc)
- if !ok {
- // Not an prebuilt_etc
- return
- }
- if !module.ConvertWithBp2build(ctx) {
- return
- }
+// ConvertWithBp2build performs bp2build conversion of PrebuiltEtc
+func (p *PrebuiltEtc) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
+ // All prebuilt_* modules are PrebuiltEtc, but at this time, we only convert prebuilt_etc modules.
if ctx.ModuleType() != "prebuilt_etc" {
return
}
- prebuiltEtcBp2BuildInternal(ctx, module)
+ prebuiltEtcBp2BuildInternal(ctx, p)
}
func prebuiltEtcBp2BuildInternal(ctx android.TopDownMutatorContext, module *PrebuiltEtc) {
diff --git a/genrule/genrule.go b/genrule/genrule.go
index e7343a2..6a91e01 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -67,13 +67,6 @@
ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) {
ctx.BottomUp("genrule_tool_deps", toolDepsMutator).Parallel()
})
-
- android.RegisterBp2BuildMutator("genrule", GenruleBp2Build)
- android.RegisterBp2BuildMutator("cc_genrule", CcGenruleBp2Build)
-}
-
-func RegisterGenruleBp2BuildDeps(ctx android.RegisterMutatorsContext) {
- ctx.BottomUp("genrule_tool_deps", toolDepsMutator)
}
var (
@@ -833,38 +826,8 @@
Cmd string
}
-// CcGenruleBp2Build is for cc_genrule.
-func CcGenruleBp2Build(ctx android.TopDownMutatorContext) {
- m, ok := ctx.Module().(*Module)
- if !ok || !m.ConvertWithBp2build(ctx) {
- return
- }
-
- if ctx.ModuleType() != "cc_genrule" {
- // Not a cc_genrule.
- return
- }
-
- genruleBp2Build(ctx)
-}
-
-// GenruleBp2Build is used for genrule.
-func GenruleBp2Build(ctx android.TopDownMutatorContext) {
- m, ok := ctx.Module().(*Module)
- if !ok || !m.ConvertWithBp2build(ctx) {
- return
- }
-
- if ctx.ModuleType() != "genrule" {
- // Not a regular genrule.
- return
- }
-
- genruleBp2Build(ctx)
-}
-
-func genruleBp2Build(ctx android.TopDownMutatorContext) {
- m, _ := ctx.Module().(*Module)
+// ConvertWithBp2build converts a Soong module -> Bazel target.
+func (m *Module) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
// Bazel only has the "tools" attribute.
tools_prop := android.BazelLabelForModuleDeps(ctx, m.properties.Tools)
tool_files_prop := android.BazelLabelForModuleSrc(ctx, m.properties.Tool_files)
diff --git a/java/app.go b/java/app.go
index b43e532..b753c0c 100755
--- a/java/app.go
+++ b/java/app.go
@@ -43,9 +43,6 @@
ctx.RegisterModuleType("android_app_certificate", AndroidAppCertificateFactory)
ctx.RegisterModuleType("override_android_app", OverrideAndroidAppModuleFactory)
ctx.RegisterModuleType("override_android_test", OverrideAndroidTestModuleFactory)
-
- android.RegisterBp2BuildMutator("android_app_certificate", AndroidAppCertificateBp2Build)
- android.RegisterBp2BuildMutator("android_app", AppBp2Build)
}
// AndroidManifest.xml merging
@@ -945,6 +942,7 @@
android.InitDefaultableModule(module)
android.InitOverridableModule(module, &module.appProperties.Overrides)
android.InitApexModule(module)
+ android.InitBazelModule(module)
return module
}
@@ -1407,23 +1405,11 @@
Certificate string
}
-func AndroidAppCertificateBp2Build(ctx android.TopDownMutatorContext) {
- module, ok := ctx.Module().(*AndroidAppCertificate)
- if !ok {
- // Not an Android app certificate
- return
- }
- if !module.ConvertWithBp2build(ctx) {
- return
- }
- if ctx.ModuleType() != "android_app_certificate" {
- return
- }
-
- androidAppCertificateBp2BuildInternal(ctx, module)
+func (m *AndroidAppCertificate) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
+ androidAppCertificateBp2Build(ctx, m)
}
-func androidAppCertificateBp2BuildInternal(ctx android.TopDownMutatorContext, module *AndroidAppCertificate) {
+func androidAppCertificateBp2Build(ctx android.TopDownMutatorContext, module *AndroidAppCertificate) {
var certificate string
if module.properties.Certificate != nil {
certificate = *module.properties.Certificate
@@ -1448,16 +1434,8 @@
Resource_files bazel.LabelListAttribute
}
-// AppBp2Build is used for android_app.
-func AppBp2Build(ctx android.TopDownMutatorContext) {
- a, ok := ctx.Module().(*AndroidApp)
- if !ok || !a.ConvertWithBp2build(ctx) {
- return
- }
- if ctx.ModuleType() != "android_app" {
- return
- }
-
+// ConvertWithBp2build is used to convert android_app to Bazel.
+func (a *AndroidApp) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
//TODO(b/209577426): Support multiple arch variants
srcs := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrcExcludes(ctx, a.properties.Srcs, a.properties.Exclude_srcs))
diff --git a/python/binary.go b/python/binary.go
index af02de6..99c6259 100644
--- a/python/binary.go
+++ b/python/binary.go
@@ -27,7 +27,6 @@
func init() {
registerPythonBinaryComponents(android.InitRegistrationContext)
- android.RegisterBp2BuildMutator("python_binary_host", PythonBinaryBp2Build)
}
func registerPythonBinaryComponents(ctx android.RegistrationContext) {
@@ -41,17 +40,7 @@
Python_version *string
}
-func PythonBinaryBp2Build(ctx android.TopDownMutatorContext) {
- m, ok := ctx.Module().(*Module)
- if !ok || !m.ConvertWithBp2build(ctx) {
- return
- }
-
- // a Module can be something other than a python_binary_host
- if ctx.ModuleType() != "python_binary_host" {
- return
- }
-
+func pythonBinaryBp2Build(ctx android.TopDownMutatorContext, m *Module) {
var main *string
for _, propIntf := range m.GetProperties() {
if props, ok := propIntf.(*BinaryProperties); ok {
diff --git a/python/library.go b/python/library.go
index 9c92ebd..d026c13 100644
--- a/python/library.go
+++ b/python/library.go
@@ -17,8 +17,6 @@
// This file contains the module types for building Python library.
import (
- "fmt"
-
"android/soong/android"
"android/soong/bazel"
@@ -27,8 +25,6 @@
func init() {
registerPythonLibraryComponents(android.InitRegistrationContext)
- android.RegisterBp2BuildMutator("python_library_host", PythonLibraryHostBp2Build)
- android.RegisterBp2BuildMutator("python_library", PythonLibraryBp2Build)
}
func registerPythonLibraryComponents(ctx android.RegistrationContext) {
@@ -50,25 +46,7 @@
Srcs_version *string
}
-func PythonLibraryHostBp2Build(ctx android.TopDownMutatorContext) {
- pythonLibBp2Build(ctx, "python_library_host")
-}
-
-func PythonLibraryBp2Build(ctx android.TopDownMutatorContext) {
- pythonLibBp2Build(ctx, "python_library")
-}
-
-func pythonLibBp2Build(ctx android.TopDownMutatorContext, modType string) {
- m, ok := ctx.Module().(*Module)
- if !ok || !m.ConvertWithBp2build(ctx) {
- return
- }
-
- // a Module can be something other than a `modType`
- if ctx.ModuleType() != modType {
- return
- }
-
+func pythonLibBp2Build(ctx android.TopDownMutatorContext, m *Module) {
// TODO(b/182306917): this doesn't fully handle all nested props versioned
// by the python version, which would have been handled by the version split
// mutator. This is sufficient for very simple python_library modules under
@@ -81,9 +59,7 @@
} else if !py2Enabled && py3Enabled {
python_version = &pyVersion3
} else if !py2Enabled && !py3Enabled {
- panic(fmt.Errorf(
- "error for '%s' module: bp2build's %s converter doesn't understand having "+
- "neither py2 nor py3 enabled", m.Name(), modType))
+ ctx.ModuleErrorf("bp2build converter doesn't understand having neither py2 nor py3 enabled")
} else {
// do nothing, since python_version defaults to PY2ANDPY3
}
diff --git a/python/python.go b/python/python.go
index 401d91f..734ac57 100644
--- a/python/python.go
+++ b/python/python.go
@@ -23,6 +23,7 @@
"strings"
"android/soong/bazel"
+
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -667,18 +668,25 @@
}
// isPythonLibModule returns whether the given module is a Python library Module or not
-// This is distinguished by the fact that Python libraries are not installable, while other Python
-// modules are.
func isPythonLibModule(module blueprint.Module) bool {
if m, ok := module.(*Module); ok {
- // Python library has no bootstrapper or installer
- if m.bootstrapper == nil && m.installer == nil {
- return true
- }
+ return m.isLibrary()
}
return false
}
+// This is distinguished by the fact that Python libraries are not installable, while other Python
+// modules are.
+func (p *Module) isLibrary() bool {
+ // Python library has no bootstrapper or installer
+ return p.bootstrapper == nil && p.installer == nil
+}
+
+func (p *Module) isBinary() bool {
+ _, ok := p.bootstrapper.(*binaryDecorator)
+ return ok
+}
+
// collectPathsFromTransitiveDeps checks for source/data files for duplicate paths
// for module and its transitive dependencies and collects list of data/source file
// zips for transitive dependencies.
@@ -752,6 +760,14 @@
return true
}
+func (p *Module) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
+ if p.isLibrary() {
+ pythonLibBp2Build(ctx, p)
+ } else if p.isBinary() {
+ pythonBinaryBp2Build(ctx, p)
+ }
+}
+
var Bool = proptools.Bool
var BoolDefault = proptools.BoolDefault
var String = proptools.String
diff --git a/sh/sh_binary.go b/sh/sh_binary.go
index a87b9cf..2d98e8b 100644
--- a/sh/sh_binary.go
+++ b/sh/sh_binary.go
@@ -42,8 +42,6 @@
pctx.Import("android/soong/android")
registerShBuildComponents(android.InitRegistrationContext)
-
- android.RegisterBp2BuildMutator("sh_binary", ShBinaryBp2Build)
}
func registerShBuildComponents(ctx android.RegistrationContext) {
@@ -540,12 +538,7 @@
// visibility
}
-func ShBinaryBp2Build(ctx android.TopDownMutatorContext) {
- m, ok := ctx.Module().(*ShBinary)
- if !ok || !m.ConvertWithBp2build(ctx) {
- return
- }
-
+func (m *ShBinary) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
srcs := bazel.MakeLabelListAttribute(
android.BazelLabelForModuleSrc(ctx, []string{*m.properties.Src}))