Refactor how bp2build gets arch-specific props.
Then plumb them to LabelAttribute.
This refactoring is required because the previous implementation did not
handle properties in shards other than the first one (e.g.
version_script) well. In addition, it also makes the code paths between
bp2build and analysis more similar.
Bug: 186650430
Test: Presubmits.
Change-Id: Ic4393e8ae47f4e88816bf45c89399efd61494d22
diff --git a/cc/bp2build.go b/cc/bp2build.go
index d52b817..1433f6f 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -58,7 +58,7 @@
}
}
- for _, p := range module.GetArchProperties(&BaseLinkerProperties{}) {
+ for _, p := range module.GetArchProperties(ctx, &BaseLinkerProperties{}) {
// arch specific linker props
if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok {
allDeps = append(allDeps, baseLinkerProps.Header_libs...)
@@ -198,7 +198,7 @@
copts.Value = append(copts.Value, includeFlag("."))
}
- for arch, props := range module.GetArchProperties(&BaseCompilerProperties{}) {
+ for arch, props := range module.GetArchProperties(ctx, &BaseCompilerProperties{}) {
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.
@@ -215,7 +215,7 @@
// After going through all archs, delete the duplicate files in the arch
// values that are already in the base srcs.Value.
- for arch, props := range module.GetArchProperties(&BaseCompilerProperties{}) {
+ for arch, props := range module.GetArchProperties(ctx, &BaseCompilerProperties{}) {
if _, ok := props.(*BaseCompilerProperties); ok {
srcs.SetValueForArch(arch.Name, bazel.SubtractBazelLabelList(srcs.GetValueForArch(arch.Name), srcs.Value))
}
@@ -269,15 +269,13 @@
linkopts.Value = baseLinkerProps.Ldflags
if baseLinkerProps.Version_script != nil {
- versionScript = bazel.LabelAttribute{
- Value: android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script),
- }
+ versionScript.Value = android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script)
}
break
}
}
- for arch, p := range module.GetArchProperties(&BaseLinkerProperties{}) {
+ for arch, p := range module.GetArchProperties(ctx, &BaseLinkerProperties{}) {
if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok {
libs := baseLinkerProps.Header_libs
libs = append(libs, baseLinkerProps.Export_header_lib_headers...)
@@ -286,6 +284,10 @@
libs = android.SortedUniqueStrings(libs)
deps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, libs))
linkopts.SetValueForArch(arch.Name, baseLinkerProps.Ldflags)
+ if baseLinkerProps.Version_script != nil {
+ versionScript.SetValueForArch(arch.Name,
+ android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script))
+ }
}
}
@@ -343,7 +345,7 @@
includeDirs = append(includeDirs, libraryDecorator.flagExporter.Properties.Export_include_dirs...)
includeDirsAttribute := bazel.MakeStringListAttribute(includeDirs)
- for arch, props := range module.GetArchProperties(&FlagExporterProperties{}) {
+ for arch, props := range module.GetArchProperties(ctx, &FlagExporterProperties{}) {
if flagExporterProperties, ok := props.(*FlagExporterProperties); ok {
archIncludeDirs := flagExporterProperties.Export_system_include_dirs
archIncludeDirs = append(archIncludeDirs, flagExporterProperties.Export_include_dirs...)