Chromium Code Reviews| 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 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 # 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. |
| 26 bootstrap = imp.load_source( | 26 bootstrap = imp.load_source( |
| 27 'bootstrap', os.path.join(os.path.dirname(__file__), 'bootstrap.py')) | 27 'bootstrap', os.path.join(os.path.dirname(__file__), 'bootstrap.py')) |
| 28 | 28 |
| 29 old = os.environ.copy() | 29 old = os.environ.copy() |
| 30 new = bootstrap.prepare_go_environ() | 30 new = bootstrap.prepare_go_environ() |
| 31 | 31 |
| 32 if len(sys.argv) == 1: | 32 if len(sys.argv) == 1: |
| 33 for key, value in sorted(new.iteritems()): | 33 for key, value in sorted(new.iteritems()): |
| 34 if old.get(key) != value: | 34 if old.get(key) != value: |
| 35 print 'export %s=%s' % (key, pipes.quote(value)) | 35 # Replace special characters with their escaped form. This will allow them |
|
mithro
2016/07/07 02:09:39
Can you move this into a function?
dnj (Google)
2016/07/07 03:43:30
Done.
| |
| 36 # to be interpreted by the shell using the $'...' notation. We will only | |
| 37 # use the $'...' notation if there was an escaped character in the string. | |
| 38 orig_value = value | |
| 39 for f, r in ( | |
| 40 ('\n', r'\n'), | |
|
mithro
2016/07/07 02:09:38
This is kind of confusing, I think
('\n', '\\n')
dnj (Google)
2016/07/07 03:43:30
Done.
| |
| 41 ('\b', r'\b'), | |
| 42 ('\r', r'\r'), | |
| 43 ('\t', r'\t'), | |
| 44 ('\v', r'\v')): | |
| 45 value = value.replace(f, r) | |
| 46 print 'export %s=%s%s' % (key, ('$') if orig_value != value else (''), | |
| 47 pipes.quote(value)) | |
| 36 else: | 48 else: |
| 37 exe = sys.argv[1] | 49 exe = sys.argv[1] |
| 38 if exe == 'python': | 50 if exe == 'python': |
| 39 exe = sys.executable | 51 exe = sys.executable |
| 40 else: | 52 else: |
| 41 # Help Windows to find the executable in new PATH, do it only when | 53 # Help Windows to find the executable in new PATH, do it only when |
| 42 # executable is referenced by name (and not by path). | 54 # executable is referenced by name (and not by path). |
| 43 if os.sep not in exe: | 55 if os.sep not in exe: |
| 44 exe = bootstrap.find_executable(exe, [bootstrap.WORKSPACE]) | 56 exe = bootstrap.find_executable(exe, [bootstrap.WORKSPACE]) |
| 45 sys.exit(subprocess.call([exe] + sys.argv[2:], env=new)) | 57 sys.exit(subprocess.call([exe] + sys.argv[2:], env=new)) |
| OLD | NEW |