summaryrefslogtreecommitdiff
path: root/tools/setup.py
diff options
context:
space:
mode:
authorBert Belder <bertbelder@gmail.com>2018-09-25 14:45:27 -0700
committerBert Belder <bertbelder@gmail.com>2018-09-26 09:52:30 -0700
commit023b4640fc4c8bf3efd4f5f8914552cdae6d142b (patch)
tree89051ecaf1a2cbe147d01501288533881e32a1be /tools/setup.py
parent1b9424e9d78990100ac82697a20515f9cb9e8335 (diff)
tools/setup: add gn_string() utility function
Diffstat (limited to 'tools/setup.py')
-rwxr-xr-xtools/setup.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/tools/setup.py b/tools/setup.py
index 1f065769a..1a0b491c0 100755
--- a/tools/setup.py
+++ b/tools/setup.py
@@ -54,6 +54,18 @@ gn_args_header = [
]
+def gn_string(s):
+ # In gn, strings are enclosed in double-quotes and use backslash as the
+ # escape character. The only escape sequences supported are:
+ # \" (for literal quote)
+ # \$ (for literal dollars sign)
+ # \\ (for literal backslash)
+ # Any other use of a backslash is treated as a literal backslash.
+ s = re.sub(r'("|\$|\\(?=["$\\]))', r'\\\1', s)
+ s = '"' + s + '"'
+ return s
+
+
def gn_args_are_generated(lines):
for line in lines:
if re.match("^\s*#.*REMOVE THIS LINE", line):