mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 04:48:52 -05:00
tools/setup: add gn_string() utility function
This commit is contained in:
parent
1b9424e9d7
commit
023b4640fc
2 changed files with 21 additions and 1 deletions
|
@ -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):
|
def gn_args_are_generated(lines):
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if re.match("^\s*#.*REMOVE THIS LINE", line):
|
if re.match("^\s*#.*REMOVE THIS LINE", line):
|
||||||
|
|
|
@ -1,11 +1,18 @@
|
||||||
# Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
# Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from setup import read_gn_args, write_gn_args
|
from setup import gn_string, read_gn_args, write_gn_args
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from tempfile import mktemp
|
from tempfile import mktemp
|
||||||
|
|
||||||
|
|
||||||
|
def gn_string_test():
|
||||||
|
assert '"abc"' == gn_string('abc')
|
||||||
|
assert '"foo\\$bar\\"baz"' == gn_string('foo$bar"baz')
|
||||||
|
assert '"do\\not\\escape"' == gn_string('do\\not\\escape')
|
||||||
|
assert '"so\\\\\\very\\\\\\"fun\\"' == gn_string('so\\\\very\\"fun\\')
|
||||||
|
|
||||||
|
|
||||||
def read_gn_args_test():
|
def read_gn_args_test():
|
||||||
# Args file doesn't exist.
|
# Args file doesn't exist.
|
||||||
(args, hand_edited) = read_gn_args("/baddir/hopefully/nonexistent/args.gn")
|
(args, hand_edited) = read_gn_args("/baddir/hopefully/nonexistent/args.gn")
|
||||||
|
@ -53,6 +60,7 @@ def write_gn_args_test():
|
||||||
|
|
||||||
|
|
||||||
def setup_test():
|
def setup_test():
|
||||||
|
gn_string_test()
|
||||||
read_gn_args_test()
|
read_gn_args_test()
|
||||||
write_gn_args_test()
|
write_gn_args_test()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue