[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 | |
---|
[904702d] | 5 | import os,re,imp,sys |
---|
[0fa325b] | 6 | from waflib import Utils,Errors,Logs |
---|
| 7 | import waflib.Node |
---|
[904702d] | 8 | HEXVERSION=0x1080700 |
---|
| 9 | WAFVERSION="1.8.7" |
---|
| 10 | WAFREVISION="e5056b9ade7bb224f53baab13a0ce136344ab602" |
---|
[0fa325b] | 11 | ABI=98 |
---|
| 12 | DBFILE='.wafpickle-%s-%d-%d'%(sys.platform,sys.hexversion,ABI) |
---|
| 13 | APPNAME='APPNAME' |
---|
| 14 | VERSION='VERSION' |
---|
| 15 | TOP='top' |
---|
| 16 | OUT='out' |
---|
| 17 | WSCRIPT_FILE='wscript' |
---|
| 18 | launch_dir='' |
---|
| 19 | run_dir='' |
---|
| 20 | top_dir='' |
---|
| 21 | out_dir='' |
---|
| 22 | waf_dir='' |
---|
| 23 | local_repo='' |
---|
| 24 | remote_repo='http://waf.googlecode.com/git/' |
---|
| 25 | remote_locs=['waflib/extras','waflib/Tools'] |
---|
| 26 | g_module=None |
---|
| 27 | STDOUT=1 |
---|
| 28 | STDERR=-1 |
---|
| 29 | BOTH=0 |
---|
| 30 | classes=[] |
---|
| 31 | def create_context(cmd_name,*k,**kw): |
---|
| 32 | global classes |
---|
| 33 | for x in classes: |
---|
| 34 | if x.cmd==cmd_name: |
---|
| 35 | return x(*k,**kw) |
---|
| 36 | ctx=Context(*k,**kw) |
---|
| 37 | ctx.fun=cmd_name |
---|
| 38 | return ctx |
---|
| 39 | class store_context(type): |
---|
| 40 | def __init__(cls,name,bases,dict): |
---|
| 41 | super(store_context,cls).__init__(name,bases,dict) |
---|
| 42 | name=cls.__name__ |
---|
| 43 | if name=='ctx'or name=='Context': |
---|
| 44 | return |
---|
| 45 | try: |
---|
| 46 | cls.cmd |
---|
| 47 | except AttributeError: |
---|
| 48 | raise Errors.WafError('Missing command for the context class %r (cmd)'%name) |
---|
| 49 | if not getattr(cls,'fun',None): |
---|
| 50 | cls.fun=cls.cmd |
---|
| 51 | global classes |
---|
| 52 | classes.insert(0,cls) |
---|
| 53 | ctx=store_context('ctx',(object,),{}) |
---|
| 54 | class Context(ctx): |
---|
| 55 | errors=Errors |
---|
| 56 | tools={} |
---|
| 57 | def __init__(self,**kw): |
---|
| 58 | try: |
---|
| 59 | rd=kw['run_dir'] |
---|
| 60 | except KeyError: |
---|
| 61 | global run_dir |
---|
| 62 | rd=run_dir |
---|
[1a31baf] | 63 | self.node_class=type("Nod3",(waflib.Node.Node,),{}) |
---|
[0fa325b] | 64 | self.node_class.__module__="waflib.Node" |
---|
| 65 | self.node_class.ctx=self |
---|
| 66 | self.root=self.node_class('',None) |
---|
| 67 | self.cur_script=None |
---|
| 68 | self.path=self.root.find_dir(rd) |
---|
| 69 | self.stack_path=[] |
---|
| 70 | self.exec_dict={'ctx':self,'conf':self,'bld':self,'opt':self} |
---|
| 71 | self.logger=None |
---|
| 72 | def __hash__(self): |
---|
| 73 | return id(self) |
---|
[904702d] | 74 | def finalize(self): |
---|
| 75 | try: |
---|
| 76 | logger=self.logger |
---|
| 77 | except AttributeError: |
---|
| 78 | pass |
---|
| 79 | else: |
---|
| 80 | Logs.free_logger(logger) |
---|
| 81 | delattr(self,'logger') |
---|
[0fa325b] | 82 | def load(self,tool_list,*k,**kw): |
---|
| 83 | tools=Utils.to_list(tool_list) |
---|
| 84 | path=Utils.to_list(kw.get('tooldir','')) |
---|
| 85 | for t in tools: |
---|
| 86 | module=load_tool(t,path) |
---|
| 87 | fun=getattr(module,kw.get('name',self.fun),None) |
---|
| 88 | if fun: |
---|
| 89 | fun(self) |
---|
| 90 | def execute(self): |
---|
| 91 | global g_module |
---|
| 92 | self.recurse([os.path.dirname(g_module.root_path)]) |
---|
| 93 | def pre_recurse(self,node): |
---|
| 94 | self.stack_path.append(self.cur_script) |
---|
| 95 | self.cur_script=node |
---|
| 96 | self.path=node.parent |
---|
| 97 | def post_recurse(self,node): |
---|
| 98 | self.cur_script=self.stack_path.pop() |
---|
| 99 | if self.cur_script: |
---|
| 100 | self.path=self.cur_script.parent |
---|
[904702d] | 101 | def recurse(self,dirs,name=None,mandatory=True,once=True,encoding=None): |
---|
[0fa325b] | 102 | try: |
---|
| 103 | cache=self.recurse_cache |
---|
| 104 | except AttributeError: |
---|
| 105 | cache=self.recurse_cache={} |
---|
| 106 | for d in Utils.to_list(dirs): |
---|
| 107 | if not os.path.isabs(d): |
---|
| 108 | d=os.path.join(self.path.abspath(),d) |
---|
| 109 | WSCRIPT=os.path.join(d,WSCRIPT_FILE) |
---|
| 110 | WSCRIPT_FUN=WSCRIPT+'_'+(name or self.fun) |
---|
| 111 | node=self.root.find_node(WSCRIPT_FUN) |
---|
| 112 | if node and(not once or node not in cache): |
---|
| 113 | cache[node]=True |
---|
| 114 | self.pre_recurse(node) |
---|
| 115 | try: |
---|
[904702d] | 116 | function_code=node.read('rU',encoding) |
---|
[0fa325b] | 117 | exec(compile(function_code,node.abspath(),'exec'),self.exec_dict) |
---|
| 118 | finally: |
---|
| 119 | self.post_recurse(node) |
---|
| 120 | elif not node: |
---|
| 121 | node=self.root.find_node(WSCRIPT) |
---|
| 122 | tup=(node,name or self.fun) |
---|
| 123 | if node and(not once or tup not in cache): |
---|
| 124 | cache[tup]=True |
---|
| 125 | self.pre_recurse(node) |
---|
| 126 | try: |
---|
[904702d] | 127 | wscript_module=load_module(node.abspath(),encoding=encoding) |
---|
[0fa325b] | 128 | user_function=getattr(wscript_module,(name or self.fun),None) |
---|
| 129 | if not user_function: |
---|
| 130 | if not mandatory: |
---|
| 131 | continue |
---|
| 132 | raise Errors.WafError('No function %s defined in %s'%(name or self.fun,node.abspath())) |
---|
| 133 | user_function(self) |
---|
| 134 | finally: |
---|
| 135 | self.post_recurse(node) |
---|
| 136 | elif not node: |
---|
| 137 | if not mandatory: |
---|
| 138 | continue |
---|
| 139 | raise Errors.WafError('No wscript file in directory %s'%d) |
---|
| 140 | def exec_command(self,cmd,**kw): |
---|
| 141 | subprocess=Utils.subprocess |
---|
| 142 | kw['shell']=isinstance(cmd,str) |
---|
| 143 | Logs.debug('runner: %r'%cmd) |
---|
| 144 | Logs.debug('runner_env: kw=%s'%kw) |
---|
| 145 | if self.logger: |
---|
| 146 | self.logger.info(cmd) |
---|
| 147 | if'stdout'not in kw: |
---|
| 148 | kw['stdout']=subprocess.PIPE |
---|
| 149 | if'stderr'not in kw: |
---|
| 150 | kw['stderr']=subprocess.PIPE |
---|
[904702d] | 151 | if Logs.verbose and not kw['shell']and not Utils.check_exe(cmd[0]): |
---|
| 152 | raise Errors.WafError("Program %s not found!"%cmd[0]) |
---|
[0fa325b] | 153 | try: |
---|
| 154 | if kw['stdout']or kw['stderr']: |
---|
| 155 | p=subprocess.Popen(cmd,**kw) |
---|
| 156 | (out,err)=p.communicate() |
---|
| 157 | ret=p.returncode |
---|
| 158 | else: |
---|
| 159 | out,err=(None,None) |
---|
| 160 | ret=subprocess.Popen(cmd,**kw).wait() |
---|
| 161 | except Exception ,e: |
---|
| 162 | raise Errors.WafError('Execution failure: %s'%str(e),ex=e) |
---|
| 163 | if out: |
---|
| 164 | if not isinstance(out,str): |
---|
| 165 | out=out.decode(sys.stdout.encoding or'iso8859-1') |
---|
| 166 | if self.logger: |
---|
| 167 | self.logger.debug('out: %s'%out) |
---|
| 168 | else: |
---|
[904702d] | 169 | Logs.info(out,extra={'stream':sys.stdout,'c1':''}) |
---|
[0fa325b] | 170 | if err: |
---|
| 171 | if not isinstance(err,str): |
---|
| 172 | err=err.decode(sys.stdout.encoding or'iso8859-1') |
---|
| 173 | if self.logger: |
---|
| 174 | self.logger.error('err: %s'%err) |
---|
| 175 | else: |
---|
[904702d] | 176 | Logs.info(err,extra={'stream':sys.stderr,'c1':''}) |
---|
[0fa325b] | 177 | return ret |
---|
| 178 | def cmd_and_log(self,cmd,**kw): |
---|
| 179 | subprocess=Utils.subprocess |
---|
| 180 | kw['shell']=isinstance(cmd,str) |
---|
| 181 | Logs.debug('runner: %r'%cmd) |
---|
| 182 | if'quiet'in kw: |
---|
| 183 | quiet=kw['quiet'] |
---|
| 184 | del kw['quiet'] |
---|
| 185 | else: |
---|
| 186 | quiet=None |
---|
| 187 | if'output'in kw: |
---|
| 188 | to_ret=kw['output'] |
---|
| 189 | del kw['output'] |
---|
| 190 | else: |
---|
| 191 | to_ret=STDOUT |
---|
[904702d] | 192 | if Logs.verbose and not kw['shell']and not Utils.check_exe(cmd[0]): |
---|
| 193 | raise Errors.WafError("Program %s not found!"%cmd[0]) |
---|
[0fa325b] | 194 | kw['stdout']=kw['stderr']=subprocess.PIPE |
---|
| 195 | if quiet is None: |
---|
| 196 | self.to_log(cmd) |
---|
| 197 | try: |
---|
| 198 | p=subprocess.Popen(cmd,**kw) |
---|
| 199 | (out,err)=p.communicate() |
---|
| 200 | except Exception ,e: |
---|
| 201 | raise Errors.WafError('Execution failure: %s'%str(e),ex=e) |
---|
| 202 | if not isinstance(out,str): |
---|
| 203 | out=out.decode(sys.stdout.encoding or'iso8859-1') |
---|
| 204 | if not isinstance(err,str): |
---|
| 205 | err=err.decode(sys.stdout.encoding or'iso8859-1') |
---|
| 206 | if out and quiet!=STDOUT and quiet!=BOTH: |
---|
| 207 | self.to_log('out: %s'%out) |
---|
| 208 | if err and quiet!=STDERR and quiet!=BOTH: |
---|
| 209 | self.to_log('err: %s'%err) |
---|
| 210 | if p.returncode: |
---|
| 211 | e=Errors.WafError('Command %r returned %r'%(cmd,p.returncode)) |
---|
| 212 | e.returncode=p.returncode |
---|
| 213 | e.stderr=err |
---|
| 214 | e.stdout=out |
---|
| 215 | raise e |
---|
| 216 | if to_ret==BOTH: |
---|
| 217 | return(out,err) |
---|
| 218 | elif to_ret==STDERR: |
---|
| 219 | return err |
---|
| 220 | return out |
---|
| 221 | def fatal(self,msg,ex=None): |
---|
| 222 | if self.logger: |
---|
| 223 | self.logger.info('from %s: %s'%(self.path.abspath(),msg)) |
---|
| 224 | try: |
---|
| 225 | msg='%s\n(complete log in %s)'%(msg,self.logger.handlers[0].baseFilename) |
---|
| 226 | except Exception: |
---|
| 227 | pass |
---|
| 228 | raise self.errors.ConfigurationError(msg,ex=ex) |
---|
| 229 | def to_log(self,msg): |
---|
| 230 | if not msg: |
---|
| 231 | return |
---|
| 232 | if self.logger: |
---|
| 233 | self.logger.info(msg) |
---|
| 234 | else: |
---|
| 235 | sys.stderr.write(str(msg)) |
---|
| 236 | sys.stderr.flush() |
---|
[904702d] | 237 | def msg(self,*k,**kw): |
---|
| 238 | try: |
---|
| 239 | msg=kw['msg'] |
---|
| 240 | except KeyError: |
---|
| 241 | msg=k[0] |
---|
| 242 | self.start_msg(msg,**kw) |
---|
| 243 | try: |
---|
| 244 | result=kw['result'] |
---|
| 245 | except KeyError: |
---|
| 246 | result=k[1] |
---|
| 247 | color=kw.get('color',None) |
---|
[0fa325b] | 248 | if not isinstance(color,str): |
---|
| 249 | color=result and'GREEN'or'YELLOW' |
---|
[904702d] | 250 | self.end_msg(result,color,**kw) |
---|
| 251 | def start_msg(self,*k,**kw): |
---|
| 252 | if kw.get('quiet',None): |
---|
| 253 | return |
---|
| 254 | msg=kw.get('msg',None)or k[0] |
---|
[0fa325b] | 255 | try: |
---|
| 256 | if self.in_msg: |
---|
| 257 | self.in_msg+=1 |
---|
| 258 | return |
---|
| 259 | except AttributeError: |
---|
| 260 | self.in_msg=0 |
---|
| 261 | self.in_msg+=1 |
---|
| 262 | try: |
---|
| 263 | self.line_just=max(self.line_just,len(msg)) |
---|
| 264 | except AttributeError: |
---|
| 265 | self.line_just=max(40,len(msg)) |
---|
| 266 | for x in(self.line_just*'-',msg): |
---|
| 267 | self.to_log(x) |
---|
| 268 | Logs.pprint('NORMAL',"%s :"%msg.ljust(self.line_just),sep='') |
---|
[904702d] | 269 | def end_msg(self,*k,**kw): |
---|
| 270 | if kw.get('quiet',None): |
---|
| 271 | return |
---|
[0fa325b] | 272 | self.in_msg-=1 |
---|
| 273 | if self.in_msg: |
---|
| 274 | return |
---|
[904702d] | 275 | result=kw.get('result',None)or k[0] |
---|
[0fa325b] | 276 | defcolor='GREEN' |
---|
| 277 | if result==True: |
---|
| 278 | msg='ok' |
---|
| 279 | elif result==False: |
---|
| 280 | msg='not found' |
---|
| 281 | defcolor='YELLOW' |
---|
| 282 | else: |
---|
| 283 | msg=str(result) |
---|
| 284 | self.to_log(msg) |
---|
[904702d] | 285 | try: |
---|
| 286 | color=kw['color'] |
---|
| 287 | except KeyError: |
---|
| 288 | if len(k)>1 and k[1]in Logs.colors_lst: |
---|
| 289 | color=k[1] |
---|
| 290 | else: |
---|
| 291 | color=defcolor |
---|
| 292 | Logs.pprint(color,msg) |
---|
[0fa325b] | 293 | def load_special_tools(self,var,ban=[]): |
---|
| 294 | global waf_dir |
---|
[904702d] | 295 | if os.path.isdir(waf_dir): |
---|
| 296 | lst=self.root.find_node(waf_dir).find_node('waflib/extras').ant_glob(var) |
---|
| 297 | for x in lst: |
---|
| 298 | if not x.name in ban: |
---|
| 299 | load_tool(x.name.replace('.py','')) |
---|
| 300 | else: |
---|
| 301 | from zipfile import PyZipFile |
---|
| 302 | waflibs=PyZipFile(waf_dir) |
---|
| 303 | lst=waflibs.namelist() |
---|
| 304 | for x in lst: |
---|
| 305 | if not re.match("waflib/extras/%s"%var.replace("*",".*"),var): |
---|
| 306 | continue |
---|
| 307 | f=os.path.basename(x) |
---|
| 308 | doban=False |
---|
| 309 | for b in ban: |
---|
| 310 | r=b.replace("*",".*") |
---|
| 311 | if re.match(b,f): |
---|
| 312 | doban=True |
---|
| 313 | if not doban: |
---|
| 314 | f=f.replace('.py','') |
---|
| 315 | load_tool(f) |
---|
[0fa325b] | 316 | cache_modules={} |
---|
[904702d] | 317 | def load_module(path,encoding=None): |
---|
[0fa325b] | 318 | try: |
---|
| 319 | return cache_modules[path] |
---|
| 320 | except KeyError: |
---|
| 321 | pass |
---|
| 322 | module=imp.new_module(WSCRIPT_FILE) |
---|
| 323 | try: |
---|
[904702d] | 324 | code=Utils.readf(path,m='rU',encoding=encoding) |
---|
| 325 | except EnvironmentError: |
---|
[0fa325b] | 326 | raise Errors.WafError('Could not read the file %r'%path) |
---|
| 327 | module_dir=os.path.dirname(path) |
---|
| 328 | sys.path.insert(0,module_dir) |
---|
| 329 | exec(compile(code,path,'exec'),module.__dict__) |
---|
| 330 | sys.path.remove(module_dir) |
---|
| 331 | cache_modules[path]=module |
---|
| 332 | return module |
---|
[904702d] | 333 | def load_tool(tool,tooldir=None,ctx=None): |
---|
[0fa325b] | 334 | if tool=='java': |
---|
| 335 | tool='javaw' |
---|
| 336 | else: |
---|
| 337 | tool=tool.replace('++','xx') |
---|
| 338 | if tooldir: |
---|
| 339 | assert isinstance(tooldir,list) |
---|
| 340 | sys.path=tooldir+sys.path |
---|
| 341 | try: |
---|
| 342 | __import__(tool) |
---|
| 343 | ret=sys.modules[tool] |
---|
| 344 | Context.tools[tool]=ret |
---|
| 345 | return ret |
---|
| 346 | finally: |
---|
| 347 | for d in tooldir: |
---|
| 348 | sys.path.remove(d) |
---|
| 349 | else: |
---|
[904702d] | 350 | for x in('waflib.Tools.%s','waflib.extras.%s','waflib.%s','%s'): |
---|
[0fa325b] | 351 | try: |
---|
[904702d] | 352 | __import__(x%tool) |
---|
| 353 | break |
---|
| 354 | except ImportError: |
---|
| 355 | x=None |
---|
| 356 | if x is None: |
---|
| 357 | __import__(tool) |
---|
| 358 | ret=sys.modules[x%tool] |
---|
[0fa325b] | 359 | Context.tools[tool]=ret |
---|
| 360 | return ret |
---|