Loading android/bazel.go +19 −11 Original line number Diff line number Diff line Loading @@ -61,8 +61,8 @@ type Bazelable interface { HandcraftedLabel() string GetBazelLabel(ctx BazelConversionPathContext, module blueprint.Module) string ConvertWithBp2build(ctx BazelConversionPathContext) bool convertWithBp2build(ctx BazelConversionPathContext, module blueprint.Module) bool GetBazelBuildFileContents(c Config, path, name string) (string, error) ConvertedToBazel(ctx BazelConversionPathContext) bool } // BazelModule is a lightweight wrapper interface around Module for Bazel-convertible modules. Loading Loading @@ -312,9 +312,10 @@ func (b *BazelModuleBase) MixedBuildsEnabled(ctx BazelConversionPathContext) boo if !ctx.Config().BazelContext.BazelEnabled() { return false } if len(b.GetBazelLabel(ctx, ctx.Module())) == 0 { if !convertedToBazel(ctx, ctx.Module()) { return false } if GenerateCcLibraryStaticOnly(ctx) { // Don't use partially-converted cc_library targets in mixed builds, // since mixed builds would generally rely on both static and shared Loading @@ -324,20 +325,33 @@ func (b *BazelModuleBase) MixedBuildsEnabled(ctx BazelConversionPathContext) boo return !mixedBuildsDisabled[ctx.Module().Name()] } // ConvertedToBazel returns whether this module has been converted (with bp2build or manually) to Bazel. func convertedToBazel(ctx BazelConversionPathContext, module blueprint.Module) bool { b, ok := module.(Bazelable) if !ok { return false } return b.convertWithBp2build(ctx, module) || b.HasHandcraftedLabel() } // ConvertWithBp2build returns whether the given BazelModuleBase should be converted with bp2build. func (b *BazelModuleBase) ConvertWithBp2build(ctx BazelConversionPathContext) bool { if bp2buildModuleDoNotConvert[ctx.Module().Name()] { return b.convertWithBp2build(ctx, ctx.Module()) } func (b *BazelModuleBase) convertWithBp2build(ctx BazelConversionPathContext, 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.ModuleType()] == false { if ctx.Config().bp2buildModuleTypeConfig[ctx.OtherModuleType(module)] == false { return false } packagePath := ctx.ModuleDir() packagePath := ctx.OtherModuleDir(module) config := ctx.Config().bp2buildPackageConfig // This is a tristate value: true, false, or unset. Loading Loading @@ -408,9 +422,3 @@ func (b *BazelModuleBase) GetBazelBuildFileContents(c Config, path, name string) } return string(data[:]), nil } // ConvertedToBazel returns whether this module has been converted to Bazel, whether automatically // or manually func (b *BazelModuleBase) ConvertedToBazel(ctx BazelConversionPathContext) bool { return b.ConvertWithBp2build(ctx) || b.HasHandcraftedLabel() } android/bazel_paths.go +7 −4 Original line number Diff line number Diff line Loading @@ -75,9 +75,10 @@ type BazelConversionPathContext interface { GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) ModuleFromName(name string) (blueprint.Module, bool) Module() Module ModuleType() string OtherModuleType(m blueprint.Module) string OtherModuleName(m blueprint.Module) string OtherModuleDir(m blueprint.Module) string AddUnconvertedBp2buildDep(string) } // BazelLabelForModuleDeps expects a list of reference to other modules, ("<module>" Loading Loading @@ -345,6 +346,9 @@ func getOtherModuleLabel(ctx BazelConversionPathContext, dep, tag string, isWhol if m == nil { panic(fmt.Errorf("No module named %q found, but was a direct dep of %q", dep, ctx.Module().Name())) } if !convertedToBazel(ctx, m) { ctx.AddUnconvertedBp2buildDep(dep) } otherLabel := bazelModuleLabel(ctx, m, tag) label := bazelModuleLabel(ctx, ctx.Module(), "") if isWholeLibs { Loading @@ -363,11 +367,10 @@ func getOtherModuleLabel(ctx BazelConversionPathContext, dep, tag string, isWhol func bazelModuleLabel(ctx BazelConversionPathContext, module blueprint.Module, tag string) string { // TODO(b/165114590): Convert tag (":name{.tag}") to corresponding Bazel implicit output targets. b, ok := module.(Bazelable) // TODO(b/181155349): perhaps return an error here if the module can't be/isn't being converted if !ok || !b.ConvertedToBazel(ctx) { if !convertedToBazel(ctx, module) { return bp2buildModuleLabel(ctx, module) } b, _ := module.(Bazelable) return b.GetBazelLabel(ctx, module) } Loading android/module.go +20 −0 Original line number Diff line number Diff line Loading @@ -316,6 +316,9 @@ type BaseModuleContext interface { AddMissingDependencies(missingDeps []string) // AddUnconvertedBp2buildDep stores module name of a direct dependency that was not converted via bp2build AddUnconvertedBp2buildDep(dep string) Target() Target TargetPrimary() bool Loading Loading @@ -496,6 +499,7 @@ type Module interface { IsConvertedByBp2build() bool // Bp2buildTargets returns the target(s) generated for Bazel via bp2build for this module Bp2buildTargets() []bp2buildInfo GetUnconvertedBp2buildDeps() []string BuildParamsForTests() []BuildParams RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams Loading Loading @@ -833,6 +837,10 @@ type commonProperties struct { // supported as Soong handles some things within a single target that we may choose to split into // multiple targets, e.g. renderscript, protos, yacc within a cc module. Bp2buildInfo []bp2buildInfo `blueprint:"mutated"` // UnconvertedBp2buildDep stores the module names of direct dependency that were not converted to // Bazel UnconvertedBp2buildDeps []string `blueprint:"mutated"` } type distProperties struct { Loading Loading @@ -1212,6 +1220,18 @@ func (m *ModuleBase) Bp2buildTargets() []bp2buildInfo { return m.commonProperties.Bp2buildInfo } // AddUnconvertedBp2buildDep stores module name of a dependency that was not converted to Bazel. func (b *baseModuleContext) AddUnconvertedBp2buildDep(dep string) { unconvertedDeps := &b.Module().base().commonProperties.UnconvertedBp2buildDeps *unconvertedDeps = append(*unconvertedDeps, dep) } // GetUnconvertedBp2buildDeps returns the list of module names of this module's direct dependencies that // were not converted to Bazel. func (m *ModuleBase) GetUnconvertedBp2buildDeps() []string { return m.commonProperties.UnconvertedBp2buildDeps } func (m *ModuleBase) AddJSONData(d *map[string]interface{}) { (*d)["Android"] = map[string]interface{}{} } Loading android/mutator.go +0 −1 Original line number Diff line number Diff line Loading @@ -532,7 +532,6 @@ func (t *topDownMutatorContext) CreateBazelTargetModule( BazelProps: bazelProps, Attrs: attrs, } t.Module().base().addBp2buildInfo(info) } Loading bp2build/bp2build.go +13 −4 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import ( "android/soong/bazel" "fmt" "os" "strings" ) // Codegen is the backend of bp2build. The code generator is responsible for Loading @@ -29,14 +30,22 @@ func Codegen(ctx *CodegenContext) CodegenMetrics { bp2buildDir := android.PathForOutput(ctx, "bp2build") android.RemoveAllOutputDir(bp2buildDir) buildToTargets, metrics, compatLayer := GenerateBazelTargets(ctx, true) bp2buildFiles := CreateBazelFiles(nil, buildToTargets, ctx.mode) res, errs := GenerateBazelTargets(ctx, true) if len(errs) > 0 { errMsgs := make([]string, len(errs)) for i, err := range errs { errMsgs[i] = fmt.Sprintf("%q", err) } fmt.Printf("ERROR: Encountered %d error(s): \nERROR: %s", len(errs), strings.Join(errMsgs, "\n")) os.Exit(1) } bp2buildFiles := CreateBazelFiles(nil, res.buildFileToTargets, ctx.mode) writeFiles(ctx, bp2buildDir, bp2buildFiles) soongInjectionDir := android.PathForOutput(ctx, bazel.SoongInjectionDirName) writeFiles(ctx, soongInjectionDir, CreateSoongInjectionFiles(compatLayer)) writeFiles(ctx, soongInjectionDir, CreateSoongInjectionFiles(res.compatLayer)) return metrics return res.metrics } // Get the output directory and create it if it doesn't exist. Loading Loading
android/bazel.go +19 −11 Original line number Diff line number Diff line Loading @@ -61,8 +61,8 @@ type Bazelable interface { HandcraftedLabel() string GetBazelLabel(ctx BazelConversionPathContext, module blueprint.Module) string ConvertWithBp2build(ctx BazelConversionPathContext) bool convertWithBp2build(ctx BazelConversionPathContext, module blueprint.Module) bool GetBazelBuildFileContents(c Config, path, name string) (string, error) ConvertedToBazel(ctx BazelConversionPathContext) bool } // BazelModule is a lightweight wrapper interface around Module for Bazel-convertible modules. Loading Loading @@ -312,9 +312,10 @@ func (b *BazelModuleBase) MixedBuildsEnabled(ctx BazelConversionPathContext) boo if !ctx.Config().BazelContext.BazelEnabled() { return false } if len(b.GetBazelLabel(ctx, ctx.Module())) == 0 { if !convertedToBazel(ctx, ctx.Module()) { return false } if GenerateCcLibraryStaticOnly(ctx) { // Don't use partially-converted cc_library targets in mixed builds, // since mixed builds would generally rely on both static and shared Loading @@ -324,20 +325,33 @@ func (b *BazelModuleBase) MixedBuildsEnabled(ctx BazelConversionPathContext) boo return !mixedBuildsDisabled[ctx.Module().Name()] } // ConvertedToBazel returns whether this module has been converted (with bp2build or manually) to Bazel. func convertedToBazel(ctx BazelConversionPathContext, module blueprint.Module) bool { b, ok := module.(Bazelable) if !ok { return false } return b.convertWithBp2build(ctx, module) || b.HasHandcraftedLabel() } // ConvertWithBp2build returns whether the given BazelModuleBase should be converted with bp2build. func (b *BazelModuleBase) ConvertWithBp2build(ctx BazelConversionPathContext) bool { if bp2buildModuleDoNotConvert[ctx.Module().Name()] { return b.convertWithBp2build(ctx, ctx.Module()) } func (b *BazelModuleBase) convertWithBp2build(ctx BazelConversionPathContext, 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.ModuleType()] == false { if ctx.Config().bp2buildModuleTypeConfig[ctx.OtherModuleType(module)] == false { return false } packagePath := ctx.ModuleDir() packagePath := ctx.OtherModuleDir(module) config := ctx.Config().bp2buildPackageConfig // This is a tristate value: true, false, or unset. Loading Loading @@ -408,9 +422,3 @@ func (b *BazelModuleBase) GetBazelBuildFileContents(c Config, path, name string) } return string(data[:]), nil } // ConvertedToBazel returns whether this module has been converted to Bazel, whether automatically // or manually func (b *BazelModuleBase) ConvertedToBazel(ctx BazelConversionPathContext) bool { return b.ConvertWithBp2build(ctx) || b.HasHandcraftedLabel() }
android/bazel_paths.go +7 −4 Original line number Diff line number Diff line Loading @@ -75,9 +75,10 @@ type BazelConversionPathContext interface { GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) ModuleFromName(name string) (blueprint.Module, bool) Module() Module ModuleType() string OtherModuleType(m blueprint.Module) string OtherModuleName(m blueprint.Module) string OtherModuleDir(m blueprint.Module) string AddUnconvertedBp2buildDep(string) } // BazelLabelForModuleDeps expects a list of reference to other modules, ("<module>" Loading Loading @@ -345,6 +346,9 @@ func getOtherModuleLabel(ctx BazelConversionPathContext, dep, tag string, isWhol if m == nil { panic(fmt.Errorf("No module named %q found, but was a direct dep of %q", dep, ctx.Module().Name())) } if !convertedToBazel(ctx, m) { ctx.AddUnconvertedBp2buildDep(dep) } otherLabel := bazelModuleLabel(ctx, m, tag) label := bazelModuleLabel(ctx, ctx.Module(), "") if isWholeLibs { Loading @@ -363,11 +367,10 @@ func getOtherModuleLabel(ctx BazelConversionPathContext, dep, tag string, isWhol func bazelModuleLabel(ctx BazelConversionPathContext, module blueprint.Module, tag string) string { // TODO(b/165114590): Convert tag (":name{.tag}") to corresponding Bazel implicit output targets. b, ok := module.(Bazelable) // TODO(b/181155349): perhaps return an error here if the module can't be/isn't being converted if !ok || !b.ConvertedToBazel(ctx) { if !convertedToBazel(ctx, module) { return bp2buildModuleLabel(ctx, module) } b, _ := module.(Bazelable) return b.GetBazelLabel(ctx, module) } Loading
android/module.go +20 −0 Original line number Diff line number Diff line Loading @@ -316,6 +316,9 @@ type BaseModuleContext interface { AddMissingDependencies(missingDeps []string) // AddUnconvertedBp2buildDep stores module name of a direct dependency that was not converted via bp2build AddUnconvertedBp2buildDep(dep string) Target() Target TargetPrimary() bool Loading Loading @@ -496,6 +499,7 @@ type Module interface { IsConvertedByBp2build() bool // Bp2buildTargets returns the target(s) generated for Bazel via bp2build for this module Bp2buildTargets() []bp2buildInfo GetUnconvertedBp2buildDeps() []string BuildParamsForTests() []BuildParams RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams Loading Loading @@ -833,6 +837,10 @@ type commonProperties struct { // supported as Soong handles some things within a single target that we may choose to split into // multiple targets, e.g. renderscript, protos, yacc within a cc module. Bp2buildInfo []bp2buildInfo `blueprint:"mutated"` // UnconvertedBp2buildDep stores the module names of direct dependency that were not converted to // Bazel UnconvertedBp2buildDeps []string `blueprint:"mutated"` } type distProperties struct { Loading Loading @@ -1212,6 +1220,18 @@ func (m *ModuleBase) Bp2buildTargets() []bp2buildInfo { return m.commonProperties.Bp2buildInfo } // AddUnconvertedBp2buildDep stores module name of a dependency that was not converted to Bazel. func (b *baseModuleContext) AddUnconvertedBp2buildDep(dep string) { unconvertedDeps := &b.Module().base().commonProperties.UnconvertedBp2buildDeps *unconvertedDeps = append(*unconvertedDeps, dep) } // GetUnconvertedBp2buildDeps returns the list of module names of this module's direct dependencies that // were not converted to Bazel. func (m *ModuleBase) GetUnconvertedBp2buildDeps() []string { return m.commonProperties.UnconvertedBp2buildDeps } func (m *ModuleBase) AddJSONData(d *map[string]interface{}) { (*d)["Android"] = map[string]interface{}{} } Loading
android/mutator.go +0 −1 Original line number Diff line number Diff line Loading @@ -532,7 +532,6 @@ func (t *topDownMutatorContext) CreateBazelTargetModule( BazelProps: bazelProps, Attrs: attrs, } t.Module().base().addBp2buildInfo(info) } Loading
bp2build/bp2build.go +13 −4 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import ( "android/soong/bazel" "fmt" "os" "strings" ) // Codegen is the backend of bp2build. The code generator is responsible for Loading @@ -29,14 +30,22 @@ func Codegen(ctx *CodegenContext) CodegenMetrics { bp2buildDir := android.PathForOutput(ctx, "bp2build") android.RemoveAllOutputDir(bp2buildDir) buildToTargets, metrics, compatLayer := GenerateBazelTargets(ctx, true) bp2buildFiles := CreateBazelFiles(nil, buildToTargets, ctx.mode) res, errs := GenerateBazelTargets(ctx, true) if len(errs) > 0 { errMsgs := make([]string, len(errs)) for i, err := range errs { errMsgs[i] = fmt.Sprintf("%q", err) } fmt.Printf("ERROR: Encountered %d error(s): \nERROR: %s", len(errs), strings.Join(errMsgs, "\n")) os.Exit(1) } bp2buildFiles := CreateBazelFiles(nil, res.buildFileToTargets, ctx.mode) writeFiles(ctx, bp2buildDir, bp2buildFiles) soongInjectionDir := android.PathForOutput(ctx, bazel.SoongInjectionDirName) writeFiles(ctx, soongInjectionDir, CreateSoongInjectionFiles(compatLayer)) writeFiles(ctx, soongInjectionDir, CreateSoongInjectionFiles(res.compatLayer)) return metrics return res.metrics } // Get the output directory and create it if it doesn't exist. Loading