diff options
author | Liz Kammer <eakammer@google.com> | 2021-03-31 18:43:55 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2021-03-31 18:43:55 +0000 |
commit | acacbc1166780ce31cb100856b373581f145453a (patch) | |
tree | 878e6cbb55e260c16114edc688aa3bf5e86d0ff8 /bazel | |
parent | 7dfaa3a7326986208b9fd3339e54ad1452c9cab0 (diff) | |
parent | a060c4521e6eaac8918b1984c2a6b6d089d00527 (diff) | |
download | soong-acacbc1166780ce31cb100856b373581f145453a.tar.gz |
Merge "Handle product_variable asflag for cc_object."
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 25e110a67..1763f2dc0 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 { @@ -225,3 +228,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 +} |