waf

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

wscript (1310B)


      1 #! /usr/bin/env python
      2 
      3 """
      4 Create a few c programs, measure the execution times on "waf times"
      5 """
      6 
      7 def options(opt):
      8 	opt.load('compiler_c')
      9 
     10 def configure(conf):
     11 	conf.load('compiler_c')
     12 
     13 def build(bld):
     14 
     15 	# add a task to create a .c file
     16 	from waflib.TaskGen import feature, before_method
     17 	@feature('foo')
     18 	@before_method('process_source')
     19 	def add_one_c_file(self):
     20 		node = self.path.find_or_declare('main%d.c' % self.num)
     21 		self.create_task('write_file', [], node)
     22 		self.source = [node] # add the .c file to the list of source
     23 
     24 	# write a slow main.c file
     25 	from waflib.Task import Task
     26 	class write_file(Task):
     27 		def run(self):
     28 			self.outputs[0].write('''
     29 #include <stdio.h>
     30 int main() {
     31 	int i;
     32 	char buf[50];
     33 	for (i=0; i < %d; ++i) {
     34 		sprintf(buf, "%%l\\n", i);
     35 	}
     36 	return 0;
     37 }''' % 2 ** (13 + self.generator.num))
     38 
     39 	for i in range(10):
     40 		# create a few programs
     41 		bld(features='foo c cprogram', num=i, target='app%d' % i)
     42 
     43 	if bld.cmd == 'times':
     44 		# measure the execution times when calling "waf times"
     45 		def measure(ctx):
     46 			for x in range(10):
     47 				tg = ctx.get_tgen_by_name('app%d' % x)
     48 				name = tg.link_task.outputs[0].abspath()
     49 				ctx.exec_command('time %s' % name, shell=True)
     50 		bld.add_post_fun(measure)
     51 
     52 from waflib.Build import BuildContext
     53 class times(BuildContext):
     54 	cmd = 'times'
     55