Loading android/bazel.go +32 −21 Original line number Diff line number Diff line Loading @@ -39,6 +39,10 @@ type bazelModuleProperties struct { // 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. Loading Loading @@ -80,9 +84,10 @@ type Bazelable interface { 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 Loading @@ -109,6 +114,7 @@ type BazelModule interface { // properties. func InitBazelModule(module BazelModule) { module.AddProperties(module.bazelProps()) module.bazelProps().Bazel_module.CanConvertToBazel = true } // bazelProps returns the Bazel properties for the given BazelModuleBase. Loading Loading @@ -147,7 +153,7 @@ func (b *BazelModuleBase) GetBazelLabel(ctx BazelConversionPathContext, module b if b.HasHandcraftedLabel() { return b.HandcraftedLabel() } if b.ConvertWithBp2build(ctx) { if b.ShouldConvertWithBp2build(ctx) { return bp2buildModuleLabel(ctx, module) } return "" // no label for unconverted module Loading Loading @@ -436,6 +442,9 @@ var ( "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 Loading Loading @@ -530,33 +539,22 @@ func convertedToBazel(ctx BazelConversionContext, module blueprint.Module) bool 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 { if !b.bazelProps().Bazel_module.CanConvertToBazel { return false } } packagePath := ctx.OtherModuleDir(module) config := ctx.Config().bp2buildPackageConfig Loading Loading @@ -629,3 +627,16 @@ func (b *BazelModuleBase) GetBazelBuildFileContents(c Config, path, name string) } 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) } android/config.go +0 −4 Original line number Diff line number Diff line Loading @@ -157,7 +157,6 @@ type config struct { runningAsBp2Build bool bp2buildPackageConfig Bp2BuildConfig bp2buildModuleTypeConfig map[string]bool Bp2buildSoongConfigDefinitions soongconfig.Bp2BuildSoongConfigDefinitions // If testAllowNonExistentPaths is true then PathForSource and PathForModuleSrc won't error Loading Loading @@ -353,8 +352,6 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string config.mockFileSystem(bp, fs) config.bp2buildModuleTypeConfig = map[string]bool{} determineBuildOS(config) return Config{config} Loading Loading @@ -522,7 +519,6 @@ func NewConfig(moduleListFile string, runGoTests bool, outDir, soongOutDir strin config.BazelContext, err = NewBazelContext(config) config.bp2buildPackageConfig = bp2buildDefaultConfig config.bp2buildModuleTypeConfig = make(map[string]bool) return Config{config}, err } Loading android/defaults.go +4 −0 Original line number Diff line number Diff line Loading @@ -173,6 +173,10 @@ func (d *DefaultsModuleBase) productVariableProperties() interface{} { 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{} Loading android/filegroup.go +2 −7 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ import ( func init() { RegisterModuleType("filegroup", FileGroupFactory) RegisterBp2BuildMutator("filegroup", FilegroupBp2Build) } var PrepareForTestWithFilegroup = FixtureRegisterWithContext(func(ctx RegistrationContext) { Loading @@ -34,12 +33,8 @@ type bazelFilegroupAttributes struct { 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)) Loading android/mutator.go +3 −26 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package android import ( "reflect" "sync" "android/soong/bazel" Loading @@ -34,12 +33,12 @@ import ( // 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 Loading @@ -47,10 +46,7 @@ func RegisterMutatorsForBazelConversion(ctx *Context, preArchMutators, bp2buildM RegisterPrebuiltsPreArchMutators, }, preArchMutators...) for _, f := range bp2buildPreArchMutators { f(mctx) } bp2buildMutators = append(bp2buildMutators, registerBp2buildConversionMutator) // Register bp2build mutators for _, f := range bp2buildMutators { Loading Loading @@ -216,10 +212,6 @@ func FinalDepsMutators(f RegisterMutatorFunc) { } 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 { Loading @@ -228,21 +220,6 @@ type Bp2buildMutatorContext interface { 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) { Loading Loading
android/bazel.go +32 −21 Original line number Diff line number Diff line Loading @@ -39,6 +39,10 @@ type bazelModuleProperties struct { // 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. Loading Loading @@ -80,9 +84,10 @@ type Bazelable interface { 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 Loading @@ -109,6 +114,7 @@ type BazelModule interface { // properties. func InitBazelModule(module BazelModule) { module.AddProperties(module.bazelProps()) module.bazelProps().Bazel_module.CanConvertToBazel = true } // bazelProps returns the Bazel properties for the given BazelModuleBase. Loading Loading @@ -147,7 +153,7 @@ func (b *BazelModuleBase) GetBazelLabel(ctx BazelConversionPathContext, module b if b.HasHandcraftedLabel() { return b.HandcraftedLabel() } if b.ConvertWithBp2build(ctx) { if b.ShouldConvertWithBp2build(ctx) { return bp2buildModuleLabel(ctx, module) } return "" // no label for unconverted module Loading Loading @@ -436,6 +442,9 @@ var ( "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 Loading Loading @@ -530,33 +539,22 @@ func convertedToBazel(ctx BazelConversionContext, module blueprint.Module) bool 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 { if !b.bazelProps().Bazel_module.CanConvertToBazel { return false } } packagePath := ctx.OtherModuleDir(module) config := ctx.Config().bp2buildPackageConfig Loading Loading @@ -629,3 +627,16 @@ func (b *BazelModuleBase) GetBazelBuildFileContents(c Config, path, name string) } 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) }
android/config.go +0 −4 Original line number Diff line number Diff line Loading @@ -157,7 +157,6 @@ type config struct { runningAsBp2Build bool bp2buildPackageConfig Bp2BuildConfig bp2buildModuleTypeConfig map[string]bool Bp2buildSoongConfigDefinitions soongconfig.Bp2BuildSoongConfigDefinitions // If testAllowNonExistentPaths is true then PathForSource and PathForModuleSrc won't error Loading Loading @@ -353,8 +352,6 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string config.mockFileSystem(bp, fs) config.bp2buildModuleTypeConfig = map[string]bool{} determineBuildOS(config) return Config{config} Loading Loading @@ -522,7 +519,6 @@ func NewConfig(moduleListFile string, runGoTests bool, outDir, soongOutDir strin config.BazelContext, err = NewBazelContext(config) config.bp2buildPackageConfig = bp2buildDefaultConfig config.bp2buildModuleTypeConfig = make(map[string]bool) return Config{config}, err } Loading
android/defaults.go +4 −0 Original line number Diff line number Diff line Loading @@ -173,6 +173,10 @@ func (d *DefaultsModuleBase) productVariableProperties() interface{} { 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{} Loading
android/filegroup.go +2 −7 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ import ( func init() { RegisterModuleType("filegroup", FileGroupFactory) RegisterBp2BuildMutator("filegroup", FilegroupBp2Build) } var PrepareForTestWithFilegroup = FixtureRegisterWithContext(func(ctx RegistrationContext) { Loading @@ -34,12 +33,8 @@ type bazelFilegroupAttributes struct { 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)) Loading
android/mutator.go +3 −26 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package android import ( "reflect" "sync" "android/soong/bazel" Loading @@ -34,12 +33,12 @@ import ( // 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 Loading @@ -47,10 +46,7 @@ func RegisterMutatorsForBazelConversion(ctx *Context, preArchMutators, bp2buildM RegisterPrebuiltsPreArchMutators, }, preArchMutators...) for _, f := range bp2buildPreArchMutators { f(mctx) } bp2buildMutators = append(bp2buildMutators, registerBp2buildConversionMutator) // Register bp2build mutators for _, f := range bp2buildMutators { Loading Loading @@ -216,10 +212,6 @@ func FinalDepsMutators(f RegisterMutatorFunc) { } 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 { Loading @@ -228,21 +220,6 @@ type Bp2buildMutatorContext interface { 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) { Loading