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

Side by Side Diff: build/env_dump.py

Issue 24208002: Fix few errors in env_dump.py. (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 # This script can either source a file and dump the enironment changes done by 6 # This script can either source a file and dump the enironment changes done by
7 # it, or just simply dump the current environment as JSON into a file. 7 # it, or just simply dump the current environment as JSON into a file.
8 8
9 import json 9 import json
10 import optparse 10 import optparse
11 import os 11 import os
12 import pipes
12 import subprocess 13 import subprocess
13 import sys 14 import sys
14 15
15 16
16 def main(): 17 def main():
17 parser = optparse.OptionParser() 18 parser = optparse.OptionParser()
18 parser.add_option('-f', '--output-json', 19 parser.add_option('-f', '--output-json',
19 help='File to dump the environment as JSON into.') 20 help='File to dump the environment as JSON into.')
20 parser.add_option( 21 parser.add_option(
21 '-d', '--dump-mode', action='store_true', 22 '-d', '--dump-mode', action='store_true',
22 help='Dump the environment to the file and exit immediately.') 23 help='Dump the environment to the file and exit immediately.')
23 24
24 options, args = parser.parse_args() 25 options, args = parser.parse_args()
25 if not options.output_json: 26 if not options.output_json:
26 parser.error('Requires --output-json option.') 27 parser.error('Requires --output-json option.')
27 28
28 if options.dump_mode: 29 if options.dump_mode:
29 if args: 30 if args:
30 parser.error("Cannot specify args with --dump-mode") 31 parser.error("Cannot specify args with --dump-mode")
31 with open(options.output_json, 'w') as f: 32 with open(options.output_json, 'w') as f:
32 json.dump(dict(os.environ), f) 33 json.dump(dict(os.environ), f)
33 else: 34 else:
34 envsetup_cmd = ' '.join(args) 35 envsetup_cmd = ' '.join(map(pipes.quote, args))
35 full_cmd = [ 36 full_cmd = [
36 'bash', '-c', 37 'bash', '-c',
37 '. %s; ./%s -d -f %s' % (envsetup_cmd, __file__, options.output_json)] 38 '. %s; %s -d -f %s' % (envsetup_cmd, os.path.abspath(__file__),
39 options.output_json)
40 ]
38 ret = subprocess.call(full_cmd) 41 ret = subprocess.call(full_cmd)
39 if ret: 42 if ret:
40 sys.exit('Error running %s and dumping env', envsetup_cmd) 43 sys.exit('Error running %s and dumping env' % envsetup_cmd)
41 44
42 45
43 if __name__ == '__main__': 46 if __name__ == '__main__':
44 sys.exit(main()) 47 sys.exit(main())
OLDNEW
« 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