From 797522f91eb3e9d928ae26d2e1b78eeb0f02f467 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Sun, 14 Apr 2019 16:54:59 +0200 Subject: [PATCH] Fix circular dep for CDIST_ORDER_DEPENDENCY Fixes #756 --- cdist/emulator.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/cdist/emulator.py b/cdist/emulator.py index 65d044d7..5103f1a4 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -283,7 +283,8 @@ class Emulator(object): self.object_source))) raise - self.log.debug("Recording requirement: %s", requirement) + self.log.debug("Recording requirement %s for %s", + requirement, self.cdist_object.name) # Save the sanitised version, not the user supplied one # (__file//bar => __file/bar) @@ -305,13 +306,26 @@ class Emulator(object): # get the type created before this one ... try: lastcreatedtype = typecreationorder[-2].strip() - if 'require' in self.env: - self.env['require'] += " " + lastcreatedtype + # __object_name is the name of the object whose type + # manifest is currently executed + __object_name = self.env.get('__object_name', None) + if lastcreatedtype == __object_name: + self.log.debug(("Not injecting require for " + "CDIST_ORDER_DEPENDENCY: %s for %s," + " %s's type manifest is currently" + " being executed"), + lastcreatedtype, + self.cdist_object.name, + lastcreatedtype) else: - self.env['require'] = lastcreatedtype - self.log.debug(("Injecting require for " - "CDIST_ORDER_DEPENDENCY: %s for %s"), - lastcreatedtype, self.cdist_object.name) + if 'require' in self.env: + self.env['require'] += " " + lastcreatedtype + else: + self.env['require'] = lastcreatedtype + self.log.debug(("Injecting require for " + "CDIST_ORDER_DEPENDENCY: %s for %s"), + lastcreatedtype, + self.cdist_object.name) except IndexError: # if no second last line, we are on the first type, # so do not set a requirement @@ -360,4 +374,6 @@ class Emulator(object): # But only if the user hasn't said otherwise. # Must prevent circular dependencies. if parent.name not in current_object.requirements: + self.log.debug("Recording autorequirement %s for %s", + current_object.name, parent.name) parent.autorequire.append(current_object.name)