diff options
author | Robert Iannucci <iannucci@google.com> | 2017-03-15 01:24:56 -0700 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-03-15 11:39:15 +0000 |
commit | e8b508556cdd1b18b7461301b35e8a20d3fe35e2 (patch) | |
tree | e665f53173b535bc265f4083cc45be213d83d1a3 | |
parent | 96cf2065f356ff93722953aa6a9d665fc377c40b (diff) |
Update recipes.py to 78c57c5d69a38ef3db86d9763d539383f98714e6.
This updates the recipes.py script to the latest version, which fixes a
couple bugs.
BUG=
Change-Id: I6a0373531ae35577de77723210d68a5a2320d815
Reviewed-on: https://skia-review.googlesource.com/9706
Reviewed-by: Eric Boren <borenet@google.com>
Commit-Queue: Eric Boren <borenet@google.com>
-rwxr-xr-x | infra/bots/recipes.py | 80 |
1 files changed, 53 insertions, 27 deletions
diff --git a/infra/bots/recipes.py b/infra/bots/recipes.py index 9a7e131cd5..5883595800 100755 --- a/infra/bots/recipes.py +++ b/infra/bots/recipes.py @@ -26,6 +26,7 @@ RECIPES_CFG = os.path.join('infra', 'config', 'recipes.cfg') BOOTSTRAP_VERSION = 1 +import argparse import ast import logging import random @@ -103,15 +104,38 @@ 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 find_engine_override(argv): + """Since the bootstrap process attempts to defer all logic to the recipes-py + repo, we need to be aware if the user is overriding the recipe_engine + dependency. This looks for and returns the overridden recipe_engine path, if + any, or None if the user didn't override it.""" + PREFIX = 'recipe_engine=' + + p = argparse.ArgumentParser() + p.add_argument('-O', '--project-override', action='append') + args, _ = p.parse_known_args(argv) + for override in args.project_override or (): + if override.startswith(PREFIX): + return override[len(PREFIX):] + return None + + def main(): if '--verbose' in sys.argv: logging.getLogger().setLevel(logging.INFO) + if REPO_ROOT is None or RECIPES_CFG is None: + logging.error( + 'In order to use this script, please copy it to your repo and ' + 'replace the REPO_ROOT and RECIPES_CFG values with approprite paths.') + sys.exit(1) + if sys.platform.startswith(('win', 'cygwin')): git = 'git.bat' else: @@ -126,40 +150,42 @@ def main(): protobuf = parse_protobuf(fh) engine_buf = get_unique([ - b for b in protobuf['deps'] if b.get('project_id') == ['recipe_engine'] ]) + b for b in protobuf.get('deps', []) + if b.get('project_id') == ['recipe_engine'] ]) engine_url = get_unique(engine_buf['url']) engine_revision = get_unique(engine_buf['revision']) engine_subpath = (get_unique(engine_buf.get('path_override', [''])) .replace('/', os.path.sep)) recipes_path = os.path.join(repo_root, - get_unique(protobuf['recipes_path']).replace('/', os.path.sep)) + get_unique(protobuf.get('recipes_path', [''])).replace('/', os.path.sep)) deps_path = os.path.join(recipes_path, '.recipe_deps') - engine_path = os.path.join(deps_path, 'recipe_engine') - - # Ensure that we have the recipe engine cloned. - def ensure_engine(): - if not os.path.exists(deps_path): - os.makedirs(deps_path) - if not os.path.exists(engine_path): - _subprocess_check_call([git, 'clone', engine_url, engine_path]) - - needs_fetch = _subprocess_call( - [git, 'rev-parse', '--verify', '%s^{commit}' % engine_revision], - cwd=engine_path, stdout=open(os.devnull, 'w')) - if needs_fetch: - _subprocess_check_call([git, 'fetch'], cwd=engine_path) - _subprocess_check_call( - [git, 'checkout', '--quiet', engine_revision], cwd=engine_path) - - try: - ensure_engine() - except subprocess.CalledProcessError: - logging.exception('ensure_engine failed') - - # Retry errors. - time.sleep(random.uniform(2,5)) - ensure_engine() + engine_path = find_engine_override(sys.argv[1:]) + if not engine_path: + # Ensure that we have the recipe engine cloned. + engine_path = os.path.join(deps_path, 'recipe_engine') + def ensure_engine(): + if not os.path.exists(deps_path): + os.makedirs(deps_path) + if not os.path.exists(engine_path): + _subprocess_check_call([git, 'clone', engine_url, engine_path]) + + needs_fetch = _subprocess_call( + [git, 'rev-parse', '--verify', '%s^{commit}' % engine_revision], + cwd=engine_path, stdout=open(os.devnull, 'w')) + if needs_fetch: + _subprocess_check_call([git, 'fetch'], cwd=engine_path) + _subprocess_check_call( + [git, 'checkout', '--quiet', engine_revision], cwd=engine_path) + + try: + ensure_engine() + except subprocess.CalledProcessError: + logging.exception('ensure_engine failed') + + # Retry errors. + time.sleep(random.uniform(2,5)) + ensure_engine() args = ['--package', recipes_cfg_path] + sys.argv[1:] return _subprocess_call([ |