4"""Helper functions useful when writing scripts that are run from GN's
5exec_script function."""
8class GNException(Exception):
13 """Prints the given value to stdout.
15 allow_dicts indicates if this function will allow converting dictionaries
16 to GN scopes. This
is only possible at the top level, you can
't nest a
17 GN scope in a list, so this should be set to
False for recursive calls.
"""
18 if isinstance(value, str):
19 if value.find(
'\n') >= 0:
20 raise GNException(
"Trying to print a string with a newline in it.")
21 return '"' + value.replace(
'"',
'\\"') +
'"'
23 if isinstance(value, list):
26 if isinstance(value, dict):
28 raise GNException(
"Attempting to recursively print a dictionary.")
31 if not isinstance(key, str):
32 raise GNException(
"Dictionary key is not a string.")
33 result +=
"%s = %s\n" % (key,
ToGNString(value[key],
False))
36 if isinstance(value, int):
39 raise GNException(
"Unsupported type when printing to GN.")
def ToGNString(value, allow_dicts=True)
static SkString join(const CommandLineFlags::StringArray &)