wscript 1.9 KB

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