diff options
author | Darius Makovsky <traveltissues@protonmail.com> | 2019-09-05 14:33:58 +0100 |
---|---|---|
committer | Darius Makovsky <traveltissues@protonmail.com> | 2019-09-05 17:52:52 +0100 |
commit | 47b84d920119ccb4202e8d49d62c7fa045bffa92 (patch) | |
tree | 2a13b31b298733438cd10f7a515b05560c4676f8 | |
parent | 8f9f7d24e7fbadbd4d2a0d1310f1d20387ca75c7 (diff) | |
download | buildstream-47b84d920119ccb4202e8d49d62c7fa045bffa92.tar.gz |
workspace.py: stage workspace into cache
Import the path during fetch and set the `__source_digest`
-rw-r--r-- | src/buildstream/plugins/sources/workspace.py | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/src/buildstream/plugins/sources/workspace.py b/src/buildstream/plugins/sources/workspace.py index 28ba0f32b..0a78c2b12 100644 --- a/src/buildstream/plugins/sources/workspace.py +++ b/src/buildstream/plugins/sources/workspace.py @@ -38,6 +38,7 @@ details on common configuration options for sources. import os from buildstream.storage.directory import Directory +from buildstream.storage._casbaseddirectory import CasBasedDirectory from buildstream import Source, SourceError, Consistency from buildstream import utils @@ -53,6 +54,7 @@ class WorkspaceSource(Source): # Cached unique key to avoid multiple file system traversal if the unique key is requested multiple times. self.__unique_key = None self.__element_sources = [] + self.__source_digest = None def set_element_sources(self, _element_sources): self.__element_sources = _element_sources @@ -61,54 +63,50 @@ class WorkspaceSource(Source): return self.__element_sources def configure(self, node): - node.validate_keys(['path', 'ref', *Source.COMMON_CONFIG_KEYS]) - self.path = self.node_get_project_path(node.get_scalar('path')) - self.ref = node.get_str('ref', None) - self.fullpath = os.path.join(self.get_project_directory(), self.path) + node.validate_keys(['path', *Source.COMMON_CONFIG_KEYS]) + self.path = node.get_str('path') + self.fullpath = self.path def preflight(self): return + def get_ref(self): + return str(self.__source_digest) + def get_unique_key(self): - return self.__unique_key + return (self.fullpath, self.__source_digest) def init_workspace(self, directory): # for each source held by the workspace we must call init_workspace for source in self.get_element_sources(): source.init_workspace(directory) + ## FIXME the node needs reconfiguring for the workspace path where things are actually exported def get_consistency(self): - if self.ref is None: + if self.__source_digest is None: return Consistency.INCONSISTENT - return Consistency.RESOLVED def load_ref(self, node): - self.ref = node.get_str('ref', None) - - def get_ref(self): - return self.ref - - def set_ref(self, ref, node): - node['ref'] = self.ref = ref + return None def fetch(self): - pass # pragma: nocover + context = self._get_context() + directory = CasBasedDirectory(context.get_cascache()) + self.stage(directory) def stage(self, directory): # directory should always be a Directory object assert isinstance(directory, Directory) with self.timed_activity("Staging local files into CAS"): - if os.path.isdir(self.fullpath) and not os.path.islink(self.fullpath): - result = directory.import_files(self.fullpath) - else: - result = directory.import_single_file(self.fullpath) + result = directory.import_files(self.fullpath) if result.overwritten or result.ignored: raise SourceError( "Failed to stage source: files clash with existing directory", reason='ensure-stage-dir-fail') + self.__source_digest = directory._get_digest() def _get_local_path(self): return self.fullpath |