|
|
|
@ -13,7 +13,6 @@
|
|
|
|
|
# pylint: disable=pointless-string-statement
|
|
|
|
|
''''exec python -u -- "$0" ${1+"$@"} # '''
|
|
|
|
|
# vi: syntax=python
|
|
|
|
|
|
|
|
|
|
"""Bootstrap script to clone and forward to the recipe engine tool.
|
|
|
|
|
|
|
|
|
|
*******************
|
|
|
|
@ -41,14 +40,14 @@ from collections import namedtuple
|
|
|
|
|
# revision (str) - the git revision for the engine to get.
|
|
|
|
|
# branch (str) - the branch to fetch for the engine as an absolute ref (e.g.
|
|
|
|
|
# refs/heads/master)
|
|
|
|
|
EngineDep = namedtuple('EngineDep',
|
|
|
|
|
'url revision branch')
|
|
|
|
|
EngineDep = namedtuple('EngineDep', 'url revision branch')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MalformedRecipesCfg(Exception):
|
|
|
|
|
|
|
|
|
|
def __init__(self, msg, path):
|
|
|
|
|
super(MalformedRecipesCfg, self).__init__('malformed recipes.cfg: %s: %r'
|
|
|
|
|
% (msg, path))
|
|
|
|
|
full_message = 'malformed recipes.cfg: %s: %r' % (msg, path)
|
|
|
|
|
super(MalformedRecipesCfg, self).__init__(full_message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parse(repo_root, recipes_cfg_path):
|
|
|
|
@ -86,8 +85,8 @@ def parse(repo_root, recipes_cfg_path):
|
|
|
|
|
|
|
|
|
|
if 'url' not in engine:
|
|
|
|
|
raise MalformedRecipesCfg(
|
|
|
|
|
'Required field "url" in dependency "recipe_engine" not found',
|
|
|
|
|
recipes_cfg_path)
|
|
|
|
|
'Required field "url" in dependency "recipe_engine" not found',
|
|
|
|
|
recipes_cfg_path)
|
|
|
|
|
|
|
|
|
|
engine.setdefault('revision', '')
|
|
|
|
|
engine.setdefault('branch', 'refs/heads/master')
|
|
|
|
@ -97,8 +96,8 @@ def parse(repo_root, recipes_cfg_path):
|
|
|
|
|
if not engine['branch'].startswith('refs/'):
|
|
|
|
|
engine['branch'] = 'refs/heads/' + engine['branch']
|
|
|
|
|
|
|
|
|
|
recipes_path = os.path.join(
|
|
|
|
|
repo_root, recipes_path.replace('/', os.path.sep))
|
|
|
|
|
recipes_path = os.path.join(repo_root,
|
|
|
|
|
recipes_path.replace('/', os.path.sep))
|
|
|
|
|
return EngineDep(**engine), recipes_path
|
|
|
|
|
except KeyError as ex:
|
|
|
|
|
raise MalformedRecipesCfg(ex.message, recipes_cfg_path)
|
|
|
|
@ -114,6 +113,7 @@ REQUIRED_BINARIES = {GIT, VPYTHON, CIPD}
|
|
|
|
|
def _is_executable(path):
|
|
|
|
|
return os.path.isfile(path) and os.access(path, os.X_OK)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: Use shutil.which once we switch to Python3.
|
|
|
|
|
def _is_on_path(basename):
|
|
|
|
|
for path in os.environ['PATH'].split(os.pathsep):
|
|
|
|
@ -129,13 +129,13 @@ def _subprocess_call(argv, **kwargs):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _git_check_call(argv, **kwargs):
|
|
|
|
|
argv = [GIT]+argv
|
|
|
|
|
argv = [GIT] + argv
|
|
|
|
|
logging.info('Running %r', argv)
|
|
|
|
|
subprocess.check_call(argv, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _git_output(argv, **kwargs):
|
|
|
|
|
argv = [GIT]+argv
|
|
|
|
|
argv = [GIT] + argv
|
|
|
|
|
logging.info('Running %r', argv)
|
|
|
|
|
return subprocess.check_output(argv, **kwargs)
|
|
|
|
|
|
|
|
|
@ -181,10 +181,15 @@ def checkout_engine(engine_path, repo_root, recipes_cfg_path):
|
|
|
|
|
_git_check_call(['init', engine_path], stdout=NUL)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
_git_check_call(['rev-parse', '--verify', '%s^{commit}' % revision],
|
|
|
|
|
cwd=engine_path, stdout=NUL, stderr=NUL)
|
|
|
|
|
_git_check_call(['rev-parse', '--verify',
|
|
|
|
|
'%s^{commit}' % revision],
|
|
|
|
|
cwd=engine_path,
|
|
|
|
|
stdout=NUL,
|
|
|
|
|
stderr=NUL)
|
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
|
_git_check_call(['fetch', url, branch], cwd=engine_path, stdout=NUL,
|
|
|
|
|
_git_check_call(['fetch', url, branch],
|
|
|
|
|
cwd=engine_path,
|
|
|
|
|
stdout=NUL,
|
|
|
|
|
stderr=NUL)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
@ -213,13 +218,12 @@ def main():
|
|
|
|
|
if recipes_cfg_path:
|
|
|
|
|
# calculate repo_root from recipes_cfg_path
|
|
|
|
|
repo_root = os.path.dirname(
|
|
|
|
|
os.path.dirname(
|
|
|
|
|
os.path.dirname(recipes_cfg_path)))
|
|
|
|
|
os.path.dirname(os.path.dirname(recipes_cfg_path)))
|
|
|
|
|
else:
|
|
|
|
|
# find repo_root with git and calculate recipes_cfg_path
|
|
|
|
|
repo_root = (_git_output(
|
|
|
|
|
['rev-parse', '--show-toplevel'],
|
|
|
|
|
cwd=os.path.abspath(os.path.dirname(__file__))).strip())
|
|
|
|
|
repo_root = (
|
|
|
|
|
_git_output(['rev-parse', '--show-toplevel'],
|
|
|
|
|
cwd=os.path.abspath(os.path.dirname(__file__))).strip())
|
|
|
|
|
repo_root = os.path.abspath(repo_root)
|
|
|
|
|
recipes_cfg_path = os.path.join(repo_root, 'infra', 'config', 'recipes.cfg')
|
|
|
|
|
args = ['--package', recipes_cfg_path] + args
|
|
|
|
@ -227,9 +231,9 @@ def main():
|
|
|
|
|
engine_path = checkout_engine(engine_override, repo_root, recipes_cfg_path)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
return _subprocess_call([
|
|
|
|
|
VPYTHON, '-u',
|
|
|
|
|
os.path.join(engine_path, 'recipe_engine', 'main.py')] + args)
|
|
|
|
|
return _subprocess_call(
|
|
|
|
|
[VPYTHON, '-u',
|
|
|
|
|
os.path.join(engine_path, 'recipe_engine', 'main.py')] + args)
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|