[0fa325b] | 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,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'] |
---|
| 9 | default_cmd="build" |
---|
| 10 | def waf_entry_point(current_directory,version,wafdir): |
---|
| 11 | Logs.init_log() |
---|
| 12 | if Context.WAFVERSION!=version: |
---|
| 13 | Logs.error('Waf script %r and library %r do not match (directory %r)'%(version,Context.WAFVERSION,wafdir)) |
---|
| 14 | sys.exit(1) |
---|
| 15 | if'--version'in sys.argv: |
---|
| 16 | Context.run_dir=current_directory |
---|
| 17 | ctx=Context.create_context('options') |
---|
| 18 | ctx.curdir=current_directory |
---|
| 19 | ctx.parse_args() |
---|
| 20 | sys.exit(0) |
---|
| 21 | Context.waf_dir=wafdir |
---|
| 22 | Context.launch_dir=current_directory |
---|
| 23 | no_climb=os.environ.get('NOCLIMB',None) |
---|
| 24 | if not no_climb: |
---|
| 25 | for k in no_climb_commands: |
---|
| 26 | if k in sys.argv: |
---|
| 27 | no_climb=True |
---|
| 28 | break |
---|
| 29 | cur=current_directory |
---|
| 30 | while cur: |
---|
| 31 | lst=os.listdir(cur) |
---|
| 32 | if Options.lockfile in lst: |
---|
| 33 | env=ConfigSet.ConfigSet() |
---|
| 34 | try: |
---|
| 35 | env.load(os.path.join(cur,Options.lockfile)) |
---|
| 36 | ino=os.stat(cur)[stat.ST_INO] |
---|
| 37 | except Exception: |
---|
| 38 | pass |
---|
| 39 | else: |
---|
| 40 | for x in[env.run_dir,env.top_dir,env.out_dir]: |
---|
| 41 | if Utils.is_win32: |
---|
| 42 | if cur==x: |
---|
| 43 | load=True |
---|
| 44 | break |
---|
| 45 | else: |
---|
| 46 | try: |
---|
| 47 | ino2=os.stat(x)[stat.ST_INO] |
---|
| 48 | except OSError: |
---|
| 49 | pass |
---|
| 50 | else: |
---|
| 51 | if ino==ino2: |
---|
| 52 | load=True |
---|
| 53 | break |
---|
| 54 | else: |
---|
| 55 | Logs.warn('invalid lock file in %s'%cur) |
---|
| 56 | load=False |
---|
| 57 | if load: |
---|
| 58 | Context.run_dir=env.run_dir |
---|
| 59 | Context.top_dir=env.top_dir |
---|
| 60 | Context.out_dir=env.out_dir |
---|
| 61 | break |
---|
| 62 | if not Context.run_dir: |
---|
| 63 | if Context.WSCRIPT_FILE in lst: |
---|
| 64 | Context.run_dir=cur |
---|
| 65 | next=os.path.dirname(cur) |
---|
| 66 | if next==cur: |
---|
| 67 | break |
---|
| 68 | cur=next |
---|
| 69 | if no_climb: |
---|
| 70 | break |
---|
| 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 |
---|
| 77 | ctx.parse_args() |
---|
| 78 | sys.exit(0) |
---|
| 79 | Logs.error('Waf: Run from a directory containing a file named %r'%Context.WSCRIPT_FILE) |
---|
| 80 | sys.exit(1) |
---|
| 81 | try: |
---|
| 82 | os.chdir(Context.run_dir) |
---|
| 83 | except OSError: |
---|
| 84 | Logs.error('Waf: The folder %r is unreadable'%Context.run_dir) |
---|
| 85 | sys.exit(1) |
---|
| 86 | try: |
---|
| 87 | set_main_module(Context.run_dir+os.sep+Context.WSCRIPT_FILE) |
---|
| 88 | except Errors.WafError ,e: |
---|
| 89 | Logs.pprint('RED',e.verbose_msg) |
---|
| 90 | Logs.error(str(e)) |
---|
| 91 | sys.exit(1) |
---|
| 92 | except Exception ,e: |
---|
| 93 | Logs.error('Waf: The wscript in %r is unreadable'%Context.run_dir,e) |
---|
| 94 | traceback.print_exc(file=sys.stdout) |
---|
| 95 | sys.exit(2) |
---|
| 96 | try: |
---|
| 97 | run_commands() |
---|
| 98 | except Errors.WafError ,e: |
---|
| 99 | if Logs.verbose>1: |
---|
| 100 | Logs.pprint('RED',e.verbose_msg) |
---|
| 101 | Logs.error(e.msg) |
---|
| 102 | sys.exit(1) |
---|
| 103 | except SystemExit: |
---|
| 104 | raise |
---|
| 105 | except Exception ,e: |
---|
| 106 | traceback.print_exc(file=sys.stdout) |
---|
| 107 | sys.exit(2) |
---|
| 108 | except KeyboardInterrupt: |
---|
| 109 | Logs.pprint('RED','Interrupted') |
---|
| 110 | sys.exit(68) |
---|
| 111 | def set_main_module(file_path): |
---|
| 112 | Context.g_module=Context.load_module(file_path) |
---|
| 113 | Context.g_module.root_path=file_path |
---|
| 114 | def set_def(obj): |
---|
| 115 | name=obj.__name__ |
---|
| 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]: |
---|
| 119 | set_def(k) |
---|
| 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 |
---|
| 126 | def parse_options(): |
---|
| 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 |
---|
| 132 | Logs.init_log() |
---|
| 133 | if Options.options.zones: |
---|
| 134 | Logs.zones=Options.options.zones.split(',') |
---|
| 135 | if not Logs.verbose: |
---|
| 136 | Logs.verbose=1 |
---|
| 137 | elif Logs.verbose>0: |
---|
| 138 | Logs.zones=['runner'] |
---|
| 139 | if Logs.verbose>2: |
---|
| 140 | Logs.zones=['*'] |
---|
| 141 | def run_command(cmd_name): |
---|
| 142 | ctx=Context.create_context(cmd_name) |
---|
| 143 | ctx.log_timer=Utils.Timer() |
---|
| 144 | ctx.options=Options.options |
---|
| 145 | ctx.cmd=cmd_name |
---|
| 146 | ctx.execute() |
---|
| 147 | return ctx |
---|
| 148 | def run_commands(): |
---|
| 149 | parse_options() |
---|
| 150 | run_command('init') |
---|
| 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(): |
---|
| 158 | if name.endswith(k): |
---|
| 159 | return True |
---|
| 160 | return False |
---|
| 161 | def distclean_dir(dirname): |
---|
| 162 | for(root,dirs,files)in os.walk(dirname): |
---|
| 163 | for f in files: |
---|
| 164 | if _can_distclean(f): |
---|
| 165 | fname=root+os.sep+f |
---|
| 166 | try: |
---|
[c101fe1] | 167 | os.remove(fname) |
---|
[0fa325b] | 168 | except OSError: |
---|
| 169 | Logs.warn('Could not remove %r'%fname) |
---|
| 170 | for x in[Context.DBFILE,'config.log']: |
---|
| 171 | try: |
---|
[c101fe1] | 172 | os.remove(x) |
---|
[0fa325b] | 173 | except OSError: |
---|
| 174 | pass |
---|
| 175 | try: |
---|
| 176 | shutil.rmtree('c4che') |
---|
| 177 | except OSError: |
---|
| 178 | pass |
---|
| 179 | def distclean(ctx): |
---|
| 180 | '''removes the build directory''' |
---|
| 181 | lst=os.listdir('.') |
---|
| 182 | for f in lst: |
---|
| 183 | if f==Options.lockfile: |
---|
| 184 | try: |
---|
| 185 | proj=ConfigSet.ConfigSet(f) |
---|
| 186 | except IOError: |
---|
| 187 | Logs.warn('Could not read %r'%f) |
---|
| 188 | continue |
---|
| 189 | if proj['out_dir']!=proj['top_dir']: |
---|
| 190 | try: |
---|
| 191 | shutil.rmtree(proj['out_dir']) |
---|
| 192 | except IOError: |
---|
| 193 | pass |
---|
| 194 | except OSError ,e: |
---|
| 195 | if e.errno!=errno.ENOENT: |
---|
| 196 | Logs.warn('project %r cannot be removed'%proj[Context.OUT]) |
---|
| 197 | else: |
---|
| 198 | distclean_dir(proj['out_dir']) |
---|
| 199 | for k in(proj['out_dir'],proj['top_dir'],proj['run_dir']): |
---|
| 200 | try: |
---|
| 201 | os.remove(os.path.join(k,Options.lockfile)) |
---|
| 202 | except OSError ,e: |
---|
| 203 | if e.errno!=errno.ENOENT: |
---|
| 204 | Logs.warn('file %r cannot be removed'%f) |
---|
[1a31baf] | 205 | if not Options.commands: |
---|
| 206 | for x in'.waf-1. waf-1. .waf3-1. waf3-1.'.split(): |
---|
| 207 | if f.startswith(x): |
---|
| 208 | shutil.rmtree(f,ignore_errors=True) |
---|
[0fa325b] | 209 | class Dist(Context.Context): |
---|
| 210 | '''creates an archive containing the project source code''' |
---|
| 211 | cmd='dist' |
---|
| 212 | fun='dist' |
---|
| 213 | algo='tar.bz2' |
---|
| 214 | ext_algo={} |
---|
| 215 | def execute(self): |
---|
| 216 | self.recurse([os.path.dirname(Context.g_module.root_path)]) |
---|
| 217 | self.archive() |
---|
| 218 | def archive(self): |
---|
| 219 | import tarfile |
---|
| 220 | arch_name=self.get_arch_name() |
---|
| 221 | try: |
---|
| 222 | self.base_path |
---|
| 223 | except AttributeError: |
---|
| 224 | self.base_path=self.path |
---|
| 225 | node=self.base_path.make_node(arch_name) |
---|
| 226 | try: |
---|
| 227 | node.delete() |
---|
| 228 | except Exception: |
---|
| 229 | pass |
---|
| 230 | files=self.get_files() |
---|
| 231 | if self.algo.startswith('tar.'): |
---|
| 232 | tar=tarfile.open(arch_name,'w:'+self.algo.replace('tar.','')) |
---|
| 233 | for x in files: |
---|
| 234 | self.add_tar_file(x,tar) |
---|
| 235 | tar.close() |
---|
| 236 | elif self.algo=='zip': |
---|
| 237 | import zipfile |
---|
| 238 | zip=zipfile.ZipFile(arch_name,'w',compression=zipfile.ZIP_DEFLATED) |
---|
| 239 | for x in files: |
---|
| 240 | archive_name=self.get_base_name()+'/'+x.path_from(self.base_path) |
---|
| 241 | zip.write(x.abspath(),archive_name,zipfile.ZIP_DEFLATED) |
---|
| 242 | zip.close() |
---|
| 243 | else: |
---|
| 244 | self.fatal('Valid algo types are tar.bz2, tar.gz or zip') |
---|
| 245 | try: |
---|
| 246 | from hashlib import sha1 as sha |
---|
| 247 | except ImportError: |
---|
| 248 | from sha import sha |
---|
| 249 | try: |
---|
| 250 | digest=" (sha=%r)"%sha(node.read()).hexdigest() |
---|
| 251 | except Exception: |
---|
| 252 | digest='' |
---|
| 253 | Logs.info('New archive created: %s%s'%(self.arch_name,digest)) |
---|
| 254 | def get_tar_path(self,node): |
---|
| 255 | return node.abspath() |
---|
| 256 | def add_tar_file(self,x,tar): |
---|
| 257 | p=self.get_tar_path(x) |
---|
| 258 | tinfo=tar.gettarinfo(name=p,arcname=self.get_tar_prefix()+'/'+x.path_from(self.base_path)) |
---|
| 259 | tinfo.uid=0 |
---|
| 260 | tinfo.gid=0 |
---|
| 261 | tinfo.uname='root' |
---|
| 262 | tinfo.gname='root' |
---|
| 263 | fu=None |
---|
| 264 | try: |
---|
| 265 | fu=open(p,'rb') |
---|
| 266 | tar.addfile(tinfo,fileobj=fu) |
---|
| 267 | finally: |
---|
| 268 | if fu: |
---|
| 269 | fu.close() |
---|
| 270 | def get_tar_prefix(self): |
---|
| 271 | try: |
---|
| 272 | return self.tar_prefix |
---|
| 273 | except AttributeError: |
---|
| 274 | return self.get_base_name() |
---|
| 275 | def get_arch_name(self): |
---|
| 276 | try: |
---|
| 277 | self.arch_name |
---|
| 278 | except AttributeError: |
---|
| 279 | self.arch_name=self.get_base_name()+'.'+self.ext_algo.get(self.algo,self.algo) |
---|
| 280 | return self.arch_name |
---|
| 281 | def get_base_name(self): |
---|
| 282 | try: |
---|
| 283 | self.base_name |
---|
| 284 | except AttributeError: |
---|
| 285 | appname=getattr(Context.g_module,Context.APPNAME,'noname') |
---|
| 286 | version=getattr(Context.g_module,Context.VERSION,'1.0') |
---|
| 287 | self.base_name=appname+'-'+version |
---|
| 288 | return self.base_name |
---|
| 289 | def get_excl(self): |
---|
| 290 | try: |
---|
| 291 | return self.excl |
---|
| 292 | except AttributeError: |
---|
| 293 | 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*' |
---|
| 294 | nd=self.root.find_node(Context.out_dir) |
---|
| 295 | if nd: |
---|
| 296 | self.excl+=' '+nd.path_from(self.base_path) |
---|
| 297 | return self.excl |
---|
| 298 | def get_files(self): |
---|
| 299 | try: |
---|
| 300 | files=self.files |
---|
| 301 | except AttributeError: |
---|
| 302 | files=self.base_path.ant_glob('**/*',excl=self.get_excl()) |
---|
| 303 | return files |
---|
| 304 | def dist(ctx): |
---|
| 305 | '''makes a tarball for redistributing the sources''' |
---|
| 306 | pass |
---|
| 307 | class DistCheck(Dist): |
---|
| 308 | fun='distcheck' |
---|
| 309 | cmd='distcheck' |
---|
| 310 | def execute(self): |
---|
| 311 | self.recurse([os.path.dirname(Context.g_module.root_path)]) |
---|
| 312 | self.archive() |
---|
| 313 | self.check() |
---|
| 314 | def check(self): |
---|
| 315 | import tempfile,tarfile |
---|
| 316 | t=None |
---|
| 317 | try: |
---|
| 318 | t=tarfile.open(self.get_arch_name()) |
---|
| 319 | for x in t: |
---|
| 320 | t.extract(x) |
---|
| 321 | finally: |
---|
| 322 | if t: |
---|
| 323 | t.close() |
---|
| 324 | cfg=[] |
---|
| 325 | if Options.options.distcheck_args: |
---|
| 326 | cfg=shlex.split(Options.options.distcheck_args) |
---|
| 327 | else: |
---|
| 328 | cfg=[x for x in sys.argv if x.startswith('-')] |
---|
| 329 | instdir=tempfile.mkdtemp('.inst',self.get_base_name()) |
---|
[c101fe1] | 330 | ret=Utils.subprocess.Popen([sys.executable,sys.argv[0],'configure','install','uninstall','--destdir='+instdir]+cfg,cwd=self.get_base_name()).wait() |
---|
[0fa325b] | 331 | if ret: |
---|
| 332 | raise Errors.WafError('distcheck failed with code %i'%ret) |
---|
| 333 | if os.path.exists(instdir): |
---|
| 334 | raise Errors.WafError('distcheck succeeded, but files were left in %s'%instdir) |
---|
| 335 | shutil.rmtree(self.get_base_name()) |
---|
| 336 | def distcheck(ctx): |
---|
| 337 | '''checks if the project compiles (tarball from 'dist')''' |
---|
| 338 | pass |
---|
| 339 | def update(ctx): |
---|
| 340 | '''updates the plugins from the *waflib/extras* directory''' |
---|
| 341 | lst=Options.options.files.split(',') |
---|
| 342 | if not lst: |
---|
| 343 | lst=[x for x in Utils.listdir(Context.waf_dir+'/waflib/extras')if x.endswith('.py')] |
---|
| 344 | for x in lst: |
---|
| 345 | tool=x.replace('.py','') |
---|
| 346 | try: |
---|
| 347 | Configure.download_tool(tool,force=True,ctx=ctx) |
---|
| 348 | except Errors.WafError: |
---|
| 349 | Logs.error('Could not find the tool %s in the remote repository'%x) |
---|
| 350 | def autoconfigure(execute_method): |
---|
| 351 | def execute(self): |
---|
| 352 | if not Configure.autoconfig: |
---|
| 353 | return execute_method(self) |
---|
| 354 | env=ConfigSet.ConfigSet() |
---|
| 355 | do_config=False |
---|
| 356 | try: |
---|
| 357 | env.load(os.path.join(Context.top_dir,Options.lockfile)) |
---|
| 358 | except Exception: |
---|
| 359 | Logs.warn('Configuring the project') |
---|
| 360 | do_config=True |
---|
| 361 | else: |
---|
| 362 | if env.run_dir!=Context.run_dir: |
---|
| 363 | do_config=True |
---|
| 364 | else: |
---|
| 365 | h=0 |
---|
| 366 | for f in env['files']: |
---|
[1a31baf] | 367 | h=Utils.h_list((h,Utils.readf(f,'rb'))) |
---|
[0fa325b] | 368 | do_config=h!=env.hash |
---|
| 369 | if do_config: |
---|
| 370 | Options.commands.insert(0,self.cmd) |
---|
| 371 | Options.commands.insert(0,'configure') |
---|
| 372 | return |
---|
| 373 | return execute_method(self) |
---|
| 374 | return execute |
---|
| 375 | Build.BuildContext.execute=autoconfigure(Build.BuildContext.execute) |
---|