summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Pollard <tom.pollard@codethink.co.uk>2019-02-08 10:44:29 +0000
committerTom Pollard <tom.pollard@codethink.co.uk>2019-02-13 13:37:32 +0000
commit118644b22b01a7849a9f8e8e9637e817ed8c443d (patch)
tree30628eedcf5b43d109f2779b8863b3b991415bd7
parentae0ee361350b13a6c0f2fb24d3a24579305a021b (diff)
downloadbuildstream-118644b22b01a7849a9f8e8e9637e817ed8c443d.tar.gz
Add cli main & user conf option for 'cache-buildtrees' context
_context.py: Add cache_buildtrees global user context, the default of which is set to by default to 'always' via the addition of cache-buildtrees to userconfig.yaml cache group. 'failure' & 'never' can be given as valid options. app.py & cli.py: Add --cache-buildtrees as a bst main option, which when passed with a valid option can override the default or user defined context for cache_buildtrees. tests/completions/completions.py: Update for the added flag.
-rw-r--r--buildstream/_context.py9
-rw-r--r--buildstream/_frontend/app.py3
-rw-r--r--buildstream/_frontend/cli.py3
-rw-r--r--buildstream/data/userconfig.yaml9
-rw-r--r--tests/frontend/completions.py2
5 files changed, 24 insertions, 2 deletions
diff --git a/buildstream/_context.py b/buildstream/_context.py
index 9c53e7d75..6fe7c3f52 100644
--- a/buildstream/_context.py
+++ b/buildstream/_context.py
@@ -121,6 +121,9 @@ class Context():
# Whether or not to attempt to pull build trees globally
self.pull_buildtrees = None
+ # Whether or not to cache build trees on artifact creation
+ self.cache_buildtrees = None
+
# Boolean, whether we double-check with the user that they meant to
# close the workspace when they're using it to access the project.
self.prompt_workspace_close_project_inaccessible = None
@@ -201,7 +204,7 @@ class Context():
# our artifactdir - the artifactdir may not have been created
# yet.
cache = _yaml.node_get(defaults, Mapping, 'cache')
- _yaml.node_validate(cache, ['quota', 'pull-buildtrees'])
+ _yaml.node_validate(cache, ['quota', 'pull-buildtrees', 'cache-buildtrees'])
self.config_cache_quota = _yaml.node_get(cache, str, 'quota')
@@ -213,6 +216,10 @@ class Context():
# Load pull build trees configuration
self.pull_buildtrees = _yaml.node_get(cache, bool, 'pull-buildtrees')
+ # Load cache build trees configuration
+ self.cache_buildtrees = _node_get_option_str(
+ cache, 'cache-buildtrees', ['always', 'failure', 'never'])
+
# Load logging config
logging = _yaml.node_get(defaults, Mapping, 'logging')
_yaml.node_validate(logging, [
diff --git a/buildstream/_frontend/app.py b/buildstream/_frontend/app.py
index b6da079bd..329f9a2c6 100644
--- a/buildstream/_frontend/app.py
+++ b/buildstream/_frontend/app.py
@@ -183,7 +183,8 @@ class App():
'builders': 'sched_builders',
'pushers': 'sched_pushers',
'network_retries': 'sched_network_retries',
- 'pull_buildtrees': 'pull_buildtrees'
+ 'pull_buildtrees': 'pull_buildtrees',
+ 'cache_buildtrees': 'cache_buildtrees'
}
for cli_option, context_attr in override_map.items():
option_value = self._main_options.get(cli_option)
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index e3c5059b9..c4dd91c75 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -251,6 +251,9 @@ def print_version(ctx, param, value):
help="The mirror to fetch from first, before attempting other mirrors")
@click.option('--pull-buildtrees', is_flag=True, default=None,
help="Include an element's build tree when pulling remote element artifacts")
+@click.option('--cache-buildtrees', default=None,
+ type=click.Choice(['always', 'failure', 'never']),
+ help="Cache artifact build tree content on creation")
@click.pass_context
def cli(context, **kwargs):
"""Build and manipulate BuildStream projects
diff --git a/buildstream/data/userconfig.yaml b/buildstream/data/userconfig.yaml
index 0834b93f6..0b4535cea 100644
--- a/buildstream/data/userconfig.yaml
+++ b/buildstream/data/userconfig.yaml
@@ -41,6 +41,15 @@ cache:
# Whether to pull build trees when downloading element artifacts
pull-buildtrees: False
+ # Whether to cache build trees on artifact creation:
+ #
+ # always - Always cache artifact build tree content
+ # failure - Only cache build trees of failed builds
+ # never - Don't cache artifact build tree content
+ #
+ cache-buildtrees: always
+
+
#
# Scheduler
#
diff --git a/tests/frontend/completions.py b/tests/frontend/completions.py
index cb151c284..c374df2a0 100644
--- a/tests/frontend/completions.py
+++ b/tests/frontend/completions.py
@@ -23,6 +23,7 @@ MAIN_OPTIONS = [
"--builders ",
"-c ",
"-C ",
+ "--cache-buildtrees ",
"--colors ",
"--config ",
"--debug ",
@@ -156,6 +157,7 @@ def test_options(cli, cmd, word_idx, expected):
@pytest.mark.parametrize("cmd,word_idx,expected", [
('bst --on-error ', 2, ['continue ', 'quit ', 'terminate ']),
+ ('bst --cache-buildtrees ', 2, ['always ', 'failure ', 'never ']),
('bst show --deps ', 3, ['all ', 'build ', 'none ', 'plan ', 'run ']),
('bst show --deps=', 2, ['all ', 'build ', 'none ', 'plan ', 'run ']),
('bst show --deps b', 3, ['build ']),