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