summaryrefslogtreecommitdiff
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
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.
-rw-r--r--src/buildstream/_loader/loader.py1
-rw-r--r--src/buildstream/_pipeline.py4
-rw-r--r--src/buildstream/element.py88
-rw-r--r--tests/artifactcache/push.py2
4 files changed, 45 insertions, 50 deletions
diff --git a/src/buildstream/_loader/loader.py b/src/buildstream/_loader/loader.py
index 5a2624c6a..207de9adb 100644
--- a/src/buildstream/_loader/loader.py
+++ b/src/buildstream/_loader/loader.py
@@ -604,7 +604,6 @@ class Loader():
provenance_str, filename, meta_element.kind))
element = Element._new_from_meta(meta_element)
- element._preflight()
element._update_state()
# If this junction element points to a sub-sub-project, we need to
diff --git a/src/buildstream/_pipeline.py b/src/buildstream/_pipeline.py
index 440bd8bd3..a96a3f731 100644
--- a/src/buildstream/_pipeline.py
+++ b/src/buildstream/_pipeline.py
@@ -125,10 +125,6 @@ class Pipeline():
def resolve_elements(self, targets):
with self._context.messenger.timed_activity("Resolving cached state", silent_nested=True):
for element in self.dependencies(targets, Scope.ALL):
-
- # Preflight
- element._preflight()
-
# Determine initial element state.
element._update_state()
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.
diff --git a/tests/artifactcache/push.py b/tests/artifactcache/push.py
index 9b976c490..da658f76b 100644
--- a/tests/artifactcache/push.py
+++ b/tests/artifactcache/push.py
@@ -124,8 +124,6 @@ def _test_push(user_config_file, project_dir, element_name, queue):
# This is duplicated from Pipeline.resolve_elements()
# as this test does not use the cli frontend.
for e in element.dependencies(Scope.ALL):
- # Preflight
- e._preflight()
# Determine initial element state.
e._update_state()