bp2build: add configurable attribute (select) support.
This CL adds a basic framework to support configurable string_list attributes, selecting on the Arch variant (x86, x86_64, arm, arm64). It offers fine-grained controls to map individual configurable properties (arch_variant) to configurable Bazel attributes, starting with the string_list type for the copts property for cc_object. This design is primarily motivated to have minimal boilerplate in bp2build mutators, allowing anyone to opt-in configurable attributes, and modify intermediate states before passing them on into the CreateBazelTargetModule instantiator. Fixes: 178130668 Test: go tests Test: build/bazel/scripts/milestone-2/demo.sh Change-Id: Id6f04d7c560312a93e193d7ca4e1b7ceb6062260
This commit is contained in:
14
cc/object.go
14
cc/object.go
@@ -93,7 +93,7 @@ func ObjectFactory() android.Module {
|
||||
type bazelObjectAttributes struct {
|
||||
Srcs bazel.LabelList
|
||||
Deps bazel.LabelList
|
||||
Copts []string
|
||||
Copts bazel.StringListAttribute
|
||||
Local_include_dirs []string
|
||||
}
|
||||
|
||||
@@ -133,13 +133,14 @@ func ObjectBp2Build(ctx android.TopDownMutatorContext) {
|
||||
ctx.ModuleErrorf("compiler must not be nil for a cc_object module")
|
||||
}
|
||||
|
||||
var copts []string
|
||||
// Set arch-specific configurable attributes
|
||||
var copts bazel.StringListAttribute
|
||||
var srcs []string
|
||||
var excludeSrcs []string
|
||||
var localIncludeDirs []string
|
||||
for _, props := range m.compiler.compilerProps() {
|
||||
if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
|
||||
copts = baseCompilerProps.Cflags
|
||||
copts.Value = baseCompilerProps.Cflags
|
||||
srcs = baseCompilerProps.Srcs
|
||||
excludeSrcs = baseCompilerProps.Exclude_srcs
|
||||
localIncludeDirs = baseCompilerProps.Local_include_dirs
|
||||
@@ -154,6 +155,13 @@ func ObjectBp2Build(ctx android.TopDownMutatorContext) {
|
||||
}
|
||||
}
|
||||
|
||||
for arch, p := range m.GetArchProperties(&BaseCompilerProperties{}) {
|
||||
if cProps, ok := p.(*BaseCompilerProperties); ok {
|
||||
copts.SetValueForArch(arch.Name, cProps.Cflags)
|
||||
}
|
||||
}
|
||||
copts.SetValueForArch("default", []string{})
|
||||
|
||||
attrs := &bazelObjectAttributes{
|
||||
Srcs: android.BazelLabelForModuleSrcExcludes(ctx, srcs, excludeSrcs),
|
||||
Deps: deps,
|
||||
|
Reference in New Issue
Block a user