waf

FORK: waf with some random patches
git clone https://git.neptards.moe/neptards/waf.git
Log | Files | Refs | README

wscript (1906B)


      1 #! /usr/bin/env python
      2 
      3 """
      4 Create a tarball of the build results. The package command aggregates
      5 the functionality of build, install and dist in a single command.
      6 
      7 $ waf configure package
      8 
      9 See also playground/distnet/ for a more enterprisey example
     10 """
     11 
     12 APPNAME = 'ex'
     13 VERSION = '1.0'
     14 
     15 top = '.'
     16 
     17 def configure(conf):
     18 	pass
     19 
     20 def build(bld):
     21 	bld(rule='touch ${TGT}', target='foo.txt')
     22 	bld.install_files('${PREFIX}/bin', 'foo.txt')
     23 
     24 # ---------------------------
     25 
     26 import shutil, os
     27 
     28 from waflib import Build
     29 class package_cls(Build.InstallContext):
     30 	# to skip the installation phase (not recommended!):
     31 	#    use "package_cls(Build.BuildContext)" instead of "package_cls(Build.InstallContext)",
     32 	#    remove the "init_dirs" method
     33 	#    change "self.tmp" to "self.bldnode"
     34 	cmd = 'package'
     35 	fun = 'build'
     36 
     37 	def init_dirs(self, *k, **kw):
     38 		super(package_cls, self).init_dirs(*k, **kw)
     39 		self.tmp = self.bldnode.make_node('package_tmp_dir')
     40 		try:
     41 			shutil.rmtree(self.tmp.abspath())
     42 		except:
     43 			pass
     44 		if os.path.exists(self.tmp.abspath()):
     45 			self.fatal('Could not remove the temporary directory %r' % self.tmp)
     46 		self.tmp.mkdir()
     47 		self.options.destdir = self.tmp.abspath()
     48 
     49 	def execute(self, *k, **kw):
     50 		back = self.options.destdir
     51 		try:
     52 			super(package_cls, self).execute(*k, **kw)
     53 		finally:
     54 			self.options.destdir = back
     55 
     56 		files = self.tmp.ant_glob('**')
     57 
     58 		# we could mess with multiple inheritance but this is probably unnecessary
     59 		from waflib import Scripting
     60 		ctx = Scripting.Dist()
     61 		ctx.arch_name = '%s%s-%s.tar.bz2' % (APPNAME, self.variant, VERSION) # if defined
     62 		ctx.files = files
     63 		ctx.tar_prefix = ''
     64 		ctx.base_path = self.tmp
     65 		ctx.archive()
     66 
     67 		shutil.rmtree(self.tmp.abspath())
     68 
     69 # for variants, add command subclasses "package_release", "package_debug", etc
     70 def init(ctx):
     71 	for x in ('release', 'debug'):
     72 			class tmp(package_cls):
     73 				cmd = 'package_' + x
     74 				variant = x
     75