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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 def config_to_pythonish(cfg): | 141 def config_to_pythonish(cfg): |
142 return jsonish_to_python(cfg.as_jsonish(), True) | 142 return jsonish_to_python(cfg.as_jsonish(), True) |
143 | 143 |
144 def resolve_revision(self, revision): | 144 def resolve_revision(self, revision): |
145 if hasattr(revision, 'resolve'): | 145 if hasattr(revision, 'resolve'): |
146 return revision.resolve(self.m.properties) | 146 return revision.resolve(self.m.properties) |
147 return revision | 147 return revision |
148 | 148 |
149 def sync(self, cfg, with_branch_heads=False, **kwargs): | 149 def sync(self, cfg, with_branch_heads=False, **kwargs): |
150 revisions = [] | 150 revisions = [] |
| 151 self.set_patch_project_revision(self.m.properties.get('patch_project'), cfg) |
151 for i, s in enumerate(cfg.solutions): | 152 for i, s in enumerate(cfg.solutions): |
152 if s.safesync_url: # prefer safesync_url in gclient mode | 153 if s.safesync_url: # prefer safesync_url in gclient mode |
153 continue | 154 continue |
154 if i == 0 and s.revision is None: | 155 if i == 0 and s.revision is None: |
155 s.revision = RevisionFallbackChain() | 156 s.revision = RevisionFallbackChain() |
156 | 157 |
157 if s.revision is not None and s.revision != '': | 158 if s.revision is not None and s.revision != '': |
158 fixed_revision = self.resolve_revision(s.revision) | 159 fixed_revision = self.resolve_revision(s.revision) |
159 if fixed_revision: | 160 if fixed_revision: |
160 revisions.extend(['--revision', '%s@%s' % (s.name, fixed_revision)]) | 161 revisions.extend(['--revision', '%s@%s' % (s.name, fixed_revision)]) |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 for (path, dir, files) in os.walk(build_path): | 330 for (path, dir, files) in os.walk(build_path): |
330 for cur_file in files: | 331 for cur_file in files: |
331 if cur_file.endswith('index.lock'): | 332 if cur_file.endswith('index.lock'): |
332 path_to_file = os.path.join(path, cur_file) | 333 path_to_file = os.path.join(path, cur_file) |
333 print 'deleting %s' % path_to_file | 334 print 'deleting %s' % path_to_file |
334 os.remove(path_to_file) | 335 os.remove(path_to_file) |
335 """, | 336 """, |
336 args=[self.m.path['slave_build']], | 337 args=[self.m.path['slave_build']], |
337 infra_step=True, | 338 infra_step=True, |
338 ) | 339 ) |
| 340 |
| 341 def calculate_patch_root(self, patch_project, gclient_config=None): |
| 342 """Returns path where a patch should be applied to based patch_project. |
| 343 |
| 344 Maps "patch_project" to a path of directories relative to checkout's root, |
| 345 which describe where to place the patch. |
| 346 |
| 347 For now, considers only first solution (c.solutions[0]), but in theory can |
| 348 be extended to all of them. |
| 349 |
| 350 See patch_projects solution config property. |
| 351 |
| 352 Returns: |
| 353 Relative path, including solution's root. |
| 354 If patch_project is not given or not recognized, it'll be just first |
| 355 solution root. |
| 356 """ |
| 357 cfg = gclient_config or self.c |
| 358 root, _ = cfg.patch_projects.get(patch_project, ('', '')) |
| 359 if root: |
| 360 # Note, that c.patch_projects contains patch roots as |
| 361 # slash(/)-separated path, which are roots of the respective project repos |
| 362 # and include actual solution name in them. |
| 363 return self.m.path.join(*root.split('/')) |
| 364 # Default case - assume patch is for first solution, as this is what most |
| 365 # projects rely on. |
| 366 return cfg.solutions[0].name |
| 367 |
| 368 def set_patch_project_revision(self, patch_project, gclient_config=None): |
| 369 """Updates config revision corresponding to patch_project. |
| 370 |
| 371 Useful for bot_update only, as this is the only consumer of gclient's config |
| 372 revision map. This doesn't overwrite the revision if it was already set. |
| 373 """ |
| 374 assert patch_project is None or isinstance(patch_project, basestring) |
| 375 cfg = gclient_config or self.c |
| 376 path, revision = cfg.patch_projects.get(patch_project, (None, None)) |
| 377 if path and revision and path not in cfg.revisions: |
| 378 cfg.revisions[path] = revision |
OLD | NEW |