summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhillip Smyth <phillipsmyth@Nexus-x240.dyn.ducie.codethink.co.uk>2018-05-15 10:51:54 +0100
committerPhillip Smyth <phillipsmyth@Nexus-x240.dyn.ducie.codethink.co.uk>2018-05-15 10:51:54 +0100
commit575d11a7b9ab2052f49a4db4e1f590325b586fb7 (patch)
tree321cac323bbbc03ba0fe2229131a4b81036fb105
parent8ea9a3f29a5326647086a845ffff6621478d4119 (diff)
downloadbuildstream-issue-21_Caching_build_trees.tar.gz
-rw-r--r--buildstream/_frontend/app.py26
-rw-r--r--buildstream/_frontend/cli.py35
2 files changed, 34 insertions, 27 deletions
diff --git a/buildstream/_frontend/app.py b/buildstream/_frontend/app.py
index 05be5f75a..1b91ee02c 100644
--- a/buildstream/_frontend/app.py
+++ b/buildstream/_frontend/app.py
@@ -387,7 +387,21 @@ class App():
# track_first (bool): Whether to track and fetch first
# force (bool): Whether to ignore contents in an existing directory
#
- def open_workspace(self, target, directory, no_checkout, track_first, force, no_cache=False):
+ def open_workspace(self, target, directory, no_checkout, track_first, force, cached_build_tree):
+
+ # If there is a remote cache, and the default value of cached_build_tree is used (flag not declared)
+ # Set default to False (Don't want to pull from server by default)
+
+ # Potentially have the default be `None` and check:
+
+ if cached_build_tree is 'use-cached' or 'auto':
+ if remote_cache_exists():
+ cached_build_tree = False
+ else:
+ cached_build_tree = True
+ else cached_build_tree is 'ignore-cached':
+ cached_build_tree = False:
+
workdir = os.path.abspath(directory)
@@ -395,15 +409,15 @@ class App():
with target.timed_activity("Extracting cached build tree"):
build_tree_path = target._build_tree_path(target._get_cache_key())
if build_tree_path is None:
- no_cache = True
+ cached_build_tree = False
else:
- no_cache = True
+ cached_build_tree = False
# Check for workspace config
if self.project.workspaces.get_workspace(target):
raise AppError("Workspace '{}' is already defined.".format(target.name))
- if no_cache:
+ if not cached_build_tree:
if not list(target.sources()):
build_depends = [x.name for x in target.dependencies(Scope.BUILD, recurse=False)]
if not build_depends:
@@ -483,7 +497,7 @@ class App():
# target (Element): The element to reset the workspace for
# track (bool): Whether to also track the source
#
- def reset_workspace(self, target, track, no_cache):
+ def reset_workspace(self, target, track, cached_build_tree):
workspace = self.project.workspaces.get_workspace(target.name)
if workspace is None:
@@ -491,7 +505,7 @@ class App():
.format(target.name))
self.close_workspace(target.name, True)
- self.open_workspace(target, workspace.path, False, track, False, no_cache)
+ self.open_workspace(target, workspace.path, False, track, False, cached_build_tree)
############################################################
# Local Functions #
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index 0990cd6a8..2cd5c7c54 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -216,9 +216,9 @@ def init(app, project_name, format_version, element_path, force):
help="Except certain dependencies from tracking")
@click.option('--track-cross-junctions', '-J', default=False, is_flag=True,
help="Allow tracking to cross junction boundaries")
-@click.option('--cached-build-tree', default='False',
- type=click.Choice(['True', 'False']),
- help="Toggle the download of the cached build tree")
+@click.option('--cached-build-tree', 'cached_build_tree', default='auto',
+ type=click.Choice(['use-cached', 'ignore-cached', 'auto']),
+ help="Use Cached build tree if available")
@click.option('--track-save', default=False, is_flag=True,
help="Deprecated: This is ignored")
@click.argument('elements', nargs=-1,
@@ -238,7 +238,6 @@ def build(app, elements, all_, track_, track_save, track_all, track_except, trac
if track_all:
track_ = elements
- with app.initialized(session_name="Build"):
app.stream.build(elements,
track_targets=track_,
track_except=track_except,
@@ -342,9 +341,9 @@ def track(app, elements, deps, except_, cross_junctions):
help='The dependency artifacts to pull (default: none)')
@click.option('--remote', '-r',
help="The URL of the remote cache (defaults to the first configured cache)")
-@click.option('--cached-build-tree', default='False',
- type=click.Choice(['True', 'False']),
- help="Toggle the download of the cached build tree")
+@click.option('--cached-build-tree', 'cached_build_tree', default='auto',
+ type=click.Choice(['use-cached', 'ignore-cached', 'auto']),
+ help="Use Cached build tree if available")
@click.argument('elements', nargs=-1,
type=click.Path(dir_okay=False, readable=True))
@click.pass_obj
@@ -586,14 +585,14 @@ def workspace():
help="Overwrite files existing in checkout directory")
@click.option('--track', 'track_', default=False, is_flag=True,
help="Track and fetch new source references before checking out the workspace")
-@click.option('--no-cache', 'no_cache', default='False',
- type=click.Choice(['True', 'False']),
+@click.option('--cached-build-tree', 'cached_build_tree', default='auto',
+ type=click.Choice(['use-cached', 'ignore-cached', 'auto']),
help="Use Cached build tree if available")
@click.argument('element',
type=click.Path(dir_okay=False, readable=True))
@click.argument('directory', type=click.Path(file_okay=False))
@click.pass_obj
-def workspace_open(app, no_checkout, force, track_, no_cache, element, directory):
+def workspace_open(app, no_checkout, force, track_, cached_build_tree, element, directory):
"""Open a workspace for manual source modification"""
if os.path.exists(directory):
@@ -611,7 +610,7 @@ def workspace_open(app, no_checkout, force, track_, no_cache, element, directory
no_checkout=no_checkout,
track_first=track_,
force=force,
- no_cache)
+ cached_build_tree)
##################################################################
@@ -666,13 +665,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',
- type=click.Choice(['True', 'False']),
+@click.option('--cached-build-tree', 'cached_build_tree', default='auto',
+ type=click.Choice(['use-cached', 'ignore-cached', 'auto']),
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, no_cache):
+def workspace_reset(app, track_, all_, elements, cached_build_tree):
"""Reset a workspace to its original state"""
# Check that the workspaces in question exist
@@ -699,13 +698,7 @@ def workspace_reset(app, track_, all_, elements, no_cache):
if all_:
elements = tuple(element_name for element_name, _ in app.project.workspaces.list())
-<<<<<<< HEAD
- app.stream.workspace_reset(elements, track_first=track_, no_cache)
-=======
- with app.initialized(elements):
- for target in app.pipeline.targets:
- app.reset_workspace(target, track_, no_cache)
->>>>>>> Original commit required additional functionality to test
+ app.stream.workspace_reset(elements, track_first=track_, cached_build_tree)
##################################################################