Merge "bp2build: Improve handling of generated_sources"

This commit is contained in:
Liz Kammer
2021-10-12 17:29:23 +00:00
committed by Gerrit Code Review
2 changed files with 55 additions and 30 deletions

View File

@@ -255,15 +255,22 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul
}
// Parse srcs from an arch or OS's props value.
parseSrcs := func(baseCompilerProps *BaseCompilerProperties) bazel.LabelList {
parseSrcs := func(props *BaseCompilerProperties) (bazel.LabelList, bool) {
anySrcs := false
// Add srcs-like dependencies such as generated files.
// First create a LabelList containing these dependencies, then merge the values with srcs.
generatedHdrsAndSrcs := baseCompilerProps.Generated_headers
generatedHdrsAndSrcs = append(generatedHdrsAndSrcs, baseCompilerProps.Generated_sources...)
generatedHdrsAndSrcsLabelList := android.BazelLabelForModuleDeps(ctx, generatedHdrsAndSrcs)
generatedHdrsAndSrcs := props.Generated_headers
generatedHdrsAndSrcs = append(generatedHdrsAndSrcs, props.Generated_sources...)
generatedHdrsAndSrcsLabelList := android.BazelLabelForModuleDepsExcludes(ctx, generatedHdrsAndSrcs, props.Exclude_generated_sources)
if len(generatedHdrsAndSrcs) > 0 || len(props.Exclude_generated_sources) > 0 {
anySrcs = true
}
allSrcsLabelList := android.BazelLabelForModuleSrcExcludes(ctx, baseCompilerProps.Srcs, baseCompilerProps.Exclude_srcs)
return bazel.AppendBazelLabelLists(allSrcsLabelList, generatedHdrsAndSrcsLabelList)
allSrcsLabelList := android.BazelLabelForModuleSrcExcludes(ctx, props.Srcs, props.Exclude_srcs)
if len(props.Srcs) > 0 || len(props.Exclude_srcs) > 0 {
anySrcs = true
}
return bazel.AppendBazelLabelLists(allSrcsLabelList, generatedHdrsAndSrcsLabelList), anySrcs
}
archVariantCompilerProps := module.GetArchVariantProperties(ctx, &BaseCompilerProperties{})
@@ -272,8 +279,7 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul
if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
// If there's arch specific srcs or exclude_srcs, generate a select entry for it.
// TODO(b/186153868): do this for OS specific srcs and exclude_srcs too.
if len(baseCompilerProps.Srcs) > 0 || len(baseCompilerProps.Exclude_srcs) > 0 {
srcsList := parseSrcs(baseCompilerProps)
if srcsList, ok := parseSrcs(baseCompilerProps); ok {
srcs.SetSelectValue(axis, config, srcsList)
}