bp2build: refactor BazelTargetModule naming boilerplate.
This CL replaces the "__bp2build__" name prefix boilerplate with a props
creation function, and centralizes the prefixing in there.
Test: TH
Test: soong tests
Change-Id: Ic963199ab60dcce0d3361abff111cfa9acd4c21b
diff --git a/bazel/properties.go b/bazel/properties.go
index 65f37e3..8055306 100644
--- a/bazel/properties.go
+++ b/bazel/properties.go
@@ -14,6 +14,11 @@
package bazel
+import (
+ "fmt"
+ "strings"
+)
+
type bazelModuleProperties struct {
// The label of the Bazel target replacing this Soong module.
Label string
@@ -41,6 +46,23 @@
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 {