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
This commit is contained in:
Jingwen Chen
2021-02-05 03:01:50 -05:00
parent b7eab01167
commit 1fd14691dd
5 changed files with 67 additions and 38 deletions

View File

@@ -17,8 +17,6 @@ package android
import (
"android/soong/bazel"
"strings"
"github.com/google/blueprint/proptools"
)
func init() {
@@ -28,7 +26,6 @@ func init() {
// 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) Name() string {
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 {