| 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 14 matching lines...) Expand all Loading... |
| 25 until it finds one set or reaches the end of the chain and returns the | 25 until it finds one set or reaches the end of the chain and returns the |
| 26 default. If the given revision was not set using revision_fallback_chain(), | 26 default. If the given revision was not set using revision_fallback_chain(), |
| 27 this function just returns it as-is. | 27 this function just returns it as-is. |
| 28 """ | 28 """ |
| 29 return (properties.get('parent_got_revision') or | 29 return (properties.get('parent_got_revision') or |
| 30 properties.get('orig_revision') or | 30 properties.get('orig_revision') or |
| 31 properties.get('revision') or | 31 properties.get('revision') or |
| 32 self._default) | 32 self._default) |
| 33 | 33 |
| 34 | 34 |
| 35 class ProjectRevisionResolver(RevisionResolver): | |
| 36 """Revision resolver that takes into account the project.""" | |
| 37 def __init__(self, project, parent_got_revision=None): | |
| 38 self.project = project | |
| 39 self.parent_got_revision = parent_got_revision or 'parent_got_revision' | |
| 40 | |
| 41 # TODO(phajdan.jr): Move to proper repo and add coverage. | |
| 42 def resolve(self, properties): # pragma: no cover | |
| 43 """Resolve the revision if project matches, otherwise default to HEAD.""" | |
| 44 if properties.get('project') == self.project: | |
| 45 return (properties.get(self.parent_got_revision) or | |
| 46 properties.get('revision') or | |
| 47 'HEAD') | |
| 48 return (properties.get(self.parent_got_revision) or | |
| 49 'HEAD') | |
| 50 | |
| 51 | |
| 52 def jsonish_to_python(spec, is_top=False): | 35 def jsonish_to_python(spec, is_top=False): |
| 53 """Turn a json spec into a python parsable object. | 36 """Turn a json spec into a python parsable object. |
| 54 | 37 |
| 55 This exists because Gclient specs, while resembling json, is actually | 38 This exists because Gclient specs, while resembling json, is actually |
| 56 ingested using a python "eval()". Therefore a bit of plumming is required | 39 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. | 40 to turn our newly constructed Gclient spec into a gclient-readable spec. |
| 58 """ | 41 """ |
| 59 ret = '' | 42 ret = '' |
| 60 if is_top: # We're the 'top' level, so treat this dict as a suite. | 43 if is_top: # We're the 'top' level, so treat this dict as a suite. |
| 61 ret = '\n'.join( | 44 ret = '\n'.join( |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 """Updates config revision corresponding to patch_project. | 351 """Updates config revision corresponding to patch_project. |
| 369 | 352 |
| 370 Useful for bot_update only, as this is the only consumer of gclient's config | 353 Useful for bot_update only, as this is the only consumer of gclient's config |
| 371 revision map. This doesn't overwrite the revision if it was already set. | 354 revision map. This doesn't overwrite the revision if it was already set. |
| 372 """ | 355 """ |
| 373 assert patch_project is None or isinstance(patch_project, basestring) | 356 assert patch_project is None or isinstance(patch_project, basestring) |
| 374 cfg = gclient_config or self.c | 357 cfg = gclient_config or self.c |
| 375 path, revision = cfg.patch_projects.get(patch_project, (None, None)) | 358 path, revision = cfg.patch_projects.get(patch_project, (None, None)) |
| 376 if path and revision and path not in cfg.revisions: | 359 if path and revision and path not in cfg.revisions: |
| 377 cfg.revisions[path] = revision | 360 cfg.revisions[path] = revision |
| OLD | NEW |