Loading bp2build/Android.bp +0 −1 Original line number Diff line number Diff line Loading @@ -11,7 +11,6 @@ bootstrap_go_package { "build_conversion.go", "bzl_conversion.go", "configurability.go", "compatibility.go", "constants.go", "conversion.go", "metrics.go", Loading bp2build/bp2build.go +1 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ func Codegen(ctx *CodegenContext) CodegenMetrics { writeFiles(ctx, bp2buildDir, bp2buildFiles) soongInjectionDir := android.PathForOutput(ctx, bazel.SoongInjectionDirName) writeFiles(ctx, soongInjectionDir, CreateSoongInjectionFiles(res.compatLayer)) writeFiles(ctx, soongInjectionDir, CreateSoongInjectionFiles(res.metrics)) return res.metrics } Loading bp2build/build_conversion.go +3 −11 Original line number Diff line number Diff line Loading @@ -249,7 +249,6 @@ func propsToAttributes(props map[string]string) string { type conversionResults struct { buildFileToTargets map[string]BazelTargets metrics CodegenMetrics compatLayer CodegenCompatLayer } func (r conversionResults) BuildDirToTargets() map[string]BazelTargets { Loading @@ -265,10 +264,6 @@ func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (convers RuleClassCount: make(map[string]int), } compatLayer := CodegenCompatLayer{ NameToLabelMap: make(map[string]string), } dirs := make(map[string]bool) var errs []error Loading @@ -285,7 +280,7 @@ func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (convers if b, ok := m.(android.Bazelable); ok && b.HasHandcraftedLabel() { metrics.handCraftedTargetCount += 1 metrics.TotalModuleCount += 1 compatLayer.AddNameToLabelEntry(m.Name(), b.HandcraftedLabel()) metrics.AddConvertedModule(m.Name()) pathToBuildFile := getBazelPackagePath(b) // We are using the entire contents of handcrafted build file, so if multiple targets within // a package have handcrafted targets, we only want to include the contents one time. Loading Loading @@ -314,10 +309,8 @@ func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (convers } targets = generateBazelTargets(bpCtx, aModule) for _, t := range targets { if t.name == m.Name() { // only add targets that exist in Soong to compatibility layer compatLayer.AddNameToLabelEntry(m.Name(), t.Label()) } metrics.AddConvertedModule(m.Name()) metrics.RuleClassCount[t.ruleClass] += 1 } } else { Loading Loading @@ -360,7 +353,6 @@ func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (convers return conversionResults{ buildFileToTargets: buildFileToTargets, metrics: metrics, compatLayer: compatLayer, }, errs } Loading bp2build/compatibility.godeleted 100644 → 0 +0 −27 Original line number Diff line number Diff line package bp2build import ( "fmt" ) // Data from the code generation process that is used to improve compatibility // between build systems. type CodegenCompatLayer struct { // A map from the original module name to the generated/handcrafted Bazel // label for legacy build systems to be able to build a fully-qualified // Bazel target from an unique module name. NameToLabelMap map[string]string } // Log an entry of module name -> Bazel target label. func (compatLayer CodegenCompatLayer) AddNameToLabelEntry(name, label string) { if existingLabel, ok := compatLayer.NameToLabelMap[name]; ok { panic(fmt.Errorf( "Module '%s' maps to more than one Bazel target label: %s, %s. "+ "This shouldn't happen. It probably indicates a bug with the bp2build internals.", name, existingLabel, label)) } compatLayer.NameToLabelMap[name] = label } bp2build/conversion.go +4 −14 Original line number Diff line number Diff line Loading @@ -16,29 +16,19 @@ type BazelFile struct { Contents string } func CreateSoongInjectionFiles(compatLayer CodegenCompatLayer) []BazelFile { func CreateSoongInjectionFiles(metrics CodegenMetrics) []BazelFile { var files []BazelFile files = append(files, newFile("cc_toolchain", GeneratedBuildFileName, "")) // Creates a //cc_toolchain package. files = append(files, newFile("cc_toolchain", "constants.bzl", config.BazelCcToolchainVars())) files = append(files, newFile("module_name_to_label", GeneratedBuildFileName, nameToLabelAliases(compatLayer.NameToLabelMap))) files = append(files, newFile("metrics", "converted_modules.txt", strings.Join(metrics.convertedModules, "\n"))) return files } func nameToLabelAliases(nameToLabelMap map[string]string) string { ret := make([]string, len(nameToLabelMap)) for k, v := range nameToLabelMap { // v is the fully qualified label rooted at '//' ret = append(ret, fmt.Sprintf( `alias( name = "%s", actual = "@%s", )`, k, v)) } return strings.Join(ret, "\n\n") func convertedModules(convertedModules []string) string { return strings.Join(convertedModules, "\n") } func CreateBazelFiles( Loading Loading
bp2build/Android.bp +0 −1 Original line number Diff line number Diff line Loading @@ -11,7 +11,6 @@ bootstrap_go_package { "build_conversion.go", "bzl_conversion.go", "configurability.go", "compatibility.go", "constants.go", "conversion.go", "metrics.go", Loading
bp2build/bp2build.go +1 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ func Codegen(ctx *CodegenContext) CodegenMetrics { writeFiles(ctx, bp2buildDir, bp2buildFiles) soongInjectionDir := android.PathForOutput(ctx, bazel.SoongInjectionDirName) writeFiles(ctx, soongInjectionDir, CreateSoongInjectionFiles(res.compatLayer)) writeFiles(ctx, soongInjectionDir, CreateSoongInjectionFiles(res.metrics)) return res.metrics } Loading
bp2build/build_conversion.go +3 −11 Original line number Diff line number Diff line Loading @@ -249,7 +249,6 @@ func propsToAttributes(props map[string]string) string { type conversionResults struct { buildFileToTargets map[string]BazelTargets metrics CodegenMetrics compatLayer CodegenCompatLayer } func (r conversionResults) BuildDirToTargets() map[string]BazelTargets { Loading @@ -265,10 +264,6 @@ func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (convers RuleClassCount: make(map[string]int), } compatLayer := CodegenCompatLayer{ NameToLabelMap: make(map[string]string), } dirs := make(map[string]bool) var errs []error Loading @@ -285,7 +280,7 @@ func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (convers if b, ok := m.(android.Bazelable); ok && b.HasHandcraftedLabel() { metrics.handCraftedTargetCount += 1 metrics.TotalModuleCount += 1 compatLayer.AddNameToLabelEntry(m.Name(), b.HandcraftedLabel()) metrics.AddConvertedModule(m.Name()) pathToBuildFile := getBazelPackagePath(b) // We are using the entire contents of handcrafted build file, so if multiple targets within // a package have handcrafted targets, we only want to include the contents one time. Loading Loading @@ -314,10 +309,8 @@ func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (convers } targets = generateBazelTargets(bpCtx, aModule) for _, t := range targets { if t.name == m.Name() { // only add targets that exist in Soong to compatibility layer compatLayer.AddNameToLabelEntry(m.Name(), t.Label()) } metrics.AddConvertedModule(m.Name()) metrics.RuleClassCount[t.ruleClass] += 1 } } else { Loading Loading @@ -360,7 +353,6 @@ func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (convers return conversionResults{ buildFileToTargets: buildFileToTargets, metrics: metrics, compatLayer: compatLayer, }, errs } Loading
bp2build/compatibility.godeleted 100644 → 0 +0 −27 Original line number Diff line number Diff line package bp2build import ( "fmt" ) // Data from the code generation process that is used to improve compatibility // between build systems. type CodegenCompatLayer struct { // A map from the original module name to the generated/handcrafted Bazel // label for legacy build systems to be able to build a fully-qualified // Bazel target from an unique module name. NameToLabelMap map[string]string } // Log an entry of module name -> Bazel target label. func (compatLayer CodegenCompatLayer) AddNameToLabelEntry(name, label string) { if existingLabel, ok := compatLayer.NameToLabelMap[name]; ok { panic(fmt.Errorf( "Module '%s' maps to more than one Bazel target label: %s, %s. "+ "This shouldn't happen. It probably indicates a bug with the bp2build internals.", name, existingLabel, label)) } compatLayer.NameToLabelMap[name] = label }
bp2build/conversion.go +4 −14 Original line number Diff line number Diff line Loading @@ -16,29 +16,19 @@ type BazelFile struct { Contents string } func CreateSoongInjectionFiles(compatLayer CodegenCompatLayer) []BazelFile { func CreateSoongInjectionFiles(metrics CodegenMetrics) []BazelFile { var files []BazelFile files = append(files, newFile("cc_toolchain", GeneratedBuildFileName, "")) // Creates a //cc_toolchain package. files = append(files, newFile("cc_toolchain", "constants.bzl", config.BazelCcToolchainVars())) files = append(files, newFile("module_name_to_label", GeneratedBuildFileName, nameToLabelAliases(compatLayer.NameToLabelMap))) files = append(files, newFile("metrics", "converted_modules.txt", strings.Join(metrics.convertedModules, "\n"))) return files } func nameToLabelAliases(nameToLabelMap map[string]string) string { ret := make([]string, len(nameToLabelMap)) for k, v := range nameToLabelMap { // v is the fully qualified label rooted at '//' ret = append(ret, fmt.Sprintf( `alias( name = "%s", actual = "@%s", )`, k, v)) } return strings.Join(ret, "\n\n") func convertedModules(convertedModules []string) string { return strings.Join(convertedModules, "\n") } func CreateBazelFiles( Loading