diff options
author | Tristan Maat <tristan.maat@codethink.co.uk> | 2018-07-16 18:03:23 +0100 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-07-18 14:45:59 +0900 |
commit | 1ec5c7b1207f212e127b15da4094ffe99504301b (patch) | |
tree | cd274404844a72abfc8525558d71ab7721d3dccd /buildstream/element.py | |
parent | 339844487ef9ea6c897254bfe8f35a6648b28a5e (diff) | |
download | buildstream-1ec5c7b1207f212e127b15da4094ffe99504301b.tar.gz |
Make elements keep track of their built artifact size
Diffstat (limited to 'buildstream/element.py')
-rw-r--r-- | buildstream/element.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/buildstream/element.py b/buildstream/element.py index 0f0bf49d6..140c824ec 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -225,6 +225,7 @@ class Element(Plugin): self.__staged_sources_directory = None # Location where Element.stage_sources() was called self.__tainted = None # Whether the artifact is tainted and should not be shared self.__required = False # Whether the artifact is required in the current session + self.__artifact_size = None # The size of data committed to the artifact cache # hash tables of loaded artifact metadata, hashed by key self.__metadata_keys = {} # Strong and weak keys for this key @@ -1397,6 +1398,16 @@ class Element(Plugin): workspace.clear_running_files() self._get_context().get_workspaces().save_config() + # We also need to update the required artifacts, since + # workspaced dependencies do not have a fixed cache key + # when the build starts. + # + # This does *not* cause a race condition, because + # _assemble_done is called before a cleanup job may be + # launched. + # + self.__artifacts.append_required_artifacts([self]) + # _assemble(): # # Internal method for running the entire build phase. @@ -1524,6 +1535,7 @@ class Element(Plugin): }), os.path.join(metadir, 'workspaced-dependencies.yaml')) with self.timed_activity("Caching artifact"): + self.__artifact_size = utils._get_dir_size(assembledir) self.__artifacts.commit(self, assembledir, self.__get_cache_keys_for_commit()) # Finally cleanup the build dir @@ -1763,6 +1775,25 @@ class Element(Plugin): workspaces = self._get_context().get_workspaces() return workspaces.get_workspace(self._get_full_name()) + # _get_artifact_size() + # + # Get the size of the artifact produced by this element in the + # current pipeline - if this element has not been assembled or + # pulled, this will be None. + # + # Note that this is the size of an artifact *before* committing it + # to the cache, the size on disk may differ. It can act as an + # approximate guide for when to do a proper size calculation. + # + # Returns: + # (int|None): The size of the artifact + # + def _get_artifact_size(self): + return self.__artifact_size + + def _get_artifact_cache(self): + return self.__artifacts + # _write_script(): # # Writes a script to the given directory. |