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/android/module.go b/android/module.go
index bf74cad..58675d4 100644
--- a/android/module.go
+++ b/android/module.go
@@ -507,13 +507,17 @@
type BazelTargetModule interface {
Module
- BazelTargetModuleProperties() *bazel.BazelTargetModuleProperties
+ bazelTargetModuleProperties() *bazel.BazelTargetModuleProperties
+ SetBazelTargetModuleProperties(props bazel.BazelTargetModuleProperties)
+
+ RuleClass() string
+ BzlLoadLocation() string
}
// InitBazelTargetModule is a wrapper function that decorates BazelTargetModule
// with property structs containing metadata for bp2build conversion.
func InitBazelTargetModule(module BazelTargetModule) {
- module.AddProperties(module.BazelTargetModuleProperties())
+ module.AddProperties(module.bazelTargetModuleProperties())
InitAndroidModule(module)
}
@@ -524,11 +528,26 @@
Properties bazel.BazelTargetModuleProperties
}
-// BazelTargetModuleProperties getter.
-func (btmb *BazelTargetModuleBase) BazelTargetModuleProperties() *bazel.BazelTargetModuleProperties {
+// bazelTargetModuleProperties getter.
+func (btmb *BazelTargetModuleBase) bazelTargetModuleProperties() *bazel.BazelTargetModuleProperties {
return &btmb.Properties
}
+// SetBazelTargetModuleProperties setter for BazelTargetModuleProperties
+func (btmb *BazelTargetModuleBase) SetBazelTargetModuleProperties(props bazel.BazelTargetModuleProperties) {
+ btmb.Properties = props
+}
+
+// RuleClass returns the rule class for this Bazel target
+func (b *BazelTargetModuleBase) RuleClass() string {
+ return b.bazelTargetModuleProperties().Rule_class
+}
+
+// BzlLoadLocation returns the rule class for this Bazel target
+func (b *BazelTargetModuleBase) BzlLoadLocation() string {
+ return b.bazelTargetModuleProperties().Bzl_load_location
+}
+
// Qualified id for a module
type qualifiedModuleName struct {
// The package (i.e. directory) in which the module is defined, without trailing /