diff options
author | Tristan van Berkom <tristan.vanberkom@codethink.co.uk> | 2020-08-13 19:01:00 +0900 |
---|---|---|
committer | Tristan van Berkom <tristan@codethink.co.uk> | 2020-10-01 13:27:30 +0900 |
commit | 751c80d4938b7c3a798d056134f58844242939b3 (patch) | |
tree | a31bd535be946b3032d22b6296a49b735ba5e2b1 /src/buildstream/plugins | |
parent | 348108d933be748727ee8aec861ecd5c168db72e (diff) | |
download | buildstream-751c80d4938b7c3a798d056134f58844242939b3.tar.gz |
Refactor: Lazily instantiate ProvenanceInformation objectstristan/lazy-provenance
As a rule, throughout the codebase we should not be using internal
ProvenanceInformation objects in our APIs, but rather Node objects.
This is because ProvenanceInformation is generated on the fly from
a Node object, and it is needlessly expensive to instantiate one before
it is absolutely needed.
This patch unilaterally fixes the codebase to pass `provenance_node`
Node objects around as arguments rather than `provenance` ProvenanceInformation
objects.
Diffstat (limited to 'src/buildstream/plugins')
-rw-r--r-- | src/buildstream/plugins/elements/junction.py | 15 | ||||
-rw-r--r-- | src/buildstream/plugins/elements/link.py | 7 |
2 files changed, 8 insertions, 14 deletions
diff --git a/src/buildstream/plugins/elements/junction.py b/src/buildstream/plugins/elements/junction.py index 425b917ef..8693313af 100644 --- a/src/buildstream/plugins/elements/junction.py +++ b/src/buildstream/plugins/elements/junction.py @@ -284,25 +284,22 @@ class JunctionElement(Element): self.ignore_junction_remotes = node.get_bool("ignore-junction-remotes", default=False) # The overrides dictionary has the target junction - # to override as a key, and a tuple consisting - # of the local overriding junction and the provenance - # of the override declaration. + # to override as a key, and the ScalarNode of the + # junction name as a value self.overrides = {} overrides_node = node.get_mapping("overrides", {}) - for key, value in overrides_node.items(): - junction_name = value.as_str() - provenance = value.get_provenance() + for key, junction_name in overrides_node.items(): # Cannot override a subproject with the project itself # - if junction_name == self.name: + if junction_name.as_str() == self.name: raise ElementError( "{}: Attempt to override subproject junction '{}' with the overriding junction '{}' itself".format( - provenance, key, junction_name + junction_name.get_provenance(), key, junction_name.as_str() ), reason="override-junction-with-self", ) - self.overrides[key] = (junction_name, provenance) + self.overrides[key] = junction_name def preflight(self): pass diff --git a/src/buildstream/plugins/elements/link.py b/src/buildstream/plugins/elements/link.py index e6d7f056e..e5e694579 100644 --- a/src/buildstream/plugins/elements/link.py +++ b/src/buildstream/plugins/elements/link.py @@ -59,12 +59,9 @@ class LinkElement(Element): node.validate_keys(["target"]) - # Hold onto the provenance of the specified target, - # allowing the loader to raise errors with better context. + # Hold onto the node, keep it around for provenance. # - target_node = node.get_scalar("target") - self.target = target_node.as_str() - self.target_provenance = target_node.get_provenance() + self.target_node = node.get_scalar("target") def preflight(self): pass |