waf

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

wscript (2486B)


      1 #! /usr/bin/env python
      2 
      3 from waflib import Task, Errors
      4 from waflib.Tools import c
      5 
      6 def options(opt):
      7 	opt.load('compiler_c')
      8 
      9 
     10 def configure(conf):
     11 	conf.load('compiler_c')
     12 
     13 
     14 def build(bld):
     15 	bld(features = 'c cprogram',
     16 		target   = 'test',
     17 		source   = 'src/main.c src/test.c',
     18 		includes = 'src')
     19 
     20 class mock(Task.Task):
     21 	run_str = 'cp ${SRC} ${TGT}'
     22 	color   = 'BLUE'
     23 
     24 
     25 # it would be better to replace the scan() method, but this is doable too
     26 
     27 def runnable_status(self):
     28 
     29 	ret = self.runnable_status_dynamic_headers2()
     30 
     31 	if ret != Task.ASK_LATER and not getattr(self, 'all_mock_done', False):
     32 		self.all_mock_done = True # run once
     33 
     34 
     35 		bld = self.generator.bld
     36 		add = False
     37 
     38 		try:
     39 			mock_tasks = bld.mock_tasks
     40 		except AttributeError:
     41 			mock_tasks = bld.mock_tasks = {}
     42 
     43 		for x in bld.raw_deps[self.uid()]:
     44 			if x.startswith('mock_'):
     45 				h_file = x[5:]
     46 				for k in [self.inputs[0].parent] + self.generator.includes_nodes:
     47 					h_node = k.find_node(h_file)
     48 					if h_node:
     49 						break
     50 
     51 				if not h_node:
     52 					raise Errors.WafError('no header for %s' % x)
     53 
     54 				m_node = h_node.parent.find_or_declare(x)
     55 				try:
     56 					tsk = mock_tasks[m_node]
     57 				except KeyError:
     58 					tsk = mock_tasks[m_node] = self.generator.create_task('mock', [h_node], [m_node])
     59 					bld.producer.outstanding.append(tsk)
     60 					bld.producer.total += 1
     61 
     62 					# preprocessor cache :-/
     63 					try:
     64 						for key in list(bld.cache_nd.keys()):
     65 							if key[1] == x:
     66 								del bld.cache_nd[key]
     67 					except (KeyError, AttributeError):
     68 						pass
     69 
     70 				add = True
     71 				self.set_run_after(tsk)
     72 
     73 		if add:
     74 			# recompute the task signature
     75 			delattr(self, 'cache_sig')
     76 			del bld.imp_sigs[self.uid()]
     77 			return self.runnable_status()
     78 
     79 		for x in bld.node_deps[self.uid()]:
     80 			if x.name.startswith('mock_'):
     81 				h_node = x.parent.get_src().find_node(x.name[5:])
     82 				if not h_node:
     83 					raise Errors.WafError('no header for %s' % x.name)
     84 
     85 				try:
     86 					tsk = mock_tasks[x]
     87 				except KeyError:
     88 					tsk = mock_tasks[x] = self.generator.create_task('mock', [h_node], [x])
     89 					bld.producer.outstanding.append(tsk)
     90 					bld.producer.total += 1
     91 
     92 				add = True
     93 				self.set_run_after(tsk)
     94 
     95 				# node get_bld_sig cache :-/
     96 				try:
     97 					delattr(x, 'cache_sig')
     98 				except AttributeError:
     99 					pass
    100 		if add:
    101 			# recompute the task signature
    102 			delattr(self, 'cache_sig')
    103 			return self.runnable_status()
    104 
    105 	return ret
    106 
    107 c.c.runnable_status_dynamic_headers2 = c.c.runnable_status
    108 c.c.runnable_status = runnable_status
    109