From: Carl Hetherington Date: Sat, 26 May 2018 21:56:42 +0000 (+0100) Subject: Fix reading of default options. X-Git-Url: https://main.carlh.net/gitweb/?a=commitdiff_plain;h=67cb7c9b6795b2772feeb47ff89ecc53bd7ca807;p=cdist.git Fix reading of default options. --- diff --git a/cdist b/cdist index a4b4c51..c1a710b 100755 --- 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)