Commit aa6520e3 authored by Robert Iannucci's avatar Robert Iannucci Committed by Commit Bot

[recipes.py] upgrade recipes.py to allow recipe_engine override

BUG=662654
TBR=nodir@chromium.org

Change-Id: Ifbce962d4968af9871ee62862b485dc1cc06cc22
Reviewed-on: https://chromium-review.googlesource.com/445044Reviewed-by: 's avatarRobbie Iannucci <iannucci@chromium.org>
Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
parent 099aacc6
......@@ -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:
......@@ -135,31 +159,32 @@ def main():
recipes_path = os.path.join(repo_root,
get_unique(protobuf['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([
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment