Changeset 904702d for waflib/Task.py
- Timestamp:
- Mar 14, 2015, 6:06:10 PM (10 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- 6d7acc8
- Parents:
- 5525507
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waflib/Task.py
r5525507 r904702d 3 3 # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file 4 4 5 import os, shutil,re,tempfile5 import os,re,sys 6 6 from waflib import Utils,Logs,Errors 7 7 NOT_RUN=0 … … 38 38 return tsk.exec_command(lst, cwd=wd, env=env.env or None) 39 39 ''' 40 def cache_outputs(cls):41 m1=cls.run42 def run(self):43 bld=self.generator.bld44 if bld.cache_global and not bld.nocache:45 if self.can_retrieve_cache():46 return 047 return m1(self)48 cls.run=run49 m2=cls.post_run50 def post_run(self):51 bld=self.generator.bld52 ret=m2(self)53 if bld.cache_global and not bld.nocache:54 self.put_files_cache()55 return ret56 cls.post_run=post_run57 return cls58 40 classes={} 59 41 class store_task_type(type): … … 68 50 (f,dvars)=compile_fun(cls.run_str,cls.shell) 69 51 cls.hcode=cls.run_str 52 cls.orig_run_str=cls.run_str 70 53 cls.run_str=None 71 54 cls.run=f … … 74 57 elif getattr(cls,'run',None)and not'hcode'in cls.__dict__: 75 58 cls.hcode=Utils.h_fun(cls.run) 76 if not getattr(cls,'nocache',None):77 cls =cache_outputs(cls)59 if sys.hexversion>0x3000000: 60 cls.hcode=cls.hcode.encode('iso8859-1','xmlcharrefreplace') 78 61 getattr(cls,'register',classes)[name]=cls 79 62 evil=store_task_type('evil',(object,),{}) … … 95 78 def __str__(self): 96 79 if hasattr(self,'fun'): 97 return 'executing: %s\n'%self.fun.__name__98 return self.__class__.__name__ +'\n'80 return self.fun.__name__ 81 return self.__class__.__name__ 99 82 def __hash__(self): 100 83 return id(self) 84 def keyword(self): 85 if hasattr(self,'fun'): 86 return'Function' 87 return'Processing' 101 88 def exec_command(self,cmd,**kw): 102 89 bld=self.generator.bld … … 151 138 pass 152 139 def log_display(self,bld): 153 bld.to_log(self.display()) 140 if self.generator.bld.progress_bar==3: 141 return 142 s=self.display() 143 if s: 144 if bld.logger: 145 logger=bld.logger 146 else: 147 logger=Logs 148 if self.generator.bld.progress_bar==1: 149 c1=Logs.colors.cursor_off 150 c2=Logs.colors.cursor_on 151 logger.info(s,extra={'stream':sys.stderr,'terminator':'','c1':c1,'c2':c2}) 152 else: 153 logger.info(s,extra={'terminator':'','c1':'','c2':''}) 154 154 def display(self): 155 155 col1=Logs.colors(self.color) … … 179 179 total=master.total 180 180 n=len(str(total)) 181 fs='[%%%dd/%%%dd] %%s%%s%%s'%(n,n) 182 return fs%(cur(),total,col1,s,col2) 181 fs='[%%%dd/%%%dd] %%s%%s%%s%%s\n'%(n,n) 182 kw=self.keyword() 183 if kw: 184 kw+=' ' 185 return fs%(cur(),total,kw,col1,s,col2) 183 186 def attr(self,att,default=None): 184 187 ret=getattr(self,att,self) … … 208 211 def colon(self,var1,var2): 209 212 tmp=self.env[var1] 213 if not tmp: 214 return[] 210 215 if isinstance(var2,str): 211 216 it=self.env[var2] … … 215 220 return[tmp%x for x in it] 216 221 else: 217 if Logs.verbose and not tmp and it:218 Logs.warn('Missing env variable %r for task %r (generator %r)'%(var1,self,self.generator))219 222 lst=[] 220 223 for y in it: … … 233 236 self.run_after=set([]) 234 237 def __str__(self): 235 env=self.env 236 src_str=' '.join([a.nice_path()for a in self.inputs]) 237 tgt_str=' '.join([a.nice_path()for a in self.outputs]) 238 name=self.__class__.__name__ 239 if self.outputs: 240 if(name.endswith('lib')or name.endswith('program'))or not self.inputs: 241 node=self.outputs[0] 242 return node.path_from(node.ctx.launch_node()) 243 if not(self.inputs or self.outputs): 244 return self.__class__.__name__ 245 if len(self.inputs)==1: 246 node=self.inputs[0] 247 return node.path_from(node.ctx.launch_node()) 248 src_str=' '.join([a.path_from(a.ctx.launch_node())for a in self.inputs]) 249 tgt_str=' '.join([a.path_from(a.ctx.launch_node())for a in self.outputs]) 238 250 if self.outputs:sep=' -> ' 239 251 else:sep='' 240 return'%s: %s%s%s\n'%(self.__class__.__name__.replace('_task',''),src_str,sep,tgt_str) 252 return'%s: %s%s%s'%(self.__class__.__name__.replace('_task',''),src_str,sep,tgt_str) 253 def keyword(self): 254 name=self.__class__.__name__ 255 if name.endswith('lib')or name.endswith('program'): 256 return'Linking' 257 if len(self.inputs)==1 and len(self.outputs)==1: 258 return'Compiling' 259 if not self.inputs: 260 if self.outputs: 261 return'Creating' 262 else: 263 return'Running' 264 return'Processing' 241 265 def __repr__(self): 242 266 try: … … 362 386 if prev==self.compute_sig_implicit_deps(): 363 387 return prev 364 except Exception: 388 except Errors.TaskNotReady: 389 raise 390 except EnvironmentError: 365 391 for x in bld.node_deps.get(self.uid(),[]): 366 if x.is_child_of(bld.srcnode):392 if not x.is_bld(): 367 393 try: 368 394 os.stat(x.abspath()) … … 420 446 if not tsk.hasrun: 421 447 raise Errors.TaskNotReady('not ready') 422 def can_retrieve_cache(self): 423 if not getattr(self,'outputs',None): 424 return None 425 sig=self.signature() 426 ssig=Utils.to_hex(self.uid())+Utils.to_hex(sig) 427 dname=os.path.join(self.generator.bld.cache_global,ssig) 428 try: 429 t1=os.stat(dname).st_mtime 430 except OSError: 431 return None 432 for node in self.outputs: 433 orig=os.path.join(dname,node.name) 434 try: 435 shutil.copy2(orig,node.abspath()) 436 os.utime(orig,None) 437 except(OSError,IOError): 438 Logs.debug('task: failed retrieving file') 439 return None 440 try: 441 t2=os.stat(dname).st_mtime 442 except OSError: 443 return None 444 if t1!=t2: 445 return None 446 for node in self.outputs: 447 node.sig=sig 448 if self.generator.bld.progress_bar<1: 449 self.generator.bld.to_log('restoring from cache %r\n'%node.abspath()) 450 self.cached=True 451 return True 452 def put_files_cache(self): 453 if getattr(self,'cached',None): 454 return None 455 if not getattr(self,'outputs',None): 456 return None 457 sig=self.signature() 458 ssig=Utils.to_hex(self.uid())+Utils.to_hex(sig) 459 dname=os.path.join(self.generator.bld.cache_global,ssig) 460 tmpdir=tempfile.mkdtemp(prefix=self.generator.bld.cache_global+os.sep+'waf') 461 try: 462 shutil.rmtree(dname) 463 except Exception: 464 pass 465 try: 466 for node in self.outputs: 467 dest=os.path.join(tmpdir,node.name) 468 shutil.copy2(node.abspath(),dest) 469 except(OSError,IOError): 470 try: 471 shutil.rmtree(tmpdir) 472 except Exception: 473 pass 474 else: 475 try: 476 os.rename(tmpdir,dname) 477 except OSError: 478 try: 479 shutil.rmtree(tmpdir) 480 except Exception: 481 pass 482 else: 483 try: 484 os.chmod(dname,Utils.O755) 485 except Exception: 486 pass 448 if sys.hexversion>0x3000000: 449 def uid(self): 450 try: 451 return self.uid_ 452 except AttributeError: 453 m=Utils.md5() 454 up=m.update 455 up(self.__class__.__name__.encode('iso8859-1','xmlcharrefreplace')) 456 for x in self.inputs+self.outputs: 457 up(x.abspath().encode('iso8859-1','xmlcharrefreplace')) 458 self.uid_=m.digest() 459 return self.uid_ 460 uid.__doc__=Task.uid.__doc__ 461 Task.uid=uid 487 462 def is_before(t1,t2): 488 463 to_list=Utils.to_list … … 579 554 g=match.group 580 555 if g('dollar'):return"$" 556 elif g('backslash'):return'\\' 581 557 elif g('subst'):extr.append((g('var'),g('code')));return"<<|@|>>" 582 558 return None
Note: See TracChangeset
for help on using the changeset viewer.