diff options
author | Liz Kammer <eakammer@google.com> | 2021-03-24 10:14:47 -0400 |
---|---|---|
committer | Liz Kammer <eakammer@google.com> | 2021-03-30 15:16:43 -0400 |
commit | a060c4521e6eaac8918b1984c2a6b6d089d00527 (patch) | |
tree | cd22f4f8cc8959a0bad2d89c2c73945e0b59096a /bazel | |
parent | dca349a7823e6efdfd15965342235077f0d77c60 (diff) | |
download | soong-a060c4521e6eaac8918b1984c2a6b6d089d00527.tar.gz |
Handle product_variable asflag for cc_object.
cc_object crtbrand sets product_variable.platform_sdk_version.asflag
and will not compile correctly within mixed builds without it.
Only handles product_variables that expand product variables.
Bug: 181794963
Test: ~/aosp/build/bazel/scripts/milestone-2/demo.sh full
Change-Id: I293fcb18032aa51f63bb7b3de94abd6d1ec38180
Diffstat (limited to 'bazel')
-rw-r--r-- | bazel/properties.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/bazel/properties.go b/bazel/properties.go index abdc1077d..38e32e714 100644 --- a/bazel/properties.go +++ b/bazel/properties.go @@ -16,6 +16,7 @@ package bazel import ( "fmt" + "regexp" "sort" ) @@ -31,6 +32,8 @@ type BazelTargetModuleProperties struct { const BazelTargetModuleNamePrefix = "__bp2build__" +var productVariableSubstitutionPattern = regexp.MustCompile("%(d|s)") + // Label is used to represent a Bazel compatible Label. Also stores the original bp text to support // string replacement. type Label struct { @@ -144,3 +147,23 @@ func (attrs *StringListAttribute) SetValueForArch(arch string, value []string) { panic(fmt.Errorf("Unknown arch: %s", arch)) } } + +// TryVariableSubstitution, replace string substitution formatting within each string in slice with +// Starlark string.format compatible tag for productVariable. +func TryVariableSubstitutions(slice []string, productVariable string) ([]string, bool) { + ret := make([]string, 0, len(slice)) + changesMade := false + for _, s := range slice { + newS, changed := TryVariableSubstitution(s, productVariable) + ret = append(ret, newS) + changesMade = changesMade || changed + } + return ret, changesMade +} + +// TryVariableSubstitution, replace string substitution formatting within s with Starlark +// string.format compatible tag for productVariable. +func TryVariableSubstitution(s string, productVariable string) (string, bool) { + sub := productVariableSubstitutionPattern.ReplaceAllString(s, "{"+productVariable+"}") + return sub, s != sub +} |