Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: build/gn_helpers.py

Issue 223783005: Add support for reading .gypi files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | build/gypi_to_gn.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 """Helper functions useful when writing scripts that are run from GN's
6 exec_script function."""
7
8 class GNException(Exception):
9 pass
10
11
12 def ToGNString(value, allow_dicts = True):
13 """Prints the given value to stdout.
14
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('"', '\\"') + '"'
22
23 if isinstance(value, list):
24 return '[ %s ]' % ', '.join(ToGNString(v) for v in value)
25
26 if isinstance(value, dict):
27 if not allow_dicts:
28 raise GNException("Attempting to recursively print a dictionary.")
29 result = ""
30 for key in value:
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))
34 return result
35
36 if isinstance(value, int):
37 return str(value)
38
39 raise GNException("Unsupported type when printing to GN.")
40
41
OLDNEW
« no previous file with comments | « no previous file | build/gypi_to_gn.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698