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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 """Resolve the revision if project matches, otherwise default to HEAD.""" | 43 """Resolve the revision if project matches, otherwise default to HEAD.""" |
44 if properties.get('project') == self.project: | 44 if properties.get('project') == self.project: |
45 return (properties.get(self.parent_got_revision) or | 45 return (properties.get(self.parent_got_revision) or |
46 properties.get('revision') or | 46 properties.get('revision') or |
47 'HEAD') | 47 'HEAD') |
48 return (properties.get(self.parent_got_revision) or | 48 return (properties.get(self.parent_got_revision) or |
49 'HEAD') | 49 'HEAD') |
50 | 50 |
51 | 51 |
52 def jsonish_to_python(spec, is_top=False): | 52 def jsonish_to_python(spec, is_top=False): |
| 53 """Turn a json spec into a python parsable object. |
| 54 |
| 55 This exists because Gclient specs, while resembling json, is actually |
| 56 ingested using a python "eval()". Therefore a bit of plumming is required |
| 57 to turn our newly constructed Gclient spec into a gclient-readable spec. |
| 58 """ |
53 ret = '' | 59 ret = '' |
54 if is_top: # We're the 'top' level, so treat this dict as a suite. | 60 if is_top: # We're the 'top' level, so treat this dict as a suite. |
55 ret = '\n'.join( | 61 ret = '\n'.join( |
56 '%s = %s' % (k, jsonish_to_python(spec[k])) for k in sorted(spec) | 62 '%s = %s' % (k, jsonish_to_python(spec[k])) for k in sorted(spec) |
57 ) | 63 ) |
58 else: | 64 else: |
59 if isinstance(spec, dict): | 65 if isinstance(spec, dict): |
60 ret += '{' | 66 ret += '{' |
61 ret += ', '.join( | 67 ret += ', '.join( |
62 "%s: %s" % (repr(str(k)), jsonish_to_python(spec[k])) | 68 "%s: %s" % (repr(str(k)), jsonish_to_python(spec[k])) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 @spec_alias.deleter | 130 @spec_alias.deleter |
125 def spec_alias(self): | 131 def spec_alias(self): |
126 self._spec_alias = None | 132 self._spec_alias = None |
127 | 133 |
128 def get_config_defaults(self): | 134 def get_config_defaults(self): |
129 return { | 135 return { |
130 'USE_MIRROR': self.use_mirror, | 136 'USE_MIRROR': self.use_mirror, |
131 'CACHE_DIR': self.m.path['git_cache'], | 137 'CACHE_DIR': self.m.path['git_cache'], |
132 } | 138 } |
133 | 139 |
| 140 @staticmethod |
| 141 def config_to_pythonish(cfg): |
| 142 return jsonish_to_python(cfg.as_jsonish(), True) |
| 143 |
134 def resolve_revision(self, revision): | 144 def resolve_revision(self, revision): |
135 if hasattr(revision, 'resolve'): | 145 if hasattr(revision, 'resolve'): |
136 return revision.resolve(self.m.properties) | 146 return revision.resolve(self.m.properties) |
137 return revision | 147 return revision |
138 | 148 |
139 def sync(self, cfg, with_branch_heads=False, **kwargs): | 149 def sync(self, cfg, with_branch_heads=False, **kwargs): |
140 revisions = [] | 150 revisions = [] |
141 for i, s in enumerate(cfg.solutions): | 151 for i, s in enumerate(cfg.solutions): |
142 if s.safesync_url: # prefer safesync_url in gclient mode | 152 if s.safesync_url: # prefer safesync_url in gclient mode |
143 continue | 153 continue |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 """Return a step generator function for gclient checkouts.""" | 244 """Return a step generator function for gclient checkouts.""" |
235 cfg = gclient_config or self.c | 245 cfg = gclient_config or self.c |
236 assert cfg.complete() | 246 assert cfg.complete() |
237 | 247 |
238 if revert is self.RevertOnTryserver: | 248 if revert is self.RevertOnTryserver: |
239 revert = self.m.tryserver.is_tryserver | 249 revert = self.m.tryserver.is_tryserver |
240 | 250 |
241 if inject_parent_got_revision: | 251 if inject_parent_got_revision: |
242 self.inject_parent_got_revision(cfg, override=True) | 252 self.inject_parent_got_revision(cfg, override=True) |
243 | 253 |
244 spec_string = jsonish_to_python(cfg.as_jsonish(), True) | 254 self('setup', ['config', '--spec', self.config_to_pythonish(cfg)], **kwargs) |
245 | |
246 self('setup', ['config', '--spec', spec_string], **kwargs) | |
247 | 255 |
248 sync_step = None | 256 sync_step = None |
249 try: | 257 try: |
250 if not cfg.GIT_MODE: | 258 if not cfg.GIT_MODE: |
251 try: | 259 try: |
252 if revert: | 260 if revert: |
253 self.revert(**kwargs) | 261 self.revert(**kwargs) |
254 finally: | 262 finally: |
255 sync_step = self.sync(cfg, with_branch_heads=with_branch_heads, | 263 sync_step = self.sync(cfg, with_branch_heads=with_branch_heads, |
256 **kwargs) | 264 **kwargs) |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 for (path, dir, files) in os.walk(build_path): | 329 for (path, dir, files) in os.walk(build_path): |
322 for cur_file in files: | 330 for cur_file in files: |
323 if cur_file.endswith('index.lock'): | 331 if cur_file.endswith('index.lock'): |
324 path_to_file = os.path.join(path, cur_file) | 332 path_to_file = os.path.join(path, cur_file) |
325 print 'deleting %s' % path_to_file | 333 print 'deleting %s' % path_to_file |
326 os.remove(path_to_file) | 334 os.remove(path_to_file) |
327 """, | 335 """, |
328 args=[self.m.path['slave_build']], | 336 args=[self.m.path['slave_build']], |
329 infra_step=True, | 337 infra_step=True, |
330 ) | 338 ) |
OLD | NEW |