Debian Codegraph @

external/boringssl/util/bot/go/env.py

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