1 | #! /usr/bin/env python |
---|
2 | # encoding: utf-8 |
---|
3 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file |
---|
4 | |
---|
5 | import copy,re,os |
---|
6 | from waflib import Task,Utils,Logs,Errors,ConfigSet,Node |
---|
7 | feats=Utils.defaultdict(set) |
---|
8 | HEADER_EXTS=['.h','.hpp','.hxx','.hh'] |
---|
9 | class task_gen(object): |
---|
10 | mappings=Utils.ordered_iter_dict() |
---|
11 | prec=Utils.defaultdict(list) |
---|
12 | def __init__(self,*k,**kw): |
---|
13 | self.source='' |
---|
14 | self.target='' |
---|
15 | self.meths=[] |
---|
16 | self.prec=Utils.defaultdict(list) |
---|
17 | self.mappings={} |
---|
18 | self.features=[] |
---|
19 | self.tasks=[] |
---|
20 | if not'bld'in kw: |
---|
21 | self.env=ConfigSet.ConfigSet() |
---|
22 | self.idx=0 |
---|
23 | self.path=None |
---|
24 | else: |
---|
25 | self.bld=kw['bld'] |
---|
26 | self.env=self.bld.env.derive() |
---|
27 | self.path=self.bld.path |
---|
28 | try: |
---|
29 | self.idx=self.bld.idx[id(self.path)]=self.bld.idx.get(id(self.path),0)+1 |
---|
30 | except AttributeError: |
---|
31 | self.bld.idx={} |
---|
32 | self.idx=self.bld.idx[id(self.path)]=1 |
---|
33 | for key,val in kw.items(): |
---|
34 | setattr(self,key,val) |
---|
35 | def __str__(self): |
---|
36 | return"<task_gen %r declared in %s>"%(self.name,self.path.abspath()) |
---|
37 | def __repr__(self): |
---|
38 | lst=[] |
---|
39 | for x in self.__dict__.keys(): |
---|
40 | if x not in('env','bld','compiled_tasks','tasks'): |
---|
41 | lst.append("%s=%s"%(x,repr(getattr(self,x)))) |
---|
42 | return"bld(%s) in %s"%(", ".join(lst),self.path.abspath()) |
---|
43 | def get_name(self): |
---|
44 | try: |
---|
45 | return self._name |
---|
46 | except AttributeError: |
---|
47 | if isinstance(self.target,list): |
---|
48 | lst=[str(x)for x in self.target] |
---|
49 | name=self._name=','.join(lst) |
---|
50 | else: |
---|
51 | name=self._name=str(self.target) |
---|
52 | return name |
---|
53 | def set_name(self,name): |
---|
54 | self._name=name |
---|
55 | name=property(get_name,set_name) |
---|
56 | def to_list(self,val): |
---|
57 | if isinstance(val,str):return val.split() |
---|
58 | else:return val |
---|
59 | def post(self): |
---|
60 | if getattr(self,'posted',None): |
---|
61 | return False |
---|
62 | self.posted=True |
---|
63 | keys=set(self.meths) |
---|
64 | self.features=Utils.to_list(self.features) |
---|
65 | for x in self.features+['*']: |
---|
66 | st=feats[x] |
---|
67 | if not st: |
---|
68 | if not x in Task.classes: |
---|
69 | Logs.warn('feature %r does not exist - bind at least one method to it'%x) |
---|
70 | keys.update(list(st)) |
---|
71 | prec={} |
---|
72 | prec_tbl=self.prec or task_gen.prec |
---|
73 | for x in prec_tbl: |
---|
74 | if x in keys: |
---|
75 | prec[x]=prec_tbl[x] |
---|
76 | tmp=[] |
---|
77 | for a in keys: |
---|
78 | for x in prec.values(): |
---|
79 | if a in x:break |
---|
80 | else: |
---|
81 | tmp.append(a) |
---|
82 | tmp.sort() |
---|
83 | out=[] |
---|
84 | while tmp: |
---|
85 | e=tmp.pop() |
---|
86 | if e in keys:out.append(e) |
---|
87 | try: |
---|
88 | nlst=prec[e] |
---|
89 | except KeyError: |
---|
90 | pass |
---|
91 | else: |
---|
92 | del prec[e] |
---|
93 | for x in nlst: |
---|
94 | for y in prec: |
---|
95 | if x in prec[y]: |
---|
96 | break |
---|
97 | else: |
---|
98 | tmp.append(x) |
---|
99 | if prec: |
---|
100 | raise Errors.WafError('Cycle detected in the method execution %r'%prec) |
---|
101 | out.reverse() |
---|
102 | self.meths=out |
---|
103 | Logs.debug('task_gen: posting %s %d'%(self,id(self))) |
---|
104 | for x in out: |
---|
105 | try: |
---|
106 | v=getattr(self,x) |
---|
107 | except AttributeError: |
---|
108 | raise Errors.WafError('%r is not a valid task generator method'%x) |
---|
109 | Logs.debug('task_gen: -> %s (%d)'%(x,id(self))) |
---|
110 | v() |
---|
111 | Logs.debug('task_gen: posted %s'%self.name) |
---|
112 | return True |
---|
113 | def get_hook(self,node): |
---|
114 | name=node.name |
---|
115 | if self.mappings: |
---|
116 | for k in self.mappings: |
---|
117 | if name.endswith(k): |
---|
118 | return self.mappings[k] |
---|
119 | for k in task_gen.mappings: |
---|
120 | if name.endswith(k): |
---|
121 | return task_gen.mappings[k] |
---|
122 | raise Errors.WafError("File %r has no mapping in %r (have you forgotten to load a waf tool?)"%(node,task_gen.mappings.keys())) |
---|
123 | def create_task(self,name,src=None,tgt=None,**kw): |
---|
124 | task=Task.classes[name](env=self.env.derive(),generator=self) |
---|
125 | if src: |
---|
126 | task.set_inputs(src) |
---|
127 | if tgt: |
---|
128 | task.set_outputs(tgt) |
---|
129 | task.__dict__.update(kw) |
---|
130 | self.tasks.append(task) |
---|
131 | return task |
---|
132 | def clone(self,env): |
---|
133 | newobj=self.bld() |
---|
134 | for x in self.__dict__: |
---|
135 | if x in('env','bld'): |
---|
136 | continue |
---|
137 | elif x in('path','features'): |
---|
138 | setattr(newobj,x,getattr(self,x)) |
---|
139 | else: |
---|
140 | setattr(newobj,x,copy.copy(getattr(self,x))) |
---|
141 | newobj.posted=False |
---|
142 | if isinstance(env,str): |
---|
143 | newobj.env=self.bld.all_envs[env].derive() |
---|
144 | else: |
---|
145 | newobj.env=env.derive() |
---|
146 | return newobj |
---|
147 | 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): |
---|
148 | ext_in=Utils.to_list(ext_in) |
---|
149 | ext_out=Utils.to_list(ext_out) |
---|
150 | if not name: |
---|
151 | name=rule |
---|
152 | cls=Task.task_factory(name,rule,color=color,ext_in=ext_in,ext_out=ext_out,before=before,after=after,scan=scan,shell=shell) |
---|
153 | def x_file(self,node): |
---|
154 | ext=decider and decider(self,node)or cls.ext_out |
---|
155 | if ext_in: |
---|
156 | _ext_in=ext_in[0] |
---|
157 | tsk=self.create_task(name,node) |
---|
158 | cnt=0 |
---|
159 | keys=set(self.mappings.keys())|set(self.__class__.mappings.keys()) |
---|
160 | for x in ext: |
---|
161 | k=node.change_ext(x,ext_in=_ext_in) |
---|
162 | tsk.outputs.append(k) |
---|
163 | if reentrant!=None: |
---|
164 | if cnt<int(reentrant): |
---|
165 | self.source.append(k) |
---|
166 | else: |
---|
167 | for y in keys: |
---|
168 | if k.name.endswith(y): |
---|
169 | self.source.append(k) |
---|
170 | break |
---|
171 | cnt+=1 |
---|
172 | if install_path: |
---|
173 | self.bld.install_files(install_path,tsk.outputs) |
---|
174 | return tsk |
---|
175 | for x in cls.ext_in: |
---|
176 | task_gen.mappings[x]=x_file |
---|
177 | return x_file |
---|
178 | def taskgen_method(func): |
---|
179 | setattr(task_gen,func.__name__,func) |
---|
180 | return func |
---|
181 | def feature(*k): |
---|
182 | def deco(func): |
---|
183 | setattr(task_gen,func.__name__,func) |
---|
184 | for name in k: |
---|
185 | feats[name].update([func.__name__]) |
---|
186 | return func |
---|
187 | return deco |
---|
188 | def before_method(*k): |
---|
189 | def deco(func): |
---|
190 | setattr(task_gen,func.__name__,func) |
---|
191 | for fun_name in k: |
---|
192 | if not func.__name__ in task_gen.prec[fun_name]: |
---|
193 | task_gen.prec[fun_name].append(func.__name__) |
---|
194 | return func |
---|
195 | return deco |
---|
196 | before=before_method |
---|
197 | def after_method(*k): |
---|
198 | def deco(func): |
---|
199 | setattr(task_gen,func.__name__,func) |
---|
200 | for fun_name in k: |
---|
201 | if not fun_name in task_gen.prec[func.__name__]: |
---|
202 | task_gen.prec[func.__name__].append(fun_name) |
---|
203 | return func |
---|
204 | return deco |
---|
205 | after=after_method |
---|
206 | def extension(*k): |
---|
207 | def deco(func): |
---|
208 | setattr(task_gen,func.__name__,func) |
---|
209 | for x in k: |
---|
210 | task_gen.mappings[x]=func |
---|
211 | return func |
---|
212 | return deco |
---|
213 | @taskgen_method |
---|
214 | def to_nodes(self,lst,path=None): |
---|
215 | tmp=[] |
---|
216 | path=path or self.path |
---|
217 | find=path.find_resource |
---|
218 | if isinstance(lst,Node.Node): |
---|
219 | lst=[lst] |
---|
220 | for x in Utils.to_list(lst): |
---|
221 | if isinstance(x,str): |
---|
222 | node=find(x) |
---|
223 | else: |
---|
224 | node=x |
---|
225 | if not node: |
---|
226 | raise Errors.WafError("source not found: %r in %r"%(x,self)) |
---|
227 | tmp.append(node) |
---|
228 | return tmp |
---|
229 | @feature('*') |
---|
230 | def process_source(self): |
---|
231 | self.source=self.to_nodes(getattr(self,'source',[])) |
---|
232 | for node in self.source: |
---|
233 | self.get_hook(node)(self,node) |
---|
234 | @feature('*') |
---|
235 | @before_method('process_source') |
---|
236 | def process_rule(self): |
---|
237 | if not getattr(self,'rule',None): |
---|
238 | return |
---|
239 | name=str(getattr(self,'name',None)or self.target or getattr(self.rule,'__name__',self.rule)) |
---|
240 | try: |
---|
241 | cache=self.bld.cache_rule_attr |
---|
242 | except AttributeError: |
---|
243 | cache=self.bld.cache_rule_attr={} |
---|
244 | cls=None |
---|
245 | if getattr(self,'cache_rule','True'): |
---|
246 | try: |
---|
247 | cls=cache[(name,self.rule)] |
---|
248 | except KeyError: |
---|
249 | pass |
---|
250 | if not cls: |
---|
251 | 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)) |
---|
252 | if getattr(self,'scan',None): |
---|
253 | cls.scan=self.scan |
---|
254 | elif getattr(self,'deps',None): |
---|
255 | def scan(self): |
---|
256 | nodes=[] |
---|
257 | for x in self.generator.to_list(getattr(self.generator,'deps',None)): |
---|
258 | node=self.generator.path.find_resource(x) |
---|
259 | if not node: |
---|
260 | self.generator.bld.fatal('Could not find %r (was it declared?)'%x) |
---|
261 | nodes.append(node) |
---|
262 | return[nodes,[]] |
---|
263 | cls.scan=scan |
---|
264 | if getattr(self,'update_outputs',None): |
---|
265 | Task.update_outputs(cls) |
---|
266 | if getattr(self,'always',None): |
---|
267 | Task.always_run(cls) |
---|
268 | for x in('after','before','ext_in','ext_out'): |
---|
269 | setattr(cls,x,getattr(self,x,[])) |
---|
270 | if getattr(self,'cache_rule','True'): |
---|
271 | cache[(name,self.rule)]=cls |
---|
272 | tsk=self.create_task(name) |
---|
273 | if getattr(self,'target',None): |
---|
274 | if isinstance(self.target,str): |
---|
275 | self.target=self.target.split() |
---|
276 | if not isinstance(self.target,list): |
---|
277 | self.target=[self.target] |
---|
278 | for x in self.target: |
---|
279 | if isinstance(x,str): |
---|
280 | tsk.outputs.append(self.path.find_or_declare(x)) |
---|
281 | else: |
---|
282 | x.parent.mkdir() |
---|
283 | tsk.outputs.append(x) |
---|
284 | if getattr(self,'install_path',None): |
---|
285 | self.bld.install_files(self.install_path,tsk.outputs) |
---|
286 | if getattr(self,'source',None): |
---|
287 | tsk.inputs=self.to_nodes(self.source) |
---|
288 | self.source=[] |
---|
289 | if getattr(self,'cwd',None): |
---|
290 | tsk.cwd=self.cwd |
---|
291 | @feature('seq') |
---|
292 | def sequence_order(self): |
---|
293 | if self.meths and self.meths[-1]!='sequence_order': |
---|
294 | self.meths.append('sequence_order') |
---|
295 | return |
---|
296 | if getattr(self,'seq_start',None): |
---|
297 | return |
---|
298 | if getattr(self.bld,'prev',None): |
---|
299 | self.bld.prev.post() |
---|
300 | for x in self.bld.prev.tasks: |
---|
301 | for y in self.tasks: |
---|
302 | y.set_run_after(x) |
---|
303 | self.bld.prev=self |
---|
304 | re_m4=re.compile('@(\w+)@',re.M) |
---|
305 | class subst_pc(Task.Task): |
---|
306 | def run(self): |
---|
307 | if getattr(self.generator,'is_copy',None): |
---|
308 | self.outputs[0].write(self.inputs[0].read('rb'),'wb') |
---|
309 | if getattr(self.generator,'chmod',None): |
---|
310 | os.chmod(self.outputs[0].abspath(),self.generator.chmod) |
---|
311 | return None |
---|
312 | if getattr(self.generator,'fun',None): |
---|
313 | return self.generator.fun(self) |
---|
314 | code=self.inputs[0].read(encoding=getattr(self.generator,'encoding','ISO8859-1')) |
---|
315 | if getattr(self.generator,'subst_fun',None): |
---|
316 | code=self.generator.subst_fun(self,code) |
---|
317 | if code is not None: |
---|
318 | self.outputs[0].write(code,encoding=getattr(self.generator,'encoding','ISO8859-1')) |
---|
319 | return |
---|
320 | code=code.replace('%','%%') |
---|
321 | lst=[] |
---|
322 | def repl(match): |
---|
323 | g=match.group |
---|
324 | if g(1): |
---|
325 | lst.append(g(1)) |
---|
326 | return"%%(%s)s"%g(1) |
---|
327 | return'' |
---|
328 | global re_m4 |
---|
329 | code=getattr(self.generator,'re_m4',re_m4).sub(repl,code) |
---|
330 | try: |
---|
331 | d=self.generator.dct |
---|
332 | except AttributeError: |
---|
333 | d={} |
---|
334 | for x in lst: |
---|
335 | tmp=getattr(self.generator,x,'')or self.env[x]or self.env[x.upper()] |
---|
336 | try: |
---|
337 | tmp=''.join(tmp) |
---|
338 | except TypeError: |
---|
339 | tmp=str(tmp) |
---|
340 | d[x]=tmp |
---|
341 | code=code%d |
---|
342 | self.outputs[0].write(code,encoding=getattr(self.generator,'encoding','ISO8859-1')) |
---|
343 | self.generator.bld.raw_deps[self.uid()]=self.dep_vars=lst |
---|
344 | try:delattr(self,'cache_sig') |
---|
345 | except AttributeError:pass |
---|
346 | if getattr(self.generator,'chmod',None): |
---|
347 | os.chmod(self.outputs[0].abspath(),self.generator.chmod) |
---|
348 | def sig_vars(self): |
---|
349 | bld=self.generator.bld |
---|
350 | env=self.env |
---|
351 | upd=self.m.update |
---|
352 | if getattr(self.generator,'fun',None): |
---|
353 | upd(Utils.h_fun(self.generator.fun)) |
---|
354 | if getattr(self.generator,'subst_fun',None): |
---|
355 | upd(Utils.h_fun(self.generator.subst_fun)) |
---|
356 | vars=self.generator.bld.raw_deps.get(self.uid(),[]) |
---|
357 | act_sig=bld.hash_env_vars(env,vars) |
---|
358 | upd(act_sig) |
---|
359 | lst=[getattr(self.generator,x,'')for x in vars] |
---|
360 | upd(Utils.h_list(lst)) |
---|
361 | return self.m.digest() |
---|
362 | @extension('.pc.in') |
---|
363 | def add_pcfile(self,node): |
---|
364 | tsk=self.create_task('subst_pc',node,node.change_ext('.pc','.pc.in')) |
---|
365 | self.bld.install_files(getattr(self,'install_path','${LIBDIR}/pkgconfig/'),tsk.outputs) |
---|
366 | class subst(subst_pc): |
---|
367 | pass |
---|
368 | @feature('subst') |
---|
369 | @before_method('process_source','process_rule') |
---|
370 | def process_subst(self): |
---|
371 | src=Utils.to_list(getattr(self,'source',[])) |
---|
372 | if isinstance(src,Node.Node): |
---|
373 | src=[src] |
---|
374 | tgt=Utils.to_list(getattr(self,'target',[])) |
---|
375 | if isinstance(tgt,Node.Node): |
---|
376 | tgt=[tgt] |
---|
377 | if len(src)!=len(tgt): |
---|
378 | raise Errors.WafError('invalid number of source/target for %r'%self) |
---|
379 | for x,y in zip(src,tgt): |
---|
380 | if not x or not y: |
---|
381 | raise Errors.WafError('null source or target for %r'%self) |
---|
382 | a,b=None,None |
---|
383 | if isinstance(x,str)and isinstance(y,str)and x==y: |
---|
384 | a=self.path.find_node(x) |
---|
385 | b=self.path.get_bld().make_node(y) |
---|
386 | if not os.path.isfile(b.abspath()): |
---|
387 | b.sig=None |
---|
388 | b.parent.mkdir() |
---|
389 | else: |
---|
390 | if isinstance(x,str): |
---|
391 | a=self.path.find_resource(x) |
---|
392 | elif isinstance(x,Node.Node): |
---|
393 | a=x |
---|
394 | if isinstance(y,str): |
---|
395 | b=self.path.find_or_declare(y) |
---|
396 | elif isinstance(y,Node.Node): |
---|
397 | b=y |
---|
398 | if not a: |
---|
399 | raise Errors.WafError('cound not find %r for %r'%(x,self)) |
---|
400 | has_constraints=False |
---|
401 | tsk=self.create_task('subst',a,b) |
---|
402 | for k in('after','before','ext_in','ext_out'): |
---|
403 | val=getattr(self,k,None) |
---|
404 | if val: |
---|
405 | has_constraints=True |
---|
406 | setattr(tsk,k,val) |
---|
407 | if not has_constraints: |
---|
408 | global HEADER_EXTS |
---|
409 | for xt in HEADER_EXTS: |
---|
410 | if b.name.endswith(xt): |
---|
411 | tsk.before=[k for k in('c','cxx')if k in Task.classes] |
---|
412 | break |
---|
413 | inst_to=getattr(self,'install_path',None) |
---|
414 | if inst_to: |
---|
415 | self.bld.install_files(inst_to,b,chmod=getattr(self,'chmod',Utils.O644)) |
---|
416 | self.source=[] |
---|