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
This commit is contained in:
Liz Kammer
2021-02-19 11:06:17 -05:00
parent ece454400d
commit fc46bc1ee4
10 changed files with 85 additions and 102 deletions

View File

@@ -507,13 +507,17 @@ type Module interface {
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 @@ type BazelTargetModuleBase struct {
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 /