akmhoque | fa8ee9b | 2014-03-14 09:06:24 -0500 | [diff] [blame^] | 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/** |
| 36 | **/.intlcache |
| 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('\\\\'): |
| 49 | ret=re.split(re_sp,path)[2:] |
| 50 | ret[0]='\\'+ret[0] |
| 51 | return ret |
| 52 | return re.split(re_sp,path) |
| 53 | if sys.platform=='cygwin': |
| 54 | split_path=split_path_cygwin |
| 55 | elif Utils.is_win32: |
| 56 | split_path=split_path_win32 |
| 57 | class Node(object): |
| 58 | __slots__=('name','sig','children','parent','cache_abspath','cache_isdir','cache_sig') |
| 59 | def __init__(self,name,parent): |
| 60 | self.name=name |
| 61 | self.parent=parent |
| 62 | if 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): |
| 67 | self.name=data[0] |
| 68 | self.parent=data[1] |
| 69 | if data[2]is not None: |
| 70 | self.children=data[2] |
| 71 | if data[3]is not None: |
| 72 | self.sig=data[3] |
| 73 | def __getstate__(self): |
| 74 | return(self.name,self.parent,getattr(self,'children',None),getattr(self,'sig',None)) |
| 75 | def __str__(self): |
| 76 | return self.name |
| 77 | def __repr__(self): |
| 78 | return self.abspath() |
| 79 | def __hash__(self): |
| 80 | return id(self) |
| 81 | def __eq__(self,node): |
| 82 | return id(self)==id(node) |
| 83 | def __copy__(self): |
| 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) |
| 89 | def chmod(self,val): |
| 90 | os.chmod(self.abspath(),val) |
| 91 | def delete(self): |
| 92 | try: |
| 93 | if hasattr(self,'children'): |
| 94 | shutil.rmtree(self.abspath()) |
| 95 | else: |
| 96 | os.remove(self.abspath()) |
| 97 | except OSError: |
| 98 | pass |
| 99 | self.evict() |
| 100 | def evict(self): |
| 101 | del self.parent.children[self.name] |
| 102 | def suffix(self): |
| 103 | k=max(0,self.name.rfind('.')) |
| 104 | return self.name[k:] |
| 105 | def height(self): |
| 106 | d=self |
| 107 | val=-1 |
| 108 | while d: |
| 109 | d=d.parent |
| 110 | val+=1 |
| 111 | return val |
| 112 | def listdir(self): |
| 113 | lst=Utils.listdir(self.abspath()) |
| 114 | lst.sort() |
| 115 | return lst |
| 116 | def mkdir(self): |
| 117 | if getattr(self,'cache_isdir',None): |
| 118 | return |
| 119 | try: |
| 120 | self.parent.mkdir() |
| 121 | except OSError: |
| 122 | pass |
| 123 | if self.name: |
| 124 | try: |
| 125 | os.makedirs(self.abspath()) |
| 126 | except OSError: |
| 127 | pass |
| 128 | if not os.path.isdir(self.abspath()): |
| 129 | raise Errors.WafError('Could not create the directory %s'%self.abspath()) |
| 130 | try: |
| 131 | self.children |
| 132 | except AttributeError: |
| 133 | self.children={} |
| 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!='.'] |
| 138 | cur=self |
| 139 | for x in lst: |
| 140 | if x=='..': |
| 141 | cur=cur.parent or cur |
| 142 | continue |
| 143 | try: |
| 144 | ch=cur.children |
| 145 | except AttributeError: |
| 146 | cur.children={} |
| 147 | else: |
| 148 | try: |
| 149 | cur=cur.children[x] |
| 150 | continue |
| 151 | except KeyError: |
| 152 | pass |
| 153 | cur=self.__class__(x,cur) |
| 154 | try: |
| 155 | os.stat(cur.abspath()) |
| 156 | except OSError: |
| 157 | cur.evict() |
| 158 | return None |
| 159 | ret=cur |
| 160 | try: |
| 161 | os.stat(ret.abspath()) |
| 162 | except OSError: |
| 163 | ret.evict() |
| 164 | return None |
| 165 | try: |
| 166 | while not getattr(cur.parent,'cache_isdir',None): |
| 167 | cur=cur.parent |
| 168 | cur.cache_isdir=True |
| 169 | except AttributeError: |
| 170 | pass |
| 171 | return ret |
| 172 | def make_node(self,lst): |
| 173 | if isinstance(lst,str): |
| 174 | lst=[x for x in split_path(lst)if x and x!='.'] |
| 175 | cur=self |
| 176 | for x in lst: |
| 177 | if x=='..': |
| 178 | cur=cur.parent or cur |
| 179 | continue |
| 180 | if getattr(cur,'children',{}): |
| 181 | if x in cur.children: |
| 182 | cur=cur.children[x] |
| 183 | continue |
| 184 | else: |
| 185 | cur.children={} |
| 186 | cur=self.__class__(x,cur) |
| 187 | return 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!='.'] |
| 191 | cur=self |
| 192 | for x in lst: |
| 193 | if x=='..': |
| 194 | cur=cur.parent or cur |
| 195 | else: |
| 196 | try: |
| 197 | cur=cur.children[x] |
| 198 | except(AttributeError,KeyError): |
| 199 | return None |
| 200 | return cur |
| 201 | def path_from(self,node): |
| 202 | c1=self |
| 203 | c2=node |
| 204 | c1h=c1.height() |
| 205 | c2h=c2.height() |
| 206 | lst=[] |
| 207 | up=0 |
| 208 | while c1h>c2h: |
| 209 | lst.append(c1.name) |
| 210 | c1=c1.parent |
| 211 | c1h-=1 |
| 212 | while c2h>c1h: |
| 213 | up+=1 |
| 214 | c2=c2.parent |
| 215 | c2h-=1 |
| 216 | while id(c1)!=id(c2): |
| 217 | lst.append(c1.name) |
| 218 | up+=1 |
| 219 | c1=c1.parent |
| 220 | c2=c2.parent |
| 221 | for i in range(up): |
| 222 | lst.append('..') |
| 223 | lst.reverse() |
| 224 | return os.sep.join(lst)or'.' |
| 225 | def abspath(self): |
| 226 | try: |
| 227 | return self.cache_abspath |
| 228 | except AttributeError: |
| 229 | pass |
| 230 | if os.sep=='/': |
| 231 | if not self.parent: |
| 232 | val=os.sep |
| 233 | elif not self.parent.name: |
| 234 | val=os.sep+self.name |
| 235 | else: |
| 236 | val=self.parent.abspath()+os.sep+self.name |
| 237 | else: |
| 238 | if not self.parent: |
| 239 | val='' |
| 240 | elif not self.parent.name: |
| 241 | val=self.name+os.sep |
| 242 | else: |
| 243 | val=self.parent.abspath().rstrip(os.sep)+os.sep+self.name |
| 244 | self.cache_abspath=val |
| 245 | return val |
| 246 | def is_child_of(self,node): |
| 247 | p=self |
| 248 | diff=self.height()-node.height() |
| 249 | while diff>0: |
| 250 | diff-=1 |
| 251 | p=p.parent |
| 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() |
| 255 | dircont.sort() |
| 256 | try: |
| 257 | lst=set(self.children.keys()) |
| 258 | except AttributeError: |
| 259 | self.children={} |
| 260 | else: |
| 261 | if remove: |
| 262 | for x in lst-set(dircont): |
| 263 | self.children[x].evict() |
| 264 | for name in dircont: |
| 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()) |
| 270 | if accepted: |
| 271 | if isdir: |
| 272 | if dir: |
| 273 | yield node |
| 274 | else: |
| 275 | if src: |
| 276 | yield node |
| 277 | if getattr(node,'cache_isdir',None)or isdir: |
| 278 | node.cache_isdir=True |
| 279 | if maxdepth: |
| 280 | for k in node.ant_iter(accept=accept,maxdepth=maxdepth-1,pats=npats,dir=dir,src=src,remove=remove): |
| 281 | yield k |
| 282 | raise StopIteration |
| 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 |
| 289 | def to_pat(s): |
| 290 | lst=Utils.to_list(s) |
| 291 | ret=[] |
| 292 | for x in lst: |
| 293 | x=x.replace('\\','/').replace('//','/') |
| 294 | if x.endswith('/'): |
| 295 | x+='**' |
| 296 | lst2=x.split('/') |
| 297 | accu=[] |
| 298 | for k in lst2: |
| 299 | if k=='**': |
| 300 | accu.append(k) |
| 301 | else: |
| 302 | k=k.replace('.','[.]').replace('*','.*').replace('?','.').replace('+','\\+') |
| 303 | k='^%s$'%k |
| 304 | try: |
| 305 | accu.append(re.compile(k,flags=reflags)) |
| 306 | except Exception ,e: |
| 307 | raise Errors.WafError("Invalid pattern: %s"%k,e) |
| 308 | ret.append(accu) |
| 309 | return ret |
| 310 | def filtre(name,nn): |
| 311 | ret=[] |
| 312 | for lst in nn: |
| 313 | if not lst: |
| 314 | pass |
| 315 | elif lst[0]=='**': |
| 316 | ret.append(lst) |
| 317 | if len(lst)>1: |
| 318 | if lst[1].match(name): |
| 319 | ret.append(lst[2:]) |
| 320 | else: |
| 321 | ret.append([]) |
| 322 | elif lst[0].match(name): |
| 323 | ret.append(lst[1:]) |
| 324 | return ret |
| 325 | def accept(name,pats): |
| 326 | nacc=filtre(name,pats[0]) |
| 327 | nrej=filtre(name,pats[1]) |
| 328 | if[]in nrej: |
| 329 | nacc=[] |
| 330 | return[nacc,nrej] |
| 331 | ret=[x for x in self.ant_iter(accept=accept,pats=[to_pat(incl),to_pat(excl)],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]) |
| 334 | return ret |
| 335 | def is_src(self): |
| 336 | cur=self |
| 337 | x=id(self.ctx.srcnode) |
| 338 | y=id(self.ctx.bldnode) |
| 339 | while cur.parent: |
| 340 | if id(cur)==y: |
| 341 | return False |
| 342 | if id(cur)==x: |
| 343 | return True |
| 344 | cur=cur.parent |
| 345 | return False |
| 346 | def is_bld(self): |
| 347 | cur=self |
| 348 | y=id(self.ctx.bldnode) |
| 349 | while cur.parent: |
| 350 | if id(cur)==y: |
| 351 | return True |
| 352 | cur=cur.parent |
| 353 | return False |
| 354 | def get_src(self): |
| 355 | cur=self |
| 356 | x=id(self.ctx.srcnode) |
| 357 | y=id(self.ctx.bldnode) |
| 358 | lst=[] |
| 359 | while cur.parent: |
| 360 | if id(cur)==y: |
| 361 | lst.reverse() |
| 362 | return self.ctx.srcnode.make_node(lst) |
| 363 | if id(cur)==x: |
| 364 | return self |
| 365 | lst.append(cur.name) |
| 366 | cur=cur.parent |
| 367 | return self |
| 368 | def get_bld(self): |
| 369 | cur=self |
| 370 | x=id(self.ctx.srcnode) |
| 371 | y=id(self.ctx.bldnode) |
| 372 | lst=[] |
| 373 | while cur.parent: |
| 374 | if id(cur)==y: |
| 375 | return self |
| 376 | if id(cur)==x: |
| 377 | lst.reverse() |
| 378 | return self.ctx.bldnode.make_node(lst) |
| 379 | lst.append(cur.name) |
| 380 | cur=cur.parent |
| 381 | lst.reverse() |
| 382 | if lst and Utils.is_win32 and len(lst[0])==2 and lst[0].endswith(':'): |
| 383 | lst[0]=lst[0][0] |
| 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) |
| 389 | if not node: |
| 390 | self=self.get_src() |
| 391 | node=self.find_node(lst) |
| 392 | if node: |
| 393 | if os.path.isdir(node.abspath()): |
| 394 | return None |
| 395 | return node |
| 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) |
| 400 | if node: |
| 401 | if not os.path.isfile(node.abspath()): |
| 402 | node.sig=None |
| 403 | node.parent.mkdir() |
| 404 | return node |
| 405 | self=self.get_src() |
| 406 | node=self.find_node(lst) |
| 407 | if node: |
| 408 | if not os.path.isfile(node.abspath()): |
| 409 | node.sig=None |
| 410 | node.parent.mkdir() |
| 411 | return node |
| 412 | node=self.get_bld().make_node(lst) |
| 413 | node.parent.mkdir() |
| 414 | return node |
| 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) |
| 419 | try: |
| 420 | if not os.path.isdir(node.abspath()): |
| 421 | return None |
| 422 | except(OSError,AttributeError): |
| 423 | return None |
| 424 | return node |
| 425 | def change_ext(self,ext,ext_in=None): |
| 426 | name=self.name |
| 427 | if ext_in is None: |
| 428 | k=name.rfind('.') |
| 429 | if k>=0: |
| 430 | name=name[:k]+ext |
| 431 | else: |
| 432 | name=name+ext |
| 433 | else: |
| 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()) |
| 438 | def bldpath(self): |
| 439 | return self.path_from(self.ctx.bldnode) |
| 440 | def srcpath(self): |
| 441 | return self.path_from(self.ctx.srcnode) |
| 442 | def relpath(self): |
| 443 | cur=self |
| 444 | x=id(self.ctx.bldnode) |
| 445 | while cur.parent: |
| 446 | if id(cur)==x: |
| 447 | return self.bldpath() |
| 448 | cur=cur.parent |
| 449 | return self.srcpath() |
| 450 | def bld_dir(self): |
| 451 | return self.parent.bldpath() |
| 452 | def bld_base(self): |
| 453 | s=os.path.splitext(self.name)[0] |
| 454 | return self.bld_dir()+os.sep+s |
| 455 | def get_bld_sig(self): |
| 456 | try: |
| 457 | return self.cache_sig |
| 458 | except AttributeError: |
| 459 | pass |
| 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 |
| 463 | return ret |
| 464 | search=search_node |
| 465 | pickle_lock=Utils.threading.Lock() |
| 466 | class Nod3(Node): |
| 467 | pass |