本文整理汇总了Python中waflib.Task.task_factory方法的典型用法代码示例。如果您正苦于以下问题:Python Task.task_factory方法的具体用法?Python Task.task_factory怎么用?Python Task.task_factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类waflib.Task
的用法示例。
在下文中一共展示了Task.task_factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_rule
# 需要导入模块: from waflib import Task [as 别名]
# 或者: from waflib.Task import task_factory [as 别名]
def process_rule(self):
if not getattr(self,'rule',None):
return
name=str(getattr(self,'name',None)or self.target or self.rule)
cls=Task.task_factory(name,self.rule,getattr(self,'vars',[]),shell=getattr(self,'shell',True),color=getattr(self,'color','BLUE'))
tsk=self.create_task(name)
if getattr(self,'target',None):
if isinstance(self.target,str):
self.target=self.target.split()
if not isinstance(self.target,list):
self.target=[self.target]
for x in self.target:
if isinstance(x,str):
tsk.outputs.append(self.path.find_or_declare(x))
else:
x.parent.mkdir()
tsk.outputs.append(x)
if getattr(self,'install_path',None):
self.bld.install_files(self.install_path,tsk.outputs)
if getattr(self,'source',None):
tsk.inputs=self.to_nodes(self.source)
self.source=[]
if getattr(self,'scan',None):
cls.scan=self.scan
if getattr(self,'cwd',None):
tsk.cwd=self.cwd
if getattr(self,'update_outputs',None)or getattr(self,'on_results',None):
Task.update_outputs(cls)
if getattr(self,'always',None):
Task.always_run(cls)
for x in['after','before','ext_in','ext_out']:
setattr(cls,x,getattr(self,x,[]))
示例2: declare_chain
# 需要导入模块: from waflib import Task [as 别名]
# 或者: from waflib.Task import task_factory [as 别名]
def declare_chain(name='',rule=None,reentrant=None,color='BLUE',ext_in=[],ext_out=[],before=[],after=[],decider=None,scan=None,install_path=None,shell=False):
ext_in=Utils.to_list(ext_in)
ext_out=Utils.to_list(ext_out)
if not name:
name=rule
cls=Task.task_factory(name,rule,color=color,ext_in=ext_in,ext_out=ext_out,before=before,after=after,scan=scan,shell=shell)
def x_file(self,node):
ext=decider and decider(self,node)or cls.ext_out
if ext_in:
_ext_in=ext_in[0]
tsk=self.create_task(name,node)
cnt=0
keys=set(self.mappings.keys())|set(self.__class__.mappings.keys())
for x in ext:
k=node.change_ext(x,ext_in=_ext_in)
tsk.outputs.append(k)
if reentrant!=None:
if cnt<int(reentrant):
self.source.append(k)
else:
for y in keys:
if k.name.endswith(y):
self.source.append(k)
break
cnt+=1
if install_path:
self.bld.install_files(install_path,tsk.outputs)
return tsk
for x in cls.ext_in:
task_gen.mappings[x]=x_file
return x_file
示例3: declare_chain
# 需要导入模块: from waflib import Task [as 别名]
# 或者: from waflib.Task import task_factory [as 别名]
def declare_chain(
name="",
rule=None,
reentrant=True,
color="BLUE",
ext_in=[],
ext_out=[],
before=[],
after=[],
decider=None,
scan=None,
):
ext_in = Utils.to_list(ext_in)
ext_out = Utils.to_list(ext_out)
cls = Task.task_factory(
name, rule, color=color, ext_in=ext_in, ext_out=ext_out, before=before, after=after, scan=scan
)
def x_file(self, node):
ext = decider and decider(self, node) or cls.ext_out
if ext_in:
_ext_in = ext_in[0]
out_source = [node.change_ext(x, ext_in=_ext_in) for x in ext]
if reentrant:
for i in range(reentrant):
self.source.append(out_source[i])
tsk = self.create_task(name, node, out_source)
for x in cls.ext_in:
task_gen.mappings[x] = x_file
return x_file
示例4: process_rule
# 需要导入模块: from waflib import Task [as 别名]
# 或者: from waflib.Task import task_factory [as 别名]
def process_rule(self):
if not getattr(self,'rule',None):
return
name=str(getattr(self,'name',None)or self.target or getattr(self.rule,'__name__',self.rule))
try:
cache=self.bld.cache_rule_attr
except AttributeError:
cache=self.bld.cache_rule_attr={}
cls=None
if getattr(self,'cache_rule','True'):
try:
cls=cache[(name,self.rule)]
except KeyError:
pass
if not cls:
cls=Task.task_factory(name,self.rule,getattr(self,'vars',[]),shell=getattr(self,'shell',True),color=getattr(self,'color','BLUE'),scan=getattr(self,'scan',None))
if getattr(self,'scan',None):
cls.scan=self.scan
elif getattr(self,'deps',None):
def scan(self):
nodes=[]
for x in self.generator.to_list(getattr(self.generator,'deps',None)):
node=self.generator.path.find_resource(x)
if not node:
self.generator.bld.fatal('Could not find %r (was it declared?)'%x)
nodes.append(node)
return[nodes,[]]
cls.scan=scan
if getattr(self,'update_outputs',None):
Task.update_outputs(cls)
if getattr(self,'always',None):
Task.always_run(cls)
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 getattr(self,'cls_str',None):
setattr(cls,'__str__',self.cls_str)
if getattr(self,'cls_keyword',None):
setattr(cls,'keyword',self.cls_keyword)
tsk=self.create_task(name)
if getattr(self,'target',None):
if isinstance(self.target,str):
self.target=self.target.split()
if not isinstance(self.target,list):
self.target=[self.target]
for x in self.target:
if isinstance(x,str):
tsk.outputs.append(self.path.find_or_declare(x))
else:
x.parent.mkdir()
tsk.outputs.append(x)
if getattr(self,'install_path',None):
self.bld.install_files(self.install_path,tsk.outputs)
if getattr(self,'source',None):
tsk.inputs=self.to_nodes(self.source)
self.source=[]
if getattr(self,'cwd',None):
tsk.cwd=self.cwd
示例5: process_rule
# 需要导入模块: from waflib import Task [as 别名]
# 或者: from waflib.Task import task_factory [as 别名]
def process_rule(self):
"""
Process the attribute ``rule``. When present, :py:meth:`waflib.TaskGen.process_source` is disabled::
def build(bld):
bld(rule='cp ${SRC} ${TGT}', source='wscript', target='bar.txt')
"""
if not getattr(self, 'rule', None):
return
# create the task class
name = str(getattr(self, 'name', None) or self.target or self.rule)
cls = Task.task_factory(name, self.rule,
getattr(self, 'vars', []),
shell=getattr(self, 'shell', True), color=getattr(self, 'color', 'BLUE'))
# now create one instance
tsk = self.create_task(name)
if getattr(self, 'target', None):
if isinstance(self.target, str):
self.target = self.target.split()
if not isinstance(self.target, list):
self.target = [self.target]
for x in self.target:
if isinstance(x, str):
tsk.outputs.append(self.path.find_or_declare(x))
else:
x.parent.mkdir() # if a node was given, create the required folders
tsk.outputs.append(x)
if getattr(self, 'install_path', None):
# from waf 1.5
# although convenient, it does not 1. allow to name the target file and 2. symlinks
# TODO remove in waf 1.7
self.bld.install_files(self.install_path, tsk.outputs)
if getattr(self, 'source', None):
tsk.inputs = self.to_nodes(self.source)
# bypass the execution of process_source by setting the source to an empty list
self.source = []
if getattr(self, 'scan', None):
cls.scan = self.scan
if getattr(self, 'cwd', None):
tsk.cwd = self.cwd
# TODO remove on_results in waf 1.7
if getattr(self, 'update_outputs', None) or getattr(self, 'on_results', None):
Task.update_outputs(cls)
if getattr(self, 'always', None):
Task.always_run(cls)
for x in ['after', 'before', 'ext_in', 'ext_out']:
setattr(cls, x, getattr(self, x, []))
示例6: declare_chain
# 需要导入模块: from waflib import Task [as 别名]
# 或者: from waflib.Task import task_factory [as 别名]
def declare_chain(name='', rule=None, reentrant=True, color='BLUE',
ext_in=[], ext_out=[], before=[], after=[], decider=None, scan=None, install_path=None, shell=False):
"""
Create a new mapping and a task class for processing files by extension.
See Tools/flex.py for an example.
:param name: name for the task class
:type name: string
:param rule: function to execute or string to be compiled in a function
:type rule: string or function
:param reentrant: re-inject the output file in the process
:type reentrant: bool
:param color: color for the task output
:type color: string
:param ext_in: execute the task only after the files of such extensions are created
:type ext_in: list of string
:param ext_out: execute the task only before files of such extensions are processed
:type ext_out: list of string
:param before: execute instances of this task before classes of the given names
:type before: list of string
:param after: execute instances of this task after classes of the given names
:type after: list of string
:param decider: if present, use it to create the output nodes for the task
:type decider: function
:param scan: scanner function for the task
:type scan: function
:param install_path: installation path for the output nodes
:type install_path: string
"""
ext_in = Utils.to_list(ext_in)
ext_out = Utils.to_list(ext_out)
if not name:
name = rule
cls = Task.task_factory(name, rule, color=color, ext_in=ext_in, ext_out=ext_out, before=before, after=after, scan=scan, shell=shell)
def x_file(self, node):
ext = decider and decider(self, node) or cls.ext_out
if ext_in:
_ext_in = ext_in[0]
out_source = [node.change_ext(x, ext_in=_ext_in) for x in ext]
if reentrant:
for i in range(reentrant):
self.source.append(out_source[i])
tsk = self.create_task(name, node, out_source)
if install_path:
self.bld.install_files(install_path, out_source)
return tsk
for x in cls.ext_in:
task_gen.mappings[x] = x_file
return x_file
示例7: declare_chain
# 需要导入模块: from waflib import Task [as 别名]
# 或者: from waflib.Task import task_factory [as 别名]
def declare_chain(name='', rule=None, reentrant=True, color='BLUE',
ext_in=[], ext_out=[], before=[], after=[], decider=None, scan=None):
"""
see Tools/flex.py for an example
while i do not like such wrappers, some people really do
"""
cls = Task.task_factory(name, rule, color=color, ext_in=ext_in, ext_out=ext_out, before=before, after=after, scan=scan)
def x_file(self, node):
ext = decider and decider(self, node) or cls.ext_out
out_source = [node.change_ext(x) for x in ext]
if reentrant:
for i in range(reentrant):
self.source.append(out_source[i])
tsk = self.create_task(name, node, out_source)
for x in cls.ext_in:
task_gen.mappings[x] = x_file
return x_file
示例8: declare_chain
# 需要导入模块: from waflib import Task [as 别名]
# 或者: from waflib.Task import task_factory [as 别名]
def declare_chain(name='',rule=None,reentrant=True,color='BLUE',ext_in=[],ext_out=[],before=[],after=[],decider=None,scan=None,install_path=None,shell=False):
ext_in=Utils.to_list(ext_in)
ext_out=Utils.to_list(ext_out)
if not name:
name=rule
cls=Task.task_factory(name,rule,color=color,ext_in=ext_in,ext_out=ext_out,before=before,after=after,scan=scan,shell=shell)
def x_file(self,node):
ext=decider and decider(self,node)or cls.ext_out
if ext_in:
_ext_in=ext_in[0]
out_source=[node.change_ext(x,ext_in=_ext_in)for x in ext]
if reentrant:
for i in range(reentrant):
self.source.append(out_source[i])
tsk=self.create_task(name,node,out_source)
if install_path:
self.bld.install_files(install_path,out_source)
return tsk
for x in cls.ext_in:
task_gen.mappings[x]=x_file
return x_file
示例9: process_rule
# 需要导入模块: from waflib import Task [as 别名]
# 或者: from waflib.Task import task_factory [as 别名]
def process_rule(self):
if not getattr(self, "rule", None):
return
name = str(getattr(self, "name", None) or self.target or self.rule)
cls = Task.task_factory(
name,
self.rule,
getattr(self, "vars", []),
shell=getattr(self, "shell", True),
color=getattr(self, "color", "BLUE"),
)
tsk = self.create_task(name)
if getattr(self, "target", None):
if isinstance(self.target, str):
self.target = self.target.split()
if not isinstance(self.target, list):
self.target = [self.target]
for x in self.target:
if isinstance(x, str):
tsk.outputs.append(self.path.find_or_declare(x))
else:
x.parent.mkdir()
tsk.outputs.append(x)
if getattr(self, "install_path", None):
self.bld.install_files(self.install_path, tsk.outputs)
if getattr(self, "source", None):
tsk.inputs = self.to_nodes(self.source)
self.source = []
if getattr(self, "scan", None):
cls.scan = self.scan
if getattr(self, "cwd", None):
tsk.cwd = self.cwd
if getattr(self, "update_outputs", None) or getattr(self, "on_results", None):
Task.update_outputs(cls)
if getattr(self, "always", None):
Task.always_run(cls)
for x in ["after", "before", "ext_in", "ext_out"]:
setattr(cls, x, getattr(self, x, []))
示例10: post_run_bison
# 需要导入模块: from waflib import Task [as 别名]
# 或者: from waflib.Task import task_factory [as 别名]
#!/usr/bin/env python
# encoding: utf-8
# John O'Meara, 2006
# Thomas Nagy 2009
"Bison processing"
from waflib import Task,TaskGen
import os
bison = '${BISON} ${BISONFLAGS} ${SRC[0].abspath()} -o ${TGT[0].name}'
cls = Task.task_factory('bison', bison, color='GREEN', ext_in=['.yc', '.y', '.yy'], ext_out='.cxx .h', before='c cxx flex')
def post_run_bison(task):
source = task.outputs[0]
header = task.outputs[1]
env = task.env
try:
os.stat(header.abspath())
except OSError:
try:
oldheader = source.change_ext(source.suffix()+'.h')
os.rename(oldheader.abspath(), header.abspath())
except OSError:
pass
task.post_run_orig()
cls.post_run_orig = cls.post_run
cls.post_run = post_run_bison
@TaskGen.extension('.y', '.yc', '.yy')
示例11: process_rule
# 需要导入模块: from waflib import Task [as 别名]
# 或者: from waflib.Task import task_factory [as 别名]
def process_rule(self):
"""
Process the attribute ``rule``. When present, :py:meth:`waflib.TaskGen.process_source` is disabled::
def build(bld):
bld(rule='cp ${SRC} ${TGT}', source='wscript', target='bar.txt')
"""
if not getattr(self, 'rule', None):
return
# create the task class
name = str(getattr(self, 'name', None) or self.target or self.rule)
# or we can put the class in a cache for performance reasons
try:
cache = self.bld.cache_rule_attr
except AttributeError:
cache = self.bld.cache_rule_attr = {}
cls = None
if getattr(self, 'cache_rule', 'True'):
try:
cls = cache[(name, self.rule)]
except KeyError:
pass
if not cls:
cls = Task.task_factory(name, self.rule,
getattr(self, 'vars', []),
shell=getattr(self, 'shell', True), color=getattr(self, 'color', 'BLUE'),
scan = getattr(self, 'scan', None))
if getattr(self, 'scan', None):
cls.scan = self.scan
elif getattr(self, 'deps', None):
def scan(self):
nodes = []
for x in self.generator.to_list(getattr(self.generator, 'deps', None)):
node = self.generator.path.find_resource(x)
if not node:
self.generator.bld.fatal('Could not find %r (was it declared?)' % x)
nodes.append(node)
return [nodes, []]
cls.scan = scan
if getattr(self, 'update_outputs', None):
Task.update_outputs(cls)
if getattr(self, 'always', None):
Task.always_run(cls)
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
# now create one instance
tsk = self.create_task(name)
if getattr(self, 'target', None):
if isinstance(self.target, str):
self.target = self.target.split()
if not isinstance(self.target, list):
self.target = [self.target]
for x in self.target:
if isinstance(x, str):
tsk.outputs.append(self.path.find_or_declare(x))
else:
x.parent.mkdir() # if a node was given, create the required folders
tsk.outputs.append(x)
if getattr(self, 'install_path', None):
# from waf 1.5
# although convenient, it does not 1. allow to name the target file and 2. symlinks
# TODO remove in waf 1.7
self.bld.install_files(self.install_path, tsk.outputs)
if getattr(self, 'source', None):
tsk.inputs = self.to_nodes(self.source)
# bypass the execution of process_source by setting the source to an empty list
self.source = []
if getattr(self, 'cwd', None):
tsk.cwd = self.cwd
示例12: declare_chain
# 需要导入模块: from waflib import Task [as 别名]
# 或者: from waflib.Task import task_factory [as 别名]
def declare_chain(name='', rule=None, reentrant=None, color='BLUE',
ext_in=[], ext_out=[], before=[], after=[], decider=None, scan=None, install_path=None, shell=False):
"""
Create a new mapping and a task class for processing files by extension.
See Tools/flex.py for an example.
:param name: name for the task class
:type name: string
:param rule: function to execute or string to be compiled in a function
:type rule: string or function
:param reentrant: re-inject the output file in the process (done automatically, set to 0 to disable)
:type reentrant: int
:param color: color for the task output
:type color: string
:param ext_in: execute the task only after the files of such extensions are created
:type ext_in: list of string
:param ext_out: execute the task only before files of such extensions are processed
:type ext_out: list of string
:param before: execute instances of this task before classes of the given names
:type before: list of string
:param after: execute instances of this task after classes of the given names
:type after: list of string
:param decider: if present, use it to create the output nodes for the task
:type decider: function
:param scan: scanner function for the task
:type scan: function
:param install_path: installation path for the output nodes
:type install_path: string
"""
ext_in = Utils.to_list(ext_in)
ext_out = Utils.to_list(ext_out)
if not name:
name = rule
cls = Task.task_factory(name, rule, color=color, ext_in=ext_in, ext_out=ext_out, before=before, after=after, scan=scan, shell=shell)
def x_file(self, node):
ext = decider and decider(self, node) or cls.ext_out
if ext_in:
_ext_in = ext_in[0]
tsk = self.create_task(name, node)
cnt = 0
keys = list(self.mappings.keys()) + list(self.__class__.mappings.keys())
for x in ext:
k = node.change_ext(x, ext_in=_ext_in)
tsk.outputs.append(k)
if reentrant != None:
if cnt < int(reentrant):
self.source.append(k)
else:
for y in keys: # ~ nfile * nextensions :-/
if k.name.endswith(y):
self.source.append(k)
break
cnt += 1
if install_path:
self.bld.install_files(install_path, tsk.outputs)
return tsk
for x in cls.ext_in:
task_gen.mappings[x] = x_file
return x_file
示例13: process_rule
# 需要导入模块: from waflib import Task [as 别名]
# 或者: from waflib.Task import task_factory [as 别名]
def process_rule(self):
"""
Processes the attribute ``rule``. When present, :py:meth:`waflib.TaskGen.process_source` is disabled::
def build(bld):
bld(rule='cp ${SRC} ${TGT}', source='wscript', target='bar.txt')
"""
if not getattr(self, 'rule', None):
return
# create the task class
name = str(getattr(self, 'name', None) or self.target or getattr(self.rule, '__name__', self.rule))
# or we can put the class in a cache for performance reasons
try:
cache = self.bld.cache_rule_attr
except AttributeError:
cache = self.bld.cache_rule_attr = {}
cls = None
if getattr(self, 'cache_rule', 'True'):
try:
cls = cache[(name, self.rule)]
except KeyError:
pass
if not cls:
rule = self.rule
if hasattr(self, 'chmod'):
def chmod_fun(tsk):
for x in tsk.outputs:
os.chmod(x.abspath(), self.chmod)
rule = (self.rule, chmod_fun)
cls = Task.task_factory(name, rule,
getattr(self, 'vars', []),
shell=getattr(self, 'shell', True), color=getattr(self, 'color', 'BLUE'),
scan = getattr(self, 'scan', None))
if getattr(self, 'scan', None):
cls.scan = self.scan
elif getattr(self, 'deps', None):
def scan(self):
nodes = []
for x in self.generator.to_list(getattr(self.generator, 'deps', None)):
node = self.generator.path.find_resource(x)
if not node:
self.generator.bld.fatal('Could not find %r (was it declared?)' % x)
nodes.append(node)
return [nodes, []]
cls.scan = scan
if getattr(self, 'always', None):
cls.always_run = True
if getattr(self, 'timeout', None):
cls.timeout = self.timeout
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 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, 'target', None):
if isinstance(self.target, str):
self.target = self.target.split()
if not isinstance(self.target, list):
self.target = [self.target]
for x in self.target:
if isinstance(x, str):
tsk.outputs.append(self.path.find_or_declare(x))
else:
x.parent.mkdir() # if a node was given, create the required folders
tsk.outputs.append(x)
if getattr(self, 'install_path', None):
self.install_task = self.add_install_files(install_to=self.install_path,
install_from=tsk.outputs, chmod=getattr(self, 'chmod', Utils.O644))
if getattr(self, 'source', None):
tsk.inputs = self.to_nodes(self.source)
# bypass the execution of process_source by setting the source to an empty list
self.source = []
if getattr(self, 'cwd', None):
tsk.cwd = self.cwd
if isinstance(tsk.run, functools.partial):
# Python documentation says: "partial objects defined in classes
# behave like static methods and do not transform into bound
# methods during instance attribute look-up."
tsk.run = functools.partial(tsk.run, tsk)
示例14: open
# 需要导入模块: from waflib import Task [as 别名]
# 或者: from waflib.Task import task_factory [as 别名]
outf = None
output = None
try:
input = open(infile, 'rb')
outf = open(outfile, 'wb')
output = gzip.GzipFile(os.path.basename(infile), fileobj=outf)
output.write(input.read())
finally:
if input:
input.close()
if output: # Must close before outf to flush compressed data.
output.close()
if outf:
outf.close()
Task.task_factory('man', gzip_func, color='BLUE')
@feature('man')
@before_method('process_source')
def process_man(self):
source = self.to_nodes(getattr(self, 'source', []))
target = getattr(self, 'target', None)
self.source = []
section = getattr(self, 'section', None)
for node in source:
if not node:
raise Errors.BuildError('cannot find input file %s for processing' % x)
# s = section or node.name.rpartition('.')[2]
示例15: process_rule
# 需要导入模块: from waflib import Task [as 别名]
# 或者: from waflib.Task import task_factory [as 别名]
def process_rule(self):
"""
Processes the attribute ``rule``. When present, :py:meth:`waflib.TaskGen.process_source` is disabled::
def build(bld):
bld(rule='cp ${SRC} ${TGT}', source='wscript', target='bar.txt')
Main attributes processed:
* rule: command to execute, it can be a tuple of strings for multiple commands
* chmod: permissions for the resulting files (integer value such as Utils.O755)
* shell: set to False to execute the command directly (default is True to use a shell)
* scan: scanner function
* vars: list of variables to trigger rebuilds, such as CFLAGS
* cls_str: string to display when executing the task
* cls_keyword: label to display when executing the task
* cache_rule: by default, try to re-use similar classes, set to False to disable
* source: list of Node or string objects representing the source files required by this task
* target: list of Node or string objects representing the files that this task creates
* cwd: current working directory (Node or string)
* stdout: standard output, set to None to prevent waf from capturing the text
* stderr: standard error, set to None to prevent waf from capturing the text
* timeout: timeout for command execution (Python 3)
* always: whether to always run the command (False by default)
* deep_inputs: whether the task must depend on the input file tasks too (False by default)
"""
if not getattr(self, 'rule', None):
return
# create the task class
name = str(getattr(self, 'name', None) or self.target or getattr(self.rule, '__name__', self.rule))
# or we can put the class in a cache for performance reasons
try:
cache = self.bld.cache_rule_attr
except AttributeError:
cache = self.bld.cache_rule_attr = {}
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')
deep_inputs = getattr(self, 'deep_inputs', False)
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, deep_inputs))
cls = None
if use_cache:
try:
cls = cache[key]
except KeyError:
pass
if not cls:
rule = self.rule
if chmod is not None:
def chmod_fun(tsk):
for x in tsk.outputs:
os.chmod(x.abspath(), tsk.generator.chmod)
if isinstance(rule, tuple):
rule = list(rule)
rule.append(chmod_fun)
rule = tuple(rule)
else:
rule = (rule, chmod_fun)
cls = Task.task_factory(name, rule, _vars, shell=shell, color=color)
if cls_str:
setattr(cls, '__str__', self.cls_str)
if cls_keyword:
setattr(cls, 'keyword', self.cls_keyword)
if deep_inputs:
Task.deep_inputs(cls)
if scan:
cls.scan = self.scan
elif has_deps:
def scan(self):
nodes = []
for x in self.generator.to_list(getattr(self.generator, 'deps', None)):
node = self.generator.path.find_resource(x)
if not node:
self.generator.bld.fatal('Could not find %r (was it declared?)' % x)
nodes.append(node)
return [nodes, []]
cls.scan = scan
if use_cache:
cache[key] = cls
#.........这里部分代码省略.........