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

Unified Diff: build/gn_helpers.py

Issue 1880903002: Switch MB to write the GN args to args.gn. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix_mb_goma
Patch Set: fix unicode handling in gn_helpers Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/mb/mb.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/gn_helpers.py
diff --git a/build/gn_helpers.py b/build/gn_helpers.py
index 6aeddae5fd853c7e58def9254e5a24a289853710..2d5d9863b949e797b351789e7d0355b9b3364321 100644
--- a/build/gn_helpers.py
+++ b/build/gn_helpers.py
@@ -24,12 +24,12 @@ class GNException(Exception):
def ToGNString(value, allow_dicts = True):
- """Prints the given value to stdout.
+ """Returns a stringified GN equivalent of the Python value.
allow_dicts indicates if this function will allow converting dictionaries
to GN scopes. This is only possible at the top level, you can't nest a
GN scope in a list, so this should be set to False for recursive calls."""
- if isinstance(value, str):
+ if isinstance(value, basestring):
if value.find('\n') >= 0:
raise GNException("Trying to print a string with a newline in it.")
return '"' + \
@@ -51,8 +51,8 @@ def ToGNString(value, allow_dicts = True):
if not allow_dicts:
raise GNException("Attempting to recursively print a dictionary.")
result = ""
- for key in value:
- if not isinstance(key, str):
+ for key in sorted(value):
+ if not isinstance(key, basestring):
raise GNException("Dictionary key is not a string.")
result += "%s = %s\n" % (key, ToGNString(value[key], False))
return result
« no previous file with comments | « no previous file | tools/mb/mb.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698