waf

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

wscript (1985B)


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