summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/buildstream/_frontend/cli.py8
-rw-r--r--src/buildstream/_stream.py22
2 files changed, 24 insertions, 6 deletions
diff --git a/src/buildstream/_frontend/cli.py b/src/buildstream/_frontend/cli.py
index 2301fcb78..b353ced93 100644
--- a/src/buildstream/_frontend/cli.py
+++ b/src/buildstream/_frontend/cli.py
@@ -950,13 +950,16 @@ def artifact():
help="Create a tarball from the artifact contents instead "
"of a file tree. If LOCATION is '-', the tarball "
"will be dumped to the standard output.")
+@click.option('--pull', 'pull_', default=False, is_flag=True,
+ help="Whether to pull the artifact if it's missing or "
+ "incomplete.")
@click.option('--directory', default=None,
type=click.Path(file_okay=False),
help="The directory to checkout the artifact to")
@click.argument('element', required=False,
type=click.Path(readable=False))
@click.pass_obj
-def artifact_checkout(app, force, deps, integrate, hardlinks, tar, directory, element):
+def artifact_checkout(app, force, deps, integrate, hardlinks, tar, pull_, directory, element):
"""Checkout contents of an artifact
When this command is executed from a workspace directory, the default
@@ -1002,7 +1005,8 @@ def artifact_checkout(app, force, deps, integrate, hardlinks, tar, directory, el
scope=scope,
integrate=True if integrate is None else integrate,
hardlinks=hardlinks,
- tar=tar)
+ tar=tar,
+ pull=pull_)
################################################################
diff --git a/src/buildstream/_stream.py b/src/buildstream/_stream.py
index 0606c906a..6f6d30f17 100644
--- a/src/buildstream/_stream.py
+++ b/src/buildstream/_stream.py
@@ -474,6 +474,8 @@ class Stream():
# will be placed at the given location. If true and
# location is '-', the tarball will be dumped on the
# standard output.
+ # pull (bool): If true will attempt to pull any missing or incomplete
+ # artifacts.
#
def checkout(self, target, *,
location=None,
@@ -481,14 +483,26 @@ class Stream():
scope=Scope.RUN,
integrate=True,
hardlinks=False,
- tar=False):
+ tar=False,
+ pull=False):
- # We only have one target in a checkout command
- elements, _ = self._load((target,), (), fetch_subprojects=True)
- target = elements[0]
+ # if pulling we need to ensure dependency artifacts are also pulled
+ selection = PipelineSelection.RUN if pull else PipelineSelection.NONE
+ elements, _ = self._load(
+ (target,), (), selection=selection,
+ fetch_subprojects=True, use_artifact_config=True)
+
+ target = elements[-1]
self._check_location_writable(location, force=force, tar=tar)
+ uncached_elts = [elt for elt in elements if not elt._cached()]
+ if uncached_elts and pull:
+ self._message(MessageType.INFO, "Attempting to fetch missing or incomplete artifact")
+ self._add_queue(PullQueue(self._scheduler))
+ self._enqueue_plan(uncached_elts)
+ self._run()
+
# Stage deps into a temporary sandbox first
try:
with target._prepare_sandbox(scope=scope, directory=None,