Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(688)

Side by Side Diff: infra/recipes.py

Issue 2163223002: Add basic chromium recipe (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « infra/config/recipes.cfg ('k') | infra/recipes/canary.expected/basic.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 # Copyright 2016 The Chromium Authors. All rights reserved. 3 # Copyright 2016 The LUCI Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed under the Apache License, Version 2.0
5 # found in the LICENSE file. 5 # that can be found in the LICENSE file.
6 6
7 """Bootstrap script to clone and forward to the recipe engine tool. 7 """Bootstrap script to clone and forward to the recipe engine tool.
8 8
9 *********************************************************************** 9 ***********************************************************************
10 ** DO NOT MODIFY EXCEPT IN THE PER-REPO CONFIGURATION SECTION BELOW. ** 10 ** DO NOT MODIFY EXCEPT IN THE PER-REPO CONFIGURATION SECTION BELOW. **
11 *********************************************************************** 11 ***********************************************************************
12 12
13 This is a copy of https://github.com/luci/recipes-py/blob/master/doc/recipes.py. 13 This is a copy of https://github.com/luci/recipes-py/blob/master/doc/recipes.py.
14 To fix bugs, fix in the github repo then copy it back to here and fix the 14 To fix bugs, fix in the github repo then copy it back to here and fix the
15 PER-REPO CONFIGURATION section to look like this one. 15 PER-REPO CONFIGURATION section to look like this one.
(...skipping 29 matching lines...) Expand all
45 45
46 We assume all fields are repeated since we don't have a proto spec to work 46 We assume all fields are repeated since we don't have a proto spec to work
47 with. 47 with.
48 48
49 Args: 49 Args:
50 fh: a filehandle containing the text format protobuf. 50 fh: a filehandle containing the text format protobuf.
51 Returns: 51 Returns:
52 A recursive dictionary of lists. 52 A recursive dictionary of lists.
53 """ 53 """
54 def parse_atom(text): 54 def parse_atom(text):
55 if text == 'true': return True 55 if text == 'true':
56 if text == 'false': return False 56 return True
57 if text == 'false':
58 return False
57 return ast.literal_eval(text) 59 return ast.literal_eval(text)
58 60
59 ret = {} 61 ret = {}
60 for line in fh: 62 for line in fh:
61 line = line.strip() 63 line = line.strip()
62 m = re.match(r'(\w+)\s*:\s*(.*)', line) 64 m = re.match(r'(\w+)\s*:\s*(.*)', line)
63 if m: 65 if m:
64 ret.setdefault(m.group(1), []).append(parse_atom(m.group(2))) 66 ret.setdefault(m.group(1), []).append(parse_atom(m.group(2)))
65 continue 67 continue
66 68
67 m = re.match(r'(\w+)\s*{', line) 69 m = re.match(r'(\w+)\s*{', line)
68 if m: 70 if m:
69 subparse = parse_protobuf(fh) 71 subparse = parse_protobuf(fh)
70 ret.setdefault(m.group(1), []).append(subparse) 72 ret.setdefault(m.group(1), []).append(subparse)
71 continue 73 continue
72 74
73 if line == '}': return ret 75 if line == '}':
74 if line == '': continue 76 return ret
77 if line == '':
78 continue
75 79
76 raise ValueError('Could not understand line: <%s>' % line) 80 raise ValueError('Could not understand line: <%s>' % line)
77 81
78 return ret 82 return ret
79 83
80 84
81 def get_unique(things): 85 def get_unique(things):
82 if len(things) == 1: 86 if len(things) == 1:
83 return things[0] 87 return things[0]
84 elif len(things) == 0: 88 elif len(things) == 0:
85 raise ValueError("Expected to get one thing, but dinna get none.") 89 raise ValueError("Expected to get one thing, but dinna get none.")
86 else: 90 else:
87 logging.warn('Expected to get one thing, but got a bunch: %s\n%s' % 91 logging.warn('Expected to get one thing, but got a bunch: %s\n%s' %
88 (things, traceback.format_stack())) 92 (things, traceback.format_stack()))
89 return things[0] 93 return things[0]
90 94
91 95
96 def _subprocess_call(argv, **kwargs):
97 logging.info('Running %r', argv)
98 return subprocess.call(argv, **kwargs)
99
100 def _subprocess_check_call(argv, **kwargs):
101 logging.info('Running %r', argv)
102 subprocess.check_call(argv, **kwargs)
103
104
92 def main(): 105 def main():
106 if '--verbose' in sys.argv:
107 logging.getLogger().setLevel(logging.INFO)
108
93 if sys.platform.startswith(('win', 'cygwin')): 109 if sys.platform.startswith(('win', 'cygwin')):
94 git = 'git.bat' 110 git = 'git.bat'
95 else: 111 else:
96 git = 'git' 112 git = 'git'
97 113
98 # Find the repository and config file to operate on. 114 # Find the repository and config file to operate on.
99 repo_root = os.path.abspath( 115 repo_root = os.path.abspath(
100 os.path.join(os.path.dirname(__file__), REPO_ROOT)) 116 os.path.join(os.path.dirname(__file__), REPO_ROOT))
101 recipes_cfg_path = os.path.join(repo_root, RECIPES_CFG) 117 recipes_cfg_path = os.path.join(repo_root, RECIPES_CFG)
102 118
(...skipping 10 matching lines...) Expand all
113 recipes_path = os.path.join(repo_root, 129 recipes_path = os.path.join(repo_root,
114 get_unique(protobuf['recipes_path']).replace('/', os.path.sep)) 130 get_unique(protobuf['recipes_path']).replace('/', os.path.sep))
115 deps_path = os.path.join(recipes_path, '.recipe_deps') 131 deps_path = os.path.join(recipes_path, '.recipe_deps')
116 engine_path = os.path.join(deps_path, 'recipe_engine') 132 engine_path = os.path.join(deps_path, 'recipe_engine')
117 133
118 # Ensure that we have the recipe engine cloned. 134 # Ensure that we have the recipe engine cloned.
119 def ensure_engine(): 135 def ensure_engine():
120 if not os.path.exists(deps_path): 136 if not os.path.exists(deps_path):
121 os.makedirs(deps_path) 137 os.makedirs(deps_path)
122 if not os.path.exists(engine_path): 138 if not os.path.exists(engine_path):
123 subprocess.check_call([git, 'clone', engine_url, engine_path]) 139 _subprocess_check_call([git, 'clone', engine_url, engine_path])
124 140
125 needs_fetch = subprocess.call( 141 needs_fetch = _subprocess_call(
126 [git, 'rev-parse', '--verify', '%s^{commit}' % engine_revision], 142 [git, 'rev-parse', '--verify', '%s^{commit}' % engine_revision],
127 cwd=engine_path, stdout=open(os.devnull, 'w')) 143 cwd=engine_path, stdout=open(os.devnull, 'w'))
128 if needs_fetch: 144 if needs_fetch:
129 subprocess.check_call([git, 'fetch'], cwd=engine_path) 145 _subprocess_check_call([git, 'fetch'], cwd=engine_path)
130 subprocess.check_call( 146 _subprocess_check_call(
131 [git, 'checkout', '--quiet', engine_revision], cwd=engine_path) 147 [git, 'checkout', '--quiet', engine_revision], cwd=engine_path)
132 148
133 try: 149 try:
134 ensure_engine() 150 ensure_engine()
135 except subprocess.CalledProcessError as e: 151 except subprocess.CalledProcessError:
136 if e.returncode == 128: # Thrown when git gets a lock error. 152 logging.exception('ensure_engine failed')
137 time.sleep(random.uniform(2,5)) 153
138 ensure_engine() 154 # Retry errors.
139 else: 155 time.sleep(random.uniform(2,5))
140 raise 156 ensure_engine()
141 157
142 args = ['--package', recipes_cfg_path, 158 args = ['--package', recipes_cfg_path,
143 '--bootstrap-script', __file__] + sys.argv[1:] 159 '--bootstrap-script', __file__] + sys.argv[1:]
144 return subprocess.call([ 160 return _subprocess_call([
145 sys.executable, '-u', 161 sys.executable, '-u',
146 os.path.join(engine_path, engine_subpath, 'recipes.py')] + args) 162 os.path.join(engine_path, engine_subpath, 'recipes.py')] + args)
147 163
148 if __name__ == '__main__': 164 if __name__ == '__main__':
149 sys.exit(main()) 165 sys.exit(main())
OLDNEW
« no previous file with comments | « infra/config/recipes.cfg ('k') | infra/recipes/canary.expected/basic.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698