OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 from recipe_engine import recipe_api |
| 6 |
| 7 |
| 8 class ChromiumCheckoutApi(recipe_api.RecipeApi): |
| 9 def __init__(self, *args, **kwargs): |
| 10 super(ChromiumCheckoutApi, self).__init__(*args, **kwargs) |
| 11 # Keep track of working directory (which contains the checkout). |
| 12 # None means "default value". |
| 13 self._working_dir = None |
| 14 |
| 15 @property |
| 16 def working_dir(self): |
| 17 """Returns parent directory of the checkout. |
| 18 |
| 19 Requires |ensure_checkout| to be called first. |
| 20 """ |
| 21 # TODO(phajdan.jr): assert ensure_checkout has been called. |
| 22 return self._working_dir |
| 23 |
| 24 def get_checkout_dir(self, bot_config): |
| 25 """Returns directory where checkout can be created. |
| 26 |
| 27 None means to use default checkout directory. |
| 28 """ |
| 29 try: |
| 30 builder_cache = self.m.path['builder_cache'] |
| 31 except KeyError: # no-op if builder cache is not set up. |
| 32 return None |
| 33 else: |
| 34 sanitized_buildername = ''.join( |
| 35 c if c.isalnum() else '_' for c in self.m.properties['buildername']) |
| 36 checkout_dir = builder_cache.join( |
| 37 bot_config.get('checkout_dir', sanitized_buildername)) |
| 38 self.m.shutil.makedirs('checkout path', checkout_dir) |
| 39 return checkout_dir |
| 40 |
| 41 def get_files_affected_by_patch(self, relative_to='src/', cwd=None): |
| 42 """Returns list of POSIX paths of files affected by patch for "analyze". |
| 43 |
| 44 Paths are relative to `relative_to` which for analyze should be 'src/'. |
| 45 """ |
| 46 patch_root = self.m.gclient.calculate_patch_root( |
| 47 self.m.properties.get('patch_project')) |
| 48 if not cwd and self.working_dir: |
| 49 cwd = self.working_dir.join(patch_root) |
| 50 files = self.m.tryserver.get_files_affected_by_patch(patch_root, cwd=cwd) |
| 51 for i, path in enumerate(files): |
| 52 path = str(path) |
| 53 assert path.startswith(relative_to) |
| 54 files[i] = path[len(relative_to):] |
| 55 return files |
| 56 |
| 57 def ensure_checkout(self, bot_config, root_solution_revision=None, |
| 58 force=False): |
| 59 """Wrapper for bot_update.ensure_checkout with chromium-specific additions. |
| 60 """ |
| 61 if self.m.platform.is_win: |
| 62 self.m.chromium.taskkill() |
| 63 |
| 64 kwargs = {} |
| 65 self._working_dir = self.get_checkout_dir(bot_config) |
| 66 if self._working_dir: |
| 67 kwargs['cwd'] = self._working_dir |
| 68 |
| 69 # Bot Update re-uses the gclient configs. |
| 70 update_step = self.m.bot_update.ensure_checkout( |
| 71 patch_root=bot_config.get('patch_root'), |
| 72 root_solution_revision=root_solution_revision, |
| 73 clobber=bot_config.get('clobber', False), |
| 74 force=force, **kwargs) |
| 75 assert update_step.json.output['did_run'] |
| 76 # HACK(dnj): Remove after 'crbug.com/398105' has landed |
| 77 self.m.chromium.set_build_properties(update_step.json.output['properties']) |
| 78 |
| 79 return update_step |
OLD | NEW |