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. | |
Sergiy Byelozyorov
2016/08/12 13:22:24
perhaps add an assert?
| |
20 """ | |
21 return self._working_dir | |
22 | |
23 def get_checkout_dir(self, bot_config): | |
24 """Returns directory where checkout can be created. | |
25 | |
26 None means to use default checkout directory. | |
27 """ | |
28 try: | |
29 builder_cache = self.m.path['builder_cache'] | |
30 except KeyError: # no-op if builder cache is not set up. | |
31 return None | |
32 else: | |
33 sanitized_buildername = ''.join( | |
34 c if c.isalnum() else '_' for c in self.m.properties['buildername']) | |
35 checkout_dir = builder_cache.join( | |
36 bot_config.get('checkout_dir', sanitized_buildername)) | |
37 self.m.shutil.makedirs('checkout path', checkout_dir) | |
38 return checkout_dir | |
39 | |
40 def get_files_affected_by_patch(self, relative_to='src/', cwd=None): | |
41 """Returns list of POSIX paths of files affected by patch for "analyze". | |
42 | |
43 Paths are relative to `relative_to` which for analyze should be 'src/'. | |
44 """ | |
45 patch_root = self.m.gclient.calculate_patch_root( | |
46 self.m.properties.get('patch_project')) | |
47 if not cwd and self.working_dir: | |
48 cwd = self.working_dir.join(patch_root) | |
Sergiy Byelozyorov
2016/08/12 13:22:24
This would require having working_dir initialized.
Sergiy Byelozyorov
2016/08/12 13:41:41
As Pawel pointed out, the if self._working_dir che
| |
49 files = self.m.tryserver.get_files_affected_by_patch(patch_root, cwd=cwd) | |
50 for i, path in enumerate(files): | |
51 path = str(path) | |
52 assert path.startswith(relative_to) | |
53 files[i] = path[len(relative_to):] | |
54 return files | |
55 | |
56 def ensure_checkout(self, bot_config, root_solution_revision=None, | |
57 force=False): | |
58 """Wrapper for bot_update.ensure_checkout with chromium-specific additions. | |
59 """ | |
60 if self.m.platform.is_win: | |
61 self.m.chromium.taskkill() | |
62 | |
63 kwargs = {} | |
64 self._working_dir = self.get_checkout_dir(bot_config) | |
65 if self._working_dir: | |
66 kwargs['cwd'] = self._working_dir | |
67 | |
68 # Bot Update re-uses the gclient configs. | |
69 update_step = self.m.bot_update.ensure_checkout( | |
70 patch_root=bot_config.get('patch_root'), | |
71 root_solution_revision=root_solution_revision, | |
72 clobber=bot_config.get('clobber', False), | |
73 force=force, **kwargs) | |
74 assert update_step.json.output['did_run'] | |
75 # HACK(dnj): Remove after 'crbug.com/398105' has landed | |
76 self.m.chromium.set_build_properties(update_step.json.output['properties']) | |
77 | |
78 return update_step | |
OLD | NEW |