Phil Dawson pushed to branch phil/source-checkout-options at BuildStream / buildstream
Commits:
-
4f946593
by Phil Dawson at 2018-12-12T09:54:38Z
-
ab2c3a60
by Phil Dawson at 2018-12-12T09:54:38Z
-
8bfc62fd
by Phil Dawson at 2018-12-12T09:54:38Z
-
564441aa
by Phil Dawson at 2018-12-12T09:54:38Z
-
5b6d52a6
by Phil Dawson at 2018-12-12T09:55:39Z
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,12 @@ |
| 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 |
+ |
|
| 5 | 11 |
o BREAKING CHANGE: Default strip-commands have been removed as they are too
|
| 6 | 12 |
specific. Recommendation if you are building in Linux is to use the
|
| 7 | 13 |
ones being used in freedesktop-sdk project, for example
|
| ... | ... | @@ -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 |
+ try:
|
|
| 1128 |
+ if include_build_scripts:
|
|
| 1129 |
+ self._write_build_scripts(temp_source_dir.name, elements)
|
|
| 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.rename(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, mount_workspaces=False)
|
| 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 |
|
| ... | ... | @@ -46,6 +48,39 @@ def test_source_checkout(datafiles, tmpdir_factory, cli, with_workspace): |
| 46 | 48 |
assert os.path.exists(os.path.join(checkout, 'checkout-deps', 'etc', 'buildstream', 'config'))
|
| 47 | 49 |
|
| 48 | 50 |
|
| 51 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
| 52 |
+@pytest.mark.parametrize('force_flag', ['--force', '-f'])
|
|
| 53 |
+def test_source_checkout_force(datafiles, cli, force_flag):
|
|
| 54 |
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
| 55 |
+ checkout = os.path.join(cli.directory, 'source-checkout')
|
|
| 56 |
+ target = 'checkout-deps.bst'
|
|
| 57 |
+ |
|
| 58 |
+ os.makedirs(os.path.join(checkout, 'some-thing'))
|
|
| 59 |
+ # Path(os.path.join(checkout, 'some-file')).touch()
|
|
| 60 |
+ |
|
| 61 |
+ result = cli.run(project=project, args=['source-checkout', force_flag, target, '--deps', 'none', checkout])
|
|
| 62 |
+ result.assert_success()
|
|
| 63 |
+ |
|
| 64 |
+ assert os.path.exists(os.path.join(checkout, 'checkout-deps', 'etc', 'buildstream', 'config'))
|
|
| 65 |
+ |
|
| 66 |
+ |
|
| 67 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
| 68 |
+def test_source_checkout_tar(datafiles, cli):
|
|
| 69 |
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
| 70 |
+ checkout = os.path.join(cli.directory, 'source-checkout.tar')
|
|
| 71 |
+ target = 'checkout-deps.bst'
|
|
| 72 |
+ |
|
| 73 |
+ result = cli.run(project=project, args=['source-checkout', '--tar', target, '--deps', 'none', checkout])
|
|
| 74 |
+ result.assert_success()
|
|
| 75 |
+ |
|
| 76 |
+ assert os.path.exists(checkout)
|
|
| 77 |
+ with tarfile.open(checkout) as tf:
|
|
| 78 |
+ expected_content = os.path.join(checkout, 'checkout-deps', 'etc', 'buildstream', 'config')
|
|
| 79 |
+ tar_members = [f.name for f in tf]
|
|
| 80 |
+ for member in tar_members:
|
|
| 81 |
+ assert member in expected_content
|
|
| 82 |
+ |
|
| 83 |
+ |
|
| 49 | 84 |
@pytest.mark.datafiles(DATA_DIR)
|
| 50 | 85 |
@pytest.mark.parametrize('deps', [('build'), ('none'), ('run'), ('all')])
|
| 51 | 86 |
def test_source_checkout_deps(datafiles, cli, deps):
|
| ... | ... | @@ -126,3 +161,38 @@ def test_source_checkout_fetch(datafiles, cli, fetch): |
| 126 | 161 |
assert os.path.exists(os.path.join(checkout, 'remote-import-dev', 'pony.h'))
|
| 127 | 162 |
else:
|
| 128 | 163 |
result.assert_main_error(ErrorDomain.PIPELINE, 'uncached-sources')
|
| 164 |
+ |
|
| 165 |
+ |
|
| 166 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
| 167 |
+def test_source_checkout_build_scripts(cli, tmpdir, datafiles):
|
|
| 168 |
+ project_path = os.path.join(datafiles.dirname, datafiles.basename)
|
|
| 169 |
+ element_name = 'source-bundle/source-bundle-hello.bst'
|
|
| 170 |
+ normal_name = 'source-bundle-source-bundle-hello'
|
|
| 171 |
+ checkout = os.path.join(str(tmpdir), 'source-checkout')
|
|
| 172 |
+ |
|
| 173 |
+ args = ['source-checkout', '--include-build-scripts', element_name, checkout]
|
|
| 174 |
+ result = cli.run(project=project_path, args=args)
|
|
| 175 |
+ result.assert_success()
|
|
| 176 |
+ |
|
| 177 |
+ # There sould be a script for each element (just one in this case) and a top level build script
|
|
| 178 |
+ expected_scripts = ['build.sh', 'build-' + normal_name]
|
|
| 179 |
+ for script in expected_scripts:
|
|
| 180 |
+ assert script in os.listdir(checkout)
|
|
| 181 |
+ |
|
| 182 |
+ |
|
| 183 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
| 184 |
+def test_source_checkout_tar_buildscripts(cli, tmpdir, datafiles):
|
|
| 185 |
+ project_path = os.path.join(datafiles.dirname, datafiles.basename)
|
|
| 186 |
+ element_name = 'source-bundle/source-bundle-hello.bst'
|
|
| 187 |
+ normal_name = 'source-bundle-source-bundle-hello'
|
|
| 188 |
+ tar_file = os.path.join(str(tmpdir), 'source-checkout.tar')
|
|
| 189 |
+ |
|
| 190 |
+ args = ['source-checkout', '--include-build-scripts', '--tar', element_name, tar_file]
|
|
| 191 |
+ result = cli.run(project=project_path, args=args)
|
|
| 192 |
+ result.assert_success()
|
|
| 193 |
+ |
|
| 194 |
+ expected_scripts = ['build.sh', 'build-' + normal_name]
|
|
| 195 |
+ |
|
| 196 |
+ with tarfile.open(tar_file, 'r') as tf:
|
|
| 197 |
+ for script in expected_scripts:
|
|
| 198 |
+ assert script in tf.getnames()
|
