OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 from recipe_engine.config_types import Path, NamedBasePath | |
7 | 6 |
8 | 7 |
9 class InfraPathsApi(recipe_api.RecipeApi): | 8 class InfraPathsApi(recipe_api.RecipeApi): |
10 def get_config_defaults(self): | 9 def get_config_defaults(self): |
11 return { | 10 return { |
12 'PLATFORM': self.m.platform.name, | 11 'PLATFORM': self.m.platform.name, |
13 'CURRENT_WORKING_DIR': self.m.path['cwd'], | 12 'CURRENT_WORKING_DIR': self.m.path['cwd'], |
14 'ROOT': self.m.path['root'], | 13 'ROOT': self.m.path['root'], |
15 } | 14 } |
16 | 15 |
17 def __init__(self, **kwargs): | 16 def __init__(self, **kwargs): |
18 super(InfraPathsApi, self).__init__(**kwargs) | 17 super(InfraPathsApi, self).__init__(**kwargs) |
19 self._config_set = False | 18 self._config_set = False |
20 | 19 |
21 def _lazy_set_config(self): | 20 def _lazy_set_config(self): |
22 if self._config_set: | 21 if self._config_set: |
23 return | 22 return |
24 self._config_set = True | 23 self._config_set = True |
25 | 24 |
26 path_config = self.m.properties.get('path_config') | 25 path_config = self.m.properties.get('path_config') |
27 if path_config in ('kitchen',): | 26 if path_config in ('kitchen',): |
28 self.set_config(path_config) | 27 self.set_config(path_config) |
29 else: | 28 else: |
30 self.set_config('buildbot') | 29 self.set_config('buildbot') |
31 | 30 |
32 for path in self._test_data.get('exists', []): | |
33 assert isinstance(path.base, NamedBasePath) | |
34 self.m.path.mock_add_paths(self[path.base.name].join(*path.pieces)) | |
35 | |
36 def __getitem__(self, name): | 31 def __getitem__(self, name): |
37 self._lazy_set_config() | 32 self._lazy_set_config() |
38 return self.c.paths[name] | 33 return self.c.paths[name] |
OLD | NEW |