You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by no...@apache.org on 2020/12/29 12:53:03 UTC

[buildstream] 06/13: cli: Add artifact checkout subcommand

This is an automated email from the ASF dual-hosted git repository.

not-in-ldap pushed a commit to branch richardmaw/artifact-subcommands
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 987d5fc2a831c525f46e53ea0fd5639eadfd1f53
Author: Richard Maw <ri...@codethink.co.uk>
AuthorDate: Wed Dec 12 18:32:39 2018 +0000

    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.
---
 buildstream/_frontend/cli.py | 81 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)

diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index ee4a912..8ac2078 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                       #
 ##################################################################