Support both $() and ${} substitution in plist files.
Some third_party libraries uses $() to represent substitution
variables in Info.plist. Add support for them to plist_util.py.
Bug: none
Change-Id: Icc16fc0ed39d4b9365ed3cf6b687f65d430b842d
Reviewed-on: https://chromium-review.googlesource.com/733841
Commit-Queue: Sylvain Defresne <[email protected]>
Reviewed-by: Robert Sesek <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#511256}(cherry picked from commit 0a50430601ceda22003b0e806f6e6378eaf85532)
Reviewed-on: https://chromium-review.googlesource.com/752381
Reviewed-by: Sylvain Defresne <[email protected]>
Cr-Commit-Position: refs/branch-heads/3239@{#401}
Cr-Branched-From: adb61db19020ed8ecee5e91b1a0ea4c924ae2988-refs/heads/master@{#508578}
diff --git a/build/config/mac/plist_util.py b/build/config/mac/plist_util.py
index 80d1323..bba0208 100644
--- a/build/config/mac/plist_util.py
+++ b/build/config/mac/plist_util.py
@@ -12,13 +12,17 @@
import shlex
-# Xcode substitutes variables like ${PRODUCT_NAME} when compiling Info.plist.
-# It also supports supports modifiers like :identifier or :rfc1034identifier.
-# SUBST_RE matches a variable substitution pattern with an optional modifier,
-# while IDENT_RE matches all characters that are not valid in an "identifier"
-# value (used when applying the modifier).
-SUBST_RE = re.compile(r'\$\{(?P<id>[^}]*?)(?P<modifier>:[^}]*)?\}')
-IDENT_RE = re.compile(r'[_/\s]')
+# Xcode substitutes variables like ${PRODUCT_NAME} or $(PRODUCT_NAME) when
+# compiling Info.plist. It also supports supports modifiers like :identifier
+# or :rfc1034identifier. SUBSTITUTION_REGEXP_LIST is a list of regular
+# expressions matching a variable substitution pattern with an optional
+# modifier, while INVALID_CHARACTER_REGEXP matches all characters that are
+# not valid in an "identifier" value (used when applying the modifier).
+INVALID_CHARACTER_REGEXP = re.compile(r'[_/\s]')
+SUBSTITUTION_REGEXP_LIST = (
+ re.compile(r'\$\{(?P<id>[^}]*?)(?P<modifier>:[^}]*)?\}'),
+ re.compile(r'\$\((?P<id>[^}]*?)(?P<modifier>:[^}]*)?\)'),
+)
class SubstitutionError(Exception):
@@ -52,12 +56,14 @@
# "rfc1034identifier" replaces them by "-" to make valid URI too).
modifier = match.group('modifier')
if modifier == ':identifier':
- return IDENT_RE.sub('_', substitutions[variable])
+ return INVALID_CHARACTER_REGEXP.sub('_', substitutions[variable])
elif modifier == ':rfc1034identifier':
- return IDENT_RE.sub('-', substitutions[variable])
+ return INVALID_CHARACTER_REGEXP.sub('-', substitutions[variable])
else:
return substitutions[variable]
- return SUBST_RE.sub(repl, value)
+ for substitution_regexp in SUBSTITUTION_REGEXP_LIST:
+ value = substitution_regexp.sub(repl, value)
+ return value
def Interpolate(value, substitutions):