wscript 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #! /usr/bin/env waf
  2. top = '.'
  3. out = 'tmp_out'
  4. import os, random, time
  5. from waflib import ConfigSet, Context, Build, Configure, Utils
  6. Configure.autoconfig='clobber'
  7. def options(opt):
  8. opt.add_option('--based', action='store', default='foo', help='base directory', dest='based')
  9. opt.add_option('--dumpf', action='store', default='foo', help='dump config to this file', dest='dumpf')
  10. opt.add_option('--force-autoconfig', action='store', default=False, dest='force_autoconfig')
  11. def configure(ctx):
  12. # force autoconfig to depend on an always-changing file - once
  13. if ctx.options.force_autoconfig:
  14. fname = ctx.options.dumpf + '_autoconfig'
  15. s = "%f%d" % (time.time(), random.randint(0, 10**9))
  16. Utils.writef(fname, s)
  17. ctx.files.append(fname)
  18. Configure.autoconfig = False
  19. def build(ctx):
  20. pass
  21. def write_conf(ctx):
  22. if not ctx.options.dumpf:
  23. raise ValueError('Missing --dumpf option')
  24. if not ctx.options.based:
  25. raise ValueError('Missing --based option')
  26. def g(x):
  27. # path from conf.options.based
  28. based = ctx.root.find_node(ctx.options.based)
  29. node = ctx.root.find_node(x)
  30. return node.path_from(based)
  31. env = ConfigSet.ConfigSet()
  32. env.cwd_dir = g(os.getcwd())
  33. env.top_dir = g(Context.top_dir)
  34. env.out_dir = g(Context.out_dir)
  35. env.run_dir = g(Context.run_dir)
  36. env.launch_dir = g(Context.launch_dir)
  37. env.store(ctx.options.dumpf)
  38. for y in (Build.BuildContext, Configure.ConfigurationContext):
  39. class tmp(y):
  40. def execute(self, *k, **kw):
  41. super(self.__class__, self).execute(*k, **kw)
  42. write_conf(self)