source: waflib/Configure.py @ 904702d

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 904702d was 904702d, checked in by Paul Brossier <piem@piem.org>, 10 years ago

waf, waflib: update to 1.8.7

  • Property mode set to 100644
File size: 11.0 KB
Line 
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
5import os,shlex,sys,time,re,shutil
6from waflib import ConfigSet,Utils,Options,Logs,Context,Build,Errors
7BREAK='break'
8CONTINUE='continue'
9WAF_CONFIG_LOG='config.log'
10autoconfig=False
11conf_template='''# project %(app)s configured on %(now)s by
12# waf %(wafver)s (abi %(abi)s, python %(pyver)x on %(systype)s)
13# using %(args)s
14#'''
15class ConfigurationContext(Context.Context):
16        '''configures the project'''
17        cmd='configure'
18        error_handlers=[]
19        def __init__(self,**kw):
20                super(ConfigurationContext,self).__init__(**kw)
21                self.environ=dict(os.environ)
22                self.all_envs={}
23                self.top_dir=None
24                self.out_dir=None
25                self.tools=[]
26                self.hash=0
27                self.files=[]
28                self.tool_cache=[]
29                self.setenv('')
30        def setenv(self,name,env=None):
31                if name not in self.all_envs or env:
32                        if not env:
33                                env=ConfigSet.ConfigSet()
34                                self.prepare_env(env)
35                        else:
36                                env=env.derive()
37                        self.all_envs[name]=env
38                self.variant=name
39        def get_env(self):
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)
44        def init_dirs(self):
45                top=self.top_dir
46                if not top:
47                        top=Options.options.top
48                if not top:
49                        top=getattr(Context.g_module,Context.TOP,None)
50                if not top:
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)
54                assert(self.srcnode)
55                out=self.out_dir
56                if not out:
57                        out=Options.options.out
58                if not out:
59                        out=getattr(Context.g_module,Context.OUT,None)
60                if not out:
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)
64                self.bldnode.mkdir()
65                if not os.path.isdir(self.bldnode.abspath()):
66                        conf.fatal('Could not create the build directory %s'%self.bldnode.abspath())
67        def execute(self):
68                self.init_dirs()
69                self.cachedir=self.bldnode.make_node(Build.CACHE_DIR)
70                self.cachedir.mkdir()
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','')
74                if app:
75                        ver=getattr(Context.g_module,'VERSION','')
76                        if ver:
77                                app="%s (%s)"%(app,ver)
78                now=time.ctime()
79                pyver=sys.hexversion
80                systype=sys.platform
81                args=" ".join(sys.argv)
82                wafver=Context.WAFVERSION
83                abi=Context.ABI
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()
93                self.store()
94                Context.top_dir=self.srcnode.abspath()
95                Context.out_dir=self.bldnode.abspath()
96                env=ConfigSet.ConfigSet()
97                env['argv']=sys.argv
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):
112                if not env.PREFIX:
113                        if Options.options.prefix or Utils.is_win32:
114                                env.PREFIX=os.path.abspath(os.path.expanduser(Options.options.prefix))
115                        else:
116                                env.PREFIX=''
117                if not env.BINDIR:
118                        if Options.options.bindir:
119                                env.BINDIR=os.path.abspath(os.path.expanduser(Options.options.bindir))
120                        else:
121                                env.BINDIR=Utils.subst_vars('${PREFIX}/bin',env)
122                if not env.LIBDIR:
123                        if Options.options.libdir:
124                                env.LIBDIR=os.path.abspath(os.path.expanduser(Options.options.libdir))
125                        else:
126                                env.LIBDIR=Utils.subst_vars('${PREFIX}/lib%s'%Utils.lib64(),env)
127        def store(self):
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)
138                for tool in tools:
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)
142                                continue
143                        self.tool_cache.append(mag)
144                        module=None
145                        try:
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))
149                        except Exception ,e:
150                                self.to_log('imp %r (%r & %r)'%(tool,tooldir,funs))
151                                self.to_log(Utils.ex_stack())
152                                raise
153                        if funs is not None:
154                                self.eval_rules(funs)
155                        else:
156                                func=getattr(module,'configure',None)
157                                if func:
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)
167                for x in self.rules:
168                        f=getattr(self,x)
169                        if not f:self.fatal("No such method '%s'."%x)
170                        try:
171                                f()
172                        except Exception ,e:
173                                ret=self.err_handler(x,e)
174                                if ret==BREAK:
175                                        break
176                                elif ret==CONTINUE:
177                                        continue
178                                else:
179                                        raise
180        def err_handler(self,fun,error):
181                pass
182def conf(f):
183        def fun(*k,**kw):
184                mandatory=True
185                if'mandatory'in kw:
186                        mandatory=kw['mandatory']
187                        del kw['mandatory']
188                try:
189                        return f(*k,**kw)
190                except Errors.ConfigurationError:
191                        if mandatory:
192                                raise
193        setattr(ConfigurationContext,f.__name__,fun)
194        setattr(Build.BuildContext,f.__name__,fun)
195        return f
196@conf
197def add_os_flags(self,var,dest=None):
198        try:self.env.append_value(dest or var,shlex.split(self.environ[var]))
199        except KeyError:pass
200@conf
201def cmd_to_list(self,cmd):
202        if isinstance(cmd,str)and cmd.find(' '):
203                try:
204                        os.stat(cmd)
205                except OSError:
206                        return shlex.split(cmd)
207                else:
208                        return[cmd]
209        return cmd
210@conf
211def 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)
219@conf
220def find_file(self,filename,path_list=[]):
221        for n in Utils.to_list(filename):
222                for d in Utils.to_list(path_list):
223                        p=os.path.join(d,n)
224                        if os.path.exists(p):
225                                return p
226        self.fatal('Could not find %r'%filename)
227@conf
228def 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))
231        ret=''
232        filename=Utils.to_list(filename)
233        msg=kw.get('msg',', '.join(filename))
234        var=kw.get('var','')
235        if not var:
236                var=re.sub(r'[-.]','_',filename[0].upper())
237        path_list=kw.get('path_list','')
238        if path_list:
239                path_list=Utils.to_list(path_list)
240        else:
241                path_list=environ.get('PATH','').split(os.pathsep)
242        if var in environ:
243                filename=environ[var]
244                if os.path.isfile(filename):
245                        ret=[filename]
246                else:
247                        ret=self.cmd_to_list(filename)
248        elif self.env[var]:
249                ret=self.env[var]
250                ret=self.cmd_to_list(ret)
251        else:
252                if not 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)
259        if ret:
260                if len(ret)==1:
261                        retmsg=ret[0]
262                else:
263                        retmsg=ret
264        else:
265                retmsg=False
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))
269        if not 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)
275                self.env[var]=ret
276        else:
277                self.env[var]=self.env[interpreter]+ret
278        return ret
279@conf
280def find_binary(self,filenames,exts,paths):
281        for f in filenames:
282                for ext in exts:
283                        exe_name=f+ext
284                        if os.path.isabs(exe_name):
285                                if os.path.isfile(exe_name):
286                                        return exe_name
287                        else:
288                                for path in paths:
289                                        x=os.path.expanduser(os.path.join(path,exe_name))
290                                        if os.path.isfile(x):
291                                                return x
292        return None
293@conf
294def run_build(self,*k,**kw):
295        lst=[str(v)for(p,v)in kw.items()if p!='env']
296        h=Utils.h_list(lst)
297        dir=self.bldnode.abspath()+os.sep+(not Utils.is_win32 and'.'or'')+'conf_check_'+Utils.to_hex(h)
298        try:
299                os.makedirs(dir)
300        except OSError:
301                pass
302        try:
303                os.stat(dir)
304        except OSError:
305                self.fatal('cannot use the configuration test folder %r'%dir)
306        cachemode=getattr(Options.options,'confcache',None)
307        if cachemode==1:
308                try:
309                        proj=ConfigSet.ConfigSet(os.path.join(dir,'cache_run_build'))
310                except OSError:
311                        pass
312                except IOError:
313                        pass
314                else:
315                        ret=proj['cache_run_build']
316                        if isinstance(ret,str)and ret.startswith('Test does not build'):
317                                self.fatal(ret)
318                        return ret
319        bdir=os.path.join(dir,'testbuild')
320        if not os.path.exists(bdir):
321                os.makedirs(bdir)
322        self.test_bld=bld=Build.BuildContext(top_dir=dir,out_dir=bdir)
323        bld.init_dirs()
324        bld.progress_bar=0
325        bld.targets='*'
326        bld.logger=self.logger
327        bld.all_envs.update(self.all_envs)
328        bld.env=kw['env']
329        bld.kw=kw
330        bld.conf=self
331        kw['build_fun'](bld)
332        ret=-1
333        try:
334                try:
335                        bld.compile()
336                except Errors.WafError:
337                        ret='Test does not build: %s'%Utils.ex_stack()
338                        self.fatal(ret)
339                else:
340                        ret=getattr(bld,'retval',0)
341        finally:
342                if cachemode==1:
343                        proj=ConfigSet.ConfigSet()
344                        proj['cache_run_build']=ret
345                        proj.store(os.path.join(dir,'cache_run_build'))
346                else:
347                        shutil.rmtree(dir)
348        return ret
349@conf
350def ret_msg(self,msg,args):
351        if isinstance(msg,str):
352                return msg
353        return msg(args)
354@conf
355def test(self,*k,**kw):
356        if not'env'in kw:
357                kw['env']=self.env.derive()
358        if kw.get('validate',None):
359                kw['validate'](kw)
360        self.start_msg(kw['msg'],**kw)
361        ret=None
362        try:
363                ret=self.run_build(*k,**kw)
364        except self.errors.ConfigurationError:
365                self.end_msg(kw['errmsg'],'YELLOW',**kw)
366                if Logs.verbose>1:
367                        raise
368                else:
369                        self.fatal('The configuration failed')
370        else:
371                kw['success']=ret
372        if kw.get('post_check',None):
373                ret=kw['post_check'](kw)
374        if ret:
375                self.end_msg(kw['errmsg'],'YELLOW',**kw)
376                self.fatal('The configuration failed %r'%ret)
377        else:
378                self.end_msg(self.ret_msg(kw['okmsg'],kw),**kw)
379        return ret
Note: See TracBrowser for help on using the repository browser.