bp2build: Refactor CreateBazelTargetModule API.
This CL refactors the CreateBazelTargetModule API to minimize boilerplate, and to establish a well defined function signature for the expected metadata about a BazelTargetModule.
Test: soong tests
Test: TH
Change-Id: I474ff5a2b0db8deeed49ba4ca73b416ccb494fdd
diff --git a/android/filegroup.go b/android/filegroup.go
index 7a6cc4f..b36238c 100644
--- a/android/filegroup.go
+++ b/android/filegroup.go
@@ -17,8 +17,6 @@
import (
"android/soong/bazel"
"strings"
-
- "github.com/google/blueprint/proptools"
)
func init() {
@@ -28,7 +26,6 @@
// https://docs.bazel.build/versions/master/be/general.html#filegroup
type bazelFilegroupAttributes struct {
- Name *string
Srcs bazel.LabelList
}
@@ -50,20 +47,23 @@
func (bfg *bazelFilegroup) GenerateAndroidBuildActions(ctx ModuleContext) {}
-// TODO: Create helper functions to avoid this boilerplate.
func FilegroupBp2Build(ctx TopDownMutatorContext) {
fg, ok := ctx.Module().(*fileGroup)
if !ok {
return
}
-
- name := "__bp2build__" + fg.base().BaseModuleName()
- ctx.CreateModule(BazelFileGroupFactory, &bazelFilegroupAttributes{
- Name: proptools.StringPtr(name),
+ attrs := &bazelFilegroupAttributes{
Srcs: BazelLabelForModuleSrcExcludes(ctx, fg.properties.Srcs, fg.properties.Exclude_srcs),
- }, &bazel.BazelTargetModuleProperties{
+ }
+
+ // Can we automate this?
+ name := "__bp2build__" + fg.Name()
+ props := bazel.BazelTargetModuleProperties{
+ Name: &name,
Rule_class: "filegroup",
- })
+ }
+
+ ctx.CreateBazelTargetModule(BazelFileGroupFactory, props, attrs)
}
type fileGroupProperties struct {