Commit dd36cfbc authored by Benjamin Schubert's avatar Benjamin Schubert
Browse files

element.py: Only cache on element error or success

Reverse the way we were handling caching by only caching
when we know it's a problem with the build or the build is a
success in order not to cache transient errors.
parent 06e28860
Loading
Loading
Loading
Loading
Loading
+6 −19
Original line number Diff line number Diff line
@@ -86,7 +86,7 @@ from . import _yaml
from ._variables import Variables
from ._versions import BST_CORE_ARTIFACT_VERSION
from ._exceptions import BstError, LoadError, LoadErrorReason, ImplError, \
    ErrorDomain, SandboxError
    ErrorDomain
from .utils import UtilError
from . import Plugin, Consistency, Scope
from . import SandboxFlags
@@ -1554,9 +1554,6 @@ class Element(Plugin):
                self.__dynamic_public = _yaml.node_copy(self.__public)

                # Call the abstract plugin methods
                collect = None
                save_artifacts = True

                try:
                    # Step 1 - Configure
                    self.configure_sandbox(sandbox)
@@ -1567,10 +1564,7 @@ class Element(Plugin):
                    # Step 4 - Assemble
                    collect = self.assemble(sandbox)  # pylint: disable=assignment-from-no-return
                    self.__set_build_result(success=True, description="succeeded")
                except BstError as e:
                    if isinstance(e, SandboxError):
                        save_artifacts = False

                except ElementError as e:
                    # Shelling into a sandbox is useful to debug this error
                    e.sandbox = True

@@ -1592,22 +1586,15 @@ class Element(Plugin):
                            self.warn("Failed to preserve workspace state for failed build sysroot: {}"
                                      .format(e))

                    if isinstance(e, ElementError):
                        collect = e.collect  # pylint: disable=no-member

                    self.__set_build_result(success=False, description=str(e), detail=e.detail)
                    self._cache_artifact(rootdir, sandbox, e.collect)

                    raise
                finally:
                    if save_artifacts:
                        artifact_size = self._cache_artifact(rootdir, sandbox, context, collect)
                else:
                        artifact_size = None

                    # Finally cleanup the build dir
                    return self._cache_artifact(rootdir, sandbox, collect)
                finally:
                    cleanup_rootdir()

        return artifact_size

    def _cache_artifact(self, rootdir, sandbox, collect):
        if collect is not None:
            try: