Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 ret += ']' | 41 ret += ']' |
| 42 elif isinstance(spec, basestring): | 42 elif isinstance(spec, basestring): |
| 43 ret = repr(str(spec)) | 43 ret = repr(str(spec)) |
| 44 else: | 44 else: |
| 45 ret = repr(spec) | 45 ret = repr(spec) |
| 46 return ret | 46 return ret |
| 47 | 47 |
| 48 | 48 |
| 49 class BotUpdateApi(recipe_api.RecipeApi): | 49 class BotUpdateApi(recipe_api.RecipeApi): |
| 50 | 50 |
| 51 def __init__(self, *args, **kwargs): | 51 def __init__(self, mastername, buildername, slavename, issue, patchset, |
| 52 self._properties = {} | 52 patch_url, repository, gerrit_ref, rietveld, revision, |
| 53 super(BotUpdateApi, self).__init__(*args, **kwargs) | 53 parent_got_revision, deps_revision_overrides, fail_patch, |
| 54 *args, **kwargs): | |
| 55 self._mastername = mastername | |
| 56 self._buildername = buildername | |
| 57 self._slavename = slavename | |
| 58 self._issue = issue | |
| 59 self._patchset = patchset | |
| 60 self._patch_url = patch_url | |
| 61 self._repository = repository | |
| 62 self._gerrit_ref = gerrit_ref | |
| 63 self._rietveld = rietveld | |
| 64 self._revision = revision | |
| 65 self._parent_got_revision = parent_got_revision | |
| 66 self._deps_revision_overrides = deps_revision_overrides | |
| 67 self._fail_patch = fail_patch | |
| 68 | |
| 69 self._properties = {} | |
|
iannucci
2016/03/01 22:36:22
can we rename this? like _last_returned_properties
martiniss
2016/03/02 01:19:55
Done. Might have to rename callers though, I'll se
| |
| 70 super(BotUpdateApi, self).__init__(*args, **kwargs) | |
| 54 | 71 |
| 55 def __call__(self, name, cmd, **kwargs): | 72 def __call__(self, name, cmd, **kwargs): |
| 56 """Wrapper for easy calling of bot_update.""" | 73 """Wrapper for easy calling of bot_update.""" |
| 57 assert isinstance(cmd, (list, tuple)) | 74 assert isinstance(cmd, (list, tuple)) |
| 58 bot_update_path = self.resource('bot_update.py') | 75 bot_update_path = self.resource('bot_update.py') |
| 59 kwargs.setdefault('infra_step', True) | 76 kwargs.setdefault('infra_step', True) |
| 60 kwargs.setdefault('env', {}) | 77 kwargs.setdefault('env', {}) |
| 61 kwargs['env'].setdefault('PATH', '%(PATH)s') | 78 kwargs['env'].setdefault('PATH', '%(PATH)s') |
| 62 kwargs['env']['PATH'] = self.m.path.pathsep.join([ | 79 kwargs['env']['PATH'] = self.m.path.pathsep.join([ |
| 63 kwargs['env']['PATH'], str(self._module.PACKAGE_DIRECTORY)]) | 80 kwargs['env']['PATH'], str(self._module.PACKAGE_DIRECTORY)]) |
| 64 return self.m.python(name, bot_update_path, cmd, **kwargs) | 81 return self.m.python(name, bot_update_path, cmd, **kwargs) |
| 65 | 82 |
| 66 @property | 83 @property |
| 67 def properties(self): | 84 def properties(self): |
| 68 return self._properties | 85 return self._properties |
| 69 | 86 |
| 70 def ensure_checkout(self, gclient_config=None, suffix=None, | 87 def ensure_checkout(self, gclient_config=None, suffix=None, |
| 71 patch=True, update_presentation=True, | 88 patch=True, update_presentation=True, |
| 72 force=False, patch_root=None, no_shallow=False, | 89 force=False, patch_root=None, no_shallow=False, |
| 73 with_branch_heads=False, refs=None, | 90 with_branch_heads=False, refs=None, |
| 74 patch_project_roots=None, patch_oauth2=False, | 91 patch_project_roots=None, patch_oauth2=False, |
| 75 output_manifest=True, clobber=False, | 92 output_manifest=True, clobber=False, |
| 76 root_solution_revision=None, **kwargs): | 93 root_solution_revision=None, rietveld=None, issue=None, |
| 94 patchset=None, **kwargs): | |
| 95 """ | |
| 96 Args: | |
| 97 gclient_config: The gclient configuration to use when running bot_update. | |
| 98 If omitted, the current gclient configuration is used. | |
| 99 rietveld: The rietveld server to use. If omitted, will infer from | |
| 100 properties. | |
|
iannucci
2016/03/01 22:36:22
mention which property for these. document the for
martiniss
2016/03/02 01:19:55
I mentioned which property these refer to. What do
| |
| 101 issue: The rietveld issue number to use. If omitted, will infer from | |
| 102 properties. | |
| 103 patchset: The rietveld issue patchset to use. If omitted, will infer from | |
| 104 properties. | |
| 105 """ | |
| 77 refs = refs or [] | 106 refs = refs or [] |
| 78 # We can re-use the gclient spec from the gclient module, since all the | 107 # We can re-use the gclient spec from the gclient module, since all the |
| 79 # data bot_update needs is already configured into the gclient spec. | 108 # data bot_update needs is already configured into the gclient spec. |
| 80 cfg = gclient_config or self.m.gclient.c | 109 cfg = gclient_config or self.m.gclient.c |
| 81 spec_string = jsonish_to_python(cfg.as_jsonish(), True) | 110 spec_string = jsonish_to_python(cfg.as_jsonish(), True) |
| 82 | 111 |
| 83 # Used by bot_update to determine if we want to run or not. | 112 # Used by bot_update to determine if we want to run or not. |
| 84 master = self.m.properties['mastername'] | 113 master = self._mastername |
| 85 builder = self.m.properties['buildername'] | 114 builder = self._buildername |
| 86 slave = self.m.properties['slavename'] | 115 slave = self._slavename |
| 87 | 116 |
| 88 # Construct our bot_update command. This basically be inclusive of | 117 # Construct our bot_update command. This basically be inclusive of |
| 89 # everything required for bot_update to know: | 118 # everything required for bot_update to know: |
| 90 root = patch_root | 119 root = patch_root |
| 91 if root is None: | 120 if root is None: |
| 92 root = cfg.solutions[0].name | 121 root = cfg.solutions[0].name |
| 93 additional = self.m.rietveld.calculate_issue_root(patch_project_roots) | 122 additional = self.m.rietveld.calculate_issue_root(patch_project_roots) |
| 94 if additional: | 123 if additional: |
| 95 root = self.m.path.join(root, additional) | 124 root = self.m.path.join(root, additional) |
| 96 | 125 |
| 97 if patch: | 126 if patch: |
| 98 issue = self.m.properties.get('issue') | 127 issue = issue or self._issue |
| 99 patchset = self.m.properties.get('patchset') | 128 patchset = patchset or self._patchset |
| 100 patch_url = self.m.properties.get('patch_url') | 129 patch_url = self._patch_url |
| 101 gerrit_repo = self.m.properties.get('repository') | 130 gerrit_repo = self._repository |
| 102 gerrit_ref = self.m.properties.get('event.patchSet.ref') | 131 gerrit_ref = self._gerrit_ref |
| 103 else: | 132 else: |
| 104 # The trybot recipe sometimes wants to de-apply the patch. In which case | 133 # The trybot recipe sometimes wants to de-apply the patch. In which case |
| 105 # we pretend the issue/patchset/patch_url never existed. | 134 # we pretend the issue/patchset/patch_url never existed. |
| 106 issue = patchset = patch_url = email_file = key_file = None | 135 issue = patchset = patch_url = email_file = key_file = None |
| 107 gerrit_repo = gerrit_ref = None | 136 gerrit_repo = gerrit_ref = None |
| 108 | 137 |
| 109 # Issue and patchset must come together. | 138 # Issue and patchset must come together. |
| 110 if issue: | 139 if issue: |
| 111 assert patchset | 140 assert patchset |
| 112 if patchset: | 141 if patchset: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 # 2. What do we want to check out (spec/root/rev/rev_map). | 173 # 2. What do we want to check out (spec/root/rev/rev_map). |
| 145 ['--spec', spec_string], | 174 ['--spec', spec_string], |
| 146 ['--root', root], | 175 ['--root', root], |
| 147 ['--revision_mapping_file', self.m.json.input(rev_map)], | 176 ['--revision_mapping_file', self.m.json.input(rev_map)], |
| 148 ['--git-cache-dir', self.m.path['git_cache']], | 177 ['--git-cache-dir', self.m.path['git_cache']], |
| 149 | 178 |
| 150 # 3. How to find the patch, if any (issue/patchset/patch_url). | 179 # 3. How to find the patch, if any (issue/patchset/patch_url). |
| 151 ['--issue', issue], | 180 ['--issue', issue], |
| 152 ['--patchset', patchset], | 181 ['--patchset', patchset], |
| 153 ['--patch_url', patch_url], | 182 ['--patch_url', patch_url], |
| 154 ['--rietveld_server', self.m.properties.get('rietveld')], | 183 ['--rietveld_server', rietveld or self._rietveld], |
| 155 ['--gerrit_repo', gerrit_repo], | 184 ['--gerrit_repo', gerrit_repo], |
| 156 ['--gerrit_ref', gerrit_ref], | 185 ['--gerrit_ref', gerrit_ref], |
| 157 ['--apply_issue_email_file', email_file], | 186 ['--apply_issue_email_file', email_file], |
| 158 ['--apply_issue_key_file', key_file], | 187 ['--apply_issue_key_file', key_file], |
| 159 | 188 |
| 160 # 4. Hookups to JSON output back into recipes. | 189 # 4. Hookups to JSON output back into recipes. |
| 161 ['--output_json', self.m.json.output()],] | 190 ['--output_json', self.m.json.output()],] |
| 162 | 191 |
| 163 | 192 |
| 164 # Collect all fixed revisions to simulate them in the json output. | 193 # Collect all fixed revisions to simulate them in the json output. |
| 165 # Fixed revision are the explicit input revisions of bot_update.py, i.e. | 194 # Fixed revision are the explicit input revisions of bot_update.py, i.e. |
| 166 # every command line parameter "--revision name@value". | 195 # every command line parameter "--revision name@value". |
| 167 fixed_revisions = {} | 196 fixed_revisions = {} |
| 168 | 197 |
| 169 revisions = {} | 198 revisions = {} |
| 170 for solution in cfg.solutions: | 199 for solution in cfg.solutions: |
| 171 if solution.revision: | 200 if solution.revision: |
| 172 revisions[solution.name] = solution.revision | 201 revisions[solution.name] = solution.revision |
| 173 elif solution == cfg.solutions[0]: | 202 elif solution == cfg.solutions[0]: |
| 174 revisions[solution.name] = ( | 203 revisions[solution.name] = ( |
| 175 self.m.properties.get('parent_got_revision') or | 204 self._parent_got_revision or |
| 176 self.m.properties.get('revision') or | 205 self._revision or |
| 177 'HEAD') | 206 'HEAD') |
| 178 if self.m.gclient.c and self.m.gclient.c.revisions: | 207 if self.m.gclient.c and self.m.gclient.c.revisions: |
| 179 revisions.update(self.m.gclient.c.revisions) | 208 revisions.update(self.m.gclient.c.revisions) |
| 180 if cfg.solutions and root_solution_revision: | 209 if cfg.solutions and root_solution_revision: |
| 181 revisions[cfg.solutions[0].name] = root_solution_revision | 210 revisions[cfg.solutions[0].name] = root_solution_revision |
| 182 # Allow for overrides required to bisect into rolls. | 211 # Allow for overrides required to bisect into rolls. |
| 183 revisions.update(self.m.properties.get('deps_revision_overrides', {})) | 212 revisions.update(self._deps_revision_overrides) |
| 184 for name, revision in sorted(revisions.items()): | 213 for name, revision in sorted(revisions.items()): |
| 185 fixed_revision = self.m.gclient.resolve_revision(revision) | 214 fixed_revision = self.m.gclient.resolve_revision(revision) |
| 186 if fixed_revision: | 215 if fixed_revision: |
| 187 fixed_revisions[name] = fixed_revision | 216 fixed_revisions[name] = fixed_revision |
| 188 flags.append(['--revision', '%s@%s' % (name, fixed_revision)]) | 217 flags.append(['--revision', '%s@%s' % (name, fixed_revision)]) |
| 189 | 218 |
| 190 # Add extra fetch refspecs. | 219 # Add extra fetch refspecs. |
| 191 for ref in refs: | 220 for ref in refs: |
| 192 flags.append(['--refs', ref]) | 221 flags.append(['--refs', ref]) |
| 193 | 222 |
| 194 # Filter out flags that are None. | 223 # Filter out flags that are None. |
| 195 cmd = [item for flag_set in flags | 224 cmd = [item for flag_set in flags |
| 196 for item in flag_set if flag_set[1] is not None] | 225 for item in flag_set if flag_set[1] is not None] |
| 197 | 226 |
| 198 if clobber: | 227 if clobber: |
| 199 cmd.append('--clobber') | 228 cmd.append('--clobber') |
| 200 if force: | 229 if force: |
| 201 cmd.append('--force') | 230 cmd.append('--force') |
| 202 if no_shallow: | 231 if no_shallow: |
| 203 cmd.append('--no_shallow') | 232 cmd.append('--no_shallow') |
| 204 if output_manifest: | 233 if output_manifest: |
| 205 cmd.append('--output_manifest') | 234 cmd.append('--output_manifest') |
| 206 if with_branch_heads or cfg.with_branch_heads: | 235 if with_branch_heads or cfg.with_branch_heads: |
| 207 cmd.append('--with_branch_heads') | 236 cmd.append('--with_branch_heads') |
| 208 | 237 |
| 209 # Inject Json output for testing. | 238 # Inject Json output for testing. |
| 210 git_mode = self.m.properties.get('mastername') not in SVN_MASTERS | 239 git_mode = self._mastername not in SVN_MASTERS |
| 211 first_sln = cfg.solutions[0].name | 240 first_sln = cfg.solutions[0].name |
| 212 step_test_data = lambda: self.test_api.output_json( | 241 step_test_data = lambda: self.test_api.output_json( |
| 213 master, builder, slave, root, first_sln, rev_map, git_mode, force, | 242 master, builder, slave, root, first_sln, rev_map, git_mode, force, |
| 214 self.m.properties.get('fail_patch', False), | 243 self._fail_patch, |
| 215 output_manifest=output_manifest, fixed_revisions=fixed_revisions) | 244 output_manifest=output_manifest, fixed_revisions=fixed_revisions) |
| 216 | 245 |
| 217 # Add suffixes to the step name, if specified. | 246 # Add suffixes to the step name, if specified. |
| 218 name = 'bot_update' | 247 name = 'bot_update' |
| 219 if not patch: | 248 if not patch: |
| 220 name += ' (without patch)' | 249 name += ' (without patch)' |
| 221 if suffix: | 250 if suffix: |
| 222 name += ' - %s' % suffix | 251 name += ' - %s' % suffix |
| 223 | 252 |
| 224 # Ah hah! Now that everything is in place, lets run bot_update! | 253 # Ah hah! Now that everything is in place, lets run bot_update! |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 | 301 |
| 273 # bot_update actually just sets root to be the folder name of the | 302 # bot_update actually just sets root to be the folder name of the |
| 274 # first solution. | 303 # first solution. |
| 275 if step_result.json.output['did_run']: | 304 if step_result.json.output['did_run']: |
| 276 co_root = step_result.json.output['root'] | 305 co_root = step_result.json.output['root'] |
| 277 cwd = kwargs.get('cwd', self.m.path['slave_build']) | 306 cwd = kwargs.get('cwd', self.m.path['slave_build']) |
| 278 if 'checkout' not in self.m.path: | 307 if 'checkout' not in self.m.path: |
| 279 self.m.path['checkout'] = cwd.join(*co_root.split(self.m.path.sep)) | 308 self.m.path['checkout'] = cwd.join(*co_root.split(self.m.path.sep)) |
| 280 | 309 |
| 281 return step_result | 310 return step_result |
| OLD | NEW |