Loading android/filegroup.go +1 −6 Original line number Diff line number Diff line Loading @@ -57,12 +57,7 @@ func FilegroupBp2Build(ctx TopDownMutatorContext) { Srcs: BazelLabelForModuleSrcExcludes(ctx, fg.properties.Srcs, fg.properties.Exclude_srcs), } // Can we automate this? name := "__bp2build__" + fg.Name() props := bazel.BazelTargetModuleProperties{ Name: &name, Rule_class: "filegroup", } props := bazel.NewBazelTargetModuleProperties(fg.Name(), "filegroup", "") ctx.CreateBazelTargetModule(BazelFileGroupFactory, props, attrs) } Loading android/mutator.go +10 −0 Original line number Diff line number Diff line Loading @@ -16,7 +16,9 @@ package android import ( "android/soong/bazel" "fmt" "reflect" "strings" "github.com/google/blueprint" "github.com/google/blueprint/proptools" Loading Loading @@ -513,6 +515,14 @@ func (t *topDownMutatorContext) CreateBazelTargetModule( factory ModuleFactory, bazelProps bazel.BazelTargetModuleProperties, attrs interface{}) BazelTargetModule { if !strings.HasPrefix(*bazelProps.Name, bazel.BazelTargetModuleNamePrefix) { panic(fmt.Errorf( "bp2build error: the bazel target module name must start with '%s': %s", bazel.BazelTargetModuleNamePrefix, *bazelProps.Name, )) } return t.CreateModule(factory, &bazelProps, attrs).(BazelTargetModule) } Loading bazel/properties.go +22 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,11 @@ package bazel import ( "fmt" "strings" ) type bazelModuleProperties struct { // The label of the Bazel target replacing this Soong module. Label string Loading Loading @@ -41,6 +46,23 @@ type BazelTargetModuleProperties struct { Bzl_load_location string } const BazelTargetModuleNamePrefix = "__bp2build__" func NewBazelTargetModuleProperties(name string, ruleClass string, bzlLoadLocation string) BazelTargetModuleProperties { if strings.HasPrefix(name, BazelTargetModuleNamePrefix) { panic(fmt.Errorf( "The %s name prefix is added automatically, do not set it manually: %s", BazelTargetModuleNamePrefix, name)) } name = BazelTargetModuleNamePrefix + name return BazelTargetModuleProperties{ Name: &name, Rule_class: ruleClass, Bzl_load_location: bzlLoadLocation, } } // Label is used to represent a Bazel compatible Label. Also stores the original bp text to support // string replacement. type Label struct { Loading bp2build/build_conversion.go +1 −1 Original line number Diff line number Diff line Loading @@ -469,7 +469,7 @@ func makeIndent(indent int) string { } func targetNameForBp2Build(c bpToBuildContext, logicModule blueprint.Module) string { return strings.Replace(c.ModuleName(logicModule), "__bp2build__", "", 1) return strings.Replace(c.ModuleName(logicModule), bazel.BazelTargetModuleNamePrefix, "", 1) } func targetNameWithVariant(c bpToBuildContext, logicModule blueprint.Module) string { Loading bp2build/testing.go +16 −23 Original line number Diff line number Diff line Loading @@ -136,11 +136,7 @@ func customBp2BuildMutator(ctx android.TopDownMutatorContext) { String_list_prop: m.props.String_list_prop, } name := "__bp2build__" + m.Name() props := bazel.BazelTargetModuleProperties{ Name: &name, Rule_class: "custom", } props := bazel.NewBazelTargetModuleProperties(m.Name(), "custom", "") ctx.CreateBazelTargetModule(customBazelModuleFactory, props, attrs) } Loading @@ -157,28 +153,25 @@ func customBp2BuildMutatorFromStarlark(ctx android.TopDownMutatorContext) { baseName := m.Name() attrs := &customBazelModuleAttributes{} myLibraryName := "__bp2build__" + baseName myLibraryProps := bazel.BazelTargetModuleProperties{ Name: &myLibraryName, Rule_class: "my_library", Bzl_load_location: "//build/bazel/rules:rules.bzl", } myLibraryProps := bazel.NewBazelTargetModuleProperties( baseName, "my_library", "//build/bazel/rules:rules.bzl", ) ctx.CreateBazelTargetModule(customBazelModuleFactory, myLibraryProps, attrs) protoLibraryName := "__bp2build__" + baseName + "_proto_library_deps" protoLibraryProps := bazel.BazelTargetModuleProperties{ Name: &protoLibraryName, Rule_class: "proto_library", Bzl_load_location: "//build/bazel/rules:proto.bzl", } protoLibraryProps := bazel.NewBazelTargetModuleProperties( baseName+"_proto_library_deps", "proto_library", "//build/bazel/rules:proto.bzl", ) ctx.CreateBazelTargetModule(customBazelModuleFactory, protoLibraryProps, attrs) myProtoLibraryName := "__bp2build__" + baseName + "_my_proto_library_deps" myProtoLibraryProps := bazel.BazelTargetModuleProperties{ Name: &myProtoLibraryName, Rule_class: "my_proto_library", Bzl_load_location: "//build/bazel/rules:proto.bzl", } myProtoLibraryProps := bazel.NewBazelTargetModuleProperties( baseName+"_my_proto_library_deps", "my_proto_library", "//build/bazel/rules:proto.bzl", ) ctx.CreateBazelTargetModule(customBazelModuleFactory, myProtoLibraryProps, attrs) } } Loading
android/filegroup.go +1 −6 Original line number Diff line number Diff line Loading @@ -57,12 +57,7 @@ func FilegroupBp2Build(ctx TopDownMutatorContext) { Srcs: BazelLabelForModuleSrcExcludes(ctx, fg.properties.Srcs, fg.properties.Exclude_srcs), } // Can we automate this? name := "__bp2build__" + fg.Name() props := bazel.BazelTargetModuleProperties{ Name: &name, Rule_class: "filegroup", } props := bazel.NewBazelTargetModuleProperties(fg.Name(), "filegroup", "") ctx.CreateBazelTargetModule(BazelFileGroupFactory, props, attrs) } Loading
android/mutator.go +10 −0 Original line number Diff line number Diff line Loading @@ -16,7 +16,9 @@ package android import ( "android/soong/bazel" "fmt" "reflect" "strings" "github.com/google/blueprint" "github.com/google/blueprint/proptools" Loading Loading @@ -513,6 +515,14 @@ func (t *topDownMutatorContext) CreateBazelTargetModule( factory ModuleFactory, bazelProps bazel.BazelTargetModuleProperties, attrs interface{}) BazelTargetModule { if !strings.HasPrefix(*bazelProps.Name, bazel.BazelTargetModuleNamePrefix) { panic(fmt.Errorf( "bp2build error: the bazel target module name must start with '%s': %s", bazel.BazelTargetModuleNamePrefix, *bazelProps.Name, )) } return t.CreateModule(factory, &bazelProps, attrs).(BazelTargetModule) } Loading
bazel/properties.go +22 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,11 @@ package bazel import ( "fmt" "strings" ) type bazelModuleProperties struct { // The label of the Bazel target replacing this Soong module. Label string Loading Loading @@ -41,6 +46,23 @@ type BazelTargetModuleProperties struct { Bzl_load_location string } const BazelTargetModuleNamePrefix = "__bp2build__" func NewBazelTargetModuleProperties(name string, ruleClass string, bzlLoadLocation string) BazelTargetModuleProperties { if strings.HasPrefix(name, BazelTargetModuleNamePrefix) { panic(fmt.Errorf( "The %s name prefix is added automatically, do not set it manually: %s", BazelTargetModuleNamePrefix, name)) } name = BazelTargetModuleNamePrefix + name return BazelTargetModuleProperties{ Name: &name, Rule_class: ruleClass, Bzl_load_location: bzlLoadLocation, } } // Label is used to represent a Bazel compatible Label. Also stores the original bp text to support // string replacement. type Label struct { Loading
bp2build/build_conversion.go +1 −1 Original line number Diff line number Diff line Loading @@ -469,7 +469,7 @@ func makeIndent(indent int) string { } func targetNameForBp2Build(c bpToBuildContext, logicModule blueprint.Module) string { return strings.Replace(c.ModuleName(logicModule), "__bp2build__", "", 1) return strings.Replace(c.ModuleName(logicModule), bazel.BazelTargetModuleNamePrefix, "", 1) } func targetNameWithVariant(c bpToBuildContext, logicModule blueprint.Module) string { Loading
bp2build/testing.go +16 −23 Original line number Diff line number Diff line Loading @@ -136,11 +136,7 @@ func customBp2BuildMutator(ctx android.TopDownMutatorContext) { String_list_prop: m.props.String_list_prop, } name := "__bp2build__" + m.Name() props := bazel.BazelTargetModuleProperties{ Name: &name, Rule_class: "custom", } props := bazel.NewBazelTargetModuleProperties(m.Name(), "custom", "") ctx.CreateBazelTargetModule(customBazelModuleFactory, props, attrs) } Loading @@ -157,28 +153,25 @@ func customBp2BuildMutatorFromStarlark(ctx android.TopDownMutatorContext) { baseName := m.Name() attrs := &customBazelModuleAttributes{} myLibraryName := "__bp2build__" + baseName myLibraryProps := bazel.BazelTargetModuleProperties{ Name: &myLibraryName, Rule_class: "my_library", Bzl_load_location: "//build/bazel/rules:rules.bzl", } myLibraryProps := bazel.NewBazelTargetModuleProperties( baseName, "my_library", "//build/bazel/rules:rules.bzl", ) ctx.CreateBazelTargetModule(customBazelModuleFactory, myLibraryProps, attrs) protoLibraryName := "__bp2build__" + baseName + "_proto_library_deps" protoLibraryProps := bazel.BazelTargetModuleProperties{ Name: &protoLibraryName, Rule_class: "proto_library", Bzl_load_location: "//build/bazel/rules:proto.bzl", } protoLibraryProps := bazel.NewBazelTargetModuleProperties( baseName+"_proto_library_deps", "proto_library", "//build/bazel/rules:proto.bzl", ) ctx.CreateBazelTargetModule(customBazelModuleFactory, protoLibraryProps, attrs) myProtoLibraryName := "__bp2build__" + baseName + "_my_proto_library_deps" myProtoLibraryProps := bazel.BazelTargetModuleProperties{ Name: &myProtoLibraryName, Rule_class: "my_proto_library", Bzl_load_location: "//build/bazel/rules:proto.bzl", } myProtoLibraryProps := bazel.NewBazelTargetModuleProperties( baseName+"_my_proto_library_deps", "my_proto_library", "//build/bazel/rules:proto.bzl", ) ctx.CreateBazelTargetModule(customBazelModuleFactory, myProtoLibraryProps, attrs) } }