summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2018-12-12 18:32:39 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2019-01-03 18:57:06 +0000
commit987d5fc2a831c525f46e53ea0fd5639eadfd1f53 (patch)
tree20795532a6dc2cc55ed7050f1ad5c29411ce644b
parent43242b56fffc2789da269caac782adedf5b1cb5e (diff)
downloadbuildstream-987d5fc2a831c525f46e53ea0fd5639eadfd1f53.tar.gz
cli: Add artifact checkout subcommand
This implements a superset of the features of `bst checkout`, but uses a --directory option rather than a location argument, and --tar takes a location instead of being a flag. If multiple element targets or any artifact refs are passed then it does not support creating a tarball, running integration commands or including dependencies of the targets.
-rw-r--r--buildstream/_frontend/cli.py81
1 files changed, 81 insertions, 0 deletions
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index ee4a91203..8ac2078d1 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -1079,6 +1079,87 @@ def artifact_log(app, artifacts):
click.echo_via_pager(data)
+#####################################################################
+# Artifact Checkout Command #
+#####################################################################
+@artifact.command(name='checkout', short_help="Checkout contents of an artifact")
+@click.option('--force', '-f', default=False, is_flag=True,
+ help="Allow files to be overwritten")
+@click.option('--deps', '-d', default=None,
+ type=click.Choice(['run', 'build', 'none']),
+ help='The dependencies to checkout (default: run)')
+@click.option('--integrate/--no-integrate', default=None, is_flag=True,
+ help="Whether to run integration commands")
+@click.option('--hardlinks', default=False, is_flag=True,
+ help="Checkout hardlinks instead of copying if possible")
+@click.option('--tar', default=None, metavar='LOCATION',
+ type=click.Path(),
+ 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('--directory', default=None,
+ type=click.Path(file_okay=False),
+ help="The directory to write the tarball to")
+@click.argument('artifacts', type=click.Path(), nargs=-1)
+@click.pass_obj
+def artifact_checkout(app, force, deps, integrate, hardlinks, tar, directory, artifacts):
+ """Checkout contents of an artifact"""
+ from ..element import Scope
+
+ if hardlinks and tar is not None:
+ click.echo("ERROR: options --hardlinks and --tar conflict", err=True)
+ sys.exit(-1)
+
+ if tar is None and directory is None:
+ click.echo("ERROR: One of --directory or --tar must be provided", err=True)
+ sys.exit(-1)
+
+ if tar is not None and directory is not None:
+ click.echo("ERROR: options --directory and --tar conflict", err=True)
+ sys.exit(-1)
+
+ if tar is not None:
+ location = tar
+ tar = True
+ else:
+ location = os.getcwd() if directory is None else directory
+ tar = False
+
+ with app.initialized():
+ cache = app.context.artifactcache
+
+ elements, artifacts = _classify_artifacts(artifacts, cache.cas,
+ app.project.directory)
+
+ if not elements and not artifacts:
+ element = app.context.guess_element()
+ if element is not None:
+ elements = [element]
+
+ if (artifacts or len(elements) > 1) and (integrate is not None or deps is not None or tar):
+ raise AppError("--integrate, --deps and --tar may not be used with artifact refs or multiple elements")
+
+ if elements and not artifacts and len(elements) == 1:
+ if deps == "build":
+ scope = Scope.BUILD
+ elif deps == "none":
+ scope = Scope.NONE
+ else:
+ scope = Scope.RUN
+ app.stream.checkout(elements[0],
+ location=location,
+ force=force,
+ scope=scope,
+ integrate=True if integrate is None else integrate,
+ hardlinks=hardlinks,
+ tar=tar)
+ return
+
+ for vdir in _load_vdirs(app, elements, artifacts):
+ vdir = vdir.descend(["files"])
+ vdir.export_files(directory, can_link=hardlinks, can_destroy=force)
+
+
##################################################################
# DEPRECATED Commands #
##################################################################