pipeline: eagerly cleanup trees in error case

The `build_stages` method short-circuits and returns early in case
any of the stages fail to build and returns None for the tree, and
build tree, therefore both of those can immediately cleaned up at
that point.
For this add a small helper `cleanup` that will call the cleanup
method for all supplied arguments, after filtering out None values.
This commit is contained in:
Christian Kellner 2020-03-21 13:20:26 +01:00 committed by David Rheinsberg
parent 08fc223276
commit 56e0ac7c92

View file

@ -17,6 +17,11 @@ RESET = "\033[0m"
BOLD = "\033[1m"
def cleanup(*objs):
"""Call cleanup method for all objects, filters None values out"""
_ = map(lambda o: o.cleanup(), filter(None, objs))
class BuildResult:
def __init__(self, origin, returncode, output):
self.name = origin.name
@ -285,6 +290,7 @@ class Pipeline:
results["stages"].append(r.as_dict())
if not r.success:
cleanup(build_tree, tree)
results["success"] = False
return results, None, None