| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 """Can be used to point environment variable to hermetic Go toolset. | 6 """Can be used to point environment variable to hermetic Go toolset. |
| 7 | 7 |
| 8 Usage (on linux and mac): | 8 Usage (on linux and mac): |
| 9 $ eval `./env.py` | 9 $ eval `./env.py` |
| 10 $ go version | 10 $ go version |
| 11 | 11 |
| 12 Or it can be used to wrap a command: | 12 Or it can be used to wrap a command: |
| 13 | 13 |
| 14 $ ./env.py go version | 14 $ ./env.py go version |
| 15 """ | 15 """ |
| 16 | 16 |
| 17 assert __name__ == '__main__' | 17 assert __name__ == '__main__' |
| 18 | 18 |
| 19 import imp | 19 import imp |
| 20 import os | 20 import os |
| 21 import pipes |
| 21 import subprocess | 22 import subprocess |
| 22 import sys | 23 import sys |
| 23 | 24 |
| 24 # Do not want to mess with sys.path, load the module directly. | 25 # Do not want to mess with sys.path, load the module directly. |
| 25 bootstrap = imp.load_source( | 26 bootstrap = imp.load_source( |
| 26 'bootstrap', os.path.join(os.path.dirname(__file__), 'bootstrap.py')) | 27 'bootstrap', os.path.join(os.path.dirname(__file__), 'bootstrap.py')) |
| 27 | 28 |
| 28 old = os.environ.copy() | 29 old = os.environ.copy() |
| 29 new = bootstrap.prepare_go_environ() | 30 new = bootstrap.prepare_go_environ() |
| 30 | 31 |
| 31 if len(sys.argv) == 1: | 32 if len(sys.argv) == 1: |
| 32 for key, value in sorted(new.iteritems()): | 33 for key, value in sorted(new.iteritems()): |
| 33 if old.get(key) != value: | 34 if old.get(key) != value: |
| 34 print 'export %s="%s"' % (key, value) | 35 print 'export %s=%s' % (key, pipes.quote(value)) |
| 35 else: | 36 else: |
| 36 exe = sys.argv[1] | 37 exe = sys.argv[1] |
| 37 if exe == 'python': | 38 if exe == 'python': |
| 38 exe = sys.executable | 39 exe = sys.executable |
| 39 else: | 40 else: |
| 40 # Help Windows to find the executable in new PATH, do it only when | 41 # Help Windows to find the executable in new PATH, do it only when |
| 41 # executable is referenced by name (and not by path). | 42 # executable is referenced by name (and not by path). |
| 42 if os.sep not in exe: | 43 if os.sep not in exe: |
| 43 exe = bootstrap.find_executable(exe, [bootstrap.WORKSPACE]) | 44 exe = bootstrap.find_executable(exe, [bootstrap.WORKSPACE]) |
| 44 sys.exit(subprocess.call([exe] + sys.argv[2:], env=new)) | 45 sys.exit(subprocess.call([exe] + sys.argv[2:], env=new)) |
| OLD | NEW |