summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-04-16 16:35:42 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-04-16 16:45:04 +0900
commitca2331c3f314ff53428b5ca9c8c2efc9d2dbd7cc (patch)
treea4250ee0787c7f834390d48731d9a1b6760898a9
parent7c2a43d103e3034aa25ac7bd8571758a50526e61 (diff)
downloadbuildstream-ca2331c3f314ff53428b5ca9c8c2efc9d2dbd7cc.tar.gz
source.py, element.py, _pipeline.py: Streamling preflighting.
Instead of having the pipeline preflight all sources separately from elements, have the element preflight it's sources. This is in order to simplify the shared code path for the pipeline and the loader to use for instantiating elements. Also updated tests to expect the new ElementError and SourceError instead of the PipelineError which was raised for preflighting before.
-rw-r--r--buildstream/_pipeline.py13
-rw-r--r--buildstream/element.py13
-rw-r--r--buildstream/source.py9
-rw-r--r--tests/pipeline/preflight.py2
-rw-r--r--tests/plugins/filter.py8
-rw-r--r--tests/sources/local.py2
-rw-r--r--tests/sources/patch.py4
7 files changed, 30 insertions, 21 deletions
diff --git a/buildstream/_pipeline.py b/buildstream/_pipeline.py
index 4b48deee9..0cdf432a6 100644
--- a/buildstream/_pipeline.py
+++ b/buildstream/_pipeline.py
@@ -662,17 +662,8 @@ class Pipeline():
# Preflights all the plugins in the pipeline
#
def _preflight(self):
- for plugin in self.dependencies(Scope.ALL, include_sources=True):
- try:
- plugin._preflight()
- except BstError as e:
- # Prepend the plugin identifier string to the error raised by
- # the plugin so that users can more quickly identify the issue
- # that a given plugin is encountering.
- #
- # Propagate the original error reason for test case purposes
- #
- raise PipelineError("{}: {}".format(plugin, e), reason=e.reason) from e
+ for element in self.dependencies(Scope.ALL):
+ element._preflight()
# _collect_unused_workspaces()
#
diff --git a/buildstream/element.py b/buildstream/element.py
index 305f8cf7e..f878c50dc 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -1093,7 +1093,8 @@ class Element(Plugin):
# _preflight():
#
- # A wrapper for calling the abstract preflight() method.
+ # A wrapper for calling the abstract preflight() method on
+ # the element and it's sources.
#
def _preflight(self):
if self.BST_FORBID_RDEPENDS:
@@ -1106,7 +1107,15 @@ class Element(Plugin):
raise ElementError("{}: Sources are forbidden for '{}' elements"
.format(self, self.get_kind()), reason="element-forbidden-sources")
- self.preflight()
+ try:
+ self.preflight()
+ except BstError as e:
+ # Prepend provenance to the error
+ raise ElementError("{}: {}".format(self, e), reason=e.reason) from e
+
+ # Preflight the sources
+ for source in self.sources():
+ source._preflight()
# _schedule_tracking():
#
diff --git a/buildstream/source.py b/buildstream/source.py
index d626fea35..9af17210e 100644
--- a/buildstream/source.py
+++ b/buildstream/source.py
@@ -344,6 +344,15 @@ class Source(Plugin):
# Private Methods used in BuildStream #
#############################################################
+ # Wrapper around preflight() method
+ #
+ def _preflight(self):
+ try:
+ self.preflight()
+ except BstError as e:
+ # Prepend provenance to the error
+ raise SourceError("{}: {}".format(self, e), reason=e.reason) from e
+
# Update cached consistency for a source
#
# This must be called whenever the state of a source may have changed.
diff --git a/tests/pipeline/preflight.py b/tests/pipeline/preflight.py
index f9eb649ff..4692d090e 100644
--- a/tests/pipeline/preflight.py
+++ b/tests/pipeline/preflight.py
@@ -16,4 +16,4 @@ def test_load_simple(cli, datafiles, tmpdir):
# Lets try to fetch it...
result = cli.run(project=basedir, args=['fetch', 'error.bst'])
- result.assert_main_error(ErrorDomain.PIPELINE, "the-preflight-error")
+ result.assert_main_error(ErrorDomain.SOURCE, "the-preflight-error")
diff --git a/tests/plugins/filter.py b/tests/plugins/filter.py
index a8e7257c3..3c092c201 100644
--- a/tests/plugins/filter.py
+++ b/tests/plugins/filter.py
@@ -63,25 +63,25 @@ def test_filter_deps_ok(datafiles, cli):
def test_filter_forbid_sources(datafiles, cli):
project = os.path.join(datafiles.dirname, datafiles.basename)
result = cli.run(project=project, args=['build', 'forbidden-source.bst'])
- result.assert_main_error(ErrorDomain.PIPELINE, 'element-forbidden-sources')
+ result.assert_main_error(ErrorDomain.ELEMENT, 'element-forbidden-sources')
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
def test_filter_forbid_multi_bdep(datafiles, cli):
project = os.path.join(datafiles.dirname, datafiles.basename)
result = cli.run(project=project, args=['build', 'forbidden-multi-bdep.bst'])
- result.assert_main_error(ErrorDomain.PIPELINE, 'filter-bdepend-wrong-count')
+ result.assert_main_error(ErrorDomain.ELEMENT, 'filter-bdepend-wrong-count')
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
def test_filter_forbid_no_bdep(datafiles, cli):
project = os.path.join(datafiles.dirname, datafiles.basename)
result = cli.run(project=project, args=['build', 'forbidden-no-bdep.bst'])
- result.assert_main_error(ErrorDomain.PIPELINE, 'filter-bdepend-wrong-count')
+ result.assert_main_error(ErrorDomain.ELEMENT, 'filter-bdepend-wrong-count')
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
def test_filter_forbid_also_rdep(datafiles, cli):
project = os.path.join(datafiles.dirname, datafiles.basename)
result = cli.run(project=project, args=['build', 'forbidden-also-rdep.bst'])
- result.assert_main_error(ErrorDomain.PIPELINE, 'filter-bdepend-also-rdepend')
+ result.assert_main_error(ErrorDomain.ELEMENT, 'filter-bdepend-also-rdepend')
diff --git a/tests/sources/local.py b/tests/sources/local.py
index 88b553677..bfddf6881 100644
--- a/tests/sources/local.py
+++ b/tests/sources/local.py
@@ -21,7 +21,7 @@ def test_missing_file(cli, tmpdir, datafiles):
result = cli.run(project=project, args=[
'show', 'target.bst'
])
- result.assert_main_error(ErrorDomain.PIPELINE, None)
+ result.assert_main_error(ErrorDomain.SOURCE, None)
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
diff --git a/tests/sources/patch.py b/tests/sources/patch.py
index 452b4f64f..2f23fd5dd 100644
--- a/tests/sources/patch.py
+++ b/tests/sources/patch.py
@@ -21,7 +21,7 @@ def test_missing_patch(cli, tmpdir, datafiles):
result = cli.run(project=project, args=[
'show', 'target.bst'
])
- result.assert_main_error(ErrorDomain.PIPELINE, 'patch-no-exist')
+ result.assert_main_error(ErrorDomain.SOURCE, 'patch-no-exist')
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
@@ -35,7 +35,7 @@ def test_non_regular_file_patch(cli, tmpdir, datafiles):
result = cli.run(project=project, args=[
'show', 'irregular.bst'
])
- result.assert_main_error(ErrorDomain.PIPELINE, "patch-not-a-file")
+ result.assert_main_error(ErrorDomain.SOURCE, "patch-not-a-file")
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))