[0fa325b] | 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 os,re,sys,shutil |
---|
| 6 | from waflib import Utils,Errors |
---|
| 7 | exclude_regs=''' |
---|
| 8 | **/*~ |
---|
| 9 | **/#*# |
---|
| 10 | **/.#* |
---|
| 11 | **/%*% |
---|
| 12 | **/._* |
---|
| 13 | **/CVS |
---|
| 14 | **/CVS/** |
---|
| 15 | **/.cvsignore |
---|
| 16 | **/SCCS |
---|
| 17 | **/SCCS/** |
---|
| 18 | **/vssver.scc |
---|
| 19 | **/.svn |
---|
| 20 | **/.svn/** |
---|
| 21 | **/BitKeeper |
---|
| 22 | **/.git |
---|
| 23 | **/.git/** |
---|
| 24 | **/.gitignore |
---|
| 25 | **/.bzr |
---|
| 26 | **/.bzrignore |
---|
| 27 | **/.bzr/** |
---|
| 28 | **/.hg |
---|
| 29 | **/.hg/** |
---|
| 30 | **/_MTN |
---|
| 31 | **/_MTN/** |
---|
| 32 | **/.arch-ids |
---|
| 33 | **/{arch} |
---|
| 34 | **/_darcs |
---|
| 35 | **/_darcs/** |
---|
[c101fe1] | 36 | **/.intlcache |
---|
[0fa325b] | 37 | **/.DS_Store''' |
---|
| 38 | def split_path(path): |
---|
| 39 | return path.split('/') |
---|
| 40 | def split_path_cygwin(path): |
---|
| 41 | if path.startswith('//'): |
---|
| 42 | ret=path.split('/')[2:] |
---|
| 43 | ret[0]='/'+ret[0] |
---|
| 44 | return ret |
---|
| 45 | return path.split('/') |
---|
| 46 | re_sp=re.compile('[/\\\\]') |
---|
| 47 | def split_path_win32(path): |
---|
| 48 | if path.startswith('\\\\'): |
---|
[904702d] | 49 | if path.startswith('\\\\?'): |
---|
| 50 | path=path[4:] |
---|
| 51 | else: |
---|
| 52 | ret=re.split(re_sp,path)[2:] |
---|
| 53 | ret[0]='\\\\'+ret[0] |
---|
| 54 | return ret |
---|
[0fa325b] | 55 | return re.split(re_sp,path) |
---|
| 56 | if sys.platform=='cygwin': |
---|
| 57 | split_path=split_path_cygwin |
---|
| 58 | elif Utils.is_win32: |
---|
| 59 | split_path=split_path_win32 |
---|
| 60 | class Node(object): |
---|
[904702d] | 61 | dict_class=dict |
---|
[0fa325b] | 62 | __slots__=('name','sig','children','parent','cache_abspath','cache_isdir','cache_sig') |
---|
| 63 | def __init__(self,name,parent): |
---|
| 64 | self.name=name |
---|
| 65 | self.parent=parent |
---|
| 66 | if parent: |
---|
| 67 | if name in parent.children: |
---|
| 68 | raise Errors.WafError('node %s exists in the parent files %r already'%(name,parent)) |
---|
| 69 | parent.children[name]=self |
---|
| 70 | def __setstate__(self,data): |
---|
| 71 | self.name=data[0] |
---|
| 72 | self.parent=data[1] |
---|
| 73 | if data[2]is not None: |
---|
[904702d] | 74 | self.children=self.dict_class(data[2]) |
---|
[0fa325b] | 75 | if data[3]is not None: |
---|
| 76 | self.sig=data[3] |
---|
| 77 | def __getstate__(self): |
---|
| 78 | return(self.name,self.parent,getattr(self,'children',None),getattr(self,'sig',None)) |
---|
| 79 | def __str__(self): |
---|
| 80 | return self.name |
---|
| 81 | def __repr__(self): |
---|
| 82 | return self.abspath() |
---|
| 83 | def __hash__(self): |
---|
| 84 | return id(self) |
---|
| 85 | def __eq__(self,node): |
---|
| 86 | return id(self)==id(node) |
---|
| 87 | def __copy__(self): |
---|
| 88 | raise Errors.WafError('nodes are not supposed to be copied') |
---|
| 89 | def read(self,flags='r',encoding='ISO8859-1'): |
---|
| 90 | return Utils.readf(self.abspath(),flags,encoding) |
---|
| 91 | def write(self,data,flags='w',encoding='ISO8859-1'): |
---|
| 92 | Utils.writef(self.abspath(),data,flags,encoding) |
---|
| 93 | def chmod(self,val): |
---|
| 94 | os.chmod(self.abspath(),val) |
---|
| 95 | def delete(self): |
---|
| 96 | try: |
---|
[904702d] | 97 | try: |
---|
| 98 | if hasattr(self,'children'): |
---|
| 99 | shutil.rmtree(self.abspath()) |
---|
| 100 | else: |
---|
| 101 | os.remove(self.abspath()) |
---|
| 102 | except OSError ,e: |
---|
| 103 | if os.path.exists(self.abspath()): |
---|
| 104 | raise e |
---|
| 105 | finally: |
---|
| 106 | self.evict() |
---|
[0fa325b] | 107 | def evict(self): |
---|
| 108 | del self.parent.children[self.name] |
---|
| 109 | def suffix(self): |
---|
| 110 | k=max(0,self.name.rfind('.')) |
---|
| 111 | return self.name[k:] |
---|
| 112 | def height(self): |
---|
| 113 | d=self |
---|
| 114 | val=-1 |
---|
| 115 | while d: |
---|
| 116 | d=d.parent |
---|
| 117 | val+=1 |
---|
| 118 | return val |
---|
| 119 | def listdir(self): |
---|
| 120 | lst=Utils.listdir(self.abspath()) |
---|
| 121 | lst.sort() |
---|
| 122 | return lst |
---|
| 123 | def mkdir(self): |
---|
| 124 | if getattr(self,'cache_isdir',None): |
---|
| 125 | return |
---|
| 126 | try: |
---|
| 127 | self.parent.mkdir() |
---|
| 128 | except OSError: |
---|
| 129 | pass |
---|
| 130 | if self.name: |
---|
| 131 | try: |
---|
| 132 | os.makedirs(self.abspath()) |
---|
| 133 | except OSError: |
---|
| 134 | pass |
---|
| 135 | if not os.path.isdir(self.abspath()): |
---|
| 136 | raise Errors.WafError('Could not create the directory %s'%self.abspath()) |
---|
| 137 | try: |
---|
| 138 | self.children |
---|
| 139 | except AttributeError: |
---|
[904702d] | 140 | self.children=self.dict_class() |
---|
[0fa325b] | 141 | self.cache_isdir=True |
---|
| 142 | def find_node(self,lst): |
---|
| 143 | if isinstance(lst,str): |
---|
| 144 | lst=[x for x in split_path(lst)if x and x!='.'] |
---|
| 145 | cur=self |
---|
| 146 | for x in lst: |
---|
| 147 | if x=='..': |
---|
| 148 | cur=cur.parent or cur |
---|
| 149 | continue |
---|
| 150 | try: |
---|
| 151 | ch=cur.children |
---|
| 152 | except AttributeError: |
---|
[904702d] | 153 | cur.children=self.dict_class() |
---|
[0fa325b] | 154 | else: |
---|
| 155 | try: |
---|
| 156 | cur=cur.children[x] |
---|
| 157 | continue |
---|
| 158 | except KeyError: |
---|
| 159 | pass |
---|
| 160 | cur=self.__class__(x,cur) |
---|
| 161 | try: |
---|
| 162 | os.stat(cur.abspath()) |
---|
| 163 | except OSError: |
---|
| 164 | cur.evict() |
---|
| 165 | return None |
---|
| 166 | ret=cur |
---|
| 167 | try: |
---|
| 168 | os.stat(ret.abspath()) |
---|
| 169 | except OSError: |
---|
| 170 | ret.evict() |
---|
| 171 | return None |
---|
| 172 | try: |
---|
| 173 | while not getattr(cur.parent,'cache_isdir',None): |
---|
| 174 | cur=cur.parent |
---|
| 175 | cur.cache_isdir=True |
---|
| 176 | except AttributeError: |
---|
| 177 | pass |
---|
| 178 | return ret |
---|
| 179 | def make_node(self,lst): |
---|
| 180 | if isinstance(lst,str): |
---|
| 181 | lst=[x for x in split_path(lst)if x and x!='.'] |
---|
| 182 | cur=self |
---|
| 183 | for x in lst: |
---|
| 184 | if x=='..': |
---|
| 185 | cur=cur.parent or cur |
---|
| 186 | continue |
---|
| 187 | if getattr(cur,'children',{}): |
---|
| 188 | if x in cur.children: |
---|
| 189 | cur=cur.children[x] |
---|
| 190 | continue |
---|
| 191 | else: |
---|
[904702d] | 192 | cur.children=self.dict_class() |
---|
[0fa325b] | 193 | cur=self.__class__(x,cur) |
---|
| 194 | return cur |
---|
| 195 | def search_node(self,lst): |
---|
| 196 | if isinstance(lst,str): |
---|
| 197 | lst=[x for x in split_path(lst)if x and x!='.'] |
---|
| 198 | cur=self |
---|
| 199 | for x in lst: |
---|
| 200 | if x=='..': |
---|
| 201 | cur=cur.parent or cur |
---|
| 202 | else: |
---|
| 203 | try: |
---|
| 204 | cur=cur.children[x] |
---|
| 205 | except(AttributeError,KeyError): |
---|
| 206 | return None |
---|
| 207 | return cur |
---|
| 208 | def path_from(self,node): |
---|
| 209 | c1=self |
---|
| 210 | c2=node |
---|
| 211 | c1h=c1.height() |
---|
| 212 | c2h=c2.height() |
---|
| 213 | lst=[] |
---|
| 214 | up=0 |
---|
| 215 | while c1h>c2h: |
---|
| 216 | lst.append(c1.name) |
---|
| 217 | c1=c1.parent |
---|
| 218 | c1h-=1 |
---|
| 219 | while c2h>c1h: |
---|
| 220 | up+=1 |
---|
| 221 | c2=c2.parent |
---|
| 222 | c2h-=1 |
---|
| 223 | while id(c1)!=id(c2): |
---|
| 224 | lst.append(c1.name) |
---|
| 225 | up+=1 |
---|
| 226 | c1=c1.parent |
---|
| 227 | c2=c2.parent |
---|
[904702d] | 228 | if c1.parent: |
---|
| 229 | for i in range(up): |
---|
| 230 | lst.append('..') |
---|
| 231 | else: |
---|
| 232 | if os.sep=='/'and lst: |
---|
| 233 | lst.append('') |
---|
[0fa325b] | 234 | lst.reverse() |
---|
| 235 | return os.sep.join(lst)or'.' |
---|
| 236 | def abspath(self): |
---|
| 237 | try: |
---|
| 238 | return self.cache_abspath |
---|
| 239 | except AttributeError: |
---|
| 240 | pass |
---|
| 241 | if os.sep=='/': |
---|
| 242 | if not self.parent: |
---|
| 243 | val=os.sep |
---|
| 244 | elif not self.parent.name: |
---|
| 245 | val=os.sep+self.name |
---|
| 246 | else: |
---|
| 247 | val=self.parent.abspath()+os.sep+self.name |
---|
| 248 | else: |
---|
| 249 | if not self.parent: |
---|
| 250 | val='' |
---|
| 251 | elif not self.parent.name: |
---|
| 252 | val=self.name+os.sep |
---|
| 253 | else: |
---|
| 254 | val=self.parent.abspath().rstrip(os.sep)+os.sep+self.name |
---|
| 255 | self.cache_abspath=val |
---|
| 256 | return val |
---|
| 257 | def is_child_of(self,node): |
---|
| 258 | p=self |
---|
| 259 | diff=self.height()-node.height() |
---|
| 260 | while diff>0: |
---|
| 261 | diff-=1 |
---|
| 262 | p=p.parent |
---|
| 263 | return id(p)==id(node) |
---|
| 264 | def ant_iter(self,accept=None,maxdepth=25,pats=[],dir=False,src=True,remove=True): |
---|
| 265 | dircont=self.listdir() |
---|
| 266 | dircont.sort() |
---|
| 267 | try: |
---|
| 268 | lst=set(self.children.keys()) |
---|
| 269 | except AttributeError: |
---|
[904702d] | 270 | self.children=self.dict_class() |
---|
[0fa325b] | 271 | else: |
---|
| 272 | if remove: |
---|
| 273 | for x in lst-set(dircont): |
---|
| 274 | self.children[x].evict() |
---|
| 275 | for name in dircont: |
---|
| 276 | npats=accept(name,pats) |
---|
| 277 | if npats and npats[0]: |
---|
| 278 | accepted=[]in npats[0] |
---|
| 279 | node=self.make_node([name]) |
---|
| 280 | isdir=os.path.isdir(node.abspath()) |
---|
| 281 | if accepted: |
---|
| 282 | if isdir: |
---|
| 283 | if dir: |
---|
| 284 | yield node |
---|
| 285 | else: |
---|
| 286 | if src: |
---|
| 287 | yield node |
---|
| 288 | if getattr(node,'cache_isdir',None)or isdir: |
---|
| 289 | node.cache_isdir=True |
---|
| 290 | if maxdepth: |
---|
| 291 | for k in node.ant_iter(accept=accept,maxdepth=maxdepth-1,pats=npats,dir=dir,src=src,remove=remove): |
---|
| 292 | yield k |
---|
| 293 | raise StopIteration |
---|
| 294 | def ant_glob(self,*k,**kw): |
---|
| 295 | src=kw.get('src',True) |
---|
| 296 | dir=kw.get('dir',False) |
---|
| 297 | excl=kw.get('excl',exclude_regs) |
---|
| 298 | incl=k and k[0]or kw.get('incl','**') |
---|
| 299 | reflags=kw.get('ignorecase',0)and re.I |
---|
| 300 | def to_pat(s): |
---|
| 301 | lst=Utils.to_list(s) |
---|
| 302 | ret=[] |
---|
| 303 | for x in lst: |
---|
| 304 | x=x.replace('\\','/').replace('//','/') |
---|
| 305 | if x.endswith('/'): |
---|
| 306 | x+='**' |
---|
| 307 | lst2=x.split('/') |
---|
| 308 | accu=[] |
---|
| 309 | for k in lst2: |
---|
| 310 | if k=='**': |
---|
| 311 | accu.append(k) |
---|
| 312 | else: |
---|
| 313 | k=k.replace('.','[.]').replace('*','.*').replace('?','.').replace('+','\\+') |
---|
| 314 | k='^%s$'%k |
---|
| 315 | try: |
---|
| 316 | accu.append(re.compile(k,flags=reflags)) |
---|
| 317 | except Exception ,e: |
---|
| 318 | raise Errors.WafError("Invalid pattern: %s"%k,e) |
---|
| 319 | ret.append(accu) |
---|
| 320 | return ret |
---|
| 321 | def filtre(name,nn): |
---|
| 322 | ret=[] |
---|
| 323 | for lst in nn: |
---|
| 324 | if not lst: |
---|
| 325 | pass |
---|
| 326 | elif lst[0]=='**': |
---|
| 327 | ret.append(lst) |
---|
| 328 | if len(lst)>1: |
---|
| 329 | if lst[1].match(name): |
---|
| 330 | ret.append(lst[2:]) |
---|
| 331 | else: |
---|
| 332 | ret.append([]) |
---|
| 333 | elif lst[0].match(name): |
---|
| 334 | ret.append(lst[1:]) |
---|
| 335 | return ret |
---|
| 336 | def accept(name,pats): |
---|
| 337 | nacc=filtre(name,pats[0]) |
---|
| 338 | nrej=filtre(name,pats[1]) |
---|
| 339 | if[]in nrej: |
---|
| 340 | nacc=[] |
---|
| 341 | return[nacc,nrej] |
---|
[c101fe1] | 342 | 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))] |
---|
[0fa325b] | 343 | if kw.get('flat',False): |
---|
| 344 | return' '.join([x.path_from(self)for x in ret]) |
---|
| 345 | return ret |
---|
| 346 | def is_src(self): |
---|
| 347 | cur=self |
---|
| 348 | x=id(self.ctx.srcnode) |
---|
| 349 | y=id(self.ctx.bldnode) |
---|
| 350 | while cur.parent: |
---|
| 351 | if id(cur)==y: |
---|
| 352 | return False |
---|
| 353 | if id(cur)==x: |
---|
| 354 | return True |
---|
| 355 | cur=cur.parent |
---|
| 356 | return False |
---|
| 357 | def is_bld(self): |
---|
| 358 | cur=self |
---|
| 359 | y=id(self.ctx.bldnode) |
---|
| 360 | while cur.parent: |
---|
| 361 | if id(cur)==y: |
---|
| 362 | return True |
---|
| 363 | cur=cur.parent |
---|
| 364 | return False |
---|
| 365 | def get_src(self): |
---|
| 366 | cur=self |
---|
| 367 | x=id(self.ctx.srcnode) |
---|
| 368 | y=id(self.ctx.bldnode) |
---|
| 369 | lst=[] |
---|
| 370 | while cur.parent: |
---|
| 371 | if id(cur)==y: |
---|
| 372 | lst.reverse() |
---|
| 373 | return self.ctx.srcnode.make_node(lst) |
---|
| 374 | if id(cur)==x: |
---|
| 375 | return self |
---|
| 376 | lst.append(cur.name) |
---|
| 377 | cur=cur.parent |
---|
| 378 | return self |
---|
| 379 | def get_bld(self): |
---|
| 380 | cur=self |
---|
| 381 | x=id(self.ctx.srcnode) |
---|
| 382 | y=id(self.ctx.bldnode) |
---|
| 383 | lst=[] |
---|
| 384 | while cur.parent: |
---|
| 385 | if id(cur)==y: |
---|
| 386 | return self |
---|
| 387 | if id(cur)==x: |
---|
| 388 | lst.reverse() |
---|
| 389 | return self.ctx.bldnode.make_node(lst) |
---|
| 390 | lst.append(cur.name) |
---|
| 391 | cur=cur.parent |
---|
| 392 | lst.reverse() |
---|
| 393 | if lst and Utils.is_win32 and len(lst[0])==2 and lst[0].endswith(':'): |
---|
| 394 | lst[0]=lst[0][0] |
---|
| 395 | return self.ctx.bldnode.make_node(['__root__']+lst) |
---|
| 396 | def find_resource(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) |
---|
| 400 | if not node: |
---|
| 401 | self=self.get_src() |
---|
| 402 | node=self.find_node(lst) |
---|
| 403 | if node: |
---|
| 404 | if os.path.isdir(node.abspath()): |
---|
| 405 | return None |
---|
| 406 | return node |
---|
| 407 | def find_or_declare(self,lst): |
---|
| 408 | if isinstance(lst,str): |
---|
| 409 | lst=[x for x in split_path(lst)if x and x!='.'] |
---|
| 410 | node=self.get_bld().search_node(lst) |
---|
| 411 | if node: |
---|
| 412 | if not os.path.isfile(node.abspath()): |
---|
| 413 | node.sig=None |
---|
| 414 | node.parent.mkdir() |
---|
| 415 | return node |
---|
| 416 | self=self.get_src() |
---|
| 417 | node=self.find_node(lst) |
---|
| 418 | if node: |
---|
| 419 | if not os.path.isfile(node.abspath()): |
---|
| 420 | node.sig=None |
---|
| 421 | node.parent.mkdir() |
---|
| 422 | return node |
---|
| 423 | node=self.get_bld().make_node(lst) |
---|
| 424 | node.parent.mkdir() |
---|
| 425 | return node |
---|
| 426 | def find_dir(self,lst): |
---|
| 427 | if isinstance(lst,str): |
---|
| 428 | lst=[x for x in split_path(lst)if x and x!='.'] |
---|
| 429 | node=self.find_node(lst) |
---|
| 430 | try: |
---|
| 431 | if not os.path.isdir(node.abspath()): |
---|
| 432 | return None |
---|
| 433 | except(OSError,AttributeError): |
---|
| 434 | return None |
---|
| 435 | return node |
---|
| 436 | def change_ext(self,ext,ext_in=None): |
---|
| 437 | name=self.name |
---|
| 438 | if ext_in is None: |
---|
| 439 | k=name.rfind('.') |
---|
| 440 | if k>=0: |
---|
| 441 | name=name[:k]+ext |
---|
| 442 | else: |
---|
| 443 | name=name+ext |
---|
| 444 | else: |
---|
| 445 | name=name[:-len(ext_in)]+ext |
---|
| 446 | return self.parent.find_or_declare([name]) |
---|
| 447 | def bldpath(self): |
---|
| 448 | return self.path_from(self.ctx.bldnode) |
---|
| 449 | def srcpath(self): |
---|
| 450 | return self.path_from(self.ctx.srcnode) |
---|
| 451 | def relpath(self): |
---|
| 452 | cur=self |
---|
| 453 | x=id(self.ctx.bldnode) |
---|
| 454 | while cur.parent: |
---|
| 455 | if id(cur)==x: |
---|
| 456 | return self.bldpath() |
---|
| 457 | cur=cur.parent |
---|
| 458 | return self.srcpath() |
---|
| 459 | def bld_dir(self): |
---|
| 460 | return self.parent.bldpath() |
---|
| 461 | def get_bld_sig(self): |
---|
| 462 | try: |
---|
| 463 | return self.cache_sig |
---|
| 464 | except AttributeError: |
---|
| 465 | pass |
---|
| 466 | if not self.is_bld()or self.ctx.bldnode is self.ctx.srcnode: |
---|
| 467 | self.sig=Utils.h_file(self.abspath()) |
---|
| 468 | self.cache_sig=ret=self.sig |
---|
| 469 | return ret |
---|
| 470 | pickle_lock=Utils.threading.Lock() |
---|
| 471 | class Nod3(Node): |
---|
| 472 | pass |
---|