summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Maat <tristan.maat@codethink.co.uk>2017-09-15 15:29:41 +0100
committerTristan Maat <tristan.maat@codethink.co.uk>2017-10-19 15:06:32 +0100
commit10847a66dc0748696829d5fd18ad17043c2c6878 (patch)
treed0883eef6e37bf2e62ab7267d5dd0ef6d56922a8
parent0f7e5df53612bb04a92631a34014bb7dae3195fd (diff)
downloadbuildstream-10847a66dc0748696829d5fd18ad17043c2c6878.tar.gz
Add warnings when staging to /buildstream/build74-prevent-artifacts-from-containing-files-in-buildstream-build
-rw-r--r--buildstream/buildelement.py13
-rw-r--r--buildstream/source.py5
-rw-r--r--setup.cfg1
-rw-r--r--tests/frontend/project/elements/install-to-build.bst4
-rw-r--r--tests/frontend/project/elements/installed-to-build.bst11
-rw-r--r--tests/frontend/project/files/build-files/buildstream/build/test1
-rw-r--r--tests/sources/generic.py28
-rw-r--r--tests/sources/generic/elements/install-to-build.bst4
-rw-r--r--tests/sources/generic/files/build-files/buildstream/build/test1
-rw-r--r--tests/sources/generic/project.conf4
10 files changed, 71 insertions, 1 deletions
diff --git a/buildstream/buildelement.py b/buildstream/buildelement.py
index 4776c90d5..3c6ebc38b 100644
--- a/buildstream/buildelement.py
+++ b/buildstream/buildelement.py
@@ -199,6 +199,19 @@ class BuildElement(Element):
if exitcode != 0:
raise ElementError("Command '{}' failed with exitcode {}".format(cmd, exitcode))
+ # %{install-root}/%{build-root} should normally not be written
+ # to - if an element later attempts to stage to a location
+ # that is not empty, we abort the build - in this case this
+ # will almost certainly happen.
+ staged_build = os.path.join(self.get_variable('install-root'),
+ self.get_variable('build-root'))
+
+ if os.path.isdir(staged_build) and os.listdir(staged_build):
+ self.warn("Writing to %{install-root}/%{build-root}.",
+ detail="Writing to this directory will almost " +
+ "certainly cause an error, since later elements " +
+ "will not be allowed to stage to %{build-root}.")
+
# Return the payload, this is configurable but is generally
# always the /buildstream/install directory
return self.get_variable('install-root')
diff --git a/buildstream/source.py b/buildstream/source.py
index a18910eb9..f044ca406 100644
--- a/buildstream/source.py
+++ b/buildstream/source.py
@@ -28,7 +28,7 @@ import shutil
from contextlib import contextmanager
from . import _yaml, _signals, utils
-from . import ImplError, LoadError, LoadErrorReason
+from . import ImplError, LoadError, LoadErrorReason, SourceError
from . import Plugin
@@ -252,6 +252,9 @@ class Source(Plugin):
directory = os.path.join(directory, self.__directory.lstrip(os.sep))
os.makedirs(directory, exist_ok=True)
+ if os.listdir(directory):
+ raise SourceError("Staging directory in '{}' not empty".format(directory))
+
if self._has_workspace():
self._stage_workspace(directory)
else:
diff --git a/setup.cfg b/setup.cfg
index 9e335fdc7..512cf3d67 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -3,6 +3,7 @@ test=pytest
[tool:pytest]
addopts = --verbose --basetemp ./tmp --pep8 --cov=buildstream --cov-config .coveragerc
+norecursedirs = integration-tests*
python_files = tests/*/*.py
pep8maxlinelength = 119
pep8ignore =
diff --git a/tests/frontend/project/elements/install-to-build.bst b/tests/frontend/project/elements/install-to-build.bst
new file mode 100644
index 000000000..a892cc69c
--- /dev/null
+++ b/tests/frontend/project/elements/install-to-build.bst
@@ -0,0 +1,4 @@
+kind: import
+sources:
+- kind: local
+ path: files/build-files
diff --git a/tests/frontend/project/elements/installed-to-build.bst b/tests/frontend/project/elements/installed-to-build.bst
new file mode 100644
index 000000000..2e963c977
--- /dev/null
+++ b/tests/frontend/project/elements/installed-to-build.bst
@@ -0,0 +1,11 @@
+kind: manual
+sources:
+- kind: local
+ path: files/build-files
+
+depends:
+- filename: install-to-build.bst
+ type: build
+
+config:
+ strip-commands: []
diff --git a/tests/frontend/project/files/build-files/buildstream/build/test b/tests/frontend/project/files/build-files/buildstream/build/test
new file mode 100644
index 000000000..9daeafb98
--- /dev/null
+++ b/tests/frontend/project/files/build-files/buildstream/build/test
@@ -0,0 +1 @@
+test
diff --git a/tests/sources/generic.py b/tests/sources/generic.py
new file mode 100644
index 000000000..6365d8d90
--- /dev/null
+++ b/tests/sources/generic.py
@@ -0,0 +1,28 @@
+import os
+import pathlib
+
+import pytest
+
+from .fixture import Setup
+from buildstream.exceptions import SourceError
+
+# Project directory
+DATA_DIR = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+ "generic",
+)
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_staging_to_existing(tmpdir, datafiles):
+ setup = Setup(datafiles, 'elements/install-to-build.bst', tmpdir)
+
+ # Create a file in the build directory (/buildstream/build)
+ build_dir = pathlib.Path(os.path.join(setup.context.builddir,
+ 'buildstream', 'build'))
+ build_dir.mkdir(parents=True)
+ build_dir.joinpath('file').touch()
+
+ # Ensure that we can't stage to an already filled build directory
+ with pytest.raises(SourceError):
+ setup.source._stage(setup.context.builddir)
diff --git a/tests/sources/generic/elements/install-to-build.bst b/tests/sources/generic/elements/install-to-build.bst
new file mode 100644
index 000000000..a892cc69c
--- /dev/null
+++ b/tests/sources/generic/elements/install-to-build.bst
@@ -0,0 +1,4 @@
+kind: import
+sources:
+- kind: local
+ path: files/build-files
diff --git a/tests/sources/generic/files/build-files/buildstream/build/test b/tests/sources/generic/files/build-files/buildstream/build/test
new file mode 100644
index 000000000..9daeafb98
--- /dev/null
+++ b/tests/sources/generic/files/build-files/buildstream/build/test
@@ -0,0 +1 @@
+test
diff --git a/tests/sources/generic/project.conf b/tests/sources/generic/project.conf
new file mode 100644
index 000000000..854e38693
--- /dev/null
+++ b/tests/sources/generic/project.conf
@@ -0,0 +1,4 @@
+# Project config for frontend build test
+name: test
+
+element-path: elements