waf

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

wscript (910B)


      1 #! /usr/bin/env python
      2 
      3 """
      4 Task semaphore demo. Compare the runtimes:
      5 
      6 	waf configure build --fast  # 0m08
      7 	waf configure build         # 1m15
      8 """
      9 
     10 import random, time
     11 from waflib import Task, TaskGen, Utils
     12 
     13 def options(opt):
     14 	opt.add_option('--fast', action='store_true', default=False, help='Disable the semaphore to compare the runtime', dest='fast')
     15 
     16 def configure(conf):
     17 	pass
     18 
     19 def build(bld):
     20 	# max 20 jobs globally
     21 	bld.jobs = 20
     22 
     23 	bld(features='make_100')
     24 
     25 	class Foo(Task.Task):
     26 		always_run = True
     27 
     28 		if not bld.options.fast:
     29 			semaphore = Task.TaskSemaphore(2) # 2 jobs maximum
     30 
     31 		def uid(self):
     32 			# unique id for each object
     33 			return Utils.h_list(self.num)
     34 
     35 		def run(self):
     36 			time.sleep(random.randint(1000, 2000) / 1000.)
     37 			print("Task %r" % self.num)
     38 
     39 	@TaskGen.feature('make_100')
     40 	def make_100_bound_tasks(self):
     41 		for x in range(100):
     42 			tsk = self.create_task('Foo')
     43 			tsk.num = x
     44