diff options
| author | Darius Makovsky <traveltissues@protonmail.com> | 2019-10-18 10:11:10 +0100 |
|---|---|---|
| committer | Darius Makovsky <traveltissues@protonmail.com> | 2019-10-23 13:08:27 +0100 |
| commit | fbc2c878bcee76cbc1c1650e509bf32f3369b411 (patch) | |
| tree | 0aad3a5e45e4624511bf5d002823774916c12b36 | |
| parent | 1e0a83d01ce25d1e4cea854343c05ae53d4d4237 (diff) | |
| download | buildstream-fbc2c878bcee76cbc1c1650e509bf32f3369b411.tar.gz | |
Extend Source API
Add `stage_into_directory()` public method.
`stage_into_directory` reimplements `LocalSource.stage()` to import the
source path on the specified directory object.
Add `_stage_into_cas()` private method. Calls `self.stage` on
a `CasBasedDirectory`.
| -rw-r--r-- | src/buildstream/source.py | 25 | ||||
| -rw-r--r-- | src/buildstream/storage/__init__.py | 1 |
2 files changed, 24 insertions, 2 deletions
diff --git a/src/buildstream/source.py b/src/buildstream/source.py index 3cde857b5..a7926e4cd 100644 --- a/src/buildstream/source.py +++ b/src/buildstream/source.py @@ -173,6 +173,7 @@ from ._exceptions import BstError, ImplError, ErrorDomain from ._loader.metasource import MetaSource from ._projectrefs import ProjectRefStorage from ._cachekey import generate_key +from .storage import CasBasedDirectory from .storage import FileBasedDirectory from .storage.directory import Directory, VirtualDirectoryError @@ -714,6 +715,25 @@ class Source(Plugin): ############################################################# # Private Methods used in BuildStream # ############################################################# + # Stage files at the localpath into the cascache + # + # Returns: + # the hash of the cas directory + def _stage_into_cas(self) -> str: + cas_dir = self._get_cas_dir() + self._stage(cas_dir) + return self._get_dir_hash(cas_dir) + + # Return a CasBasedDirectory object held at the invocation context + # + def _get_cas_dir(self) -> CasBasedDirectory: + cas = self._get_context().get_cascache() + return CasBasedDirectory(cas) + + # Return the hash of a CasBasedDirectory digest + # + def _get_dir_hash(self, vdir: CasBasedDirectory) -> str: + return vdir._get_digest().hash # Wrapper around preflight() method # @@ -788,8 +808,9 @@ class Source(Plugin): key = {} key['directory'] = self.__directory if self.BST_NO_PRESTAGE_KEY: - self._stage(self.__directory) - key['unique'] = self.get_unique_key() # pylint: disable=assignment-from-no-return + key['unique'] = self._stage_into_cas() + else: + key['unique'] = self.get_unique_key() # pylint: disable=assignment-from-no-return return key # _project_refs(): diff --git a/src/buildstream/storage/__init__.py b/src/buildstream/storage/__init__.py index 33424ac8d..5571cd807 100644 --- a/src/buildstream/storage/__init__.py +++ b/src/buildstream/storage/__init__.py @@ -19,4 +19,5 @@ # Jim MacArthur <jim.macarthur@codethink.co.uk> from ._filebaseddirectory import FileBasedDirectory +from ._casbaseddirectory import CasBasedDirectory from .directory import Directory |
