mirror of https://gitlab.com/ita1024/waf.git
Improve process_rule cache accuracy
This commit is contained in:
parent
15c45b365d
commit
b95cd931fd
|
@ -558,22 +558,33 @@ def process_rule(self):
|
|||
except AttributeError:
|
||||
cache = self.bld.cache_rule_attr = {}
|
||||
|
||||
cache_rule = getattr(self, 'cache_rule', 'True')
|
||||
key = (name, self.rule)
|
||||
chmod = getattr(self, 'chmod', None)
|
||||
shell = getattr(self, 'shell', True)
|
||||
color = getattr(self, 'color', 'BLUE')
|
||||
scan = getattr(self, 'scan', None)
|
||||
_vars = getattr(self, 'vars', [])
|
||||
cls_str = getattr(self, 'cls_str', None)
|
||||
cls_keyword = getattr(self, 'cls_keyword', None)
|
||||
use_cache = getattr(self, 'cache_rule', 'True')
|
||||
|
||||
scan_val = has_deps = hasattr(self, 'deps')
|
||||
if scan:
|
||||
scan_val = id(scan)
|
||||
|
||||
key = Utils.h_list((name, self.rule, chmod, shell, color, cls_str, cls_keyword, scan_val, _vars))
|
||||
|
||||
cls = None
|
||||
if cache_rule:
|
||||
if use_cache:
|
||||
try:
|
||||
cls = cache[key]
|
||||
except KeyError:
|
||||
pass
|
||||
if not cls:
|
||||
|
||||
rule = self.rule
|
||||
if hasattr(self, 'chmod'):
|
||||
if chmod is not None:
|
||||
def chmod_fun(tsk):
|
||||
for x in tsk.outputs:
|
||||
os.chmod(x.abspath(), self.chmod)
|
||||
os.chmod(x.abspath(), tsk.generator.chmod)
|
||||
if isinstance(rule, tuple):
|
||||
rule = list(rule)
|
||||
rule.append(chmod_fun)
|
||||
|
@ -581,13 +592,17 @@ def process_rule(self):
|
|||
else:
|
||||
rule = (rule, chmod_fun)
|
||||
|
||||
cls = Task.task_factory(name, rule,
|
||||
getattr(self, 'vars', []),
|
||||
shell=getattr(self, 'shell', True), color=getattr(self, 'color', 'BLUE'))
|
||||
cls = Task.task_factory(name, rule, _vars, shell=shell, color=color)
|
||||
|
||||
if getattr(self, 'scan', None):
|
||||
if cls_str:
|
||||
setattr(cls, '__str__', self.cls_str)
|
||||
|
||||
if cls_keyword:
|
||||
setattr(cls, 'keyword', self.cls_keyword)
|
||||
|
||||
if scan:
|
||||
cls.scan = self.scan
|
||||
elif getattr(self, 'deps', None):
|
||||
elif has_deps:
|
||||
def scan(self):
|
||||
nodes = []
|
||||
for x in self.generator.to_list(getattr(self.generator, 'deps', None)):
|
||||
|
@ -598,27 +613,23 @@ def process_rule(self):
|
|||
return [nodes, []]
|
||||
cls.scan = scan
|
||||
|
||||
if getattr(self, 'always', None):
|
||||
cls.always_run = True
|
||||
|
||||
if getattr(self, 'timeout', None):
|
||||
cls.timeout = self.timeout
|
||||
|
||||
# TODO use these values in the cache key if provided
|
||||
# (may cause excessive caching)
|
||||
for x in ('after', 'before', 'ext_in', 'ext_out'):
|
||||
setattr(cls, x, getattr(self, x, []))
|
||||
|
||||
if cache_rule:
|
||||
if use_cache:
|
||||
cache[key] = cls
|
||||
|
||||
if getattr(self, 'cls_str', None):
|
||||
setattr(cls, '__str__', self.cls_str)
|
||||
|
||||
if getattr(self, 'cls_keyword', None):
|
||||
setattr(cls, 'keyword', self.cls_keyword)
|
||||
|
||||
# now create one instance
|
||||
tsk = self.create_task(name)
|
||||
|
||||
if getattr(self, 'timeout', None):
|
||||
tsk.timeout = self.timeout
|
||||
|
||||
if getattr(self, 'always', None):
|
||||
tsk.always_run = True
|
||||
|
||||
if getattr(self, 'target', None):
|
||||
if isinstance(self.target, str):
|
||||
self.target = self.target.split()
|
||||
|
|
Loading…
Reference in New Issue