Handle product vars *flags props in cc* modules

Test: build/bazel/ci/bp2build.sh
Bug: 188497994
Change-Id: Ifb379e370075d6a7bc55b82d79c210c31ef377e9
This commit is contained in:
Liz Kammer
2021-05-26 08:45:30 -04:00
parent f6840284b6
commit ba7a9c5e4a
5 changed files with 56 additions and 33 deletions

View File

@@ -19,6 +19,8 @@ import (
"android/soong/android"
"android/soong/bazel"
"github.com/google/blueprint/proptools"
)
// bp2build functions and helpers for converting cc_* modules to Bazel.
@@ -444,18 +446,25 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul
}
}
productVarPropNameToAttribute := map[string]*bazel.StringListAttribute{
"Cflags": &copts,
"Asflags": &asFlags,
"CppFlags": &cppFlags,
}
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")
for propName, attr := range productVarPropNameToAttribute {
if props, exists := productVariableProps[propName]; exists {
for _, prop := range props {
flags, ok := prop.Property.([]string)
if !ok {
ctx.ModuleErrorf("Could not convert product variable %s property", proptools.PropertyNameForField(propName))
}
newFlags, _ := bazel.TryVariableSubstitutions(flags, prop.ProductConfigVariable)
attr.ProductValues = append(attr.ProductValues, bazel.ProductVariableValues{
ProductVariable: prop.ProductConfigVariable,
Values: newFlags,
})
}
newFlags, _ := bazel.TryVariableSubstitutions(flags, prop.ProductConfigVariable)
copts.ProductValues = append(copts.ProductValues, bazel.ProductVariableValues{
ProductVariable: prop.ProductConfigVariable,
Values: newFlags,
})
}
}