0
Files
src/build/env_dump.py
Ingemar Ådahl 504c076b19 Set Python shebang in build to /usr/bin/env python
A common solution for developers using Linux distributions were
/usr/bin/python is linked to /usr/bin/python3 is to put a python ->
python2 symlink earlier in the PATH when working with python2-only
projects. This doesn't work when shebangs bypasses any environment
configuration.

The change was generated by executing:
  sed -i 's|#!/usr/bin/python|#!/usr/bin/env python|' \
    $(grep -rl '#!/usr/bin/python' build)

Change-Id: I2de77532fd31a0348ec58f4d9af4b7172dc1b9ed
Reviewed-on: https://chromium-review.googlesource.com/559347
Reviewed-by: John Budorick <jbudorick@chromium.org>
Commit-Queue: Ingemar Ådahl <ingemara@opera.com>
Cr-Commit-Position: refs/heads/master@{#484266}
2017-07-05 14:42:43 +00:00

57 lines
1.7 KiB
Python
Executable File

#!/usr/bin/env 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 pipes
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 sys.stdout and exit immediately.')
parser.disable_interspersed_args()
options, args = parser.parse_args()
if options.dump_mode:
if args or options.output_json:
parser.error('Cannot specify args or --output-json with --dump-mode.')
json.dump(dict(os.environ), sys.stdout)
else:
if not options.output_json:
parser.error('Requires --output-json option.')
envsetup_cmd = ' '.join(map(pipes.quote, args))
full_cmd = [
'bash', '-c',
'. %s > /dev/null; %s -d' % (envsetup_cmd, os.path.abspath(__file__))
]
try:
output = subprocess.check_output(full_cmd)
except Exception as e:
sys.exit('Error running %s and dumping environment.' % envsetup_cmd)
env_diff = {}
new_env = json.loads(output)
for k, val in new_env.items():
if k == '_' or (k in os.environ and os.environ[k] == val):
continue
env_diff[k] = val
with open(options.output_json, 'w') as f:
json.dump(env_diff, f)
if __name__ == '__main__':
sys.exit(main())