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

@@ -780,7 +780,6 @@ type genRuleProperties struct {
}
type bazelGenruleAttributes struct {
Name *string
Srcs bazel.LabelList
Outs []string
Tools bazel.LabelList
@@ -804,7 +803,7 @@ func GenruleBp2Build(ctx android.TopDownMutatorContext) {
if !ok {
return
}
name := "__bp2build__" + m.Name()
// Bazel only has the "tools" attribute.
tools := android.BazelLabelForModuleDeps(ctx, m.properties.Tools)
tool_files := android.BazelLabelForModuleSrc(ctx, m.properties.Tool_files)
@@ -847,16 +846,22 @@ func GenruleBp2Build(ctx android.TopDownMutatorContext) {
}
}
// Create the BazelTargetModule.
ctx.CreateModule(BazelGenruleFactory, &bazelGenruleAttributes{
Name: proptools.StringPtr(name),
attrs := &bazelGenruleAttributes{
Srcs: srcs,
Outs: outs,
Cmd: cmd,
Tools: tools,
}, &bazel.BazelTargetModuleProperties{
}
// Can we automate this?
name := "__bp2build__" + m.Name()
props := bazel.BazelTargetModuleProperties{
Name: &name,
Rule_class: "genrule",
})
}
// Create the BazelTargetModule.
ctx.CreateBazelTargetModule(BazelGenruleFactory, props, attrs)
}
func (m *bazelGenrule) Name() string {