3 # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
6 from waflib import Utils,Errors,Logs
10 WAFREVISION="daa91dba4b881d86bc25eec90a3745ebaeece835"
12 DBFILE='.wafpickle-%s-%d-%d'%(sys.platform,sys.hexversion,ABI)
17 WSCRIPT_FILE='wscript'
24 remote_repo='http://waf.googlecode.com/git/'
25 remote_locs=['waflib/extras','waflib/Tools']
31 def create_context(cmd_name,*k,**kw):
39 class store_context(type):
40 def __init__(cls,name,bases,dict):
41 super(store_context,cls).__init__(name,bases,dict)
43 if name=='ctx'or name=='Context':
47 except AttributeError:
48 raise Errors.WafError('Missing command for the context class %r (cmd)'%name)
49 if not getattr(cls,'fun',None):
53 ctx=store_context('ctx',(object,),{})
57 def __init__(self,**kw):
63 class node_class(waflib.Node.Node):
65 self.node_class=node_class
66 self.node_class.__module__="waflib.Node"
67 self.node_class.__name__="Nod3"
68 self.node_class.ctx=self
69 self.root=self.node_class('',None)
71 self.path=self.root.find_dir(rd)
73 self.exec_dict={'ctx':self,'conf':self,'bld':self,'opt':self}
77 def load(self,tool_list,*k,**kw):
78 tools=Utils.to_list(tool_list)
79 path=Utils.to_list(kw.get('tooldir',''))
81 module=load_tool(t,path)
82 fun=getattr(module,kw.get('name',self.fun),None)
87 self.recurse([os.path.dirname(g_module.root_path)])
88 def pre_recurse(self,node):
89 self.stack_path.append(self.cur_script)
92 def post_recurse(self,node):
93 self.cur_script=self.stack_path.pop()
95 self.path=self.cur_script.parent
96 def recurse(self,dirs,name=None,mandatory=True,once=True):
98 cache=self.recurse_cache
99 except AttributeError:
100 cache=self.recurse_cache={}
101 for d in Utils.to_list(dirs):
102 if not os.path.isabs(d):
103 d=os.path.join(self.path.abspath(),d)
104 WSCRIPT=os.path.join(d,WSCRIPT_FILE)
105 WSCRIPT_FUN=WSCRIPT+'_'+(name or self.fun)
106 node=self.root.find_node(WSCRIPT_FUN)
107 if node and(not once or node not in cache):
109 self.pre_recurse(node)
111 function_code=node.read('rU')
112 exec(compile(function_code,node.abspath(),'exec'),self.exec_dict)
114 self.post_recurse(node)
116 node=self.root.find_node(WSCRIPT)
117 tup=(node,name or self.fun)
118 if node and(not once or tup not in cache):
120 self.pre_recurse(node)
122 wscript_module=load_module(node.abspath())
123 user_function=getattr(wscript_module,(name or self.fun),None)
124 if not user_function:
127 raise Errors.WafError('No function %s defined in %s'%(name or self.fun,node.abspath()))
130 self.post_recurse(node)
134 raise Errors.WafError('No wscript file in directory %s'%d)
135 def exec_command(self,cmd,**kw):
136 subprocess=Utils.subprocess
137 kw['shell']=isinstance(cmd,str)
138 Logs.debug('runner: %r'%cmd)
139 Logs.debug('runner_env: kw=%s'%kw)
141 self.logger.info(cmd)
143 kw['stdout']=subprocess.PIPE
145 kw['stderr']=subprocess.PIPE
147 if kw['stdout']or kw['stderr']:
148 p=subprocess.Popen(cmd,**kw)
149 (out,err)=p.communicate()
153 ret=subprocess.Popen(cmd,**kw).wait()
155 raise Errors.WafError('Execution failure: %s'%str(e),ex=e)
157 if not isinstance(out,str):
158 out=out.decode(sys.stdout.encoding or'iso8859-1')
160 self.logger.debug('out: %s'%out)
162 sys.stdout.write(out)
164 if not isinstance(err,str):
165 err=err.decode(sys.stdout.encoding or'iso8859-1')
167 self.logger.error('err: %s'%err)
169 sys.stderr.write(err)
171 def cmd_and_log(self,cmd,**kw):
172 subprocess=Utils.subprocess
173 kw['shell']=isinstance(cmd,str)
174 Logs.debug('runner: %r'%cmd)
185 kw['stdout']=kw['stderr']=subprocess.PIPE
189 p=subprocess.Popen(cmd,**kw)
190 (out,err)=p.communicate()
192 raise Errors.WafError('Execution failure: %s'%str(e),ex=e)
193 if not isinstance(out,str):
194 out=out.decode(sys.stdout.encoding or'iso8859-1')
195 if not isinstance(err,str):
196 err=err.decode(sys.stdout.encoding or'iso8859-1')
197 if out and quiet!=STDOUT and quiet!=BOTH:
198 self.to_log('out: %s'%out)
199 if err and quiet!=STDERR and quiet!=BOTH:
200 self.to_log('err: %s'%err)
202 e=Errors.WafError('Command %r returned %r'%(cmd,p.returncode))
203 e.returncode=p.returncode
212 def fatal(self,msg,ex=None):
214 self.logger.info('from %s: %s'%(self.path.abspath(),msg))
216 msg='%s\n(complete log in %s)'%(msg,self.logger.handlers[0].baseFilename)
219 raise self.errors.ConfigurationError(msg,ex=ex)
220 def to_log(self,msg):
224 self.logger.info(msg)
226 sys.stderr.write(str(msg))
228 def msg(self,msg,result,color=None):
230 if not isinstance(color,str):
231 color=result and'GREEN'or'YELLOW'
232 self.end_msg(result,color)
233 def start_msg(self,msg):
238 except AttributeError:
242 self.line_just=max(self.line_just,len(msg))
243 except AttributeError:
244 self.line_just=max(40,len(msg))
245 for x in(self.line_just*'-',msg):
247 Logs.pprint('NORMAL',"%s :"%msg.ljust(self.line_just),sep='')
248 def end_msg(self,result,color=None):
261 Logs.pprint(color or defcolor,msg)
262 def load_special_tools(self,var,ban=[]):
264 lst=self.root.find_node(waf_dir).find_node('waflib/extras').ant_glob(var)
266 if not x.name in ban:
267 load_tool(x.name.replace('.py',''))
269 def load_module(path):
271 return cache_modules[path]
274 module=imp.new_module(WSCRIPT_FILE)
276 code=Utils.readf(path,m='rU')
277 except(IOError,OSError):
278 raise Errors.WafError('Could not read the file %r'%path)
279 module_dir=os.path.dirname(path)
280 sys.path.insert(0,module_dir)
281 exec(compile(code,path,'exec'),module.__dict__)
282 sys.path.remove(module_dir)
283 cache_modules[path]=module
285 def load_tool(tool,tooldir=None):
288 elif tool=='compiler_cc':
291 tool=tool.replace('++','xx')
293 assert isinstance(tooldir,list)
294 sys.path=tooldir+sys.path
297 ret=sys.modules[tool]
298 Context.tools[tool]=ret
306 os.stat(os.path.join(waf_dir,'waflib','extras',tool+'.py'))
309 os.stat(os.path.join(waf_dir,'waflib','Tools',tool+'.py'))
313 d='waflib.Tools.%s'%tool
315 d='waflib.extras.%s'%tool
318 Context.tools[tool]=ret