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

Unified Diff: build/env_dump.py

Issue 23618049: Helper script which can source a bash script and dump environment as JSON. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/env_dump.py
diff --git a/build/env_dump.py b/build/env_dump.py
new file mode 100755
index 0000000000000000000000000000000000000000..b84597c995be15c46cdf59801e00a77d7f08a8a4
--- /dev/null
+++ b/build/env_dump.py
@@ -0,0 +1,44 @@
+#!/usr/bin/python
+# Copyright 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# This script can either source a file and dump the enironment changes done by
+# it, or just simply dump the current environment as JSON into a file.
+
+import json
+import optparse
+import os
+import subprocess
+import sys
+
+
+def main():
+ parser = optparse.OptionParser()
+ parser.add_option('-f', '--output-json',
+ help='File to dump the environment as JSON into.')
+ parser.add_option(
+ '-d', '--dump-mode', action='store_true',
+ help='Dump the environment to the file and exit immediately.')
+
+ options, args = parser.parse_args()
+ if not options.output_json:
+ parser.error('Requires --output-json option.')
+
+ if options.dump_mode:
+ if args:
+ parser.error("Cannot specify args with --dump-mode")
+ with open(options.output_json, 'w') as f:
+ json.dump(dict(os.environ), f)
+ else:
+ envsetup_cmd = ' '.join(args)
Isaac (away) 2013/09/15 08:32:25 ' '.join(pipes.quote(a) for a in args) would be
Isaac (away) 2013/09/15 08:34:02 Or: ' '.join(map(pipes.quote, args))
iannucci 2013/09/15 09:16:47 +1, I missed this.
+ full_cmd = [
+ 'bash', '-c',
+ '. %s; ./%s -d -f %s' % (envsetup_cmd, __file__, options.output_json)]
Isaac (away) 2013/09/15 08:32:25 maybe the '.' at the beginning of line 37 should b
iannucci 2013/09/15 09:16:47 -1 on this. I would argue that the '.' (sourcing t
Isaac (away) 2013/09/15 09:28:04 :-D
+ ret = subprocess.call(full_cmd)
+ if ret:
+ sys.exit('Error running %s and dumping env', envsetup_cmd)
Isaac (away) 2013/09/15 08:32:25 AFAIK, sys.exit only takes one arg. Running new sc
iannucci 2013/09/15 09:16:47 Oh, yeah, sys.exit takes an error code, not a stri
Isaac (away) 2013/09/15 09:28:04 It actually can take a string (siva showed me this
Siva Chandra 2013/09/15 09:39:14 sys.exit takes a string: http://docs.python.org/2.
+
+
+if __name__ == '__main__':
+ sys.exit(main())
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698