Loading bazel/properties.go +5 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import ( "path/filepath" "regexp" "sort" "strings" ) // BazelTargetModuleProperties contain properties and metadata used for Loading @@ -33,6 +34,10 @@ type BazelTargetModuleProperties struct { const BazelTargetModuleNamePrefix = "__bp2build__" func StripNamePrefix(moduleName string) string { return strings.TrimPrefix(moduleName, BazelTargetModuleNamePrefix) } var productVariableSubstitutionPattern = regexp.MustCompile("%(d|s)") // Label is used to represent a Bazel compatible Label. Also stores the original Loading bp2build/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ bootstrap_go_package { "build_conversion.go", "bzl_conversion.go", "configurability.go", "compatibility.go", "constants.go", "conversion.go", "metrics.go", Loading bp2build/bp2build.go +2 −2 Original line number Diff line number Diff line Loading @@ -29,12 +29,12 @@ func Codegen(ctx *CodegenContext) CodegenMetrics { bp2buildDir := android.PathForOutput(ctx, "bp2build") android.RemoveAllOutputDir(bp2buildDir) buildToTargets, metrics := GenerateBazelTargets(ctx, true) buildToTargets, metrics, compatLayer := GenerateBazelTargets(ctx, true) bp2buildFiles := CreateBazelFiles(nil, buildToTargets, ctx.mode) writeFiles(ctx, bp2buildDir, bp2buildFiles) soongInjectionDir := android.PathForOutput(ctx, bazel.SoongInjectionDirName) writeFiles(ctx, soongInjectionDir, CreateSoongInjectionFiles()) writeFiles(ctx, soongInjectionDir, CreateSoongInjectionFiles(compatLayer)) return metrics } Loading bp2build/build_conversion.go +20 −2 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ type BazelAttributes struct { type BazelTarget struct { name string packageName string content string ruleClass string bzlLoadLocation string Loading @@ -44,6 +45,16 @@ func (t BazelTarget) IsLoadedFromStarlark() bool { return t.bzlLoadLocation != "" } // Label is the fully qualified Bazel label constructed from the BazelTarget's // package name and target name. func (t BazelTarget) Label() string { if t.packageName == "." { return "//:" + t.name } else { return "//" + t.packageName + ":" + t.name } } // BazelTargets is a typedef for a slice of BazelTarget objects. type BazelTargets []BazelTarget Loading Loading @@ -213,7 +224,7 @@ func propsToAttributes(props map[string]string) string { return attributes } func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (map[string]BazelTargets, CodegenMetrics) { func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (map[string]BazelTargets, CodegenMetrics, CodegenCompatLayer) { buildFileToTargets := make(map[string]BazelTargets) buildFileToAppend := make(map[string]bool) Loading @@ -222,6 +233,10 @@ func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (map[str RuleClassCount: make(map[string]int), } compatLayer := CodegenCompatLayer{ NameToLabelMap: make(map[string]string), } dirs := make(map[string]bool) bpCtx := ctx.Context() Loading @@ -236,6 +251,7 @@ func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (map[str if b, ok := m.(android.Bazelable); ok && b.HasHandcraftedLabel() { metrics.handCraftedTargetCount += 1 metrics.TotalModuleCount += 1 compatLayer.AddNameToLabelEntry(m.Name(), b.HandcraftedLabel()) 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 @@ -253,6 +269,7 @@ func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (map[str } else if btm, ok := m.(android.BazelTargetModule); ok { t = generateBazelTarget(bpCtx, m, btm) metrics.RuleClassCount[t.ruleClass] += 1 compatLayer.AddNameToLabelEntry(m.Name(), t.Label()) } else { metrics.TotalModuleCount += 1 return Loading Loading @@ -283,7 +300,7 @@ func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (map[str } } return buildFileToTargets, metrics return buildFileToTargets, metrics, compatLayer } func getBazelPackagePath(b android.Bazelable) string { Loading Loading @@ -324,6 +341,7 @@ func generateBazelTarget(ctx bpToBuildContext, m blueprint.Module, btm android.B targetName := targetNameForBp2Build(ctx, m) return BazelTarget{ name: targetName, packageName: ctx.ModuleDir(m), ruleClass: ruleClass, bzlLoadLocation: bzlLoadLocation, content: fmt.Sprintf( Loading bp2build/build_conversion_test.go +37 −31 Original line number Diff line number Diff line Loading @@ -1414,25 +1414,31 @@ filegroup { }, }, { description: "filegroup bazel_module.label and bp2build", description: "filegroup bazel_module.label and bp2build in subdir", moduleTypeUnderTest: "filegroup", moduleTypeUnderTestFactory: android.FileGroupFactory, moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, bp: `filegroup { dir: "other", bp: ``, fs: map[string]string{ "other/Android.bp": `filegroup { name: "fg_foo", bazel_module: { label: "//other:fg_foo", bp2build_available: true, }, } filegroup { name: "fg_bar", bazel_module: { label: "//other:fg_bar" }, }`, "other/BUILD.bazel": `// definition for fg_bar`, }, expectedBazelTargets: []string{ `filegroup( name = "fg_foo", )`, `// BUILD file`, }, fs: map[string]string{ "other/BUILD.bazel": `// BUILD file`, )`, `// definition for fg_bar`, }, }, { Loading Loading
bazel/properties.go +5 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import ( "path/filepath" "regexp" "sort" "strings" ) // BazelTargetModuleProperties contain properties and metadata used for Loading @@ -33,6 +34,10 @@ type BazelTargetModuleProperties struct { const BazelTargetModuleNamePrefix = "__bp2build__" func StripNamePrefix(moduleName string) string { return strings.TrimPrefix(moduleName, BazelTargetModuleNamePrefix) } var productVariableSubstitutionPattern = regexp.MustCompile("%(d|s)") // Label is used to represent a Bazel compatible Label. Also stores the original Loading
bp2build/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ bootstrap_go_package { "build_conversion.go", "bzl_conversion.go", "configurability.go", "compatibility.go", "constants.go", "conversion.go", "metrics.go", Loading
bp2build/bp2build.go +2 −2 Original line number Diff line number Diff line Loading @@ -29,12 +29,12 @@ func Codegen(ctx *CodegenContext) CodegenMetrics { bp2buildDir := android.PathForOutput(ctx, "bp2build") android.RemoveAllOutputDir(bp2buildDir) buildToTargets, metrics := GenerateBazelTargets(ctx, true) buildToTargets, metrics, compatLayer := GenerateBazelTargets(ctx, true) bp2buildFiles := CreateBazelFiles(nil, buildToTargets, ctx.mode) writeFiles(ctx, bp2buildDir, bp2buildFiles) soongInjectionDir := android.PathForOutput(ctx, bazel.SoongInjectionDirName) writeFiles(ctx, soongInjectionDir, CreateSoongInjectionFiles()) writeFiles(ctx, soongInjectionDir, CreateSoongInjectionFiles(compatLayer)) return metrics } Loading
bp2build/build_conversion.go +20 −2 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ type BazelAttributes struct { type BazelTarget struct { name string packageName string content string ruleClass string bzlLoadLocation string Loading @@ -44,6 +45,16 @@ func (t BazelTarget) IsLoadedFromStarlark() bool { return t.bzlLoadLocation != "" } // Label is the fully qualified Bazel label constructed from the BazelTarget's // package name and target name. func (t BazelTarget) Label() string { if t.packageName == "." { return "//:" + t.name } else { return "//" + t.packageName + ":" + t.name } } // BazelTargets is a typedef for a slice of BazelTarget objects. type BazelTargets []BazelTarget Loading Loading @@ -213,7 +224,7 @@ func propsToAttributes(props map[string]string) string { return attributes } func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (map[string]BazelTargets, CodegenMetrics) { func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (map[string]BazelTargets, CodegenMetrics, CodegenCompatLayer) { buildFileToTargets := make(map[string]BazelTargets) buildFileToAppend := make(map[string]bool) Loading @@ -222,6 +233,10 @@ func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (map[str RuleClassCount: make(map[string]int), } compatLayer := CodegenCompatLayer{ NameToLabelMap: make(map[string]string), } dirs := make(map[string]bool) bpCtx := ctx.Context() Loading @@ -236,6 +251,7 @@ func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (map[str if b, ok := m.(android.Bazelable); ok && b.HasHandcraftedLabel() { metrics.handCraftedTargetCount += 1 metrics.TotalModuleCount += 1 compatLayer.AddNameToLabelEntry(m.Name(), b.HandcraftedLabel()) 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 @@ -253,6 +269,7 @@ func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (map[str } else if btm, ok := m.(android.BazelTargetModule); ok { t = generateBazelTarget(bpCtx, m, btm) metrics.RuleClassCount[t.ruleClass] += 1 compatLayer.AddNameToLabelEntry(m.Name(), t.Label()) } else { metrics.TotalModuleCount += 1 return Loading Loading @@ -283,7 +300,7 @@ func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (map[str } } return buildFileToTargets, metrics return buildFileToTargets, metrics, compatLayer } func getBazelPackagePath(b android.Bazelable) string { Loading Loading @@ -324,6 +341,7 @@ func generateBazelTarget(ctx bpToBuildContext, m blueprint.Module, btm android.B targetName := targetNameForBp2Build(ctx, m) return BazelTarget{ name: targetName, packageName: ctx.ModuleDir(m), ruleClass: ruleClass, bzlLoadLocation: bzlLoadLocation, content: fmt.Sprintf( Loading
bp2build/build_conversion_test.go +37 −31 Original line number Diff line number Diff line Loading @@ -1414,25 +1414,31 @@ filegroup { }, }, { description: "filegroup bazel_module.label and bp2build", description: "filegroup bazel_module.label and bp2build in subdir", moduleTypeUnderTest: "filegroup", moduleTypeUnderTestFactory: android.FileGroupFactory, moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, bp: `filegroup { dir: "other", bp: ``, fs: map[string]string{ "other/Android.bp": `filegroup { name: "fg_foo", bazel_module: { label: "//other:fg_foo", bp2build_available: true, }, } filegroup { name: "fg_bar", bazel_module: { label: "//other:fg_bar" }, }`, "other/BUILD.bazel": `// definition for fg_bar`, }, expectedBazelTargets: []string{ `filegroup( name = "fg_foo", )`, `// BUILD file`, }, fs: map[string]string{ "other/BUILD.bazel": `// BUILD file`, )`, `// definition for fg_bar`, }, }, { Loading