summaryrefslogtreecommitdiff
path: root/src/buildstream/element.py
diff options
context:
space:
mode:
authorJames Ennis <james.ennis@codethink.co.uk>2019-07-11 09:43:28 +0100
committerbst-marge-bot <marge-bot@buildstream.build>2019-07-16 09:13:39 +0000
commit1313989ce22160e8d225c8b22c47b2c07556fa21 (patch)
tree2b8caa9af1bffb0a7b344b9ddab43ab487feb980 /src/buildstream/element.py
parent385e3719c7e6dc15f72c0acaca54622b3c073ecc (diff)
downloadbuildstream-1313989ce22160e8d225c8b22c47b2c07556fa21.tar.gz
_pipeline.py, loader.py: Move Element._preflight() to new_from_meta()
It's essential to call preflight() when loading/resolving the Elements. This patch moves the preflight call to new_from_meta, so that it is called as soon as the Element is created. This avoids the need for having multiple callsites.
Diffstat (limited to 'src/buildstream/element.py')
-rw-r--r--src/buildstream/element.py88
1 files changed, 45 insertions, 43 deletions
diff --git a/src/buildstream/element.py b/src/buildstream/element.py
index 570e473e9..1451be9b9 100644
--- a/src/buildstream/element.py
+++ b/src/buildstream/element.py
@@ -969,6 +969,8 @@ class Element(Plugin):
dependency.__reverse_build_deps.add(element)
element.__remaining_build_deps_uncached = len(element.__build_dependencies)
+ element.__preflight()
+
return element
# _clear_meta_elements_cache()
@@ -1226,49 +1228,6 @@ class Element(Plugin):
_, display_key, _ = self._get_display_key()
return display_key
- # _preflight():
- #
- # A wrapper for calling the abstract preflight() method on
- # the element and its sources.
- #
- def _preflight(self):
-
- if self.BST_FORBID_RDEPENDS and self.BST_FORBID_BDEPENDS:
- if any(self.dependencies(Scope.RUN, recurse=False)) or any(self.dependencies(Scope.BUILD, recurse=False)):
- raise ElementError("{}: Dependencies are forbidden for '{}' elements"
- .format(self, self.get_kind()), reason="element-forbidden-depends")
-
- if self.BST_FORBID_RDEPENDS:
- if any(self.dependencies(Scope.RUN, recurse=False)):
- raise ElementError("{}: Runtime dependencies are forbidden for '{}' elements"
- .format(self, self.get_kind()), reason="element-forbidden-rdepends")
-
- if self.BST_FORBID_BDEPENDS:
- if any(self.dependencies(Scope.BUILD, recurse=False)):
- raise ElementError("{}: Build dependencies are forbidden for '{}' elements"
- .format(self, self.get_kind()), reason="element-forbidden-bdepends")
-
- if self.BST_FORBID_SOURCES:
- if any(self.sources()):
- 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, detail=e.detail) from e
-
- # Ensure that the first source does not need access to previous soruces
- if self.__sources and self.__sources[0]._requires_previous_sources():
- raise ElementError("{}: {} cannot be the first source of an element "
- "as it requires access to previous sources"
- .format(self, self.__sources[0]))
-
- # Preflight the sources
- for source in self.sources():
- source._preflight()
-
# _schedule_tracking():
#
# Force an element state to be inconsistent. Any sources appear to be
@@ -2370,6 +2329,49 @@ class Element(Plugin):
# have been executed.
sandbox._callback(mark_workspace_prepared)
+ # __preflight():
+ #
+ # A internal wrapper for calling the abstract preflight() method on
+ # the element and its sources.
+ #
+ def __preflight(self):
+
+ if self.BST_FORBID_RDEPENDS and self.BST_FORBID_BDEPENDS:
+ if any(self.dependencies(Scope.RUN, recurse=False)) or any(self.dependencies(Scope.BUILD, recurse=False)):
+ raise ElementError("{}: Dependencies are forbidden for '{}' elements"
+ .format(self, self.get_kind()), reason="element-forbidden-depends")
+
+ if self.BST_FORBID_RDEPENDS:
+ if any(self.dependencies(Scope.RUN, recurse=False)):
+ raise ElementError("{}: Runtime dependencies are forbidden for '{}' elements"
+ .format(self, self.get_kind()), reason="element-forbidden-rdepends")
+
+ if self.BST_FORBID_BDEPENDS:
+ if any(self.dependencies(Scope.BUILD, recurse=False)):
+ raise ElementError("{}: Build dependencies are forbidden for '{}' elements"
+ .format(self, self.get_kind()), reason="element-forbidden-bdepends")
+
+ if self.BST_FORBID_SOURCES:
+ if any(self.sources()):
+ 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, detail=e.detail) from e
+
+ # Ensure that the first source does not need access to previous soruces
+ if self.__sources and self.__sources[0]._requires_previous_sources():
+ raise ElementError("{}: {} cannot be the first source of an element "
+ "as it requires access to previous sources"
+ .format(self, self.__sources[0]))
+
+ # Preflight the sources
+ for source in self.sources():
+ source._preflight()
+
# __assert_cached()
#
# Raises an error if the artifact is not cached.