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,imp,sys |
---|
6 | from waflib import Utils,Errors,Logs |
---|
7 | import waflib.Node |
---|
8 | HEXVERSION=0x1070f00 |
---|
9 | WAFVERSION="1.7.15" |
---|
10 | WAFREVISION="f63ac9793de2d4eaae884e55d4ff70a761dcbab2" |
---|
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 |
---|
63 | self.node_class=type("Nod3",(waflib.Node.Node,),{}) |
---|
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) |
---|
74 | def load(self,tool_list,*k,**kw): |
---|
75 | tools=Utils.to_list(tool_list) |
---|
76 | path=Utils.to_list(kw.get('tooldir','')) |
---|
77 | for t in tools: |
---|
78 | module=load_tool(t,path) |
---|
79 | fun=getattr(module,kw.get('name',self.fun),None) |
---|
80 | if fun: |
---|
81 | fun(self) |
---|
82 | def execute(self): |
---|
83 | global g_module |
---|
84 | self.recurse([os.path.dirname(g_module.root_path)]) |
---|
85 | def pre_recurse(self,node): |
---|
86 | self.stack_path.append(self.cur_script) |
---|
87 | self.cur_script=node |
---|
88 | self.path=node.parent |
---|
89 | def post_recurse(self,node): |
---|
90 | self.cur_script=self.stack_path.pop() |
---|
91 | if self.cur_script: |
---|
92 | self.path=self.cur_script.parent |
---|
93 | def recurse(self,dirs,name=None,mandatory=True,once=True): |
---|
94 | try: |
---|
95 | cache=self.recurse_cache |
---|
96 | except AttributeError: |
---|
97 | cache=self.recurse_cache={} |
---|
98 | for d in Utils.to_list(dirs): |
---|
99 | if not os.path.isabs(d): |
---|
100 | d=os.path.join(self.path.abspath(),d) |
---|
101 | WSCRIPT=os.path.join(d,WSCRIPT_FILE) |
---|
102 | WSCRIPT_FUN=WSCRIPT+'_'+(name or self.fun) |
---|
103 | node=self.root.find_node(WSCRIPT_FUN) |
---|
104 | if node and(not once or node not in cache): |
---|
105 | cache[node]=True |
---|
106 | self.pre_recurse(node) |
---|
107 | try: |
---|
108 | function_code=node.read('rU') |
---|
109 | exec(compile(function_code,node.abspath(),'exec'),self.exec_dict) |
---|
110 | finally: |
---|
111 | self.post_recurse(node) |
---|
112 | elif not node: |
---|
113 | node=self.root.find_node(WSCRIPT) |
---|
114 | tup=(node,name or self.fun) |
---|
115 | if node and(not once or tup not in cache): |
---|
116 | cache[tup]=True |
---|
117 | self.pre_recurse(node) |
---|
118 | try: |
---|
119 | wscript_module=load_module(node.abspath()) |
---|
120 | user_function=getattr(wscript_module,(name or self.fun),None) |
---|
121 | if not user_function: |
---|
122 | if not mandatory: |
---|
123 | continue |
---|
124 | raise Errors.WafError('No function %s defined in %s'%(name or self.fun,node.abspath())) |
---|
125 | user_function(self) |
---|
126 | finally: |
---|
127 | self.post_recurse(node) |
---|
128 | elif not node: |
---|
129 | if not mandatory: |
---|
130 | continue |
---|
131 | raise Errors.WafError('No wscript file in directory %s'%d) |
---|
132 | def exec_command(self,cmd,**kw): |
---|
133 | subprocess=Utils.subprocess |
---|
134 | kw['shell']=isinstance(cmd,str) |
---|
135 | Logs.debug('runner: %r'%cmd) |
---|
136 | Logs.debug('runner_env: kw=%s'%kw) |
---|
137 | if self.logger: |
---|
138 | self.logger.info(cmd) |
---|
139 | if'stdout'not in kw: |
---|
140 | kw['stdout']=subprocess.PIPE |
---|
141 | if'stderr'not in kw: |
---|
142 | kw['stderr']=subprocess.PIPE |
---|
143 | try: |
---|
144 | if kw['stdout']or kw['stderr']: |
---|
145 | p=subprocess.Popen(cmd,**kw) |
---|
146 | (out,err)=p.communicate() |
---|
147 | ret=p.returncode |
---|
148 | else: |
---|
149 | out,err=(None,None) |
---|
150 | ret=subprocess.Popen(cmd,**kw).wait() |
---|
151 | except Exception ,e: |
---|
152 | raise Errors.WafError('Execution failure: %s'%str(e),ex=e) |
---|
153 | if out: |
---|
154 | if not isinstance(out,str): |
---|
155 | out=out.decode(sys.stdout.encoding or'iso8859-1') |
---|
156 | if self.logger: |
---|
157 | self.logger.debug('out: %s'%out) |
---|
158 | else: |
---|
159 | sys.stdout.write(out) |
---|
160 | if err: |
---|
161 | if not isinstance(err,str): |
---|
162 | err=err.decode(sys.stdout.encoding or'iso8859-1') |
---|
163 | if self.logger: |
---|
164 | self.logger.error('err: %s'%err) |
---|
165 | else: |
---|
166 | sys.stderr.write(err) |
---|
167 | return ret |
---|
168 | def cmd_and_log(self,cmd,**kw): |
---|
169 | subprocess=Utils.subprocess |
---|
170 | kw['shell']=isinstance(cmd,str) |
---|
171 | Logs.debug('runner: %r'%cmd) |
---|
172 | if'quiet'in kw: |
---|
173 | quiet=kw['quiet'] |
---|
174 | del kw['quiet'] |
---|
175 | else: |
---|
176 | quiet=None |
---|
177 | if'output'in kw: |
---|
178 | to_ret=kw['output'] |
---|
179 | del kw['output'] |
---|
180 | else: |
---|
181 | to_ret=STDOUT |
---|
182 | kw['stdout']=kw['stderr']=subprocess.PIPE |
---|
183 | if quiet is None: |
---|
184 | self.to_log(cmd) |
---|
185 | try: |
---|
186 | p=subprocess.Popen(cmd,**kw) |
---|
187 | (out,err)=p.communicate() |
---|
188 | except Exception ,e: |
---|
189 | raise Errors.WafError('Execution failure: %s'%str(e),ex=e) |
---|
190 | if not isinstance(out,str): |
---|
191 | out=out.decode(sys.stdout.encoding or'iso8859-1') |
---|
192 | if not isinstance(err,str): |
---|
193 | err=err.decode(sys.stdout.encoding or'iso8859-1') |
---|
194 | if out and quiet!=STDOUT and quiet!=BOTH: |
---|
195 | self.to_log('out: %s'%out) |
---|
196 | if err and quiet!=STDERR and quiet!=BOTH: |
---|
197 | self.to_log('err: %s'%err) |
---|
198 | if p.returncode: |
---|
199 | e=Errors.WafError('Command %r returned %r'%(cmd,p.returncode)) |
---|
200 | e.returncode=p.returncode |
---|
201 | e.stderr=err |
---|
202 | e.stdout=out |
---|
203 | raise e |
---|
204 | if to_ret==BOTH: |
---|
205 | return(out,err) |
---|
206 | elif to_ret==STDERR: |
---|
207 | return err |
---|
208 | return out |
---|
209 | def fatal(self,msg,ex=None): |
---|
210 | if self.logger: |
---|
211 | self.logger.info('from %s: %s'%(self.path.abspath(),msg)) |
---|
212 | try: |
---|
213 | msg='%s\n(complete log in %s)'%(msg,self.logger.handlers[0].baseFilename) |
---|
214 | except Exception: |
---|
215 | pass |
---|
216 | raise self.errors.ConfigurationError(msg,ex=ex) |
---|
217 | def to_log(self,msg): |
---|
218 | if not msg: |
---|
219 | return |
---|
220 | if self.logger: |
---|
221 | self.logger.info(msg) |
---|
222 | else: |
---|
223 | sys.stderr.write(str(msg)) |
---|
224 | sys.stderr.flush() |
---|
225 | def msg(self,msg,result,color=None): |
---|
226 | self.start_msg(msg) |
---|
227 | if not isinstance(color,str): |
---|
228 | color=result and'GREEN'or'YELLOW' |
---|
229 | self.end_msg(result,color) |
---|
230 | def start_msg(self,msg): |
---|
231 | try: |
---|
232 | if self.in_msg: |
---|
233 | self.in_msg+=1 |
---|
234 | return |
---|
235 | except AttributeError: |
---|
236 | self.in_msg=0 |
---|
237 | self.in_msg+=1 |
---|
238 | try: |
---|
239 | self.line_just=max(self.line_just,len(msg)) |
---|
240 | except AttributeError: |
---|
241 | self.line_just=max(40,len(msg)) |
---|
242 | for x in(self.line_just*'-',msg): |
---|
243 | self.to_log(x) |
---|
244 | Logs.pprint('NORMAL',"%s :"%msg.ljust(self.line_just),sep='') |
---|
245 | def end_msg(self,result,color=None): |
---|
246 | self.in_msg-=1 |
---|
247 | if self.in_msg: |
---|
248 | return |
---|
249 | defcolor='GREEN' |
---|
250 | if result==True: |
---|
251 | msg='ok' |
---|
252 | elif result==False: |
---|
253 | msg='not found' |
---|
254 | defcolor='YELLOW' |
---|
255 | else: |
---|
256 | msg=str(result) |
---|
257 | self.to_log(msg) |
---|
258 | Logs.pprint(color or defcolor,msg) |
---|
259 | def load_special_tools(self,var,ban=[]): |
---|
260 | global waf_dir |
---|
261 | lst=self.root.find_node(waf_dir).find_node('waflib/extras').ant_glob(var) |
---|
262 | for x in lst: |
---|
263 | if not x.name in ban: |
---|
264 | load_tool(x.name.replace('.py','')) |
---|
265 | cache_modules={} |
---|
266 | def load_module(path): |
---|
267 | try: |
---|
268 | return cache_modules[path] |
---|
269 | except KeyError: |
---|
270 | pass |
---|
271 | module=imp.new_module(WSCRIPT_FILE) |
---|
272 | try: |
---|
273 | code=Utils.readf(path,m='rU') |
---|
274 | except(IOError,OSError): |
---|
275 | raise Errors.WafError('Could not read the file %r'%path) |
---|
276 | module_dir=os.path.dirname(path) |
---|
277 | sys.path.insert(0,module_dir) |
---|
278 | exec(compile(code,path,'exec'),module.__dict__) |
---|
279 | sys.path.remove(module_dir) |
---|
280 | cache_modules[path]=module |
---|
281 | return module |
---|
282 | def load_tool(tool,tooldir=None): |
---|
283 | if tool=='java': |
---|
284 | tool='javaw' |
---|
285 | elif tool=='compiler_cc': |
---|
286 | tool='compiler_c' |
---|
287 | else: |
---|
288 | tool=tool.replace('++','xx') |
---|
289 | if tooldir: |
---|
290 | assert isinstance(tooldir,list) |
---|
291 | sys.path=tooldir+sys.path |
---|
292 | try: |
---|
293 | __import__(tool) |
---|
294 | ret=sys.modules[tool] |
---|
295 | Context.tools[tool]=ret |
---|
296 | return ret |
---|
297 | finally: |
---|
298 | for d in tooldir: |
---|
299 | sys.path.remove(d) |
---|
300 | else: |
---|
301 | global waf_dir |
---|
302 | try: |
---|
303 | os.stat(os.path.join(waf_dir,'waflib','extras',tool+'.py')) |
---|
304 | except OSError: |
---|
305 | try: |
---|
306 | os.stat(os.path.join(waf_dir,'waflib','Tools',tool+'.py')) |
---|
307 | except OSError: |
---|
308 | d=tool |
---|
309 | else: |
---|
310 | d='waflib.Tools.%s'%tool |
---|
311 | else: |
---|
312 | d='waflib.extras.%s'%tool |
---|
313 | __import__(d) |
---|
314 | ret=sys.modules[d] |
---|
315 | Context.tools[tool]=ret |
---|
316 | return ret |
---|