waf

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

strip_hack.py (1620B)


      1 #! /usr/bin/env python
      2 
      3 """
      4 This is a hack; In general two tasks should not provide
      5 the same output nodes (bad abstraction), and this cannot
      6 scale to more than one operation
      7 
      8 In this case, the strip task has the same inputs as outputs
      9 so the constraints added by Task.set_file_constraints
     10 to prevent race conditions:
     11 
     12 - By setting the input node to be the link task output node
     13   the strip tasks will run after their link tasks
     14 - By setting the output node to be the link task output node,
     15   any other task that also uses this output node will wait
     16   for the strip task to finish too
     17 - By overriding the runnable_status method, the strip task
     18   will avoid the deadlock and force itself to run only when
     19   the link task has run
     20 """
     21 
     22 def configure(conf):
     23 	conf.find_program('strip')
     24 
     25 from waflib import Task, TaskGen
     26 class strip(Task.Task):
     27 	run_str = '${STRIP} ${SRC}'
     28 	color   = 'BLUE'
     29 	no_errcheck_out = True
     30 
     31 	def keyword(self):
     32 		return 'Stripping'
     33 
     34 	def runnable_status(self):
     35 		if self in self.run_after:
     36 			self.run_after.remove(self)
     37 		ret = super(strip, self).runnable_status()
     38 		if ret == Task.ASK_LATER:
     39 			return ret
     40 
     41 		if self.generator.link_task.hasrun == Task.SUCCESS:
     42 			# ensure that stripping always runs
     43 			# when a binary is written
     44 			return Task.RUN_ME
     45 		return Task.SKIP_ME
     46 
     47 @TaskGen.feature('cshlib', 'cxxshlib', 'cprogram', 'cxxprogram', 'fcprogram', 'fcshlib')
     48 @TaskGen.after('apply_link')
     49 def add_strip_task(self):
     50 	if getattr(self, 'link_task', None):
     51 		exe_node = self.link_task.outputs[0]
     52 		# special case: same inputs and outputs for a task
     53 		self.create_task('strip', exe_node, exe_node)
     54