3
# WARNING! Do not edit! http://waf.googlecode.com/svn/docs/wafbook/single.html#_obtaining_the_waf_file
5
import os,shutil,traceback,errno,sys,stat
6
from waflib import Utils,Configure,Logs,Options,ConfigSet,Context,Errors,Build,Node
7
build_dir_override=None
8
no_climb_commands=['configure']
10
def waf_entry_point(current_directory,version,wafdir):
12
if Context.WAFVERSION!=version:
13
Logs.error('Waf script %r and library %r do not match (directory %r)'%(version,Context.WAFVERSION,wafdir))
15
if'--version'in sys.argv:
16
ctx=Context.create_context('options')
17
ctx.curdir=current_directory
20
Context.waf_dir=wafdir
21
Context.launch_dir=current_directory
22
no_climb=os.environ.get('NOCLIMB',None)
24
for k in no_climb_commands:
31
if Options.lockfile in lst:
32
env=ConfigSet.ConfigSet()
34
env.load(os.path.join(cur,Options.lockfile))
35
ino=os.stat(cur)[stat.ST_INO]
39
for x in[env.run_dir,env.top_dir,env.out_dir]:
46
ino2=os.stat(x)[stat.ST_INO]
54
Logs.warn('invalid lock file in %s'%cur)
57
Context.run_dir=env.run_dir
58
Context.top_dir=env.top_dir
59
Context.out_dir=env.out_dir
61
if not Context.run_dir:
62
if Context.WSCRIPT_FILE in lst:
64
next=os.path.dirname(cur)
70
if not Context.run_dir:
71
if'-h'in sys.argv or'--help'in sys.argv:
72
Logs.warn('No wscript file found: the help message may be incomplete')
73
ctx=Context.create_context('options')
74
ctx.curdir=current_directory
77
Logs.error('Waf: Run from a directory containing a file named %r'%Context.WSCRIPT_FILE)
80
os.chdir(Context.run_dir)
82
Logs.error('Waf: The folder %r is unreadable'%Context.run_dir)
85
set_main_module(Context.run_dir+os.sep+Context.WSCRIPT_FILE)
86
except Errors.WafError ,e:
87
Logs.pprint('RED',e.verbose_msg)
91
Logs.error('Waf: The wscript in %r is unreadable'%Context.run_dir,e)
92
traceback.print_exc(file=sys.stdout)
97
except Errors.WafError ,e:
99
Logs.pprint('RED',e.verbose_msg)
103
traceback.print_exc(file=sys.stdout)
105
except KeyboardInterrupt:
106
Logs.pprint('RED','Interrupted')
108
def set_main_module(file_path):
109
Context.g_module=Context.load_module(file_path)
110
Context.g_module.root_path=file_path
113
if not name in Context.g_module.__dict__:
114
setattr(Context.g_module,name,obj)
115
for k in[update,dist,distclean,distcheck,update]:
117
if not'init'in Context.g_module.__dict__:
118
Context.g_module.init=Utils.nada
119
if not'shutdown'in Context.g_module.__dict__:
120
Context.g_module.shutdown=Utils.nada
121
if not'options'in Context.g_module.__dict__:
122
Context.g_module.options=Utils.nada
124
Context.create_context('options').execute()
125
if not Options.commands:
126
Options.commands=[default_cmd]
127
Logs.verbose=Options.options.verbose
129
if Options.options.zones:
130
Logs.zones=Options.options.zones.split(',')
134
Logs.zones=['runner']
137
def run_command(cmd_name):
138
ctx=Context.create_context(cmd_name)
139
ctx.options=Options.options
145
while Options.commands:
146
cmd_name=Options.commands.pop(0)
148
run_command(cmd_name)
149
if not Options.options.progress_bar:
150
elapsed=' (%s)'%str(timer)
151
Logs.info('%r finished successfully%s'%(cmd_name,elapsed))
152
run_command('shutdown')
153
def _can_distclean(name):
154
for k in'.o .moc .exe'.split():
158
def distclean_dir(dirname):
159
for(root,dirs,files)in os.walk(dirname):
161
if _can_distclean(f):
166
Logs.warn('could not remove %r'%fname)
167
for x in[Context.DBFILE,'config.log']:
173
shutil.rmtree('c4che')
177
'''removes the build directory'''
180
if f==Options.lockfile:
182
proj=ConfigSet.ConfigSet(f)
184
Logs.warn('could not read %r'%f)
186
if proj['out_dir']!=proj['top_dir']:
188
shutil.rmtree(proj['out_dir'])
192
if e.errno!=errno.ENOENT:
193
Logs.warn('project %r cannot be removed'%proj[Context.OUT])
195
distclean_dir(proj['out_dir'])
196
for k in(proj['out_dir'],proj['top_dir'],proj['run_dir']):
198
os.remove(os.path.join(k,Options.lockfile))
200
if e.errno!=errno.ENOENT:
201
Logs.warn('file %r cannot be removed'%f)
202
if f.startswith('.waf-')and not Options.commands:
203
shutil.rmtree(f,ignore_errors=True)
204
class Dist(Context.Context):
210
self.recurse([os.path.dirname(Context.g_module.root_path)])
214
arch_name=self.get_arch_name()
218
self.base_path=self.path
219
node=self.base_path.make_node(arch_name)
224
files=self.get_files()
225
if self.algo.startswith('tar.'):
226
tar=tarfile.open(arch_name,'w:'+self.algo.replace('tar.',''))
228
tinfo=tar.gettarinfo(name=x.abspath(),arcname=self.get_tar_prefix()+'/'+x.path_from(self.base_path))
235
fu=open(x.abspath(),'rb')
236
tar.addfile(tinfo,fileobj=fu)
240
elif self.algo=='zip':
242
zip=zipfile.ZipFile(arch_name,'w',compression=zipfile.ZIP_DEFLATED)
244
archive_name=self.get_base_name()+'/'+x.path_from(self.base_path)
245
zip.write(x.abspath(),archive_name,zipfile.ZIP_DEFLATED)
248
self.fatal('Valid algo types are tar.bz2, tar.gz or zip')
250
from hashlib import sha1 as sha
254
digest=" (sha=%r)"%sha(node.read()).hexdigest()
257
Logs.info('New archive created: %s%s'%(self.arch_name,digest))
258
def get_tar_prefix(self):
260
return self.tar_prefix
262
return self.get_base_name()
263
def get_arch_name(self):
267
self.arch_name=self.get_base_name()+'.'+self.ext_algo.get(self.algo,self.algo)
268
return self.arch_name
269
def get_base_name(self):
273
appname=getattr(Context.g_module,Context.APPNAME,'noname')
274
version=getattr(Context.g_module,Context.VERSION,'1.0')
275
self.base_name=appname+'-'+version
276
return self.base_name
281
self.excl=Node.exclude_regs+' **/waf-1.6.* **/.waf-1.6* **/*~ **/*.rej **/*.orig **/*.pyc **/*.pyo **/*.bak **/*.swp **/.lock-w*'
282
nd=self.root.find_node(Context.out_dir)
284
self.excl+=' '+nd.path_from(self.base_path)
290
files=self.base_path.ant_glob('**/*',excl=self.get_excl())
293
'''makes a tarball for redistributing the sources'''
295
class DistCheck(Dist):
299
self.recurse([os.path.dirname(Context.g_module.root_path)])
303
import tempfile,tarfile
306
t=tarfile.open(self.get_arch_name())
312
instdir=tempfile.mkdtemp('.inst',self.get_base_name())
313
ret=Utils.subprocess.Popen([sys.argv[0],'configure','install','uninstall','--destdir='+instdir],cwd=self.get_base_name()).wait()
315
raise Errors.WafError('distcheck failed with code %i'%ret)
316
if os.path.exists(instdir):
317
raise Errors.WafError('distcheck succeeded, but files were left in %s'%instdir)
318
shutil.rmtree(self.get_base_name())
320
'''checks if the project compiles (tarball from 'dist')'''
323
'''updates the plugins from the *waflib/extras* directory'''
324
lst=Options.options.files.split(',')
326
lst=[x for x in Utils.listdir(Context.waf_dir+'/waflib/extras')if x.endswith('.py')]
328
tool=x.replace('.py','')
330
Configure.download_tool(tool,force=True,ctx=ctx)
331
except Errors.WafError:
332
Logs.error('Could not find the tool %s in the remote repository'%x)
333
def autoconfigure(execute_method):
335
if not Configure.autoconfig:
336
return execute_method(self)
337
env=ConfigSet.ConfigSet()
340
env.load(os.path.join(Context.top_dir,Options.lockfile))
342
Logs.warn('Configuring the project')
345
if env.run_dir!=Context.run_dir:
349
for f in env['files']:
350
h=hash((h,Utils.readf(f,'rb')))
351
do_config=h!=env.hash
353
Options.commands.insert(0,self.cmd)
354
Options.commands.insert(0,'configure')
356
return execute_method(self)
358
Build.BuildContext.execute=autoconfigure(Build.BuildContext.execute)