From 1cc8a873b292965c2b2d288ac288f6791a3001c2 Mon Sep 17 00:00:00 2001 From: Darius Makovsky Date: Thu, 12 Sep 2019 16:53:34 +0100 Subject: Revert "WIP initial deprecation of workspaces" This reverts commit 414829f40501d76e1dc4ee7fcb5a91b4e4efa3f4. --- src/buildstream/_workspaces.py | 97 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 2 deletions(-) diff --git a/src/buildstream/_workspaces.py b/src/buildstream/_workspaces.py index f5e884f8f..a16c840e5 100644 --- a/src/buildstream/_workspaces.py +++ b/src/buildstream/_workspaces.py @@ -244,7 +244,11 @@ class WorkspaceProjectCache(): # class Workspace(): def __init__(self, toplevel_project, *, last_successful=None, path=None, prepared=False, running_files=None): + self.prepared = prepared + self.last_successful = last_successful self._path = path + self.running_files = running_files if running_files is not None else {} + self._toplevel_project = toplevel_project self._key = None @@ -256,7 +260,14 @@ class Workspace(): # (dict) A dict representation of the workspace # def to_dict(self): - return {'path': self._path} + 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 + return ret # from_dict(): # @@ -277,6 +288,19 @@ class Workspace(): # Just pass the dictionary as kwargs return cls(toplevel_project, **dictionary) + # differs() + # + # Checks if two workspaces are different in any way. + # + # Args: + # other (Workspace): Another workspace instance + # + # Returns: + # True if the workspace differs from 'other', otherwise False + # + def differs(self, other): + return self.to_dict() != other.to_dict() + # invalidate_key() # # Invalidate the workspace key, forcing a recalculation next time @@ -285,6 +309,45 @@ class Workspace(): def invalidate_key(self): self._key = None + # stage() + # + # Stage the workspace to the given directory. + # + # Args: + # directory (str) - The directory into which to stage this workspace + # + def stage(self, directory): + fullpath = self.get_absolute_path() + if os.path.isdir(fullpath): + utils.copy_files(fullpath, directory) + else: + destfile = os.path.join(directory, os.path.basename(self.get_absolute_path())) + utils.safe_copy(fullpath, destfile) + + # add_running_files() + # + # Append a list of files to the running_files for the given + # dependency. Duplicate files will be ignored. + # + # Args: + # dep_name (str) - The dependency name whose files to append to + # files (str) - A list of files to append + # + def add_running_files(self, dep_name, files): + if dep_name in self.running_files: + # ruamel.py cannot serialize sets in python3.4 + to_add = set(files) - set(self.running_files[dep_name]) + self.running_files[dep_name].extend(to_add) + else: + self.running_files[dep_name] = list(files) + + # clear_running_files() + # + # Clear all running files associated with this workspace. + # + def clear_running_files(self): + self.running_files = {} + # get_key() # # Get a unique key for this workspace. @@ -408,6 +471,27 @@ class Workspaces(): return None return self._workspaces[element_name] + # update_workspace() + # + # Update the datamodel with a new Workspace instance + # + # Args: + # element_name (str): The name of the element to update a workspace for + # workspace_dict (Workspace): A serialized workspace dictionary + # + # Returns: + # (bool): Whether the workspace has changed as a result + # + def update_workspace(self, element_name, workspace_dict): + assert element_name in self._workspaces + + workspace = Workspace.from_dict(self._toplevel_project, workspace_dict) + if self._workspaces[element_name].differs(workspace): + self._workspaces[element_name] = workspace + return True + + return False + # delete_workspace() # # Remove the workspace from the workspace element. Note that this @@ -544,7 +628,16 @@ class Workspaces(): # (Workspace): A newly instantiated Workspace # def _load_workspace(self, node): - dictionary = {'path': node.get_str('path')} + running_files = node.get_mapping('running_files', default=None) + if running_files: + running_files = running_files._strip_node_info() + + dictionary = { + 'prepared': node.get_bool('prepared', default=False), + 'path': node.get_str('path'), + 'last_successful': node.get_str('last_successful', default=None), + 'running_files': running_files, + } return Workspace.from_dict(self._toplevel_project, dictionary) # _get_filename(): -- cgit v1.2.1