Commit ca2331c3 authored by Tristan Van Berkom's avatar Tristan Van Berkom
Browse files

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.
parent 7c2a43d1
Loading
Loading
Loading
Loading
+2 −11
Original line number Diff line number Diff line
@@ -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()
    #
+11 −2
Original line number Diff line number Diff line
@@ -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")

        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():
    #
+9 −0
Original line number Diff line number Diff line
@@ -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.
+1 −1
Original line number Diff line number Diff line
@@ -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")
+4 −4
Original line number Diff line number Diff line
@@ -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')
Loading