summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Maat <tristan.maat@codethink.co.uk>2019-09-18 15:03:05 +0100
committerTristan Maat <tristan.maat@codethink.co.uk>2019-10-10 12:21:15 +0100
commitacf99b789a92e9e124e9492d1dbbc34b83f5ab23 (patch)
tree37aae10af52ccad97cc08d0fffb2feccb50b56aa
parent28803a91bb0525a197de004dce5fbe750a00fbde (diff)
downloadbuildstream-acf99b789a92e9e124e9492d1dbbc34b83f5ab23.tar.gz
loader.py: Avoid loading deps of junction metaelements
By avoiding this, loading metaelements of junctions becomes cheap even for junctions with erroneous dependencies, and we can ignore their task reporting. Task reporting for junction metaelement loading is confusing, since the junction element itself will never be part of the pipeline, so we'd rather not have this show up as an actual loaded element. Elements loaded from the junction are loaded separately, therefore this does not affect their progress display.
-rw-r--r--src/buildstream/_loader/loader.py20
-rw-r--r--tests/format/junctions.py2
2 files changed, 20 insertions, 2 deletions
diff --git a/src/buildstream/_loader/loader.py b/src/buildstream/_loader/loader.py
index d578787a3..5eaed9337 100644
--- a/src/buildstream/_loader/loader.py
+++ b/src/buildstream/_loader/loader.py
@@ -593,12 +593,30 @@ class Loader():
# meta junction element
# XXX: This is a likely point for progress reporting to end up
# missing some elements, but it currently doesn't appear to be the case.
- meta_element = self._collect_element(self._elements[filename], None)
+ meta_element = self._collect_element_no_deps(self._elements[filename], None)
if meta_element.kind != 'junction':
raise LoadError("{}{}: Expected junction but element kind is {}"
.format(provenance_str, filename, meta_element.kind),
LoadErrorReason.INVALID_DATA)
+ # We check that junctions have no dependencies a little
+ # early. This is cheating, since we don't technically know
+ # that junctions aren't allowed to have dependencies.
+ #
+ # However, this makes progress reporting more intuitive
+ # because we don't need to load dependencies of an element
+ # that shouldn't have any, and therefore don't need to
+ # duplicate the load count for elements that shouldn't be.
+ #
+ # We also fail slightly earlier (since we don't need to go
+ # through the entire loading process), which is nice UX. It
+ # would be nice if this could be done for *all* element types,
+ # but since we haven't loaded those yet that's impossible.
+ if self._elements[filename].dependencies:
+ raise LoadError(
+ "Dependencies are forbidden for 'junction' elements",
+ LoadErrorReason.INVALID_JUNCTION)
+
element = Element._new_from_meta(meta_element)
element._update_state()
diff --git a/tests/format/junctions.py b/tests/format/junctions.py
index b810c55a3..a0af521a2 100644
--- a/tests/format/junctions.py
+++ b/tests/format/junctions.py
@@ -238,7 +238,7 @@ def test_invalid_with_deps(cli, datafiles):
copy_subprojects(project, datafiles, ['base'])
result = cli.run(project=project, args=['build', 'junction-with-deps.bst'])
- result.assert_main_error(ErrorDomain.ELEMENT, 'element-forbidden-depends')
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_JUNCTION)
# Test that we error correctly when a junction is directly depended on