diff options
author | Darius Makovsky <traveltissues@protonmail.com> | 2019-12-02 15:30:36 +0000 |
---|---|---|
committer | Darius Makovsky <traveltissues@protonmail.com> | 2019-12-02 16:40:51 +0000 |
commit | 3599d294b43b76b21b404c304b58d72ee57654f1 (patch) | |
tree | e44105787b49a773b6b581c14ecd06c048a8c9ef | |
parent | a215b331d74c3d6cf139655cdf6b231179ccfc6f (diff) | |
download | buildstream-3599d294b43b76b21b404c304b58d72ee57654f1.tar.gz |
Add additional keys to workspace config:
* `last_artifact_ref`
* `last_dep_hash`
* replace `last_successful` with `last_digest`
-rw-r--r-- | src/buildstream/_loader/loader.py | 5 | ||||
-rw-r--r-- | src/buildstream/_stream.py | 2 | ||||
-rw-r--r-- | src/buildstream/_workspaces.py | 38 | ||||
-rw-r--r-- | src/buildstream/element.py | 14 | ||||
-rw-r--r-- | src/buildstream/plugins/sources/workspace.py | 14 | ||||
-rw-r--r-- | tests/frontend/workspace.py | 4 |
6 files changed, 53 insertions, 24 deletions
diff --git a/src/buildstream/_loader/loader.py b/src/buildstream/_loader/loader.py index 3b18af691..8aa37298d 100644 --- a/src/buildstream/_loader/loader.py +++ b/src/buildstream/_loader/loader.py @@ -452,7 +452,10 @@ class Loader: if workspace: workspace_node = {"kind": "workspace"} workspace_node["path"] = workspace.get_absolute_path() - workspace_node["last_successful"] = str(workspace.to_dict().get("last_successful", "")) + workspace_dict = workspace.to_dict() + workspace_node["last_digest"] = str(workspace_dict.get("last_digest", "")) + workspace_node["last_artifact_ref"] = str(workspace_dict.get("last_artifact_ref", "")) + workspace_node["last_dep_hash"] = str(workspace_dict.get("last_dep_hash", "")) node[Symbol.SOURCES] = [workspace_node] skip_workspace = False diff --git a/src/buildstream/_stream.py b/src/buildstream/_stream.py index 4b8409323..c08fbad1a 100644 --- a/src/buildstream/_stream.py +++ b/src/buildstream/_stream.py @@ -926,7 +926,7 @@ class Stream: if soft: workspace.prepared = False - workspace.last_successful = None + workspace.last_digest = None self._message( MessageType.INFO, "Reset workspace state for {} at: {}".format(element.name, workspace_path) ) diff --git a/src/buildstream/_workspaces.py b/src/buildstream/_workspaces.py index 3d50fd9c0..3176482c3 100644 --- a/src/buildstream/_workspaces.py +++ b/src/buildstream/_workspaces.py @@ -232,22 +232,36 @@ class WorkspaceProjectCache: # An object to contain various helper functions and data required for # workspaces. # -# last_successful, path and running_files are intended to be public -# properties, but may be best accessed using this classes' helper -# methods. +# last_digest, last_artifact_ref, last_dep_hash, path and running_files +# are intended to be public properties, but may be best accessed using +# this classes' helper methods. # # Args: # toplevel_project (Project): Top project. Will be used for resolving relative workspace paths. # path (str): The path that should host this workspace -# last_successful (str): The key of the last successful build of this workspace +# last_digest (str): The key of the last build of this workspace +# last_artifact_ref (str): The cache key of the most recent artifact +# last_dep_hash (str): The hash of the dependency tree # running_files (dict): A dict mapping dependency elements to files # changed between failed builds. Should be # made obsolete with failed build artifacts. # class Workspace: - def __init__(self, toplevel_project, *, last_successful=None, path=None, prepared=False, running_files=None): + def __init__( + self, + toplevel_project, + *, + last_digest=None, + last_artifact_ref=None, + last_dep_hash=None, + path=None, + prepared=False, + running_files=None + ): self.prepared = prepared - self.last_successful = last_successful + self.last_digest = last_digest + self.last_artifact_ref = last_artifact_ref + self.last_dep_hash = last_dep_hash self._path = path self.running_files = running_files if running_files is not None else {} @@ -263,8 +277,12 @@ class Workspace: # def to_dict(self): ret = {"prepared": self.prepared, "path": self._path, "running_files": self.running_files} - if self.last_successful is not None: - ret["last_successful"] = self.last_successful + if self.last_artifact_ref is not None: + ret["last_artifact_ref"] = self.last_artifact_ref + if self.last_digest is not None: + ret["last_digest"] = self.last_digest + if self.last_dep_hash is not None: + ret["last_dep_hash"] = self.last_dep_hash return ret # from_dict(): @@ -632,7 +650,9 @@ class Workspaces: dictionary = { "prepared": node.get_bool("prepared", default=False), "path": node.get_str("path"), - "last_successful": node.get_str("last_successful", default=None), + "last_digest": node.get_str("last_digest", default=None), + "last_artifact_ref": node.get_str("last_artifact_ref", default=None), + "last_dep_hash": node.get_str("last_dep_hash", default=None), "running_files": running_files, } return Workspace.from_dict(self._toplevel_project, dictionary) diff --git a/src/buildstream/element.py b/src/buildstream/element.py index 4bd3ae8b3..00b2088e7 100644 --- a/src/buildstream/element.py +++ b/src/buildstream/element.py @@ -752,20 +752,20 @@ class Element(Plugin): workspace = self._get_workspace() context = self._get_context() - if self.__can_build_incrementally() and workspace.last_successful: + if self.__can_build_incrementally() and workspace.last_digest: # Try to perform an incremental build if the last successful # build is still in the artifact cache # - if self.__artifacts.contains(self, workspace.last_successful): - last_successful = Artifact(self, context, strong_key=workspace.last_successful) + if self.__artifacts.contains(self, workspace.last_digest): + last_digest = Artifact(self, context, strong_key=workspace.last_digest) # Get a dict of dependency strong keys - old_dep_keys = last_successful.get_metadata_dependencies() + old_dep_keys = last_digest.get_metadata_dependencies() else: # Last successful build is no longer in the artifact cache, # so let's reset it and perform a full build now. workspace.prepared = False - workspace.last_successful = None + workspace.last_digest = None self.info("Resetting workspace state, last successful build is no longer in the cache") @@ -1600,7 +1600,7 @@ class Element(Plugin): # key = self._get_cache_key() workspace = self._get_workspace() - workspace.last_successful = key + workspace.last_digest = key workspace.clear_running_files() self._get_context().get_workspaces().save_config() @@ -2408,7 +2408,7 @@ class Element(Plugin): # FIXME: ideally we don't have to check this, eventually we would # like to get the saved old_ref and apply the new workspace on top # to support incremental builds. - if [s._key for s in self.__sources] == [workspace.last_successful]: + if [s._key for s in self.__sources] == [workspace.last_digest]: prepared = False if not prepared: diff --git a/src/buildstream/plugins/sources/workspace.py b/src/buildstream/plugins/sources/workspace.py index 3d4c93b5c..df62aa51b 100644 --- a/src/buildstream/plugins/sources/workspace.py +++ b/src/buildstream/plugins/sources/workspace.py @@ -55,16 +55,22 @@ class WorkspaceSource(Source): self.__unique_key = None # the digest of the Directory following the import of the workspace self.__digest = None - # the cache key of the last successful workspace - self.__last_successful = None + # the cache key of the last workspace build + self.__last_digest = None + # the ref of the last workspace artifact + self.__last_artifact_ref = None + # the hash of the last workspace dependency graph + self.__last_dep_hash = None def track(self) -> SourceRef: # pylint: disable=arguments-differ return None def configure(self, node: MappingNode) -> None: - node.validate_keys(["path", "last_successful", "kind"]) + node.validate_keys(["path", "last_digest", "last_artifact_ref", "last_dep_hash", "kind"]) self.path = node.get_str("path") - self.__last_successful = node.get_str("last_successful") + self.__last_digest = node.get_str("last_digest") + self.__last_artifact_ref = node.get_str("last_artifact_ref") + self.__last_dep_hash = node.get_str("last_dep_hash") def preflight(self) -> None: pass # pragma: nocover diff --git a/tests/frontend/workspace.py b/tests/frontend/workspace.py index 80db8cc98..ec361caf4 100644 --- a/tests/frontend/workspace.py +++ b/tests/frontend/workspace.py @@ -873,7 +873,7 @@ def test_list_unsupported_workspace(cli, datafiles, workspace_cfg): "workspaces": { "alpha.bst": { "path": "/workspaces/bravo", - "last_successful": "some_key", + "last_digest": "some_key", "running_files": {"beta.bst": ["some_file"]}, } }, @@ -884,7 +884,7 @@ def test_list_unsupported_workspace(cli, datafiles, workspace_cfg): "alpha.bst": { "prepared": False, "path": "/workspaces/bravo", - "last_successful": "some_key", + "last_digest": "some_key", "running_files": {"beta.bst": ["some_file"]}, } }, |