Phil Dawson pushed to branch phil/source-checkout-options at BuildStream / buildstream
Commits:
-
896bb460
by Phil Dawson at 2018-11-19T12:55:39Z
6 changed files:
- buildstream/_frontend/cli.py
- buildstream/_stream.py
- doc/source/using_commands.rst
- tests/completions/completions.py
- tests/frontend/help.py
- − tests/frontend/source_bundle.py
Changes:
... | ... | @@ -838,34 +838,3 @@ def workspace_list(app): |
838 | 838 |
|
839 | 839 |
with app.initialized():
|
840 | 840 |
app.stream.workspace_list()
|
841 |
- |
|
842 |
- |
|
843 |
-##################################################################
|
|
844 |
-# Source Bundle Command #
|
|
845 |
-##################################################################
|
|
846 |
-@cli.command(name="source-bundle", short_help="Produce a build bundle to be manually executed")
|
|
847 |
-@click.option('--except', 'except_', multiple=True,
|
|
848 |
- type=click.Path(readable=False),
|
|
849 |
- help="Elements to except from the tarball")
|
|
850 |
-@click.option('--compression', default='gz',
|
|
851 |
- type=click.Choice(['none', 'gz', 'bz2', 'xz']),
|
|
852 |
- help="Compress the tar file using the given algorithm.")
|
|
853 |
-@click.option('--track', 'track_', default=False, is_flag=True,
|
|
854 |
- help="Track new source references before bundling")
|
|
855 |
-@click.option('--force', '-f', default=False, is_flag=True,
|
|
856 |
- help="Overwrite an existing tarball")
|
|
857 |
-@click.option('--directory', default=os.getcwd(),
|
|
858 |
- help="The directory to write the tarball to")
|
|
859 |
-@click.argument('element',
|
|
860 |
- type=click.Path(readable=False))
|
|
861 |
-@click.pass_obj
|
|
862 |
-def source_bundle(app, element, force, directory,
|
|
863 |
- track_, compression, except_):
|
|
864 |
- """Produce a source bundle to be manually executed
|
|
865 |
- """
|
|
866 |
- with app.initialized():
|
|
867 |
- app.stream.source_bundle(element, directory,
|
|
868 |
- track_first=track_,
|
|
869 |
- force=force,
|
|
870 |
- compression=compression,
|
|
871 |
- except_targets=except_)
|
... | ... | @@ -670,87 +670,6 @@ class Stream(): |
670 | 670 |
'workspaces': workspaces
|
671 | 671 |
})
|
672 | 672 |
|
673 |
- # source_bundle()
|
|
674 |
- #
|
|
675 |
- # Create a host buildable tarball bundle for the given target.
|
|
676 |
- #
|
|
677 |
- # Args:
|
|
678 |
- # target (str): The target element to bundle
|
|
679 |
- # directory (str): The directory to output the tarball
|
|
680 |
- # track_first (bool): Track new source references before bundling
|
|
681 |
- # compression (str): The compression type to use
|
|
682 |
- # force (bool): Overwrite an existing tarball
|
|
683 |
- #
|
|
684 |
- def source_bundle(self, target, directory, *,
|
|
685 |
- track_first=False,
|
|
686 |
- force=False,
|
|
687 |
- compression="gz",
|
|
688 |
- except_targets=()):
|
|
689 |
- |
|
690 |
- if track_first:
|
|
691 |
- track_targets = (target,)
|
|
692 |
- else:
|
|
693 |
- track_targets = ()
|
|
694 |
- |
|
695 |
- elements, track_elements = self._load((target,), track_targets,
|
|
696 |
- selection=PipelineSelection.ALL,
|
|
697 |
- except_targets=except_targets,
|
|
698 |
- track_selection=PipelineSelection.ALL,
|
|
699 |
- fetch_subprojects=True)
|
|
700 |
- |
|
701 |
- # source-bundle only supports one target
|
|
702 |
- target = self.targets[0]
|
|
703 |
- |
|
704 |
- self._message(MessageType.INFO, "Bundling sources for target {}".format(target.name))
|
|
705 |
- |
|
706 |
- # Find the correct filename for the compression algorithm
|
|
707 |
- tar_location = os.path.join(directory, target.normal_name + ".tar")
|
|
708 |
- if compression != "none":
|
|
709 |
- tar_location += "." + compression
|
|
710 |
- |
|
711 |
- # Attempt writing a file to generate a good error message
|
|
712 |
- # early
|
|
713 |
- #
|
|
714 |
- # FIXME: A bit hackish
|
|
715 |
- try:
|
|
716 |
- open(tar_location, mode="x")
|
|
717 |
- os.remove(tar_location)
|
|
718 |
- except IOError as e:
|
|
719 |
- raise StreamError("Cannot write to {0}: {1}"
|
|
720 |
- .format(tar_location, e)) from e
|
|
721 |
- |
|
722 |
- # Fetch and possibly track first
|
|
723 |
- #
|
|
724 |
- self._fetch(elements, track_elements=track_elements)
|
|
725 |
- |
|
726 |
- # We don't use the scheduler for this as it is almost entirely IO
|
|
727 |
- # bound.
|
|
728 |
- |
|
729 |
- # Create a temporary directory to build the source tree in
|
|
730 |
- builddir = self._context.builddir
|
|
731 |
- os.makedirs(builddir, exist_ok=True)
|
|
732 |
- prefix = "{}-".format(target.normal_name)
|
|
733 |
- |
|
734 |
- with TemporaryDirectory(prefix=prefix, dir=builddir) as tempdir:
|
|
735 |
- source_directory = os.path.join(tempdir, 'source')
|
|
736 |
- try:
|
|
737 |
- os.makedirs(source_directory)
|
|
738 |
- except OSError as e:
|
|
739 |
- raise StreamError("Failed to create directory: {}"
|
|
740 |
- .format(e)) from e
|
|
741 |
- |
|
742 |
- # Any elements that don't implement _write_script
|
|
743 |
- # should not be included in the later stages.
|
|
744 |
- elements = [
|
|
745 |
- element for element in elements
|
|
746 |
- if self._write_element_script(source_directory, element)
|
|
747 |
- ]
|
|
748 |
- |
|
749 |
- self._write_element_sources(os.path.join(tempdir, "source"), elements)
|
|
750 |
- self._write_master_build_script(tempdir, elements)
|
|
751 |
- self._collect_sources(tempdir, tar_location,
|
|
752 |
- target.normal_name, compression)
|
|
753 |
- |
|
754 | 673 |
# redirect_element_names()
|
755 | 674 |
#
|
756 | 675 |
# Takes a list of element names and returns a list where elements have been
|
... | ... | @@ -86,13 +86,6 @@ project's main directory. |
86 | 86 |
|
87 | 87 |
----
|
88 | 88 |
|
89 |
-.. _invoking_source_bundle:
|
|
90 |
- |
|
91 |
-.. click:: buildstream._frontend.cli:source_bundle
|
|
92 |
- :prog: bst source bundle
|
|
93 |
- |
|
94 |
-----
|
|
95 |
- |
|
96 | 89 |
.. _invoking_workspace:
|
97 | 90 |
|
98 | 91 |
.. click:: buildstream._frontend.cli:workspace
|
... | ... | @@ -16,7 +16,6 @@ MAIN_COMMANDS = [ |
16 | 16 |
'shell ',
|
17 | 17 |
'show ',
|
18 | 18 |
'source-checkout ',
|
19 |
- 'source-bundle ',
|
|
20 | 19 |
'track ',
|
21 | 20 |
'workspace '
|
22 | 21 |
]
|
... | ... | @@ -25,7 +25,6 @@ def test_help_main(cli): |
25 | 25 |
('push'),
|
26 | 26 |
('shell'),
|
27 | 27 |
('show'),
|
28 |
- ('source-bundle'),
|
|
29 | 28 |
('track'),
|
30 | 29 |
('workspace')
|
31 | 30 |
])
|
1 |
-#
|
|
2 |
-# Copyright (C) 2018 Bloomberg Finance LP
|
|
3 |
-#
|
|
4 |
-# This program is free software; you can redistribute it and/or
|
|
5 |
-# modify it under the terms of the GNU Lesser General Public
|
|
6 |
-# License as published by the Free Software Foundation; either
|
|
7 |
-# version 2 of the License, or (at your option) any later version.
|
|
8 |
-#
|
|
9 |
-# This library is distributed in the hope that it will be useful,
|
|
10 |
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12 |
-# Lesser General Public License for more details.
|
|
13 |
-#
|
|
14 |
-# You should have received a copy of the GNU Lesser General Public
|
|
15 |
-# License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
16 |
-#
|
|
17 |
-# Authors: Chandan Singh <csingh43 bloomberg net>
|
|
18 |
-#
|
|
19 |
- |
|
20 |
-import os
|
|
21 |
-import tarfile
|
|
22 |
- |
|
23 |
-import pytest
|
|
24 |
- |
|
25 |
-from tests.testutils import cli
|
|
26 |
- |
|
27 |
-# Project directory
|
|
28 |
-DATA_DIR = os.path.join(
|
|
29 |
- os.path.dirname(os.path.realpath(__file__)),
|
|
30 |
- "project",
|
|
31 |
-)
|
|
32 |
- |
|
33 |
- |
|
34 |
-@pytest.mark.datafiles(DATA_DIR)
|
|
35 |
-def test_source_bundle(cli, tmpdir, datafiles):
|
|
36 |
- project_path = os.path.join(datafiles.dirname, datafiles.basename)
|
|
37 |
- element_name = 'source-bundle/source-bundle-hello.bst'
|
|
38 |
- normal_name = 'source-bundle-source-bundle-hello'
|
|
39 |
- |
|
40 |
- # Verify that we can correctly produce a source-bundle
|
|
41 |
- args = ['source-bundle', element_name, '--directory', str(tmpdir)]
|
|
42 |
- result = cli.run(project=project_path, args=args)
|
|
43 |
- result.assert_success()
|
|
44 |
- |
|
45 |
- # Verify that the source-bundle contains our sources and a build script
|
|
46 |
- with tarfile.open(os.path.join(str(tmpdir), '{}.tar.gz'.format(normal_name))) as bundle:
|
|
47 |
- assert os.path.join(normal_name, 'source', normal_name, 'llamas.txt') in bundle.getnames()
|
|
48 |
- assert os.path.join(normal_name, 'build.sh') in bundle.getnames()
|