Phil Dawson pushed to branch phil/source-checkout-options at BuildStream / buildstream
Commits:
-
9a997fb2
by Phil Dawson at 2018-12-06T16:51:18Z
-
68b896ff
by Phil Dawson at 2018-12-06T16:51:18Z
-
4ba51180
by Phil Dawson at 2018-12-06T16:51:18Z
-
aed2037c
by Phil Dawson at 2018-12-06T16:51:18Z
-
0c4f3996
by Phil Dawson at 2018-12-06T16:51:18Z
-
59acce1c
by Phil Dawson at 2018-12-06T16:51:18Z
8 changed files:
- NEWS
- 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
- tests/frontend/source_checkout.py
Changes:
... | ... | @@ -2,6 +2,17 @@ |
2 | 2 |
buildstream 1.3.1
|
3 | 3 |
=================
|
4 | 4 |
|
5 |
+ o BREAKING CHANGE: The bst source-bundle command has been removed. The
|
|
6 |
+ functionality it provided has been replaced by the `--include-build-scripts`
|
|
7 |
+ option of the `bst source-checkout` command. To produce a tarball containing
|
|
8 |
+ an element's sources and generated build scripts you can do the command
|
|
9 |
+ `bst source-checkout --include-build-scripts --tar foo.bst some-file.tar`
|
|
10 |
+ |
|
11 |
+ o A `bst source-checkout` command has been added. This command allows an
|
|
12 |
+ element's sources to be checkout out into a user specified location. For
|
|
13 |
+ example, `bst source-checkout foo.bst some/path/` will collect the sources
|
|
14 |
+ of `foo.bst` and place them in the directory `some/path`.
|
|
15 |
+ |
|
5 | 16 |
o All elements must now be suffixed with `.bst`
|
6 | 17 |
Attempting to use an element that does not have the `.bst` extension,
|
7 | 18 |
will result in a warning.
|
... | ... | @@ -684,6 +684,8 @@ def checkout(app, element, location, force, deps, integrate, hardlinks, tar): |
684 | 684 |
# Source Checkout Command #
|
685 | 685 |
##################################################################
|
686 | 686 |
@cli.command(name='source-checkout', short_help='Checkout sources for an element')
|
687 |
+@click.option('--force', '-f', default=False, is_flag=True,
|
|
688 |
+ help="Allow files to be overwritten")
|
|
687 | 689 |
@click.option('--except', 'except_', multiple=True,
|
688 | 690 |
type=click.Path(readable=False),
|
689 | 691 |
help="Except certain dependencies")
|
... | ... | @@ -692,19 +694,26 @@ def checkout(app, element, location, force, deps, integrate, hardlinks, tar): |
692 | 694 |
help='The dependencies whose sources to checkout (default: none)')
|
693 | 695 |
@click.option('--fetch', 'fetch_', default=False, is_flag=True,
|
694 | 696 |
help='Fetch elements if they are not fetched')
|
695 |
-@click.argument('element',
|
|
696 |
- type=click.Path(readable=False))
|
|
697 |
+@click.option('--tar', 'tar', default=False, is_flag=True,
|
|
698 |
+ help='Create a tarball from the element\'s sources instead of a '
|
|
699 |
+ 'file tree.')
|
|
700 |
+@click.option('--include-build-scripts', 'build_scripts', is_flag=True)
|
|
701 |
+@click.argument('element', type=click.Path(readable=False))
|
|
697 | 702 |
@click.argument('location', type=click.Path())
|
698 | 703 |
@click.pass_obj
|
699 |
-def source_checkout(app, element, location, deps, fetch_, except_):
|
|
704 |
+def source_checkout(app, element, location, force, deps, fetch_, except_,
|
|
705 |
+ tar, build_scripts):
|
|
700 | 706 |
"""Checkout sources of an element to the specified location
|
701 | 707 |
"""
|
702 | 708 |
with app.initialized():
|
703 | 709 |
app.stream.source_checkout(element,
|
704 | 710 |
location=location,
|
711 |
+ force=force,
|
|
705 | 712 |
deps=deps,
|
706 | 713 |
fetch=fetch_,
|
707 |
- except_targets=except_)
|
|
714 |
+ except_targets=except_,
|
|
715 |
+ tar=tar,
|
|
716 |
+ include_build_scripts=build_scripts)
|
|
708 | 717 |
|
709 | 718 |
|
710 | 719 |
##################################################################
|
... | ... | @@ -835,34 +844,3 @@ def workspace_list(app): |
835 | 844 |
|
836 | 845 |
with app.initialized():
|
837 | 846 |
app.stream.workspace_list()
|
838 |
- |
|
839 |
- |
|
840 |
-##################################################################
|
|
841 |
-# Source Bundle Command #
|
|
842 |
-##################################################################
|
|
843 |
-@cli.command(name="source-bundle", short_help="Produce a build bundle to be manually executed")
|
|
844 |
-@click.option('--except', 'except_', multiple=True,
|
|
845 |
- type=click.Path(readable=False),
|
|
846 |
- help="Elements to except from the tarball")
|
|
847 |
-@click.option('--compression', default='gz',
|
|
848 |
- type=click.Choice(['none', 'gz', 'bz2', 'xz']),
|
|
849 |
- help="Compress the tar file using the given algorithm.")
|
|
850 |
-@click.option('--track', 'track_', default=False, is_flag=True,
|
|
851 |
- help="Track new source references before bundling")
|
|
852 |
-@click.option('--force', '-f', default=False, is_flag=True,
|
|
853 |
- help="Overwrite an existing tarball")
|
|
854 |
-@click.option('--directory', default=os.getcwd(),
|
|
855 |
- help="The directory to write the tarball to")
|
|
856 |
-@click.argument('element',
|
|
857 |
- type=click.Path(readable=False))
|
|
858 |
-@click.pass_obj
|
|
859 |
-def source_bundle(app, element, force, directory,
|
|
860 |
- track_, compression, except_):
|
|
861 |
- """Produce a source bundle to be manually executed
|
|
862 |
- """
|
|
863 |
- with app.initialized():
|
|
864 |
- app.stream.source_bundle(element, directory,
|
|
865 |
- track_first=track_,
|
|
866 |
- force=force,
|
|
867 |
- compression=compression,
|
|
868 |
- except_targets=except_)
|
... | ... | @@ -25,8 +25,8 @@ import stat |
25 | 25 |
import shlex
|
26 | 26 |
import shutil
|
27 | 27 |
import tarfile
|
28 |
-from contextlib import contextmanager
|
|
29 |
-from tempfile import TemporaryDirectory
|
|
28 |
+import tempfile
|
|
29 |
+from contextlib import contextmanager, suppress
|
|
30 | 30 |
|
31 | 31 |
from ._exceptions import StreamError, ImplError, BstError, set_last_task_error
|
32 | 32 |
from ._message import Message, MessageType
|
... | ... | @@ -449,11 +449,14 @@ class Stream(): |
449 | 449 |
#
|
450 | 450 |
def source_checkout(self, target, *,
|
451 | 451 |
location=None,
|
452 |
+ force=False,
|
|
452 | 453 |
deps='none',
|
453 | 454 |
fetch=False,
|
454 |
- except_targets=()):
|
|
455 |
+ except_targets=(),
|
|
456 |
+ tar=False,
|
|
457 |
+ include_build_scripts=False):
|
|
455 | 458 |
|
456 |
- self._check_location_writable(location)
|
|
459 |
+ self._check_location_writable(location, force=force, tar=tar)
|
|
457 | 460 |
|
458 | 461 |
elements, _ = self._load((target,), (),
|
459 | 462 |
selection=deps,
|
... | ... | @@ -467,7 +470,8 @@ class Stream(): |
467 | 470 |
|
468 | 471 |
# Stage all sources determined by scope
|
469 | 472 |
try:
|
470 |
- self._write_element_sources(location, elements)
|
|
473 |
+ self._source_checkout(elements, location, force, deps,
|
|
474 |
+ fetch, tar, include_build_scripts)
|
|
471 | 475 |
except BstError as e:
|
472 | 476 |
raise StreamError("Error while writing sources"
|
473 | 477 |
": '{}'".format(e), detail=e.detail, reason=e.reason) from e
|
... | ... | @@ -724,87 +728,6 @@ class Stream(): |
724 | 728 |
'workspaces': workspaces
|
725 | 729 |
})
|
726 | 730 |
|
727 |
- # source_bundle()
|
|
728 |
- #
|
|
729 |
- # Create a host buildable tarball bundle for the given target.
|
|
730 |
- #
|
|
731 |
- # Args:
|
|
732 |
- # target (str): The target element to bundle
|
|
733 |
- # directory (str): The directory to output the tarball
|
|
734 |
- # track_first (bool): Track new source references before bundling
|
|
735 |
- # compression (str): The compression type to use
|
|
736 |
- # force (bool): Overwrite an existing tarball
|
|
737 |
- #
|
|
738 |
- def source_bundle(self, target, directory, *,
|
|
739 |
- track_first=False,
|
|
740 |
- force=False,
|
|
741 |
- compression="gz",
|
|
742 |
- except_targets=()):
|
|
743 |
- |
|
744 |
- if track_first:
|
|
745 |
- track_targets = (target,)
|
|
746 |
- else:
|
|
747 |
- track_targets = ()
|
|
748 |
- |
|
749 |
- elements, track_elements = self._load((target,), track_targets,
|
|
750 |
- selection=PipelineSelection.ALL,
|
|
751 |
- except_targets=except_targets,
|
|
752 |
- track_selection=PipelineSelection.ALL,
|
|
753 |
- fetch_subprojects=True)
|
|
754 |
- |
|
755 |
- # source-bundle only supports one target
|
|
756 |
- target = self.targets[0]
|
|
757 |
- |
|
758 |
- self._message(MessageType.INFO, "Bundling sources for target {}".format(target.name))
|
|
759 |
- |
|
760 |
- # Find the correct filename for the compression algorithm
|
|
761 |
- tar_location = os.path.join(directory, target.normal_name + ".tar")
|
|
762 |
- if compression != "none":
|
|
763 |
- tar_location += "." + compression
|
|
764 |
- |
|
765 |
- # Attempt writing a file to generate a good error message
|
|
766 |
- # early
|
|
767 |
- #
|
|
768 |
- # FIXME: A bit hackish
|
|
769 |
- try:
|
|
770 |
- open(tar_location, mode="x")
|
|
771 |
- os.remove(tar_location)
|
|
772 |
- except IOError as e:
|
|
773 |
- raise StreamError("Cannot write to {0}: {1}"
|
|
774 |
- .format(tar_location, e)) from e
|
|
775 |
- |
|
776 |
- # Fetch and possibly track first
|
|
777 |
- #
|
|
778 |
- self._fetch(elements, track_elements=track_elements)
|
|
779 |
- |
|
780 |
- # We don't use the scheduler for this as it is almost entirely IO
|
|
781 |
- # bound.
|
|
782 |
- |
|
783 |
- # Create a temporary directory to build the source tree in
|
|
784 |
- builddir = self._context.builddir
|
|
785 |
- os.makedirs(builddir, exist_ok=True)
|
|
786 |
- prefix = "{}-".format(target.normal_name)
|
|
787 |
- |
|
788 |
- with TemporaryDirectory(prefix=prefix, dir=builddir) as tempdir:
|
|
789 |
- source_directory = os.path.join(tempdir, 'source')
|
|
790 |
- try:
|
|
791 |
- os.makedirs(source_directory)
|
|
792 |
- except OSError as e:
|
|
793 |
- raise StreamError("Failed to create directory: {}"
|
|
794 |
- .format(e)) from e
|
|
795 |
- |
|
796 |
- # Any elements that don't implement _write_script
|
|
797 |
- # should not be included in the later stages.
|
|
798 |
- elements = [
|
|
799 |
- element for element in elements
|
|
800 |
- if self._write_element_script(source_directory, element)
|
|
801 |
- ]
|
|
802 |
- |
|
803 |
- self._write_element_sources(os.path.join(tempdir, "source"), elements)
|
|
804 |
- self._write_build_script(tempdir, elements)
|
|
805 |
- self._collect_sources(tempdir, tar_location,
|
|
806 |
- target.normal_name, compression)
|
|
807 |
- |
|
808 | 731 |
# redirect_element_names()
|
809 | 732 |
#
|
810 | 733 |
# Takes a list of element names and returns a list where elements have been
|
... | ... | @@ -1185,6 +1108,54 @@ class Stream(): |
1185 | 1108 |
|
1186 | 1109 |
sandbox_vroot.export_files(directory, can_link=True, can_destroy=True)
|
1187 | 1110 |
|
1111 |
+ # Helper function for source_checkout()
|
|
1112 |
+ def _source_checkout(self, elements,
|
|
1113 |
+ location=None,
|
|
1114 |
+ force=False,
|
|
1115 |
+ deps='none',
|
|
1116 |
+ fetch=False,
|
|
1117 |
+ tar=False,
|
|
1118 |
+ include_build_scripts=False):
|
|
1119 |
+ location = os.path.abspath(location)
|
|
1120 |
+ location_parent = os.path.abspath(os.path.join(location, ".."))
|
|
1121 |
+ |
|
1122 |
+ # Stage all our sources in a temporary directory. The this
|
|
1123 |
+ # directory can be used to either construct a tarball or moved
|
|
1124 |
+ # to the final desired location.
|
|
1125 |
+ temp_source_dir = tempfile.TemporaryDirectory(dir=location_parent)
|
|
1126 |
+ self._write_element_sources(temp_source_dir.name, elements)
|
|
1127 |
+ if include_build_scripts:
|
|
1128 |
+ self._write_build_scripts(temp_source_dir.name, elements)
|
|
1129 |
+ try:
|
|
1130 |
+ if tar:
|
|
1131 |
+ self._create_tarball(temp_source_dir.name, location)
|
|
1132 |
+ else:
|
|
1133 |
+ self._move_directory(temp_source_dir.name, location, force)
|
|
1134 |
+ except OSError as e:
|
|
1135 |
+ raise StreamError("Failed to checkout sources to {}: {}"
|
|
1136 |
+ .format(location, e)) from e
|
|
1137 |
+ finally:
|
|
1138 |
+ with suppress(FileNotFoundError):
|
|
1139 |
+ temp_source_dir.cleanup()
|
|
1140 |
+ |
|
1141 |
+ # Move a directory src to dest. This will work across devices and
|
|
1142 |
+ # may optionaly overwrite existing files.
|
|
1143 |
+ def _move_directory(self, src, dest, force=False):
|
|
1144 |
+ def is_empty_dir(path):
|
|
1145 |
+ return os.path.isdir(dest) and not os.listdir(dest)
|
|
1146 |
+ |
|
1147 |
+ try:
|
|
1148 |
+ os.renames(src, dest)
|
|
1149 |
+ return
|
|
1150 |
+ except OSError:
|
|
1151 |
+ pass
|
|
1152 |
+ |
|
1153 |
+ if force or is_empty_dir(dest):
|
|
1154 |
+ try:
|
|
1155 |
+ utils.link_files(src, dest)
|
|
1156 |
+ except utils.UtilError as e:
|
|
1157 |
+ raise StreamError("Failed to move directory: {}".format(e)) from e
|
|
1158 |
+ |
|
1188 | 1159 |
# Write the element build script to the given directory
|
1189 | 1160 |
def _write_element_script(self, directory, element):
|
1190 | 1161 |
try:
|
... | ... | @@ -1201,8 +1172,28 @@ class Stream(): |
1201 | 1172 |
os.makedirs(element_source_dir)
|
1202 | 1173 |
element._stage_sources_at(element_source_dir)
|
1203 | 1174 |
|
1175 |
+ # Create a tarball from the content of directory
|
|
1176 |
+ def _create_tarball(self, directory, tar_name):
|
|
1177 |
+ try:
|
|
1178 |
+ with utils.save_file_atomic(tar_name, mode='wb') as f:
|
|
1179 |
+ # This TarFile does not need to be explicitly closed
|
|
1180 |
+ # as the underlying file object will be closed be the
|
|
1181 |
+ # save_file_atomic contect manager
|
|
1182 |
+ tarball = tarfile.open(fileobj=f, mode='w')
|
|
1183 |
+ for item in os.listdir(str(directory)):
|
|
1184 |
+ file_to_add = os.path.join(directory, item)
|
|
1185 |
+ tarball.add(file_to_add, arcname=item)
|
|
1186 |
+ except OSError as e:
|
|
1187 |
+ raise StreamError("Failed to create tar archive: {}".format(e)) from e
|
|
1188 |
+ |
|
1189 |
+ # Write all the build_scripts for elements in the directory location
|
|
1190 |
+ def _write_build_scripts(self, location, elements):
|
|
1191 |
+ for element in elements:
|
|
1192 |
+ self._write_element_script(location, element)
|
|
1193 |
+ self._write_master_build_script(location, elements)
|
|
1194 |
+ |
|
1204 | 1195 |
# Write a master build script to the sandbox
|
1205 |
- def _write_build_script(self, directory, elements):
|
|
1196 |
+ def _write_master_build_script(self, directory, elements):
|
|
1206 | 1197 |
|
1207 | 1198 |
module_string = ""
|
1208 | 1199 |
for element in elements:
|
... | ... | @@ -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()
|
1 | 1 |
import os
|
2 | 2 |
import pytest
|
3 |
+import tarfile
|
|
4 |
+from pathlib import Path
|
|
3 | 5 |
|
4 | 6 |
from tests.testutils import cli
|
5 | 7 |
|
... | ... | @@ -39,6 +41,39 @@ def test_source_checkout(datafiles, cli): |
39 | 41 |
assert os.path.exists(os.path.join(checkout, 'checkout-deps', 'etc', 'buildstream', 'config'))
|
40 | 42 |
|
41 | 43 |
|
44 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
45 |
+@pytest.mark.parametrize('force_flag', ['--force', '-f'])
|
|
46 |
+def test_source_checkout_force(datafiles, cli, force_flag):
|
|
47 |
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
48 |
+ checkout = os.path.join(cli.directory, 'source-checkout')
|
|
49 |
+ target = 'checkout-deps.bst'
|
|
50 |
+ |
|
51 |
+ os.makedirs(os.path.join(checkout, 'some-thing'))
|
|
52 |
+ # Path(os.path.join(checkout, 'some-file')).touch()
|
|
53 |
+ |
|
54 |
+ result = cli.run(project=project, args=['source-checkout', force_flag, target, '--deps', 'none', checkout])
|
|
55 |
+ result.assert_success()
|
|
56 |
+ |
|
57 |
+ assert os.path.exists(os.path.join(checkout, 'checkout-deps', 'etc', 'buildstream', 'config'))
|
|
58 |
+ |
|
59 |
+ |
|
60 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
61 |
+def test_source_checkout_tar(datafiles, cli):
|
|
62 |
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
63 |
+ checkout = os.path.join(cli.directory, 'source-checkout.tar')
|
|
64 |
+ target = 'checkout-deps.bst'
|
|
65 |
+ |
|
66 |
+ result = cli.run(project=project, args=['source-checkout', '--tar', target, '--deps', 'none', checkout])
|
|
67 |
+ result.assert_success()
|
|
68 |
+ |
|
69 |
+ assert os.path.exists(checkout)
|
|
70 |
+ with tarfile.open(checkout) as tf:
|
|
71 |
+ expected_content = os.path.join(checkout, 'checkout-deps', 'etc', 'buildstream', 'config')
|
|
72 |
+ tar_members = [f.name for f in tf]
|
|
73 |
+ for member in tar_members:
|
|
74 |
+ assert member in expected_content
|
|
75 |
+ |
|
76 |
+ |
|
42 | 77 |
@pytest.mark.datafiles(DATA_DIR)
|
43 | 78 |
@pytest.mark.parametrize('deps', [('build'), ('none'), ('run'), ('all')])
|
44 | 79 |
def test_source_checkout_deps(datafiles, cli, deps):
|
... | ... | @@ -119,3 +154,38 @@ def test_source_checkout_fetch(datafiles, cli, fetch): |
119 | 154 |
assert os.path.exists(os.path.join(checkout, 'remote-import-dev', 'pony.h'))
|
120 | 155 |
else:
|
121 | 156 |
result.assert_main_error(ErrorDomain.PIPELINE, 'uncached-sources')
|
157 |
+ |
|
158 |
+ |
|
159 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
160 |
+def test_source_checkout_build_scripts(cli, tmpdir, datafiles):
|
|
161 |
+ project_path = os.path.join(datafiles.dirname, datafiles.basename)
|
|
162 |
+ element_name = 'source-bundle/source-bundle-hello.bst'
|
|
163 |
+ normal_name = 'source-bundle-source-bundle-hello'
|
|
164 |
+ checkout = os.path.join(str(tmpdir), 'source-checkout')
|
|
165 |
+ |
|
166 |
+ args = ['source-checkout', '--include-build-scripts', element_name, checkout]
|
|
167 |
+ result = cli.run(project=project_path, args=args)
|
|
168 |
+ result.assert_success()
|
|
169 |
+ |
|
170 |
+ # There sould be a script for each element (just one in this case) and a top level build script
|
|
171 |
+ expected_scripts = ['build.sh', 'build-' + normal_name]
|
|
172 |
+ for script in expected_scripts:
|
|
173 |
+ assert script in os.listdir(checkout)
|
|
174 |
+ |
|
175 |
+ |
|
176 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
177 |
+def test_source_checkout_tar_buildscripts(cli, tmpdir, datafiles):
|
|
178 |
+ project_path = os.path.join(datafiles.dirname, datafiles.basename)
|
|
179 |
+ element_name = 'source-bundle/source-bundle-hello.bst'
|
|
180 |
+ normal_name = 'source-bundle-source-bundle-hello'
|
|
181 |
+ tar_file = os.path.join(str(tmpdir), 'source-checkout.tar')
|
|
182 |
+ |
|
183 |
+ args = ['source-checkout', '--include-build-scripts', '--tar', element_name, tar_file]
|
|
184 |
+ result = cli.run(project=project_path, args=args)
|
|
185 |
+ result.assert_success()
|
|
186 |
+ |
|
187 |
+ expected_scripts = ['build.sh', 'build-' + normal_name]
|
|
188 |
+ |
|
189 |
+ with tarfile.open(tar_file, 'r') as tf:
|
|
190 |
+ for script in expected_scripts:
|
|
191 |
+ assert script in tf.getnames()
|