summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhillip Smyth <phillip.smyth@codethink.co.uk>2018-03-20 15:29:23 +0000
committerPhillip Smyth <phillipsmyth@Nexus-x240.dyn.ducie.codethink.co.uk>2018-05-10 11:10:28 +0100
commit3bb30be2866718f909be0f914731574e7ff4c5b3 (patch)
treed8e93c8cf9d5a007c16790707ce36888585cb936
parent32c307664bfd576723c5d977a09d57ec3b9cd369 (diff)
downloadbuildstream-3bb30be2866718f909be0f914731574e7ff4c5b3.tar.gz
Introducing caching of build trees
`cache-build-tree` var has been added to the project.conf defaults (defaulting to False) When cache-build-tree is set to True, the contents of the sandbox build directory is copied to the cache The cache key dict has been updated to reflect the status of `cache-build-tree`
-rw-r--r--buildstream/_frontend/cli.py5
-rw-r--r--buildstream/_project.py3
-rw-r--r--buildstream/data/projectconfig.yaml3
-rw-r--r--buildstream/element.py20
4 files changed, 28 insertions, 3 deletions
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index 41736ac2f..6c9adb7e6 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -655,10 +655,13 @@ def workspace_close(app, remove_dir, all_, elements):
help="Track and fetch the latest source before resetting")
@click.option('--all', '-a', 'all_', default=False, is_flag=True,
help="Reset all open workspaces")
+@click.option('--no-cache', 'no_cache', default=False, is_flag=True,
+ help="Use Cached build tree if available")
@click.argument('elements', nargs=-1,
type=click.Path(dir_okay=False, readable=True))
@click.pass_obj
-def workspace_reset(app, track_, all_, elements):
+def workspace_reset(app, track_, all_, element, no_cache):
+ type=click.Path(dir_okay=False, readable=True))
"""Reset a workspace to its original state"""
# Check that the workspaces in question exist
diff --git a/buildstream/_project.py b/buildstream/_project.py
index 12074ab3a..fec39eef9 100644
--- a/buildstream/_project.py
+++ b/buildstream/_project.py
@@ -249,7 +249,8 @@ class Project():
'aliases', 'name',
'artifacts', 'options',
'fail-on-overlap', 'shell',
- 'ref-storage', 'sandbox'
+ 'ref-storage', 'sandbox',
+ 'cache-build-tree'
])
# The project name, element path and option declarations
diff --git a/buildstream/data/projectconfig.yaml b/buildstream/data/projectconfig.yaml
index b4ad2dcb9..f512f1dee 100644
--- a/buildstream/data/projectconfig.yaml
+++ b/buildstream/data/projectconfig.yaml
@@ -33,6 +33,9 @@ variables:
element-name: ""
project-name: ""
+ # Whether or not to cache build trees
+ cache-build-tree: True
+
# Path configuration, to be used in build instructions.
#
prefix: "/usr"
diff --git a/buildstream/element.py b/buildstream/element.py
index c563b79af..64a3f7949 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -928,6 +928,17 @@ class Element(Plugin):
def _get_redundant_source_refs(cls):
return cls.__redundant_source_refs
+ # _build_tree_path():
+ #
+ # Returns the path of the cached build tree if it exists
+ #
+ def _build_tree_path(self):
+ build_tree_path = os.path.join(self.__extract()[0], 'buildtree')
+ if os.path.isdir(build_tree_path):
+ return build_tree_path
+ else:
+ return None
+
# _reset_load_state()
#
# This is called by Pipeline.cleanup() and is used to
@@ -1479,6 +1490,12 @@ class Element(Plugin):
# Hard link files from collect dir to files directory
utils.link_files(collectdir, filesdir)
+ # Copy build tree contents
+ if self.get_variable('cache-build-tree'):
+ sandbox_build_dir = os.path.join(sandbox_root, self.get_variable('build-root'))
+ if os.path.isdir(sandbox_build_dir):
+ shutil.copytree(sandbox_build_dir, os.path.join(assembledir, 'buildtree'))
+
# Copy build log
if self.__log_path:
shutil.copyfile(self.__log_path, os.path.join(logsdir, 'build.log'))
@@ -1905,7 +1922,8 @@ class Element(Plugin):
'sources': [s._get_unique_key(workspace is None) for s in self.__sources],
'workspace': '' if workspace is None else workspace.get_key(),
'public': self.__public,
- 'cache': type(self.__artifacts).__name__
+ 'cache': type(self.__artifacts).__name__,
+ 'cache-build-tree': self.get_variable('cache-build-tree')
}
cache_key_dict = self.__cache_key_dict.copy()