Index: scripts/slave/recipes.py |
diff --git a/scripts/slave/recipes.py b/scripts/slave/recipes.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..00ab7f2b4c156b51ee051b812ea3f5a9155ca2d4 |
--- /dev/null |
+++ b/scripts/slave/recipes.py |
@@ -0,0 +1,86 @@ |
+#!/usr/bin/env python |
+ |
+# Copyright 2015 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+"""Bootstrap script to clone and forward to the recipe engine tool.""" |
+ |
+import os |
+import re |
+import subprocess |
+import sys |
+import time |
+ |
+BOOTSTRAP_VERSION = 1 |
+RECIPES_CFG = os.path.join( |
+ os.pardir, os.pardir, 'infra', 'config', 'recipes.cfg') |
+ |
+ENGINE_REPO = 'https://github.com/luqui/recipes-py.git' |
luqui
2015/09/14 18:29:07
Change to googlesource before land
|
+ENGINE_SUBPATH = '' |
+ |
+def main(): |
+ # Find the repository and config file to operate on. |
+ git_dir = os.path.dirname( |
+ subprocess.check_output(['git', 'rev-parse', '--git-dir'], |
+ cwd=os.path.dirname(__file__)).strip()) |
+ recipes_cfg_path = os.path.join(os.path.dirname(__file__), RECIPES_CFG) |
+ |
+ # Parse the recipe engine revision and recipes path from the protobuf file |
+ # (we don't use the protobuf library because we need this script to be self- |
+ # contained). |
+ engine_revision = None |
+ recipes_path = '' |
+ with open(recipes_cfg_path, 'rU') as fh: |
+ for line in fh: |
+ match = re.match(r'engine_revision\s*:\s*"(.*?)"\s*', line) |
+ if match: |
+ engine_revision = match.group(1) |
+ |
+ match = re.match(r'recipes_path\s*:\s*"(.*?)"\s*', line) |
+ if match: |
+ recipes_path = match.group(1) |
+ |
+ # Don't scan past the first curly block. |
+ if re.match(r'.*{\s*', line): |
+ break |
+ |
+ assert engine_revision is not None, ( |
+ 'Could not parse engine_revision field from %s' % recipes_cfg_path) |
+ |
+ recipes_path = os.path.join(git_dir, 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_REPO, 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 as e: |
+ if e.returncode == 128: # Thrown when git gets a lock error. |
+ time.sleep(5) |
+ ensure_engine() |
+ else: |
+ raise |
+ |
+ args = ([sys.argv[0]] + ['--package', recipes_cfg_path, |
+ '--bootstrap-script', __file__] + sys.argv[1:]) |
+ os.execvp( |
+ os.path.join(engine_path, ENGINE_SUBPATH, 'recipes.py'), |
+ args) |
+ |
+if __name__ == '__main__': |
+ main() |