update recipe bootstrap script (2c5509f)

BUG=chromium:618127

Review-Url: https://codereview.chromium.org/2131153002
changes/90/365990/1
phajdan.jr 9 years ago committed by Commit bot
parent 6874ac10da
commit 90b9f5f404

@ -1,14 +1,33 @@
#!/usr/bin/env python #!/usr/bin/env python
# Copyright 2015 The Chromium Authors. All rights reserved. # Copyright 2016 The LUCI Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed under the Apache License, Version 2.0
# found in the LICENSE file. # that can be found in the LICENSE file.
"""Bootstrap script to clone and forward to the recipe engine tool.""" """Bootstrap script to clone and forward to the recipe engine tool.
***********************************************************************
** DO NOT MODIFY EXCEPT IN THE PER-REPO CONFIGURATION SECTION BELOW. **
***********************************************************************
This is a copy of https://github.com/luci/recipes-py/blob/master/doc/recipes.py.
To fix bugs, fix in the github repo then copy it back to here and fix the
PER-REPO CONFIGURATION section to look like this one.
"""
import os
#### PER-REPO CONFIGURATION (editable) ####
# The root of the repository relative to the directory of this file.
REPO_ROOT = ''
# The path of the recipes.cfg file relative to the root of the repository.
RECIPES_CFG = os.path.join('infra', 'config', 'recipes.cfg')
#### END PER-REPO CONFIGURATION ####
BOOTSTRAP_VERSION = 1
import ast import ast
import logging import logging
import os
import random import random
import re import re
import subprocess import subprocess
@ -16,12 +35,6 @@ import sys
import time import time
import traceback import traceback
BOOTSTRAP_VERSION = 1
# The root of the repository relative to the directory of this file.
REPO_ROOT = ''
# The path of the recipes.cfg file relative to the root of the repository.
RECIPES_CFG = os.path.join('infra', 'config', 'recipes.cfg')
def parse_protobuf(fh): def parse_protobuf(fh):
"""Parse the protobuf text format just well enough to understand recipes.cfg. """Parse the protobuf text format just well enough to understand recipes.cfg.
@ -39,8 +52,10 @@ def parse_protobuf(fh):
A recursive dictionary of lists. A recursive dictionary of lists.
""" """
def parse_atom(text): def parse_atom(text):
if text == 'true': return True if text == 'true':
if text == 'false': return False return True
if text == 'false':
return False
return ast.literal_eval(text) return ast.literal_eval(text)
ret = {} ret = {}
@ -57,10 +72,12 @@ def parse_protobuf(fh):
ret.setdefault(m.group(1), []).append(subparse) ret.setdefault(m.group(1), []).append(subparse)
continue continue
if line == '}': return ret if line == '}':
if line == '': continue return ret
if line == '':
continue
raise Exception('Could not understand line: <%s>' % line) raise ValueError('Could not understand line: <%s>' % line)
return ret return ret
@ -76,7 +93,19 @@ def get_unique(things):
return things[0] return things[0]
def _subprocess_call(argv, **kwargs):
logging.info('Running %r', argv)
return subprocess.call(argv, **kwargs)
def _subprocess_check_call(argv, **kwargs):
logging.info('Running %r', argv)
subprocess.check_call(argv, **kwargs)
def main(): def main():
if '--verbose' in sys.argv:
logging.getLogger().setLevel(logging.INFO)
if sys.platform.startswith(('win', 'cygwin')): if sys.platform.startswith(('win', 'cygwin')):
git = 'git.bat' git = 'git.bat'
else: else:
@ -107,28 +136,28 @@ def main():
if not os.path.exists(deps_path): if not os.path.exists(deps_path):
os.makedirs(deps_path) os.makedirs(deps_path)
if not os.path.exists(engine_path): if not os.path.exists(engine_path):
subprocess.check_call([git, 'clone', engine_url, engine_path]) _subprocess_check_call([git, 'clone', engine_url, engine_path])
needs_fetch = subprocess.call( needs_fetch = _subprocess_call(
[git, 'rev-parse', '--verify', '%s^{commit}' % engine_revision], [git, 'rev-parse', '--verify', '%s^{commit}' % engine_revision],
cwd=engine_path, stdout=open(os.devnull, 'w')) cwd=engine_path, stdout=open(os.devnull, 'w'))
if needs_fetch: if needs_fetch:
subprocess.check_call([git, 'fetch'], cwd=engine_path) _subprocess_check_call([git, 'fetch'], cwd=engine_path)
subprocess.check_call( _subprocess_check_call(
[git, 'checkout', '--quiet', engine_revision], cwd=engine_path) [git, 'checkout', '--quiet', engine_revision], cwd=engine_path)
try: try:
ensure_engine() ensure_engine()
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError:
if e.returncode == 128: # Thrown when git gets a lock error. logging.exception('ensure_engine failed')
time.sleep(random.uniform(2,5))
ensure_engine() # Retry errors.
else: time.sleep(random.uniform(2,5))
raise ensure_engine()
args = ['--package', recipes_cfg_path, args = ['--package', recipes_cfg_path,
'--bootstrap-script', __file__] + sys.argv[1:] '--bootstrap-script', __file__] + sys.argv[1:]
return subprocess.call([ return _subprocess_call([
sys.executable, '-u', sys.executable, '-u',
os.path.join(engine_path, engine_subpath, 'recipes.py')] + args) os.path.join(engine_path, engine_subpath, 'recipes.py')] + args)

Loading…
Cancel
Save