diff options
author | William Salmon <will.salmon@codethink.co.uk> | 2020-04-16 14:59:08 +0100 |
---|---|---|
committer | William Salmon <will.salmon@codethink.co.uk> | 2020-04-20 10:14:32 +0100 |
commit | 61cd77922f51458b90541239b56943606de955e2 (patch) | |
tree | 65520d3e74b2e5e24abb5d4136b5688e18ffce69 | |
parent | f093e630d6d4272930f45595d5f1b069879412ce (diff) | |
download | buildstream-willsalmon/workspaceFix.tar.gz |
_workspaces.py: Update workspace version if possiblewillsalmon/workspaceFix
This also informs the user which workspaces are open.
-rw-r--r-- | src/buildstream/_workspaces.py | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/src/buildstream/_workspaces.py b/src/buildstream/_workspaces.py index a54a17ff1..25c432416 100644 --- a/src/buildstream/_workspaces.py +++ b/src/buildstream/_workspaces.py @@ -434,6 +434,17 @@ class Workspaces: "format-version": BST_WORKSPACE_FORMAT_VERSION, "workspaces": {element: workspace.to_dict() for element, workspace in self._workspaces.items()}, } + self._save_config(config) + + # _save_config() + # Dump a given workspace config to file. + # + # Args: + # config (dict) - The config to be saved to file. + # + def _save_config(self, config): + assert utils._is_main_process() + os.makedirs(self._bst_directory, exist_ok=True) _yaml.roundtrip_dump(config, self._get_filename()) @@ -461,9 +472,9 @@ class Workspaces: # _parse_workspace_config_format() # - # If workspace config is in old-style format, i.e. it is using - # source-specific workspaces, try to convert it to element-specific - # workspaces. + # If workspace config is in bst1.4 format and there are no workspaces + # then prompt user for confirmation to update it. Other wise list the + # work spaces that need closing. # # Args: # workspaces (dict): current workspace config, usually output of _load_workspace_config() @@ -482,10 +493,28 @@ class Workspaces: ) if version < 4: + if workspaces.get_node("workspaces").keys() == []: + # If a old workspace file exists but with no workspaces + # then silently update the version. + config = { + "format-version": BST_WORKSPACE_FORMAT_VERSION, + "workspaces": {}, + } + self._save_config(config) + return {} + extra_error = ( + "The following workspaces need removing before format can be updated:\n" + + "\n".join( + [ + "{}: {}".format(element, node.get_str("path")) + for element, node in workspaces.get_mapping("workspaces").items() + ] + ) + + "\nPlease use a older version of bst to remove these workspaces." + ) # bst 1.x workspaces do not separate source and build files. raise LoadError( - "Workspace configuration format version {} not supported." - "Please recreate this workspace.".format(version), + "Workspace configuration format version {} not supported.\n".format(version) + extra_error, LoadErrorReason.INVALID_DATA, ) |