From 1c63e4d7ee9d9aab66c0559bad647005463b5650 Mon Sep 17 00:00:00 2001 From: Thomas Nagy Date: Thu, 22 Dec 2016 18:28:03 +0100 Subject: [PATCH] Simplify TaskGen.process_rule --- waflib/TaskGen.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/waflib/TaskGen.py b/waflib/TaskGen.py index e3547437..453ba0ab 100644 --- a/waflib/TaskGen.py +++ b/waflib/TaskGen.py @@ -558,10 +558,13 @@ def process_rule(self): except AttributeError: cache = self.bld.cache_rule_attr = {} + cache_rule = getattr(self, 'cache_rule', 'True') + key = (name, self.rule) + cls = None - if getattr(self, 'cache_rule', 'True'): + if cache_rule: try: - cls = cache[(name, self.rule)] + cls = cache[key] except KeyError: pass if not cls: @@ -571,8 +574,8 @@ def process_rule(self): def chmod_fun(tsk): for x in tsk.outputs: os.chmod(x.abspath(), self.chmod) - if isinstance(self.rule, tuple): - rule = list(self.rule) + if isinstance(rule, tuple): + rule = list(rule) rule.append(chmod_fun) rule = tuple(rule) else: @@ -580,8 +583,8 @@ def process_rule(self): cls = Task.task_factory(name, rule, getattr(self, 'vars', []), - shell=getattr(self, 'shell', True), color=getattr(self, 'color', 'BLUE'), - scan = getattr(self, 'scan', None)) + shell=getattr(self, 'shell', True), color=getattr(self, 'color', 'BLUE')) + if getattr(self, 'scan', None): cls.scan = self.scan elif getattr(self, 'deps', None): @@ -604,8 +607,8 @@ def process_rule(self): for x in ('after', 'before', 'ext_in', 'ext_out'): setattr(cls, x, getattr(self, x, [])) - if getattr(self, 'cache_rule', 'True'): - cache[(name, self.rule)] = cls + if cache_rule: + cache[key] = cls if getattr(self, 'cls_str', None): setattr(cls, '__str__', self.cls_str)