skia2/tools/infra/go.py
Hal Canary 389c8e9d2d [minor] mark scripts as executable
if a filename ends with `.py` and  the file begins with '#!.*python.*',
make it executable.

Change-Id: I41de516ff37343d3b0979bde9fd61813aec7365c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/254439
Commit-Queue: Hal Canary <halcanary@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
Auto-Submit: Hal Canary <halcanary@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
2019-11-21 17:06:27 +00:00

51 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python
#
# Copyright 2019 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import subprocess
import sys
INFRA_GO = 'go.skia.org/infra'
WHICH = 'where' if sys.platform == 'win32' else 'which'
def check():
'''Verify that golang is properly installed. If not, exit with an error.'''
def _fail(msg):
print >> sys.stderr, msg
sys.exit(1)
try:
go_exe = subprocess.check_output([WHICH, 'go'])
except (subprocess.CalledProcessError, OSError):
go_exe = None
if not go_exe:
_fail('Unable to find Golang installation; see '
'https://golang.org/doc/install')
if not os.environ.get('GOPATH'):
_fail('GOPATH environment variable is not set; is Golang properly '
'installed?')
go_bin = os.path.join(os.environ['GOPATH'], 'bin')
for entry in os.environ.get('PATH', '').split(os.pathsep):
if entry == go_bin:
break
else:
_fail('%s not in PATH; is Golang properly installed?' % go_bin)
def get(url):
'''Clone or update the given repo URL via "go get".'''
check()
subprocess.check_call(['go', 'get', '-u', url])
def update_infra():
'''Update the local checkout of the Skia infra codebase.'''
get(INFRA_GO + '/...')