Fix reading of default options.
authorCarl Hetherington <cth@carlh.net>
Sat, 26 May 2018 21:56:42 +0000 (22:56 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 26 May 2018 21:56:42 +0000 (22:56 +0100)
cdist

diff --git a/cdist b/cdist
index a4b4c51ba01dae331c9993b9a5c40e5243c643ac..c1a710bebb0e09c92bdce55caf8c33e753a99d58 100755 (executable)
--- a/cdist
+++ b/cdist
@@ -789,8 +789,14 @@ class Tree(object):
         with TreeDirectory(self):
             return self.cscript[function](self.target, *args)
 
-    def build_dependencies(self, options=None):
+    def add_defaults(self, options):
+        """Add the defaults from this into a dict options"""
+        if 'option_defaults' in self.cscript:
+            for k, v in self.cscript['option_defaults']().items():
+                if not k in options:
+                    options[k] = v
 
+    def build_dependencies(self, options):
         if not 'dependencies' in self.cscript:
             return
 
@@ -803,31 +809,35 @@ class Tree(object):
         for d in deps:
             dep = globals.trees.get(d[0], d[1], self.target, self.name)
 
-            options = dict()
-            # Make the options to pass in from the option_defaults of the thing
-            # we are building and any options specified by the parent.
-            if 'option_defaults' in dep.cscript:
-                for k, v in dep.cscript['option_defaults']().items():
-                    options[k] = v
-
+            # Start with the options passed in
+            dep_options = copy.copy(options)
+            # Add things specified by the parent
             if len(d) > 2:
                 for k, v in d[2].items():
-                    options[k] = v
+                    if not k in dep_options:
+                        dep_options[k] = v
+            # Then fill in the dependency's defaults
+            dep.add_defaults(dep_options)
 
             msg = 'Building dependency %s %s of %s' % (d[0], d[1], self.name)
-            if len(options) > 0:
-                msg += ' with options %s' % options
+            if len(dep_options) > 0:
+                msg += ' with options %s' % dep_options
             log(msg)
 
-            dep.build_dependencies(options)
-            dep.build(options)
+            dep.build_dependencies(dep_options)
+            dep.build(dep_options)
 
-    def build(self, options=None):
+    def build(self, options):
         if self.built:
             return
 
         variables = copy.copy(self.target.variables)
 
+        # Start with the options passed in
+        options = copy.copy(options)
+        # Fill in the defaults
+        self.add_defaults(options)
+
         if not globals.dry_run:
             if len(inspect.getargspec(self.cscript['build']).args) == 2:
                 self.call('build', options)