OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 from recipe_engine import recipe_api | 5 from recipe_engine import recipe_api |
6 | 6 |
7 | 7 |
8 class RevisionResolver(object): | 8 class RevisionResolver(object): |
9 """Resolves the revision based on build properties.""" | 9 """Resolves the revision based on build properties.""" |
10 | 10 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 revisions.extend(['--revision', '%s@%s' % (s.name, fixed_revision)]) | 144 revisions.extend(['--revision', '%s@%s' % (s.name, fixed_revision)]) |
145 | 145 |
146 for name, revision in sorted(cfg.revisions.items()): | 146 for name, revision in sorted(cfg.revisions.items()): |
147 fixed_revision = self.resolve_revision(revision) | 147 fixed_revision = self.resolve_revision(revision) |
148 if fixed_revision: | 148 if fixed_revision: |
149 revisions.extend(['--revision', '%s@%s' % (name, fixed_revision)]) | 149 revisions.extend(['--revision', '%s@%s' % (name, fixed_revision)]) |
150 | 150 |
151 test_data_paths = set(cfg.got_revision_mapping.keys() + | 151 test_data_paths = set(cfg.got_revision_mapping.keys() + |
152 [s.name for s in cfg.solutions]) | 152 [s.name for s in cfg.solutions]) |
153 step_test_data = lambda: ( | 153 step_test_data = lambda: ( |
154 self.test_api.output_json(test_data_paths, cfg.GIT_MODE)) | 154 self.test_api.output_json(test_data_paths)) |
155 try: | 155 try: |
156 if not cfg.GIT_MODE: # pragma: no cover | 156 # clean() isn't used because the gclient sync flags passed in checkout() |
157 args = ['sync', '--nohooks', '--force', '--verbose'] | 157 # do much the same thing, and they're more correct than doing a separate |
158 if cfg.delete_unversioned_trees: | 158 # 'gclient revert' because it makes sure the other args are correct when |
159 args.append('--delete_unversioned_trees') | 159 # a repo was deleted and needs to be re-cloned (notably |
160 if with_branch_heads: | 160 # --with_branch_heads), whereas 'revert' uses default args for clone |
161 args.append('--with_branch_heads') | 161 # operations. |
162 self('sync', args + revisions + ['--output-json', self.m.json.output()], | 162 # |
163 step_test_data=step_test_data, | 163 # TODO(mmoss): To be like current official builders, this step could |
164 **kwargs) | 164 # just delete the whole <slave_name>/build/ directory and start each |
165 else: | 165 # build from scratch. That might be the least bad solution, at least |
166 # clean() isn't used because the gclient sync flags passed in checkout() | 166 # until we have a reliable gclient method to produce a pristine working |
167 # do much the same thing, and they're more correct than doing a separate | 167 # dir for git-based builds (e.g. maybe some combination of 'git |
168 # 'gclient revert' because it makes sure the other args are correct when | 168 # reset/clean -fx' and removing the 'out' directory). |
169 # a repo was deleted and needs to be re-cloned (notably | 169 j = '-j2' if self.m.platform.is_win else '-j8' |
170 # --with_branch_heads), whereas 'revert' uses default args for clone | 170 args = ['sync', '--verbose', '--with_branch_heads', '--nohooks', j, |
171 # operations. | 171 '--reset', '--force', '--upstream', '--no-nag-max'] |
172 # | 172 if cfg.delete_unversioned_trees: |
173 # TODO(mmoss): To be like current official builders, this step could | 173 args.append('--delete_unversioned_trees') |
174 # just delete the whole <slave_name>/build/ directory and start each | 174 self('sync', args + revisions + |
175 # build from scratch. That might be the least bad solution, at least | 175 ['--output-json', self.m.json.output()], |
176 # until we have a reliable gclient method to produce a pristine working | 176 step_test_data=step_test_data, |
177 # dir for git-based builds (e.g. maybe some combination of 'git | 177 **kwargs) |
178 # reset/clean -fx' and removing the 'out' directory). | |
179 j = '-j2' if self.m.platform.is_win else '-j8' | |
180 args = ['sync', '--verbose', '--with_branch_heads', '--nohooks', j, | |
181 '--reset', '--force', '--upstream', '--no-nag-max'] | |
182 if cfg.delete_unversioned_trees: | |
183 args.append('--delete_unversioned_trees') | |
184 self('sync', args + revisions + | |
185 ['--output-json', self.m.json.output()], | |
186 step_test_data=step_test_data, | |
187 **kwargs) | |
188 finally: | 178 finally: |
189 result = self.m.step.active_result | 179 result = self.m.step.active_result |
190 data = result.json.output | 180 data = result.json.output |
191 for path, info in data['solutions'].iteritems(): | 181 for path, info in data['solutions'].iteritems(): |
192 # gclient json paths always end with a slash | 182 # gclient json paths always end with a slash |
193 path = path.rstrip('/') | 183 path = path.rstrip('/') |
194 if path in cfg.got_revision_mapping: | 184 if path in cfg.got_revision_mapping: |
195 propname = cfg.got_revision_mapping[path] | 185 propname = cfg.got_revision_mapping[path] |
196 result.presentation.properties[propname] = info['revision'] | 186 result.presentation.properties[propname] = info['revision'] |
197 | 187 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 if revert is self.RevertOnTryserver: | 222 if revert is self.RevertOnTryserver: |
233 revert = self.m.tryserver.is_tryserver | 223 revert = self.m.tryserver.is_tryserver |
234 | 224 |
235 if inject_parent_got_revision: | 225 if inject_parent_got_revision: |
236 self.inject_parent_got_revision(cfg, override=True) | 226 self.inject_parent_got_revision(cfg, override=True) |
237 | 227 |
238 self('setup', ['config', '--spec', self.config_to_pythonish(cfg)], **kwargs) | 228 self('setup', ['config', '--spec', self.config_to_pythonish(cfg)], **kwargs) |
239 | 229 |
240 sync_step = None | 230 sync_step = None |
241 try: | 231 try: |
242 if not cfg.GIT_MODE: # pragma: no cover | 232 sync_step = self.sync(cfg, with_branch_heads=with_branch_heads, |
243 try: | 233 **kwargs) |
244 if revert: | |
245 self.revert(**kwargs) | |
246 finally: | |
247 sync_step = self.sync(cfg, with_branch_heads=with_branch_heads, | |
248 **kwargs) | |
249 else: | |
250 sync_step = self.sync(cfg, with_branch_heads=with_branch_heads, | |
251 **kwargs) | |
252 | 234 |
253 cfg_cmds = [ | 235 cfg_cmds = [ |
254 ('user.name', 'local_bot'), | 236 ('user.name', 'local_bot'), |
255 ('user.email', 'local_bot@example.com'), | 237 ('user.email', 'local_bot@example.com'), |
256 ] | 238 ] |
257 for var, val in cfg_cmds: | 239 for var, val in cfg_cmds: |
258 name = 'recurse (git config %s)' % var | 240 name = 'recurse (git config %s)' % var |
259 self(name, ['recurse', 'git', 'config', var, val], **kwargs) | 241 self(name, ['recurse', 'git', 'config', var, val], **kwargs) |
260 | |
261 finally: | 242 finally: |
262 cwd = kwargs.get('cwd', self.m.path['slave_build']) | 243 cwd = kwargs.get('cwd', self.m.path['slave_build']) |
263 if 'checkout' not in self.m.path: | 244 if 'checkout' not in self.m.path: |
264 self.m.path['checkout'] = cwd.join( | 245 self.m.path['checkout'] = cwd.join( |
265 *cfg.solutions[0].name.split(self.m.path.sep)) | 246 *cfg.solutions[0].name.split(self.m.path.sep)) |
266 | 247 |
267 return sync_step | 248 return sync_step |
268 | 249 |
269 def revert(self, **kwargs): # pragma: no cover | 250 def revert(self, **kwargs): # pragma: no cover |
270 """Return a gclient_safe_revert step.""" | 251 """Return a gclient_safe_revert step.""" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 """Updates config revision corresponding to patch_project. | 334 """Updates config revision corresponding to patch_project. |
354 | 335 |
355 Useful for bot_update only, as this is the only consumer of gclient's config | 336 Useful for bot_update only, as this is the only consumer of gclient's config |
356 revision map. This doesn't overwrite the revision if it was already set. | 337 revision map. This doesn't overwrite the revision if it was already set. |
357 """ | 338 """ |
358 assert patch_project is None or isinstance(patch_project, basestring) | 339 assert patch_project is None or isinstance(patch_project, basestring) |
359 cfg = gclient_config or self.c | 340 cfg = gclient_config or self.c |
360 path, revision = cfg.patch_projects.get(patch_project, (None, None)) | 341 path, revision = cfg.patch_projects.get(patch_project, (None, None)) |
361 if path and revision and path not in cfg.revisions: | 342 if path and revision and path not in cfg.revisions: |
362 cfg.revisions[path] = revision | 343 cfg.revisions[path] = revision |
OLD | NEW |