wscript 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #! /usr/bin/env python
  2. # encoding: utf-8
  3. VERSION='0.0.1'
  4. APPNAME='cc_test'
  5. top = '.'
  6. out = 'build'
  7. """
  8. Call "waf build_all_at_once"
  9. The commands will be executed in parallel, but the processes
  10. will be limited by a bounded semaphore to avoid excessive usage.
  11. """
  12. def options(opt):
  13. opt.load('compiler_c')
  14. def configure(conf):
  15. conf.setenv('debug')
  16. conf.load('compiler_c')
  17. conf.env.DEFINES = ["A=1"]
  18. conf.setenv('release', env=conf.env.derive())
  19. conf.env.CFLAGS = ['-O2']
  20. conf.env.DEFINES = ["A=2"]
  21. def build(bld):
  22. if not bld.variant:
  23. bld.fatal('call "waf build_debug" or "waf build_release", and try "waf --help"')
  24. bld.program(source='main.c', target='app', includes='.')
  25. from waflib.Build import BuildContext, CleanContext, InstallContext, UninstallContext
  26. for x in 'debug release'.split():
  27. for y in (BuildContext, CleanContext, InstallContext, UninstallContext):
  28. name = y.__name__.replace('Context','').lower()
  29. class tmp(y):
  30. cmd = name + '_' + x
  31. variant = x
  32. def buildall(ctx):
  33. import waflib.Options
  34. waflib.Options.commands.extend(['build_debug', 'build_release'])
  35. # The following defines a command which builds all the variants at once
  36. from waflib import Build, Task, Options, Utils, Scripting
  37. Scripting.default_cmd = "build_all_at_once"
  38. class buildall_ctx(Build.BuildContext):
  39. cmd = fun = "build_all_at_once"
  40. variant = ""
  41. def compile(self): pass
  42. def build_all_at_once(ctx):
  43. sem = Utils.threading.Semaphore(Options.options.jobs)
  44. def with_sem(f):
  45. def f2(self):
  46. sem.acquire()
  47. f(self)
  48. sem.release()
  49. return f2
  50. Task.Task.process = with_sem(Task.Task.process)
  51. threads = []
  52. for var in ctx.all_envs:
  53. if var == '': continue
  54. cls = type(Build.BuildContext)(var, (Build.BuildContext,), {'cmd': var, 'variant': var})
  55. bld = cls(top_dir=ctx.top_dir, out_dir=ctx.out_dir)
  56. bld.targets = ctx.targets
  57. t = Utils.threading.Thread()
  58. t.run = bld.execute
  59. threads.append(t)
  60. for t in threads: t.start()
  61. for t in threads: t.join()