summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Maat <tristan.maat@codethink.co.uk>2018-03-12 12:56:55 +0000
committerTristan Maat <tristan.maat@codethink.co.uk>2018-03-27 14:32:54 +0100
commit1d9ea9171dbf4c3244c9acf8da7a00c6825c3217 (patch)
tree3fe8ee681feb0f4fce28fbc1e00455e17544b004
parent18896a9e02e2677910c567de25760dd0432ac43a (diff)
downloadbuildstream-1d9ea9171dbf4c3244c9acf8da7a00c6825c3217.tar.gz
Add list of running files to workspace metadata
-rw-r--r--buildstream/_workspaces.py39
-rw-r--r--buildstream/element.py6
2 files changed, 39 insertions, 6 deletions
diff --git a/buildstream/_workspaces.py b/buildstream/_workspaces.py
index 36b2c9e74..a621f277f 100644
--- a/buildstream/_workspaces.py
+++ b/buildstream/_workspaces.py
@@ -25,7 +25,7 @@ from . import _yaml
from ._exceptions import LoadError, LoadErrorReason
-BST_WORKSPACE_FORMAT_VERSION = 1
+BST_WORKSPACE_FORMAT_VERSION = 2
# Workspace()
@@ -41,11 +41,15 @@ BST_WORKSPACE_FORMAT_VERSION = 1
# path (str): The path that should host this workspace
# project (Project): The project this workspace is part of
# last_successful (str): The key of the last successful build of this workspace
+# 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, path, project, last_successful=None):
+ def __init__(self, path, project, last_successful=None, running_files=None):
self.last_successful = last_successful
self.path = path
+ self.running_files = running_files if running_files is not None else {}
self._element = None
self._project = project
@@ -55,11 +59,14 @@ class Workspace():
def from_yaml_node(cls, node, project):
path = _yaml.node_get(node, str, 'path')
last_successful = _yaml.node_get(node, str, 'last_successful', default_value='')
+ running_files = _yaml.node_get(node, dict, 'running_files', default_value={})
if last_successful == '':
last_successful = None
+ if running_files == {}:
+ running_files = None
- return cls(path, project, last_successful)
+ return cls(path, project, last_successful, running_files)
# _to_dict()
#
@@ -69,7 +76,7 @@ class Workspace():
# (dict) A dict representation of the workspace
#
def _to_dict(self):
- to_return = ['path', 'last_successful']
+ to_return = ['path', 'last_successful', 'running_files']
return {key: val for key, val in self.__dict__.items()
if key in to_return and val is not None}
@@ -116,6 +123,28 @@ class Workspace():
destfile = os.path.join(directory, os.path.basename(self.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 (Element) - The dependency whose files to append to
+ # files (str) - A list of files to append
+ #
+ def add_running_files(self, dep, files):
+ if dep.name in self.running_files:
+ self.running_files[dep.name] |= set(files)
+ else:
+ self.running_files[dep.name] = set(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.
@@ -314,7 +343,7 @@ class Workspaces():
for element, config in _yaml.node_items(workspaces)
}
- elif version == BST_WORKSPACE_FORMAT_VERSION:
+ elif version == 1 or version == BST_WORKSPACE_FORMAT_VERSION:
workspaces = _yaml.node_get(workspaces, dict, "workspaces", default_value={})
res = {element: Workspace.from_yaml_node(node, self._project)
for element, node in _yaml.node_items(workspaces)}
diff --git a/buildstream/element.py b/buildstream/element.py
index bc3063b6c..fa523d8b1 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -523,6 +523,9 @@ class Element(Plugin):
# files, since removed files will be picked up by
# build systems anyway.
to_update, _, added = self.__artifacts.diff(dep, key_old, key_new, subdir='files')
+ workspace.add_running_files(dep, to_update + added)
+ self._get_project()._workspaces.save_config()
+ to_update.extend(workspace.running_files[dep.name])
result = dep.stage_artifact(sandbox,
path=path,
@@ -893,10 +896,11 @@ class Element(Plugin):
self._update_state()
- if self._workspaced():
+ if self._workspaced() and self._cached():
key = self._get_cache_key()
workspace = self._get_workspace()
workspace.last_successful = key
+ workspace.clear_running_files()
self._get_project()._workspaces.save_config()
# _cached():