diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-04-05 21:10:28 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-04-05 22:14:32 +0900 |
commit | 857751fb6479afa0ee83d4759891f7c4837b87bb (patch) | |
tree | 1f2f9fe26d872e7068a5a523019b5f4e24e5361d | |
parent | 81ec36354812b6f554a20f5c9823415e39080217 (diff) | |
download | buildstream-857751fb6479afa0ee83d4759891f7c4837b87bb.tar.gz |
_loader.py: Some fixes in how we load sources for junctions
o Ensure that we call Source._load_ref(), and consider project.refs this way
o Ensure that we report a warning in the case that project.refs is in use
and the loaded junction source has a redundant ref which is going to
be ignored
o Report more distinct machine readable errors for failures to load
junction element sources
o Handle Consistency.INCONSISTENT and Consistency.RESOLVED separately:
- The user should be told something different depending on whether
they need to fetch or whether they need to track.
- It is never possible to automatically fetch the source in the
case that the source has no ref to begin with.
This also adjusts the test/loader/junctions.py test to expect the new error
-rw-r--r-- | buildstream/_loader.py | 31 | ||||
-rw-r--r-- | tests/loader/junctions.py | 2 |
2 files changed, 30 insertions, 3 deletions
diff --git a/buildstream/_loader.py b/buildstream/_loader.py index 047a09f2e..6d384ae2c 100644 --- a/buildstream/_loader.py +++ b/buildstream/_loader.py @@ -25,6 +25,7 @@ import tempfile import shutil from ._exceptions import LoadError, LoadErrorReason +from ._message import Message, MessageType from . import Consistency from ._project import Project from . import _yaml @@ -350,16 +351,33 @@ class Loader(): for meta_source in meta_element.sources: source = meta_element.project.create_source(meta_source.kind, meta_source) + redundant_ref = source._load_ref() + if redundant_ref: + self._message(MessageType.WARN, + "Ignoring redundant ref in junction element {}".format(element.name)) source._preflight() - if source.get_consistency() != Consistency.CACHED: + # Handle the case where a subproject needs to be fetched + # + if source.get_consistency() == Consistency.RESOLVED: if self.context._fetch_subprojects: if ticker: ticker(filename, 'Fetching subproject from {} source'.format(meta_source.kind)) source.fetch() else: - raise LoadError(LoadErrorReason.MISSING_FILE, "Subproject fetch needed for {}".format(filename)) + detail = "Try fetching the project with `bst fetch {}`".format(filename) + raise LoadError(LoadErrorReason.SUBPROJECT_FETCH_NEEDED, + "Subproject fetch needed for junction: {}".format(filename), + detail=detail) + + # Handle the case where a subproject has no ref + # + elif source.get_consistency() == Consistency.INCONSISTENT: + detail = "Try tracking the junction element with `bst track {}`".format(filename) + raise LoadError(LoadErrorReason.SUBPROJECT_INCONSISTENT, + "Subproject has no ref for junction: {}".format(filename), + detail=detail) source._stage(basedir) @@ -636,3 +654,12 @@ class Loader(): if self.tempdir.startswith(self.context.builddir + os.sep): if os.path.exists(self.tempdir): shutil.rmtree(self.tempdir) + + # _message() + # + # Local message propagator + # + def _message(self, message_type, message, **kwargs): + args = dict(kwargs) + self.context.message( + Message(None, message_type, message, **args)) diff --git a/tests/loader/junctions.py b/tests/loader/junctions.py index 0634b8aa2..df77e0064 100644 --- a/tests/loader/junctions.py +++ b/tests/loader/junctions.py @@ -221,7 +221,7 @@ def test_git_show(cli, tmpdir, datafiles): assert result.exit_code != 0 assert result.exception assert isinstance(result.exception, LoadError) - assert result.exception.reason == LoadErrorReason.MISSING_FILE + assert result.exception.reason == LoadErrorReason.SUBPROJECT_FETCH_NEEDED # Explicitly fetch subproject result = cli.run(project=project, args=['fetch', 'base.bst']) |