Refactor BazelTargetModule
This eliminates the need to remove quotes, delete attributes, and
re-checking that name has correct prefix. Additionally, this allows
assignment directly to the BazelTargetModuleProperties struct, which
allows defaulting unused fields and clarity of which field is being set.
Test: go test soong tests
Test: ran ./build/bazel/scripts/milestone-2/demo.sh
Change-Id: Ia9bfcce76234c793a4ddd5f29a661150f83341c9
diff --git a/bazel/properties.go b/bazel/properties.go
index 8055306..a4df4bc 100644
--- a/bazel/properties.go
+++ b/bazel/properties.go
@@ -14,11 +14,6 @@
package bazel
-import (
- "fmt"
- "strings"
-)
-
type bazelModuleProperties struct {
// The label of the Bazel target replacing this Soong module.
Label string
@@ -37,32 +32,15 @@
// BazelTargetModuleProperties contain properties and metadata used for
// Blueprint to BUILD file conversion.
type BazelTargetModuleProperties struct {
- Name *string
-
// The Bazel rule class for this target.
- Rule_class string
+ Rule_class string `blueprint:"mutated"`
// The target label for the bzl file containing the definition of the rule class.
- Bzl_load_location string
+ Bzl_load_location string `blueprint:"mutated"`
}
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 {