3 # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
5 import os,re,sys,shutil
6 from waflib import Utils,Errors
39 return path.split('/')
40 def split_path_cygwin(path):
41 if path.startswith('//'):
42 ret=path.split('/')[2:]
45 return path.split('/')
46 re_sp=re.compile('[/\\\\]')
47 def split_path_win32(path):
48 if path.startswith('\\\\'):
49 ret=re.split(re_sp,path)[2:]
52 return re.split(re_sp,path)
53 if sys.platform=='cygwin':
54 split_path=split_path_cygwin
56 split_path=split_path_win32
58 __slots__=('name','sig','children','parent','cache_abspath','cache_isdir','cache_sig')
59 def __init__(self,name,parent):
63 if name in parent.children:
64 raise Errors.WafError('node %s exists in the parent files %r already'%(name,parent))
65 parent.children[name]=self
66 def __setstate__(self,data):
69 if data[2]is not None:
71 if data[3]is not None:
73 def __getstate__(self):
74 return(self.name,self.parent,getattr(self,'children',None),getattr(self,'sig',None))
81 def __eq__(self,node):
82 return id(self)==id(node)
84 raise Errors.WafError('nodes are not supposed to be copied')
85 def read(self,flags='r',encoding='ISO8859-1'):
86 return Utils.readf(self.abspath(),flags,encoding)
87 def write(self,data,flags='w',encoding='ISO8859-1'):
88 Utils.writef(self.abspath(),data,flags,encoding)
90 os.chmod(self.abspath(),val)
93 if hasattr(self,'children'):
94 shutil.rmtree(self.abspath())
96 os.remove(self.abspath())
101 del self.parent.children[self.name]
103 k=max(0,self.name.rfind('.'))
113 lst=Utils.listdir(self.abspath())
117 if getattr(self,'cache_isdir',None):
125 os.makedirs(self.abspath())
128 if not os.path.isdir(self.abspath()):
129 raise Errors.WafError('Could not create the directory %s'%self.abspath())
132 except AttributeError:
134 self.cache_isdir=True
135 def find_node(self,lst):
136 if isinstance(lst,str):
137 lst=[x for x in split_path(lst)if x and x!='.']
141 cur=cur.parent or cur
145 except AttributeError:
153 cur=self.__class__(x,cur)
155 os.stat(cur.abspath())
161 os.stat(ret.abspath())
166 while not getattr(cur.parent,'cache_isdir',None):
169 except AttributeError:
172 def make_node(self,lst):
173 if isinstance(lst,str):
174 lst=[x for x in split_path(lst)if x and x!='.']
178 cur=cur.parent or cur
180 if getattr(cur,'children',{}):
181 if x in cur.children:
186 cur=self.__class__(x,cur)
188 def search_node(self,lst):
189 if isinstance(lst,str):
190 lst=[x for x in split_path(lst)if x and x!='.']
194 cur=cur.parent or cur
198 except(AttributeError,KeyError):
201 def path_from(self,node):
216 while id(c1)!=id(c2):
224 return os.sep.join(lst)or'.'
227 return self.cache_abspath
228 except AttributeError:
233 elif not self.parent.name:
236 val=self.parent.abspath()+os.sep+self.name
240 elif not self.parent.name:
243 val=self.parent.abspath().rstrip(os.sep)+os.sep+self.name
244 self.cache_abspath=val
246 def is_child_of(self,node):
248 diff=self.height()-node.height()
252 return id(p)==id(node)
253 def ant_iter(self,accept=None,maxdepth=25,pats=[],dir=False,src=True,remove=True):
254 dircont=self.listdir()
257 lst=set(self.children.keys())
258 except AttributeError:
262 for x in lst-set(dircont):
263 self.children[x].evict()
265 npats=accept(name,pats)
266 if npats and npats[0]:
267 accepted=[]in npats[0]
268 node=self.make_node([name])
269 isdir=os.path.isdir(node.abspath())
277 if getattr(node,'cache_isdir',None)or isdir:
278 node.cache_isdir=True
280 for k in node.ant_iter(accept=accept,maxdepth=maxdepth-1,pats=npats,dir=dir,src=src,remove=remove):
283 def ant_glob(self,*k,**kw):
284 src=kw.get('src',True)
285 dir=kw.get('dir',False)
286 excl=kw.get('excl',exclude_regs)
287 incl=k and k[0]or kw.get('incl','**')
288 reflags=kw.get('ignorecase',0)and re.I
293 x=x.replace('\\','/').replace('//','/')
302 k=k.replace('.','[.]').replace('*','.*').replace('?','.').replace('+','\\+')
305 accu.append(re.compile(k,flags=reflags))
307 raise Errors.WafError("Invalid pattern: %s"%k,e)
318 if lst[1].match(name):
322 elif lst[0].match(name):
325 def accept(name,pats):
326 nacc=filtre(name,pats[0])
327 nrej=filtre(name,pats[1])
331 ret=[x for x in self.ant_iter(accept=accept,pats=[to_pat(incl),to_pat(excl)],maxdepth=kw.get('maxdepth',25),dir=dir,src=src,remove=kw.get('remove',True))]
332 if kw.get('flat',False):
333 return' '.join([x.path_from(self)for x in ret])
337 x=id(self.ctx.srcnode)
338 y=id(self.ctx.bldnode)
348 y=id(self.ctx.bldnode)
356 x=id(self.ctx.srcnode)
357 y=id(self.ctx.bldnode)
362 return self.ctx.srcnode.make_node(lst)
370 x=id(self.ctx.srcnode)
371 y=id(self.ctx.bldnode)
378 return self.ctx.bldnode.make_node(lst)
382 if lst and Utils.is_win32 and len(lst[0])==2 and lst[0].endswith(':'):
384 return self.ctx.bldnode.make_node(['__root__']+lst)
385 def find_resource(self,lst):
386 if isinstance(lst,str):
387 lst=[x for x in split_path(lst)if x and x!='.']
388 node=self.get_bld().search_node(lst)
391 node=self.find_node(lst)
393 if os.path.isdir(node.abspath()):
396 def find_or_declare(self,lst):
397 if isinstance(lst,str):
398 lst=[x for x in split_path(lst)if x and x!='.']
399 node=self.get_bld().search_node(lst)
401 if not os.path.isfile(node.abspath()):
406 node=self.find_node(lst)
408 if not os.path.isfile(node.abspath()):
412 node=self.get_bld().make_node(lst)
415 def find_dir(self,lst):
416 if isinstance(lst,str):
417 lst=[x for x in split_path(lst)if x and x!='.']
418 node=self.find_node(lst)
420 if not os.path.isdir(node.abspath()):
422 except(OSError,AttributeError):
425 def change_ext(self,ext,ext_in=None):
434 name=name[:-len(ext_in)]+ext
435 return self.parent.find_or_declare([name])
436 def nice_path(self,env=None):
437 return self.path_from(self.ctx.launch_node())
439 return self.path_from(self.ctx.bldnode)
441 return self.path_from(self.ctx.srcnode)
444 x=id(self.ctx.bldnode)
447 return self.bldpath()
449 return self.srcpath()
451 return self.parent.bldpath()
453 s=os.path.splitext(self.name)[0]
454 return self.bld_dir()+os.sep+s
455 def get_bld_sig(self):
457 return self.cache_sig
458 except AttributeError:
460 if not self.is_bld()or self.ctx.bldnode is self.ctx.srcnode:
461 self.sig=Utils.h_file(self.abspath())
462 self.cache_sig=ret=self.sig
465 pickle_lock=Utils.threading.Lock()