OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 | |
3 # Copyright 2015 The Chromium Authors. All rights reserved. | |
4 # Use of this source code is governed by a BSD-style license that can be | |
5 # found in the LICENSE file. | |
6 | |
7 """Bootstrap script to clone and forward to the recipe engine tool.""" | |
8 | |
9 import os | |
10 import re | |
11 import subprocess | |
12 import sys | |
13 import time | |
14 | |
15 BOOTSTRAP_VERSION = 1 | |
16 RECIPES_CFG = os.path.join( | |
17 os.pardir, os.pardir, 'infra', 'config', 'recipes.cfg') | |
18 | |
19 ENGINE_REPO = 'https://github.com/luqui/recipes-py.git' | |
luqui
2015/09/14 18:29:07
Change to googlesource before land
| |
20 ENGINE_SUBPATH = '' | |
21 | |
22 def main(): | |
23 # Find the repository and config file to operate on. | |
24 git_dir = os.path.dirname( | |
25 subprocess.check_output(['git', 'rev-parse', '--git-dir'], | |
26 cwd=os.path.dirname(__file__)).strip()) | |
27 recipes_cfg_path = os.path.join(os.path.dirname(__file__), RECIPES_CFG) | |
28 | |
29 # Parse the recipe engine revision and recipes path from the protobuf file | |
30 # (we don't use the protobuf library because we need this script to be self- | |
31 # contained). | |
32 engine_revision = None | |
33 recipes_path = '' | |
34 with open(recipes_cfg_path, 'rU') as fh: | |
35 for line in fh: | |
36 match = re.match(r'engine_revision\s*:\s*"(.*?)"\s*', line) | |
37 if match: | |
38 engine_revision = match.group(1) | |
39 | |
40 match = re.match(r'recipes_path\s*:\s*"(.*?)"\s*', line) | |
41 if match: | |
42 recipes_path = match.group(1) | |
43 | |
44 # Don't scan past the first curly block. | |
45 if re.match(r'.*{\s*', line): | |
46 break | |
47 | |
48 assert engine_revision is not None, ( | |
49 'Could not parse engine_revision field from %s' % recipes_cfg_path) | |
50 | |
51 recipes_path = os.path.join(git_dir, recipes_path.replace('/', os.path.sep)) | |
52 deps_path = os.path.join(recipes_path, '.recipe_deps') | |
53 engine_path = os.path.join(deps_path, 'recipe_engine') | |
54 | |
55 # Ensure that we have the recipe engine cloned | |
56 def ensure_engine(): | |
57 if not os.path.exists(deps_path): | |
58 os.makedirs(deps_path) | |
59 if not os.path.exists(engine_path): | |
60 subprocess.check_call(['git', 'clone', ENGINE_REPO, engine_path]) | |
61 | |
62 needs_fetch = subprocess.call( | |
63 ['git', 'rev-parse', '--verify', '%s^{commit}' % engine_revision], | |
64 cwd=engine_path, stdout=open(os.devnull, 'w')) | |
65 if needs_fetch: | |
66 subprocess.check_call(['git', 'fetch'], cwd=engine_path) | |
67 subprocess.check_call( | |
68 ['git', 'checkout', '--quiet', engine_revision], cwd=engine_path) | |
69 | |
70 try: | |
71 ensure_engine() | |
72 except subprocess.CalledProcessError as e: | |
73 if e.returncode == 128: # Thrown when git gets a lock error. | |
74 time.sleep(5) | |
75 ensure_engine() | |
76 else: | |
77 raise | |
78 | |
79 args = ([sys.argv[0]] + ['--package', recipes_cfg_path, | |
80 '--bootstrap-script', __file__] + sys.argv[1:]) | |
81 os.execvp( | |
82 os.path.join(engine_path, ENGINE_SUBPATH, 'recipes.py'), | |
83 args) | |
84 | |
85 if __name__ == '__main__': | |
86 main() | |
OLD | NEW |