go.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env python
  2. #
  3. # Copyright 2019 Google Inc.
  4. #
  5. # Use of this source code is governed by a BSD-style license that can be
  6. # found in the LICENSE file.
  7. import os
  8. import subprocess
  9. import sys
  10. INFRA_GO = 'go.skia.org/infra'
  11. WHICH = 'where' if sys.platform == 'win32' else 'which'
  12. def check():
  13. '''Verify that golang is properly installed. If not, exit with an error.'''
  14. def _fail(msg):
  15. print >> sys.stderr, msg
  16. sys.exit(1)
  17. try:
  18. go_exe = subprocess.check_output([WHICH, 'go'])
  19. except (subprocess.CalledProcessError, OSError):
  20. go_exe = None
  21. if not go_exe:
  22. _fail('Unable to find Golang installation; see '
  23. 'https://golang.org/doc/install')
  24. if not os.environ.get('GOPATH'):
  25. _fail('GOPATH environment variable is not set; is Golang properly '
  26. 'installed?')
  27. go_bin = os.path.join(os.environ['GOPATH'], 'bin')
  28. for entry in os.environ.get('PATH', '').split(os.pathsep):
  29. if entry == go_bin:
  30. break
  31. else:
  32. _fail('%s not in PATH; is Golang properly installed?' % go_bin)
  33. def get(url):
  34. '''Clone or update the given repo URL via "go get".'''
  35. check()
  36. subprocess.check_call(['go', 'get', '-u', url])
  37. def update_infra():
  38. '''Update the local checkout of the Skia infra codebase.'''
  39. get(INFRA_GO + '/...')