Handle product config vars in bp2build.

Test: bp2build ci  & mixed build libc
Bug: 183595873
Change-Id: I2d87434ff4df5a24efc5e3e38f087de035228934
This commit is contained in:
Liz Kammer
2021-05-06 13:54:29 -04:00
parent 32cf58a8fc
commit 6fd7b3fee9
6 changed files with 149 additions and 31 deletions

View File

@@ -318,6 +318,21 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul
}
}
productVariableProps := android.ProductVariableProperties(ctx)
if props, exists := productVariableProps["Cflags"]; exists {
for _, prop := range props {
flags, ok := prop.Property.([]string)
if !ok {
ctx.ModuleErrorf("Could not convert product variable cflag property")
}
newFlags, _ := bazel.TryVariableSubstitutions(flags, prop.ProductConfigVariable)
copts.ProductValues = append(copts.ProductValues, bazel.ProductVariableValues{
ProductVariable: prop.ProductConfigVariable,
Values: newFlags,
})
}
}
return compilerAttributes{
srcs: srcs,
copts: copts,

View File

@@ -116,7 +116,7 @@ type bazelObjectAttributes struct {
Hdrs bazel.LabelListAttribute
Deps bazel.LabelListAttribute
Copts bazel.StringListAttribute
Asflags []string
Asflags bazel.StringListAttribute
}
type bazelObject struct {
@@ -157,7 +157,7 @@ func ObjectBp2Build(ctx android.TopDownMutatorContext) {
// Set arch-specific configurable attributes
compilerAttrs := bp2BuildParseCompilerProps(ctx, m)
var asFlags []string
var asFlags bazel.StringListAttribute
var deps bazel.LabelListAttribute
for _, props := range m.linker.linkerProps() {
@@ -176,10 +176,11 @@ func ObjectBp2Build(ctx android.TopDownMutatorContext) {
ctx.ModuleErrorf("Could not convert product variable asflag property")
return
}
// TODO(b/183595873) handle other product variable usages -- as selects?
if newFlags, subbed := bazel.TryVariableSubstitutions(flags, prop.ProductConfigVariable); subbed {
asFlags = append(asFlags, newFlags...)
}
newFlags, _ := bazel.TryVariableSubstitutions(flags, prop.ProductConfigVariable)
asFlags.ProductValues = append(asFlags.ProductValues, bazel.ProductVariableValues{
ProductVariable: prop.ProductConfigVariable,
Values: newFlags,
})
}
}
// TODO(b/183595872) warn/error if we're not handling product variables