Skip to content
Snippets Groups Projects
Commit 355ddf28 authored by Phil Dawson's avatar Phil Dawson
Browse files

Remove source bundle command

This is part of the work towards #672
parent 7735b3c4
No related branches found
No related tags found
No related merge requests found
Pipeline #37146891 passed
......@@ -838,34 +838,3 @@ def workspace_list(app):
with app.initialized():
app.stream.workspace_list()
##################################################################
# Source Bundle Command #
##################################################################
@cli.command(name="source-bundle", short_help="Produce a build bundle to be manually executed")
@click.option('--except', 'except_', multiple=True,
type=click.Path(readable=False),
help="Elements to except from the tarball")
@click.option('--compression', default='gz',
type=click.Choice(['none', 'gz', 'bz2', 'xz']),
help="Compress the tar file using the given algorithm.")
@click.option('--track', 'track_', default=False, is_flag=True,
help="Track new source references before bundling")
@click.option('--force', '-f', default=False, is_flag=True,
help="Overwrite an existing tarball")
@click.option('--directory', default=os.getcwd(),
help="The directory to write the tarball to")
@click.argument('element',
type=click.Path(readable=False))
@click.pass_obj
def source_bundle(app, element, force, directory,
track_, compression, except_):
"""Produce a source bundle to be manually executed
"""
with app.initialized():
app.stream.source_bundle(element, directory,
track_first=track_,
force=force,
compression=compression,
except_targets=except_)
......@@ -670,87 +670,6 @@ class Stream():
'workspaces': workspaces
})
# source_bundle()
#
# Create a host buildable tarball bundle for the given target.
#
# Args:
# target (str): The target element to bundle
# directory (str): The directory to output the tarball
# track_first (bool): Track new source references before bundling
# compression (str): The compression type to use
# force (bool): Overwrite an existing tarball
#
def source_bundle(self, target, directory, *,
track_first=False,
force=False,
compression="gz",
except_targets=()):
if track_first:
track_targets = (target,)
else:
track_targets = ()
elements, track_elements = self._load((target,), track_targets,
selection=PipelineSelection.ALL,
except_targets=except_targets,
track_selection=PipelineSelection.ALL,
fetch_subprojects=True)
# source-bundle only supports one target
target = self.targets[0]
self._message(MessageType.INFO, "Bundling sources for target {}".format(target.name))
# Find the correct filename for the compression algorithm
tar_location = os.path.join(directory, target.normal_name + ".tar")
if compression != "none":
tar_location += "." + compression
# Attempt writing a file to generate a good error message
# early
#
# FIXME: A bit hackish
try:
open(tar_location, mode="x")
os.remove(tar_location)
except IOError as e:
raise StreamError("Cannot write to {0}: {1}"
.format(tar_location, e)) from e
# Fetch and possibly track first
#
self._fetch(elements, track_elements=track_elements)
# We don't use the scheduler for this as it is almost entirely IO
# bound.
# Create a temporary directory to build the source tree in
builddir = self._context.builddir
os.makedirs(builddir, exist_ok=True)
prefix = "{}-".format(target.normal_name)
with TemporaryDirectory(prefix=prefix, dir=builddir) as tempdir:
source_directory = os.path.join(tempdir, 'source')
try:
os.makedirs(source_directory)
except OSError as e:
raise StreamError("Failed to create directory: {}"
.format(e)) from e
# Any elements that don't implement _write_script
# should not be included in the later stages.
elements = [
element for element in elements
if self._write_element_script(source_directory, element)
]
self._write_element_sources(os.path.join(tempdir, "source"), elements)
self._write_master_build_script(tempdir, elements)
self._collect_sources(tempdir, tar_location,
target.normal_name, compression)
# redirect_element_names()
#
# Takes a list of element names and returns a list where elements have been
......
......@@ -86,13 +86,6 @@ project's main directory.
----
.. _invoking_source_bundle:
.. click:: buildstream._frontend.cli:source_bundle
:prog: bst source bundle
----
.. _invoking_workspace:
.. click:: buildstream._frontend.cli:workspace
......
......@@ -16,7 +16,6 @@ MAIN_COMMANDS = [
'shell ',
'show ',
'source-checkout ',
'source-bundle ',
'track ',
'workspace '
]
......
......@@ -25,7 +25,6 @@ def test_help_main(cli):
('push'),
('shell'),
('show'),
('source-bundle'),
('track'),
('workspace')
])
......
#
# Copyright (C) 2018 Bloomberg Finance LP
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
#
# Authors: Chandan Singh <csingh43@bloomberg.net>
#
import os
import tarfile
import pytest
from tests.testutils import cli
# Project directory
DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"project",
)
@pytest.mark.datafiles(DATA_DIR)
def test_source_bundle(cli, tmpdir, datafiles):
project_path = os.path.join(datafiles.dirname, datafiles.basename)
element_name = 'source-bundle/source-bundle-hello.bst'
normal_name = 'source-bundle-source-bundle-hello'
# Verify that we can correctly produce a source-bundle
args = ['source-bundle', element_name, '--directory', str(tmpdir)]
result = cli.run(project=project_path, args=args)
result.assert_success()
# Verify that the source-bundle contains our sources and a build script
with tarfile.open(os.path.join(str(tmpdir), '{}.tar.gz'.format(normal_name))) as bundle:
assert os.path.join(normal_name, 'source', normal_name, 'llamas.txt') in bundle.getnames()
assert os.path.join(normal_name, 'build.sh') in bundle.getnames()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment