summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChandan Singh <csingh43@bloomberg.net>2018-09-18 18:14:06 +0100
committerChandan Singh <chandan.devel@gmail.com>2018-09-21 13:10:08 +0000
commite209beb0ce71eb2214cd5ac663a577dbf423ecc2 (patch)
treeee6a774fca5d151f48f2e50f550c16f2fa7f6671
parent55c93a82ecea4f7bf35c5367408ef5c3696560b5 (diff)
downloadbuildstream-e209beb0ce71eb2214cd5ac663a577dbf423ecc2.tar.gz
_stream.py: Ensure source-bundle's source directory exists
Currently, `source-bundle` command is entirely broken as it tries to stage the sources in a directory that doesn't exist. Fix it by ensuring that we create the necessary directories before calling any methods that try to use those directories. This fix comes with a regression test to ensure that the basic use-case of `source-bundle` continues to work in future. Fixes https://gitlab.com/BuildStream/buildstream/issues/651.
-rw-r--r--buildstream/_stream.py2
-rw-r--r--tests/frontend/project/elements/source-bundle/source-bundle-hello.bst6
-rw-r--r--tests/frontend/project/files/source-bundle/llamas.txt1
-rw-r--r--tests/frontend/source_bundle.py48
4 files changed, 57 insertions, 0 deletions
diff --git a/buildstream/_stream.py b/buildstream/_stream.py
index 2e78a1c45..f4661cc2a 100644
--- a/buildstream/_stream.py
+++ b/buildstream/_stream.py
@@ -703,6 +703,7 @@ class Stream():
# 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:
@@ -1085,6 +1086,7 @@ class Stream():
for element in elements:
source_dir = os.path.join(directory, "source")
element_source_dir = os.path.join(source_dir, element.normal_name)
+ os.makedirs(element_source_dir)
element._stage_sources_at(element_source_dir)
diff --git a/tests/frontend/project/elements/source-bundle/source-bundle-hello.bst b/tests/frontend/project/elements/source-bundle/source-bundle-hello.bst
new file mode 100644
index 000000000..98c3a9556
--- /dev/null
+++ b/tests/frontend/project/elements/source-bundle/source-bundle-hello.bst
@@ -0,0 +1,6 @@
+kind: import
+description: the kind of this element must implement generate_script() method
+
+sources:
+- kind: local
+ path: files/source-bundle
diff --git a/tests/frontend/project/files/source-bundle/llamas.txt b/tests/frontend/project/files/source-bundle/llamas.txt
new file mode 100644
index 000000000..f98b24871
--- /dev/null
+++ b/tests/frontend/project/files/source-bundle/llamas.txt
@@ -0,0 +1 @@
+llamas
diff --git a/tests/frontend/source_bundle.py b/tests/frontend/source_bundle.py
new file mode 100644
index 000000000..f72e80a3b
--- /dev/null
+++ b/tests/frontend/source_bundle.py
@@ -0,0 +1,48 @@
+#
+# 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()