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,sys,errno,traceback,inspect,re,shutil,datetime,gc,platform |
---|
6 | import subprocess |
---|
7 | from collections import deque,defaultdict |
---|
8 | try: |
---|
9 | import _winreg as winreg |
---|
10 | except ImportError: |
---|
11 | try: |
---|
12 | import winreg |
---|
13 | except ImportError: |
---|
14 | winreg=None |
---|
15 | from waflib import Errors |
---|
16 | try: |
---|
17 | from collections import UserDict |
---|
18 | except ImportError: |
---|
19 | from UserDict import UserDict |
---|
20 | try: |
---|
21 | from hashlib import md5 |
---|
22 | except ImportError: |
---|
23 | try: |
---|
24 | from md5 import md5 |
---|
25 | except ImportError: |
---|
26 | pass |
---|
27 | try: |
---|
28 | import threading |
---|
29 | except ImportError: |
---|
30 | if not'JOBS'in os.environ: |
---|
31 | os.environ['JOBS']='1' |
---|
32 | class threading(object): |
---|
33 | pass |
---|
34 | class Lock(object): |
---|
35 | def acquire(self): |
---|
36 | pass |
---|
37 | def release(self): |
---|
38 | pass |
---|
39 | threading.Lock=threading.Thread=Lock |
---|
40 | else: |
---|
41 | run_old=threading.Thread.run |
---|
42 | def run(*args,**kwargs): |
---|
43 | try: |
---|
44 | run_old(*args,**kwargs) |
---|
45 | except(KeyboardInterrupt,SystemExit): |
---|
46 | raise |
---|
47 | except Exception: |
---|
48 | sys.excepthook(*sys.exc_info()) |
---|
49 | threading.Thread.run=run |
---|
50 | SIG_NIL='iluvcuteoverload' |
---|
51 | O644=420 |
---|
52 | O755=493 |
---|
53 | rot_chr=['\\','|','/','-'] |
---|
54 | rot_idx=0 |
---|
55 | try: |
---|
56 | from collections import OrderedDict as ordered_iter_dict |
---|
57 | except ImportError: |
---|
58 | class ordered_iter_dict(dict): |
---|
59 | def __init__(self,*k,**kw): |
---|
60 | self.lst=[] |
---|
61 | dict.__init__(self,*k,**kw) |
---|
62 | def clear(self): |
---|
63 | dict.clear(self) |
---|
64 | self.lst=[] |
---|
65 | def __setitem__(self,key,value): |
---|
66 | dict.__setitem__(self,key,value) |
---|
67 | try: |
---|
68 | self.lst.remove(key) |
---|
69 | except ValueError: |
---|
70 | pass |
---|
71 | self.lst.append(key) |
---|
72 | def __delitem__(self,key): |
---|
73 | dict.__delitem__(self,key) |
---|
74 | try: |
---|
75 | self.lst.remove(key) |
---|
76 | except ValueError: |
---|
77 | pass |
---|
78 | def __iter__(self): |
---|
79 | for x in self.lst: |
---|
80 | yield x |
---|
81 | def keys(self): |
---|
82 | return self.lst |
---|
83 | is_win32=sys.platform in('win32','cli','os2') |
---|
84 | def readf(fname,m='r',encoding='ISO8859-1'): |
---|
85 | if sys.hexversion>0x3000000 and not'b'in m: |
---|
86 | m+='b' |
---|
87 | f=open(fname,m) |
---|
88 | try: |
---|
89 | txt=f.read() |
---|
90 | finally: |
---|
91 | f.close() |
---|
92 | if encoding: |
---|
93 | txt=txt.decode(encoding) |
---|
94 | else: |
---|
95 | txt=txt.decode() |
---|
96 | else: |
---|
97 | f=open(fname,m) |
---|
98 | try: |
---|
99 | txt=f.read() |
---|
100 | finally: |
---|
101 | f.close() |
---|
102 | return txt |
---|
103 | def writef(fname,data,m='w',encoding='ISO8859-1'): |
---|
104 | if sys.hexversion>0x3000000 and not'b'in m: |
---|
105 | data=data.encode(encoding) |
---|
106 | m+='b' |
---|
107 | f=open(fname,m) |
---|
108 | try: |
---|
109 | f.write(data) |
---|
110 | finally: |
---|
111 | f.close() |
---|
112 | def h_file(fname): |
---|
113 | f=open(fname,'rb') |
---|
114 | m=md5() |
---|
115 | try: |
---|
116 | while fname: |
---|
117 | fname=f.read(200000) |
---|
118 | m.update(fname) |
---|
119 | finally: |
---|
120 | f.close() |
---|
121 | return m.digest() |
---|
122 | def readf_win32(f,m='r',encoding='ISO8859-1'): |
---|
123 | flags=os.O_NOINHERIT|os.O_RDONLY |
---|
124 | if'b'in m: |
---|
125 | flags|=os.O_BINARY |
---|
126 | if'+'in m: |
---|
127 | flags|=os.O_RDWR |
---|
128 | try: |
---|
129 | fd=os.open(f,flags) |
---|
130 | except OSError: |
---|
131 | raise IOError('Cannot read from %r'%f) |
---|
132 | if sys.hexversion>0x3000000 and not'b'in m: |
---|
133 | m+='b' |
---|
134 | f=os.fdopen(fd,m) |
---|
135 | try: |
---|
136 | txt=f.read() |
---|
137 | finally: |
---|
138 | f.close() |
---|
139 | if encoding: |
---|
140 | txt=txt.decode(encoding) |
---|
141 | else: |
---|
142 | txt=txt.decode() |
---|
143 | else: |
---|
144 | f=os.fdopen(fd,m) |
---|
145 | try: |
---|
146 | txt=f.read() |
---|
147 | finally: |
---|
148 | f.close() |
---|
149 | return txt |
---|
150 | def writef_win32(f,data,m='w',encoding='ISO8859-1'): |
---|
151 | if sys.hexversion>0x3000000 and not'b'in m: |
---|
152 | data=data.encode(encoding) |
---|
153 | m+='b' |
---|
154 | flags=os.O_CREAT|os.O_TRUNC|os.O_WRONLY|os.O_NOINHERIT |
---|
155 | if'b'in m: |
---|
156 | flags|=os.O_BINARY |
---|
157 | if'+'in m: |
---|
158 | flags|=os.O_RDWR |
---|
159 | try: |
---|
160 | fd=os.open(f,flags) |
---|
161 | except OSError: |
---|
162 | raise IOError('Cannot write to %r'%f) |
---|
163 | f=os.fdopen(fd,m) |
---|
164 | try: |
---|
165 | f.write(data) |
---|
166 | finally: |
---|
167 | f.close() |
---|
168 | def h_file_win32(fname): |
---|
169 | try: |
---|
170 | fd=os.open(fname,os.O_BINARY|os.O_RDONLY|os.O_NOINHERIT) |
---|
171 | except OSError: |
---|
172 | raise IOError('Cannot read from %r'%fname) |
---|
173 | f=os.fdopen(fd,'rb') |
---|
174 | m=md5() |
---|
175 | try: |
---|
176 | while fname: |
---|
177 | fname=f.read(200000) |
---|
178 | m.update(fname) |
---|
179 | finally: |
---|
180 | f.close() |
---|
181 | return m.digest() |
---|
182 | readf_unix=readf |
---|
183 | writef_unix=writef |
---|
184 | h_file_unix=h_file |
---|
185 | if hasattr(os,'O_NOINHERIT')and sys.hexversion<0x3040000: |
---|
186 | readf=readf_win32 |
---|
187 | writef=writef_win32 |
---|
188 | h_file=h_file_win32 |
---|
189 | try: |
---|
190 | x=''.encode('hex') |
---|
191 | except LookupError: |
---|
192 | import binascii |
---|
193 | def to_hex(s): |
---|
194 | ret=binascii.hexlify(s) |
---|
195 | if not isinstance(ret,str): |
---|
196 | ret=ret.decode('utf-8') |
---|
197 | return ret |
---|
198 | else: |
---|
199 | def to_hex(s): |
---|
200 | return s.encode('hex') |
---|
201 | to_hex.__doc__=""" |
---|
202 | Return the hexadecimal representation of a string |
---|
203 | |
---|
204 | :param s: string to convert |
---|
205 | :type s: string |
---|
206 | """ |
---|
207 | def listdir_win32(s): |
---|
208 | if not s: |
---|
209 | try: |
---|
210 | import ctypes |
---|
211 | except ImportError: |
---|
212 | return[x+':\\'for x in list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')] |
---|
213 | else: |
---|
214 | dlen=4 |
---|
215 | maxdrives=26 |
---|
216 | buf=ctypes.create_string_buffer(maxdrives*dlen) |
---|
217 | ndrives=ctypes.windll.kernel32.GetLogicalDriveStringsA(maxdrives*dlen,ctypes.byref(buf)) |
---|
218 | return[str(buf.raw[4*i:4*i+2].decode('ascii'))for i in range(int(ndrives/dlen))] |
---|
219 | if len(s)==2 and s[1]==":": |
---|
220 | s+=os.sep |
---|
221 | if not os.path.isdir(s): |
---|
222 | e=OSError('%s is not a directory'%s) |
---|
223 | e.errno=errno.ENOENT |
---|
224 | raise e |
---|
225 | return os.listdir(s) |
---|
226 | listdir=os.listdir |
---|
227 | if is_win32: |
---|
228 | listdir=listdir_win32 |
---|
229 | def num2ver(ver): |
---|
230 | if isinstance(ver,str): |
---|
231 | ver=tuple(ver.split('.')) |
---|
232 | if isinstance(ver,tuple): |
---|
233 | ret=0 |
---|
234 | for i in range(4): |
---|
235 | if i<len(ver): |
---|
236 | ret+=256**(3-i)*int(ver[i]) |
---|
237 | return ret |
---|
238 | return ver |
---|
239 | def ex_stack(): |
---|
240 | exc_type,exc_value,tb=sys.exc_info() |
---|
241 | exc_lines=traceback.format_exception(exc_type,exc_value,tb) |
---|
242 | return''.join(exc_lines) |
---|
243 | def to_list(sth): |
---|
244 | if isinstance(sth,str): |
---|
245 | return sth.split() |
---|
246 | else: |
---|
247 | return sth |
---|
248 | def split_path_unix(path): |
---|
249 | return path.split('/') |
---|
250 | def split_path_cygwin(path): |
---|
251 | if path.startswith('//'): |
---|
252 | ret=path.split('/')[2:] |
---|
253 | ret[0]='/'+ret[0] |
---|
254 | return ret |
---|
255 | return path.split('/') |
---|
256 | re_sp=re.compile('[/\\\\]') |
---|
257 | def split_path_win32(path): |
---|
258 | if path.startswith('\\\\'): |
---|
259 | ret=re.split(re_sp,path)[2:] |
---|
260 | ret[0]='\\'+ret[0] |
---|
261 | return ret |
---|
262 | return re.split(re_sp,path) |
---|
263 | if sys.platform=='cygwin': |
---|
264 | split_path=split_path_cygwin |
---|
265 | elif is_win32: |
---|
266 | split_path=split_path_win32 |
---|
267 | else: |
---|
268 | split_path=split_path_unix |
---|
269 | split_path.__doc__=""" |
---|
270 | Split a path by / or \\. This function is not like os.path.split |
---|
271 | |
---|
272 | :type path: string |
---|
273 | :param path: path to split |
---|
274 | :return: list of strings |
---|
275 | """ |
---|
276 | def check_dir(path): |
---|
277 | if not os.path.isdir(path): |
---|
278 | try: |
---|
279 | os.makedirs(path) |
---|
280 | except OSError ,e: |
---|
281 | if not os.path.isdir(path): |
---|
282 | raise Errors.WafError('Cannot create the folder %r'%path,ex=e) |
---|
283 | def check_exe(name,env=None): |
---|
284 | if not name: |
---|
285 | raise ValueError('Cannot execute an empty string!') |
---|
286 | def is_exe(fpath): |
---|
287 | return os.path.isfile(fpath)and os.access(fpath,os.X_OK) |
---|
288 | fpath,fname=os.path.split(name) |
---|
289 | if fpath and is_exe(name): |
---|
290 | return os.path.abspath(name) |
---|
291 | else: |
---|
292 | env=env or os.environ |
---|
293 | for path in env["PATH"].split(os.pathsep): |
---|
294 | path=path.strip('"') |
---|
295 | exe_file=os.path.join(path,name) |
---|
296 | if is_exe(exe_file): |
---|
297 | return os.path.abspath(exe_file) |
---|
298 | return None |
---|
299 | def def_attrs(cls,**kw): |
---|
300 | for k,v in kw.items(): |
---|
301 | if not hasattr(cls,k): |
---|
302 | setattr(cls,k,v) |
---|
303 | def quote_define_name(s): |
---|
304 | fu=re.sub('[^a-zA-Z0-9]','_',s) |
---|
305 | fu=re.sub('_+','_',fu) |
---|
306 | fu=fu.upper() |
---|
307 | return fu |
---|
308 | def h_list(lst): |
---|
309 | m=md5() |
---|
310 | m.update(str(lst)) |
---|
311 | return m.digest() |
---|
312 | def h_fun(fun): |
---|
313 | try: |
---|
314 | return fun.code |
---|
315 | except AttributeError: |
---|
316 | try: |
---|
317 | h=inspect.getsource(fun) |
---|
318 | except IOError: |
---|
319 | h="nocode" |
---|
320 | try: |
---|
321 | fun.code=h |
---|
322 | except AttributeError: |
---|
323 | pass |
---|
324 | return h |
---|
325 | reg_subst=re.compile(r"(\\\\)|(\$\$)|\$\{([^}]+)\}") |
---|
326 | def subst_vars(expr,params): |
---|
327 | def repl_var(m): |
---|
328 | if m.group(1): |
---|
329 | return'\\' |
---|
330 | if m.group(2): |
---|
331 | return'$' |
---|
332 | try: |
---|
333 | return params.get_flat(m.group(3)) |
---|
334 | except AttributeError: |
---|
335 | return params[m.group(3)] |
---|
336 | return reg_subst.sub(repl_var,expr) |
---|
337 | def destos_to_binfmt(key): |
---|
338 | if key=='darwin': |
---|
339 | return'mac-o' |
---|
340 | elif key in('win32','cygwin','uwin','msys'): |
---|
341 | return'pe' |
---|
342 | return'elf' |
---|
343 | def unversioned_sys_platform(): |
---|
344 | s=sys.platform |
---|
345 | if s=='java': |
---|
346 | from java.lang import System |
---|
347 | s=System.getProperty('os.name') |
---|
348 | if s=='Mac OS X': |
---|
349 | return'darwin' |
---|
350 | elif s.startswith('Windows '): |
---|
351 | return'win32' |
---|
352 | elif s=='OS/2': |
---|
353 | return'os2' |
---|
354 | elif s=='HP-UX': |
---|
355 | return'hpux' |
---|
356 | elif s in('SunOS','Solaris'): |
---|
357 | return'sunos' |
---|
358 | else:s=s.lower() |
---|
359 | if s=='powerpc': |
---|
360 | return'darwin' |
---|
361 | if s=='win32'or s=='os2': |
---|
362 | return s |
---|
363 | return re.split('\d+$',s)[0] |
---|
364 | def nada(*k,**kw): |
---|
365 | pass |
---|
366 | class Timer(object): |
---|
367 | def __init__(self): |
---|
368 | self.start_time=datetime.datetime.utcnow() |
---|
369 | def __str__(self): |
---|
370 | delta=datetime.datetime.utcnow()-self.start_time |
---|
371 | days=delta.days |
---|
372 | hours,rem=divmod(delta.seconds,3600) |
---|
373 | minutes,seconds=divmod(rem,60) |
---|
374 | seconds+=delta.microseconds*1e-6 |
---|
375 | result='' |
---|
376 | if days: |
---|
377 | result+='%dd'%days |
---|
378 | if days or hours: |
---|
379 | result+='%dh'%hours |
---|
380 | if days or hours or minutes: |
---|
381 | result+='%dm'%minutes |
---|
382 | return'%s%.3fs'%(result,seconds) |
---|
383 | if is_win32: |
---|
384 | old=shutil.copy2 |
---|
385 | def copy2(src,dst): |
---|
386 | old(src,dst) |
---|
387 | shutil.copystat(src,dst) |
---|
388 | setattr(shutil,'copy2',copy2) |
---|
389 | if os.name=='java': |
---|
390 | try: |
---|
391 | gc.disable() |
---|
392 | gc.enable() |
---|
393 | except NotImplementedError: |
---|
394 | gc.disable=gc.enable |
---|
395 | def read_la_file(path): |
---|
396 | sp=re.compile(r'^([^=]+)=\'(.*)\'$') |
---|
397 | dc={} |
---|
398 | for line in readf(path).splitlines(): |
---|
399 | try: |
---|
400 | _,left,right,_=sp.split(line.strip()) |
---|
401 | dc[left]=right |
---|
402 | except ValueError: |
---|
403 | pass |
---|
404 | return dc |
---|
405 | def nogc(fun): |
---|
406 | def f(*k,**kw): |
---|
407 | try: |
---|
408 | gc.disable() |
---|
409 | ret=fun(*k,**kw) |
---|
410 | finally: |
---|
411 | gc.enable() |
---|
412 | return ret |
---|
413 | f.__doc__=fun.__doc__ |
---|
414 | return f |
---|
415 | def run_once(fun): |
---|
416 | cache={} |
---|
417 | def wrap(k): |
---|
418 | try: |
---|
419 | return cache[k] |
---|
420 | except KeyError: |
---|
421 | ret=fun(k) |
---|
422 | cache[k]=ret |
---|
423 | return ret |
---|
424 | wrap.__cache__=cache |
---|
425 | return wrap |
---|
426 | def get_registry_app_path(key,filename): |
---|
427 | if not winreg: |
---|
428 | return None |
---|
429 | try: |
---|
430 | result=winreg.QueryValue(key,"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\%s.exe"%filename[0]) |
---|
431 | except WindowsError: |
---|
432 | pass |
---|
433 | else: |
---|
434 | if os.path.isfile(result): |
---|
435 | return result |
---|
436 | def lib64(): |
---|
437 | if os.sep=='/': |
---|
438 | is_64=platform.architecture()[0]=='64bit' |
---|
439 | if os.path.exists('/usr/lib64')and not os.path.exists('/usr/lib32'): |
---|
440 | return'64'if is_64 else'' |
---|
441 | else: |
---|
442 | return''if is_64 else'32' |
---|
443 | return'' |
---|