diff options
author | Jürg Billeter <j@bitron.ch> | 2020-07-01 16:34:45 +0200 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2020-07-06 09:39:13 +0200 |
commit | 8745864ceea5da0ee984cce89791f452c0dadcbc (patch) | |
tree | 23b150a719e5e4c42584d4dda383eaa572e4c7a8 | |
parent | 7c03094ad35d89f59a750a8be7c13e6c592e306d (diff) | |
download | buildstream-8745864ceea5da0ee984cce89791f452c0dadcbc.tar.gz |
Add `bst source push` command
-rw-r--r-- | doc/source/using_commands.rst | 7 | ||||
-rw-r--r-- | src/buildstream/_frontend/cli.py | 52 | ||||
-rw-r--r-- | src/buildstream/_stream.py | 42 | ||||
-rw-r--r-- | tests/frontend/completions.py | 1 |
4 files changed, 102 insertions, 0 deletions
diff --git a/doc/source/using_commands.rst b/doc/source/using_commands.rst index 276a17ce6..27fe692d3 100644 --- a/doc/source/using_commands.rst +++ b/doc/source/using_commands.rst @@ -144,6 +144,13 @@ Source subcommands ---- +.. _invoking_source_push: + +.. click:: buildstream._frontend.cli:source_push + :prog: bst source push + +---- + .. _invoking_source_checkout: .. click:: buildstream._frontend.cli:source_checkout diff --git a/src/buildstream/_frontend/cli.py b/src/buildstream/_frontend/cli.py index d5fa47091..0adfdd84a 100644 --- a/src/buildstream/_frontend/cli.py +++ b/src/buildstream/_frontend/cli.py @@ -820,6 +820,58 @@ def source_fetch(app, elements, deps, except_, remote): ################################################################## +# Source Push Command # +################################################################## +@source.command(name="push", short_help="Push sources in a pipeline") +@click.option( + "--deps", + "-d", + default=_PipelineSelection.NONE, + show_default=True, + type=FastEnumType( + _PipelineSelection, + [ + _PipelineSelection.NONE, + _PipelineSelection.PLAN, + _PipelineSelection.BUILD, + _PipelineSelection.RUN, + _PipelineSelection.ALL, + ], + ), + help="The dependencies to push", +) +@click.option( + "--remote", "-r", default=None, help="The URL of the remote source cache (defaults to the first configured cache)" +) +@click.argument("elements", nargs=-1, type=click.Path(readable=False)) +@click.pass_obj +def source_push(app, elements, deps, remote): + """Push sources required to build the pipeline + + Specifying no elements will result in pushing the sources of the default + targets of the project. If no default targets are configured, sources of + all project elements will be pushed. + + When this command is executed from a workspace directory, the default + is to push the sources of the workspace element. + + Specify `--deps` to control which sources to fetch: + + \b + none: No dependencies, just the element itself + plan: Only dependencies required for the build plan + run: Runtime dependencies, including the element itself + build: Build time dependencies, excluding the element itself + all: All dependencies + """ + with app.initialized(session_name="Push"): + if not elements: + elements = app.project.get_default_targets() + + app.stream.source_push(elements, selection=deps, remote=remote) + + +################################################################## # Source Track Command # ################################################################## @source.command(name="track", short_help="Track new source references") diff --git a/src/buildstream/_stream.py b/src/buildstream/_stream.py index 3d646a756..989a00db7 100644 --- a/src/buildstream/_stream.py +++ b/src/buildstream/_stream.py @@ -376,6 +376,48 @@ class Stream: self._enqueue_plan(elements, queue=track_queue) self._run() + # source_push() + # + # Push sources. + # + # Args: + # targets (list of str): Targets to push + # selection (_PipelineSelection): The selection mode for the specified targets + # remote (str): The URL of a specific remote server to push to, or None + # + # If `remote` specified as None, then regular configuration will be used + # to determine where to push sources to. + # + # If any of the given targets are missing their expected sources, + # a fetch queue will be created if user context and available remotes allow for + # attempting to fetch them. + # + def source_push(self, targets, *, selection=_PipelineSelection.NONE, remote=None): + + use_source_config = True + if remote: + use_source_config = False + + elements = self._load( + targets, + selection=selection, + use_source_config=use_source_config, + source_remote_url=remote, + load_refs=True, + ) + + if not self._sourcecache.has_push_remotes(): + raise StreamError("No source caches available for pushing sources") + + self._pipeline.assert_consistent(elements) + + self._add_queue(FetchQueue(self._scheduler, skip_cached=True)) + + self._add_queue(SourcePushQueue(self._scheduler)) + + self._enqueue_plan(elements) + self._run() + # pull() # # Pulls artifacts from remote artifact server(s) diff --git a/tests/frontend/completions.py b/tests/frontend/completions.py index a5e3c8ed3..952ed177b 100644 --- a/tests/frontend/completions.py +++ b/tests/frontend/completions.py @@ -44,6 +44,7 @@ MAIN_OPTIONS = [ SOURCE_COMMANDS = [ "checkout ", "fetch ", + "push ", "track ", ] |