3 # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
5 import os,shlex,sys,time,re,shutil
6 from waflib import ConfigSet,Utils,Options,Logs,Context,Build,Errors
9 WAF_CONFIG_LOG='config.log'
11 conf_template='''# project %(app)s configured on %(now)s by
12 # waf %(wafver)s (abi %(abi)s, python %(pyver)x on %(systype)s)
15 class ConfigurationContext(Context.Context):
16 '''configures the project'''
19 def __init__(self,**kw):
20 super(ConfigurationContext,self).__init__(**kw)
21 self.environ=dict(os.environ)
30 def setenv(self,name,env=None):
31 if name not in self.all_envs or env:
33 env=ConfigSet.ConfigSet()
37 self.all_envs[name]=env
40 return self.all_envs[self.variant]
41 def set_env(self,val):
42 self.all_envs[self.variant]=val
43 env=property(get_env,set_env)
47 top=Options.options.top
49 top=getattr(Context.g_module,Context.TOP,None)
51 top=self.path.abspath()
52 top=os.path.abspath(top)
53 self.srcnode=(os.path.isabs(top)and self.root or self.path).find_dir(top)
57 out=Options.options.out
59 out=getattr(Context.g_module,Context.OUT,None)
61 out=Options.lockfile.replace('.lock-waf_%s_'%sys.platform,'').replace('.lock-waf','')
62 out=os.path.realpath(out)
63 self.bldnode=(os.path.isabs(out)and self.root or self.path).make_node(out)
65 if not os.path.isdir(self.bldnode.abspath()):
66 conf.fatal('Could not create the build directory %s'%self.bldnode.abspath())
69 self.cachedir=self.bldnode.make_node(Build.CACHE_DIR)
71 path=os.path.join(self.bldnode.abspath(),WAF_CONFIG_LOG)
72 self.logger=Logs.make_logger(path,'cfg')
73 app=getattr(Context.g_module,'APPNAME','')
75 ver=getattr(Context.g_module,'VERSION','')
77 app="%s (%s)"%(app,ver)
81 args=" ".join(sys.argv)
82 wafver=Context.WAFVERSION
84 self.to_log(conf_template%vars())
85 self.msg('Setting top to',self.srcnode.abspath())
86 self.msg('Setting out to',self.bldnode.abspath())
87 if id(self.srcnode)==id(self.bldnode):
88 Logs.warn('Setting top == out (remember to use "update_outputs")')
89 elif id(self.path)!=id(self.srcnode):
90 if self.srcnode.is_child_of(self.path):
91 Logs.warn('Are you certain that you do not want to set top="." ?')
92 super(ConfigurationContext,self).execute()
94 Context.top_dir=self.srcnode.abspath()
95 Context.out_dir=self.bldnode.abspath()
96 env=ConfigSet.ConfigSet()
98 env['options']=Options.options.__dict__
99 env.run_dir=Context.run_dir
100 env.top_dir=Context.top_dir
101 env.out_dir=Context.out_dir
102 env['hash']=self.hash
103 env['files']=self.files
104 env['environ']=dict(self.environ)
105 if not self.env.NO_LOCK_IN_RUN:
106 env.store(os.path.join(Context.run_dir,Options.lockfile))
107 if not self.env.NO_LOCK_IN_TOP:
108 env.store(os.path.join(Context.top_dir,Options.lockfile))
109 if not self.env.NO_LOCK_IN_OUT:
110 env.store(os.path.join(Context.out_dir,Options.lockfile))
111 def prepare_env(self,env):
113 if Options.options.prefix or Utils.is_win32:
114 env.PREFIX=os.path.abspath(os.path.expanduser(Options.options.prefix))
118 if Options.options.bindir:
119 env.BINDIR=os.path.abspath(os.path.expanduser(Options.options.bindir))
121 env.BINDIR=Utils.subst_vars('${PREFIX}/bin',env)
123 if Options.options.libdir:
124 env.LIBDIR=os.path.abspath(os.path.expanduser(Options.options.libdir))
126 env.LIBDIR=Utils.subst_vars('${PREFIX}/lib%s'%Utils.lib64(),env)
128 n=self.cachedir.make_node('build.config.py')
129 n.write('version = 0x%x\ntools = %r\n'%(Context.HEXVERSION,self.tools))
130 if not self.all_envs:
131 self.fatal('nothing to store in the configuration context!')
132 for key in self.all_envs:
133 tmpenv=self.all_envs[key]
134 tmpenv.store(os.path.join(self.cachedir.abspath(),key+Build.CACHE_SUFFIX))
135 def load(self,input,tooldir=None,funs=None):
136 tools=Utils.to_list(input)
137 if tooldir:tooldir=Utils.to_list(tooldir)
139 mag=(tool,id(self.env),funs)
140 if mag in self.tool_cache:
141 self.to_log('(tool %s is already loaded, skipping)'%tool)
143 self.tool_cache.append(mag)
146 module=Context.load_tool(tool,tooldir,ctx=self)
147 except ImportError ,e:
148 self.fatal('Could not load the Waf tool %r from %r\n%s'%(tool,sys.path,e))
150 self.to_log('imp %r (%r & %r)'%(tool,tooldir,funs))
151 self.to_log(Utils.ex_stack())
154 self.eval_rules(funs)
156 func=getattr(module,'configure',None)
158 if type(func)is type(Utils.readf):func(self)
159 else:self.eval_rules(func)
160 self.tools.append({'tool':tool,'tooldir':tooldir,'funs':funs})
161 def post_recurse(self,node):
162 super(ConfigurationContext,self).post_recurse(node)
163 self.hash=Utils.h_list((self.hash,node.read('rb')))
164 self.files.append(node.abspath())
165 def eval_rules(self,rules):
166 self.rules=Utils.to_list(rules)
169 if not f:self.fatal("No such method '%s'."%x)
173 ret=self.err_handler(x,e)
180 def err_handler(self,fun,error):
186 mandatory=kw['mandatory']
190 except Errors.ConfigurationError:
193 setattr(ConfigurationContext,f.__name__,fun)
194 setattr(Build.BuildContext,f.__name__,fun)
197 def add_os_flags(self,var,dest=None):
198 try:self.env.append_value(dest or var,shlex.split(self.environ[var]))
201 def cmd_to_list(self,cmd):
202 if isinstance(cmd,str)and cmd.find(' '):
206 return shlex.split(cmd)
211 def check_waf_version(self,mini='1.7.99',maxi='1.9.0',**kw):
212 self.start_msg('Checking for waf version in %s-%s'%(str(mini),str(maxi)),**kw)
213 ver=Context.HEXVERSION
214 if Utils.num2ver(mini)>ver:
215 self.fatal('waf version should be at least %r (%r found)'%(Utils.num2ver(mini),ver))
216 if Utils.num2ver(maxi)<ver:
217 self.fatal('waf version should be at most %r (%r found)'%(Utils.num2ver(maxi),ver))
218 self.end_msg('ok',**kw)
220 def find_file(self,filename,path_list=[]):
221 for n in Utils.to_list(filename):
222 for d in Utils.to_list(path_list):
224 if os.path.exists(p):
226 self.fatal('Could not find %r'%filename)
228 def find_program(self,filename,**kw):
229 exts=kw.get('exts',Utils.is_win32 and'.exe,.com,.bat,.cmd'or',.sh,.pl,.py')
230 environ=kw.get('environ',getattr(self,'environ',os.environ))
232 filename=Utils.to_list(filename)
233 msg=kw.get('msg',', '.join(filename))
236 var=re.sub(r'[-.]','_',filename[0].upper())
237 path_list=kw.get('path_list','')
239 path_list=Utils.to_list(path_list)
241 path_list=environ.get('PATH','').split(os.pathsep)
243 filename=environ[var]
244 if os.path.isfile(filename):
247 ret=self.cmd_to_list(filename)
250 ret=self.cmd_to_list(ret)
253 ret=self.find_binary(filename,exts.split(','),path_list)
254 if not ret and Utils.winreg:
255 ret=Utils.get_registry_app_path(Utils.winreg.HKEY_CURRENT_USER,filename)
256 if not ret and Utils.winreg:
257 ret=Utils.get_registry_app_path(Utils.winreg.HKEY_LOCAL_MACHINE,filename)
258 ret=self.cmd_to_list(ret)
266 self.msg("Checking for program '%s'"%msg,retmsg,**kw)
267 if not kw.get('quiet',None):
268 self.to_log('find program=%r paths=%r var=%r -> %r'%(filename,path_list,var,ret))
270 self.fatal(kw.get('errmsg','')or'Could not find the program %r'%filename)
271 interpreter=kw.get('interpreter',None)
272 if interpreter is None:
273 if not Utils.check_exe(ret[0],env=environ):
274 self.fatal('Program %r is not executable'%ret)
277 self.env[var]=self.env[interpreter]+ret
280 def find_binary(self,filenames,exts,paths):
284 if os.path.isabs(exe_name):
285 if os.path.isfile(exe_name):
289 x=os.path.expanduser(os.path.join(path,exe_name))
290 if os.path.isfile(x):
294 def run_build(self,*k,**kw):
295 lst=[str(v)for(p,v)in kw.items()if p!='env']
297 dir=self.bldnode.abspath()+os.sep+(not Utils.is_win32 and'.'or'')+'conf_check_'+Utils.to_hex(h)
305 self.fatal('cannot use the configuration test folder %r'%dir)
306 cachemode=getattr(Options.options,'confcache',None)
309 proj=ConfigSet.ConfigSet(os.path.join(dir,'cache_run_build'))
315 ret=proj['cache_run_build']
316 if isinstance(ret,str)and ret.startswith('Test does not build'):
319 bdir=os.path.join(dir,'testbuild')
320 if not os.path.exists(bdir):
322 self.test_bld=bld=Build.BuildContext(top_dir=dir,out_dir=bdir)
326 bld.logger=self.logger
327 bld.all_envs.update(self.all_envs)
336 except Errors.WafError:
337 ret='Test does not build: %s'%Utils.ex_stack()
340 ret=getattr(bld,'retval',0)
343 proj=ConfigSet.ConfigSet()
344 proj['cache_run_build']=ret
345 proj.store(os.path.join(dir,'cache_run_build'))
350 def ret_msg(self,msg,args):
351 if isinstance(msg,str):
355 def test(self,*k,**kw):
357 kw['env']=self.env.derive()
358 if kw.get('validate',None):
360 self.start_msg(kw['msg'],**kw)
363 ret=self.run_build(*k,**kw)
364 except self.errors.ConfigurationError:
365 self.end_msg(kw['errmsg'],'YELLOW',**kw)
369 self.fatal('The configuration failed')
372 if kw.get('post_check',None):
373 ret=kw['post_check'](kw)
375 self.end_msg(kw['errmsg'],'YELLOW',**kw)
376 self.fatal('The configuration failed %r'%ret)
378 self.end_msg(self.ret_msg(kw['okmsg'],kw),**kw)