3
# WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
5
import os,shlex,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
Context.run_dir=current_directory
17
ctx=Context.create_context('options')
18
ctx.curdir=current_directory
21
Context.waf_dir=wafdir
22
Context.launch_dir=current_directory
23
no_climb=os.environ.get('NOCLIMB',None)
25
for k in no_climb_commands:
32
if Options.lockfile in lst:
33
env=ConfigSet.ConfigSet()
35
env.load(os.path.join(cur,Options.lockfile))
36
ino=os.stat(cur)[stat.ST_INO]
40
for x in[env.run_dir,env.top_dir,env.out_dir]:
47
ino2=os.stat(x)[stat.ST_INO]
55
Logs.warn('invalid lock file in %s'%cur)
58
Context.run_dir=env.run_dir
59
Context.top_dir=env.top_dir
60
Context.out_dir=env.out_dir
62
if not Context.run_dir:
63
if Context.WSCRIPT_FILE in lst:
65
next=os.path.dirname(cur)
71
if not Context.run_dir:
72
if'-h'in sys.argv or'--help'in sys.argv:
73
Logs.warn('No wscript file found: the help message may be incomplete')
74
Context.run_dir=current_directory
75
ctx=Context.create_context('options')
76
ctx.curdir=current_directory
79
Logs.error('Waf: Run from a directory containing a file named %r'%Context.WSCRIPT_FILE)
82
os.chdir(Context.run_dir)
84
Logs.error('Waf: The folder %r is unreadable'%Context.run_dir)
87
set_main_module(Context.run_dir+os.sep+Context.WSCRIPT_FILE)
88
except Errors.WafError ,e:
89
Logs.pprint('RED',e.verbose_msg)
93
Logs.error('Waf: The wscript in %r is unreadable'%Context.run_dir,e)
94
traceback.print_exc(file=sys.stdout)
98
except Errors.WafError ,e:
100
Logs.pprint('RED',e.verbose_msg)
106
traceback.print_exc(file=sys.stdout)
108
except KeyboardInterrupt:
109
Logs.pprint('RED','Interrupted')
111
def set_main_module(file_path):
112
Context.g_module=Context.load_module(file_path)
113
Context.g_module.root_path=file_path
116
if not name in Context.g_module.__dict__:
117
setattr(Context.g_module,name,obj)
118
for k in[update,dist,distclean,distcheck,update]:
120
if not'init'in Context.g_module.__dict__:
121
Context.g_module.init=Utils.nada
122
if not'shutdown'in Context.g_module.__dict__:
123
Context.g_module.shutdown=Utils.nada
124
if not'options'in Context.g_module.__dict__:
125
Context.g_module.options=Utils.nada
127
Context.create_context('options').execute()
128
if not Options.commands:
129
Options.commands=[default_cmd]
130
Options.commands=[x for x in Options.commands if x!='options']
131
Logs.verbose=Options.options.verbose
133
if Options.options.zones:
134
Logs.zones=Options.options.zones.split(',')
138
Logs.zones=['runner']
141
def run_command(cmd_name):
142
ctx=Context.create_context(cmd_name)
143
ctx.log_timer=Utils.Timer()
144
ctx.options=Options.options
151
while Options.commands:
152
cmd_name=Options.commands.pop(0)
153
ctx=run_command(cmd_name)
154
Logs.info('%r finished successfully (%s)'%(cmd_name,str(ctx.log_timer)))
155
run_command('shutdown')
156
def _can_distclean(name):
157
for k in'.o .moc .exe'.split():
161
def distclean_dir(dirname):
162
for(root,dirs,files)in os.walk(dirname):
164
if _can_distclean(f):
169
Logs.warn('could not remove %r'%fname)
170
for x in[Context.DBFILE,'config.log']:
176
shutil.rmtree('c4che')
180
'''removes the build directory'''
183
if f==Options.lockfile:
185
proj=ConfigSet.ConfigSet(f)
187
Logs.warn('could not read %r'%f)
189
if proj['out_dir']!=proj['top_dir']:
191
shutil.rmtree(proj['out_dir'])
195
if e.errno!=errno.ENOENT:
196
Logs.warn('project %r cannot be removed'%proj[Context.OUT])
198
distclean_dir(proj['out_dir'])
199
for k in(proj['out_dir'],proj['top_dir'],proj['run_dir']):
201
os.remove(os.path.join(k,Options.lockfile))
203
if e.errno!=errno.ENOENT:
204
Logs.warn('file %r cannot be removed'%f)
205
if f.startswith('.waf')and not Options.commands:
206
shutil.rmtree(f,ignore_errors=True)
207
class Dist(Context.Context):
208
'''creates an archive containing the project source code'''
214
self.recurse([os.path.dirname(Context.g_module.root_path)])
218
arch_name=self.get_arch_name()
221
except AttributeError:
222
self.base_path=self.path
223
node=self.base_path.make_node(arch_name)
228
files=self.get_files()
229
if self.algo.startswith('tar.'):
230
tar=tarfile.open(arch_name,'w:'+self.algo.replace('tar.',''))
232
self.add_tar_file(x,tar)
234
elif self.algo=='zip':
236
zip=zipfile.ZipFile(arch_name,'w',compression=zipfile.ZIP_DEFLATED)
238
archive_name=self.get_base_name()+'/'+x.path_from(self.base_path)
239
zip.write(x.abspath(),archive_name,zipfile.ZIP_DEFLATED)
242
self.fatal('Valid algo types are tar.bz2, tar.gz or zip')
244
from hashlib import sha1 as sha
248
digest=" (sha=%r)"%sha(node.read()).hexdigest()
251
Logs.info('New archive created: %s%s'%(self.arch_name,digest))
252
def get_tar_path(self,node):
253
return node.abspath()
254
def add_tar_file(self,x,tar):
255
p=self.get_tar_path(x)
256
tinfo=tar.gettarinfo(name=p,arcname=self.get_tar_prefix()+'/'+x.path_from(self.base_path))
264
tar.addfile(tinfo,fileobj=fu)
268
def get_tar_prefix(self):
270
return self.tar_prefix
271
except AttributeError:
272
return self.get_base_name()
273
def get_arch_name(self):
276
except AttributeError:
277
self.arch_name=self.get_base_name()+'.'+self.ext_algo.get(self.algo,self.algo)
278
return self.arch_name
279
def get_base_name(self):
282
except AttributeError:
283
appname=getattr(Context.g_module,Context.APPNAME,'noname')
284
version=getattr(Context.g_module,Context.VERSION,'1.0')
285
self.base_name=appname+'-'+version
286
return self.base_name
290
except AttributeError:
291
self.excl=Node.exclude_regs+' **/waf-1.7.* **/.waf-1.7* **/waf3-1.7.* **/.waf3-1.7* **/*~ **/*.rej **/*.orig **/*.pyc **/*.pyo **/*.bak **/*.swp **/.lock-w*'
292
nd=self.root.find_node(Context.out_dir)
294
self.excl+=' '+nd.path_from(self.base_path)
299
except AttributeError:
300
files=self.base_path.ant_glob('**/*',excl=self.get_excl())
303
'''makes a tarball for redistributing the sources'''
305
class DistCheck(Dist):
309
self.recurse([os.path.dirname(Context.g_module.root_path)])
313
import tempfile,tarfile
316
t=tarfile.open(self.get_arch_name())
323
if Options.options.distcheck_args:
324
cfg=shlex.split(Options.options.distcheck_args)
326
cfg=[x for x in sys.argv if x.startswith('-')]
327
instdir=tempfile.mkdtemp('.inst',self.get_base_name())
328
ret=Utils.subprocess.Popen([sys.argv[0],'configure','install','uninstall','--destdir='+instdir]+cfg,cwd=self.get_base_name()).wait()
330
raise Errors.WafError('distcheck failed with code %i'%ret)
331
if os.path.exists(instdir):
332
raise Errors.WafError('distcheck succeeded, but files were left in %s'%instdir)
333
shutil.rmtree(self.get_base_name())
335
'''checks if the project compiles (tarball from 'dist')'''
338
'''updates the plugins from the *waflib/extras* directory'''
339
lst=Options.options.files.split(',')
341
lst=[x for x in Utils.listdir(Context.waf_dir+'/waflib/extras')if x.endswith('.py')]
343
tool=x.replace('.py','')
345
Configure.download_tool(tool,force=True,ctx=ctx)
346
except Errors.WafError:
347
Logs.error('Could not find the tool %s in the remote repository'%x)
348
def autoconfigure(execute_method):
350
if not Configure.autoconfig:
351
return execute_method(self)
352
env=ConfigSet.ConfigSet()
355
env.load(os.path.join(Context.top_dir,Options.lockfile))
357
Logs.warn('Configuring the project')
360
if env.run_dir!=Context.run_dir:
364
for f in env['files']:
365
h=hash((h,Utils.readf(f,'rb')))
366
do_config=h!=env.hash
368
Options.commands.insert(0,self.cmd)
369
Options.commands.insert(0,'configure')
371
return execute_method(self)
373
Build.BuildContext.execute=autoconfigure(Build.BuildContext.execute)