Chromium Code Reviews| Index: recipe_modules/path/api.py |
| diff --git a/recipe_modules/path/api.py b/recipe_modules/path/api.py |
| index dd6a4ba7ad9687f9ddba3d3d8ee395a94da6718a..5fff002cb1f1b8d8df01ac41704950f11b9997a6 100644 |
| --- a/recipe_modules/path/api.py |
| +++ b/recipe_modules/path/api.py |
| @@ -161,13 +161,19 @@ class PathApi(recipe_api.RecipeApi): |
| # Used in mkdtemp when generating and checking expectations. |
| self._test_counter = 0 |
| + def _read_module_property(self, property_name, default=None): |
| + """Reads a path property module from "$recipe_engine/path". If absent, |
| + returns the default. |
| + """ |
| + props = self.m.properties.get('$recipe_engine/path', {}) |
| + return props.get(property_name, default) |
| + |
| def _read_path(self, property_name, default): # pragma: no cover |
| """Reads a path from a property. If absent, returns the default. |
| Validates that the path is absolute. |
| """ |
| - props = self.m.properties.get('$recipe_engine/path', {}) |
| - value = props.get(property_name) |
| + value = self._read_module_property(property_name) |
| if not value: |
| assert os.path.isabs(default), default |
| return default |
| @@ -198,11 +204,14 @@ class PathApi(recipe_api.RecipeApi): |
| self._cache_dir = _split_path(cache_dir) |
| else: |
| self._path_mod = fake_path(self, self._test_data.get('exists', [])) |
| + self._tmp_dir_volatile = self._test_data.get('tmp_dir_volatile', False) |
|
nodir
2017/04/10 16:59:21
self._tmp_dir_volatile is not used
dnj
2017/04/10 17:05:20
oh whoops, thanks
|
| self._startup_cwd = ['/', 'b', 'FakeTestingCWD'] |
| # Appended to placeholder '[TMP]' to get fake path in test. |
| self._temp_dir = ['/'] |
| self._cache_dir = ['/', 'b', 'c'] |
| + self._volatile_paths = self._read_module_property('volatile', []) |
| + |
| self.set_config('BASE') |
| def mock_add_paths(self, path): |
| @@ -213,6 +222,14 @@ class PathApi(recipe_api.RecipeApi): |
| def assert_absolute(self, path): |
| assert self.abspath(path) == str(path), '%s is not absolute' % path |
| + def is_volatile(self, base): |
| + """Returns (bool): True if the named path is declared as volatile. |
| + |
| + A path is volatile if it is scoped to the recipe engine execution. Note that |
| + some paths may be volatile, but not explicitly declared as such. |
| + """ |
| + return base in self.c.volatile_paths or base in self._volatile_paths |
| + |
| def mkdtemp(self, prefix): |
| """Makes a new temp directory, returns path to it.""" |
| if not self._test_data.enabled: # pragma: no cover |