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

Side by Side Diff: recipe_modules/bot_update/api.py

Issue 1706893003: Revert of Bot update cleanup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 4 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | recipe_modules/bot_update/example.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 5
6 """Recipe module to ensure a checkout is consistant on a bot.""" 6 """Recipe module to ensure a checkout is consistant on a bot."""
7 7
8 from recipe_engine import recipe_api 8 from recipe_engine import recipe_api
9 9
10 10
11 # This is just for testing, to indicate if a master is using a Git scheduler
12 # or not.
13 SVN_MASTERS = (
14 'experimental.svn',
15 )
16
11 17
12 def jsonish_to_python(spec, is_top=False): 18 def jsonish_to_python(spec, is_top=False):
13 """Turn a json spec into a python parsable object. 19 """Turn a json spec into a python parsable object.
14 20
15 This exists because Gclient specs, while resembling json, is actually 21 This exists because Gclient specs, while resembling json, is actually
16 ingested using a python "eval()". Therefore a bit of plumming is required 22 ingested using a python "eval()". Therefore a bit of plumming is required
17 to turn our newly constructed Gclient spec into a gclient-readable spec. 23 to turn our newly constructed Gclient spec into a gclient-readable spec.
18 """ 24 """
19 ret = '' 25 ret = ''
20 if is_top: # We're the 'top' level, so treat this dict as a suite. 26 if is_top: # We're the 'top' level, so treat this dict as a suite.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 kwargs.setdefault('env', {}) 60 kwargs.setdefault('env', {})
55 kwargs['env'].setdefault('PATH', '%(PATH)s') 61 kwargs['env'].setdefault('PATH', '%(PATH)s')
56 kwargs['env']['PATH'] = self.m.path.pathsep.join([ 62 kwargs['env']['PATH'] = self.m.path.pathsep.join([
57 kwargs['env']['PATH'], str(self._module.PACKAGE_DIRECTORY)]) 63 kwargs['env']['PATH'], str(self._module.PACKAGE_DIRECTORY)])
58 return self.m.python(name, bot_update_path, cmd, **kwargs) 64 return self.m.python(name, bot_update_path, cmd, **kwargs)
59 65
60 @property 66 @property
61 def properties(self): 67 def properties(self):
62 return self._properties 68 return self._properties
63 69
64 # Note: force is ignored.
65 def ensure_checkout(self, gclient_config=None, suffix=None, 70 def ensure_checkout(self, gclient_config=None, suffix=None,
66 patch=True, update_presentation=True, 71 patch=True, update_presentation=True,
67 force=True, patch_root=None, no_shallow=False, 72 force=False, patch_root=None, no_shallow=False,
68 with_branch_heads=False, refs=None, 73 with_branch_heads=False, refs=None,
69 patch_project_roots=None, patch_oauth2=False, 74 patch_project_roots=None, patch_oauth2=False,
70 output_manifest=True, clobber=False, 75 output_manifest=True, clobber=False,
71 root_solution_revision=None, **kwargs): 76 root_solution_revision=None, **kwargs):
72 refs = refs or [] 77 refs = refs or []
73 # We can re-use the gclient spec from the gclient module, since all the 78 # We can re-use the gclient spec from the gclient module, since all the
74 # data bot_update needs is already configured into the gclient spec. 79 # data bot_update needs is already configured into the gclient spec.
75 cfg = gclient_config or self.m.gclient.c 80 cfg = gclient_config or self.m.gclient.c
76 spec_string = jsonish_to_python(cfg.as_jsonish(), True) 81 spec_string = jsonish_to_python(cfg.as_jsonish(), True)
77 82
83 # Used by bot_update to determine if we want to run or not.
84 master = self.m.properties['mastername']
85 builder = self.m.properties['buildername']
86 slave = self.m.properties['slavename']
87
78 # Construct our bot_update command. This basically be inclusive of 88 # Construct our bot_update command. This basically be inclusive of
79 # everything required for bot_update to know: 89 # everything required for bot_update to know:
80 root = patch_root 90 root = patch_root
81 if root is None: 91 if root is None:
82 root = cfg.solutions[0].name 92 root = cfg.solutions[0].name
83 additional = self.m.rietveld.calculate_issue_root(patch_project_roots) 93 additional = self.m.rietveld.calculate_issue_root(patch_project_roots)
84 if additional: 94 if additional:
85 root = self.m.path.join(root, additional) 95 root = self.m.path.join(root, additional)
86 96
87 if patch: 97 if patch:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 key_file = self.m.path['build'].join( 129 key_file = self.m.path['build'].join(
120 'site_config', '.rietveld_secret_key') 130 'site_config', '.rietveld_secret_key')
121 else: 131 else:
122 email_file = key_file = None 132 email_file = key_file = None
123 133
124 rev_map = {} 134 rev_map = {}
125 if self.m.gclient.c: 135 if self.m.gclient.c:
126 rev_map = self.m.gclient.c.got_revision_mapping.as_jsonish() 136 rev_map = self.m.gclient.c.got_revision_mapping.as_jsonish()
127 137
128 flags = [ 138 flags = [
129 # 1. What do we want to check out (spec/root/rev/rev_map). 139 # 1. Do we want to run? (master/builder/slave).
140 ['--master', master],
141 ['--builder', builder],
142 ['--slave', slave],
143
144 # 2. What do we want to check out (spec/root/rev/rev_map).
130 ['--spec', spec_string], 145 ['--spec', spec_string],
131 ['--root', root], 146 ['--root', root],
132 ['--revision_mapping_file', self.m.json.input(rev_map)], 147 ['--revision_mapping_file', self.m.json.input(rev_map)],
133 ['--git-cache-dir', self.m.path['git_cache']], 148 ['--git-cache-dir', self.m.path['git_cache']],
134 149
135 # 2. How to find the patch, if any (issue/patchset/patch_url). 150 # 3. How to find the patch, if any (issue/patchset/patch_url).
136 ['--issue', issue], 151 ['--issue', issue],
137 ['--patchset', patchset], 152 ['--patchset', patchset],
138 ['--patch_url', patch_url], 153 ['--patch_url', patch_url],
139 ['--rietveld_server', self.m.properties.get('rietveld')], 154 ['--rietveld_server', self.m.properties.get('rietveld')],
140 ['--gerrit_repo', gerrit_repo], 155 ['--gerrit_repo', gerrit_repo],
141 ['--gerrit_ref', gerrit_ref], 156 ['--gerrit_ref', gerrit_ref],
142 ['--apply_issue_email_file', email_file], 157 ['--apply_issue_email_file', email_file],
143 ['--apply_issue_key_file', key_file], 158 ['--apply_issue_key_file', key_file],
144 159
145 # 3. Hookups to JSON output back into recipes. 160 # 4. Hookups to JSON output back into recipes.
146 ['--output_json', self.m.json.output()],] 161 ['--output_json', self.m.json.output()],]
147 162
148 163
149 # Collect all fixed revisions to simulate them in the json output. 164 # Collect all fixed revisions to simulate them in the json output.
150 # Fixed revision are the explicit input revisions of bot_update.py, i.e. 165 # Fixed revision are the explicit input revisions of bot_update.py, i.e.
151 # every command line parameter "--revision name@value". 166 # every command line parameter "--revision name@value".
152 fixed_revisions = {} 167 fixed_revisions = {}
153 168
154 revisions = {} 169 revisions = {}
155 for solution in cfg.solutions: 170 for solution in cfg.solutions:
(...skipping 19 matching lines...) Expand all
175 # Add extra fetch refspecs. 190 # Add extra fetch refspecs.
176 for ref in refs: 191 for ref in refs:
177 flags.append(['--refs', ref]) 192 flags.append(['--refs', ref])
178 193
179 # Filter out flags that are None. 194 # Filter out flags that are None.
180 cmd = [item for flag_set in flags 195 cmd = [item for flag_set in flags
181 for item in flag_set if flag_set[1] is not None] 196 for item in flag_set if flag_set[1] is not None]
182 197
183 if clobber: 198 if clobber:
184 cmd.append('--clobber') 199 cmd.append('--clobber')
200 if force:
201 cmd.append('--force')
185 if no_shallow: 202 if no_shallow:
186 cmd.append('--no_shallow') 203 cmd.append('--no_shallow')
187 if output_manifest: 204 if output_manifest:
188 cmd.append('--output_manifest') 205 cmd.append('--output_manifest')
189 if with_branch_heads or cfg.with_branch_heads: 206 if with_branch_heads or cfg.with_branch_heads:
190 cmd.append('--with_branch_heads') 207 cmd.append('--with_branch_heads')
191 208
192 # Inject Json output for testing. 209 # Inject Json output for testing.
210 git_mode = self.m.properties.get('mastername') not in SVN_MASTERS
193 first_sln = cfg.solutions[0].name 211 first_sln = cfg.solutions[0].name
194 step_test_data = lambda: self.test_api.output_json( 212 step_test_data = lambda: self.test_api.output_json(
195 root, first_sln, rev_map, self.m.properties.get('fail_patch', False), 213 master, builder, slave, root, first_sln, rev_map, git_mode, force,
214 self.m.properties.get('fail_patch', False),
196 output_manifest=output_manifest, fixed_revisions=fixed_revisions) 215 output_manifest=output_manifest, fixed_revisions=fixed_revisions)
197 216
198 # Add suffixes to the step name, if specified. 217 # Add suffixes to the step name, if specified.
199 name = 'bot_update' 218 name = 'bot_update'
200 if not patch: 219 if not patch:
201 name += ' (without patch)' 220 name += ' (without patch)'
202 if suffix: 221 if suffix:
203 name += ' - %s' % suffix 222 name += ' - %s' % suffix
204 223
205 # Ah hah! Now that everything is in place, lets run bot_update! 224 # Ah hah! Now that everything is in place, lets run bot_update!
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 272
254 # bot_update actually just sets root to be the folder name of the 273 # bot_update actually just sets root to be the folder name of the
255 # first solution. 274 # first solution.
256 if step_result.json.output['did_run']: 275 if step_result.json.output['did_run']:
257 co_root = step_result.json.output['root'] 276 co_root = step_result.json.output['root']
258 cwd = kwargs.get('cwd', self.m.path['slave_build']) 277 cwd = kwargs.get('cwd', self.m.path['slave_build'])
259 if 'checkout' not in self.m.path: 278 if 'checkout' not in self.m.path:
260 self.m.path['checkout'] = cwd.join(*co_root.split(self.m.path.sep)) 279 self.m.path['checkout'] = cwd.join(*co_root.split(self.m.path.sep))
261 280
262 return step_result 281 return step_result
OLDNEW
« no previous file with comments | « no previous file | recipe_modules/bot_update/example.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698