Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

env.py 1.3 KiB

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