wscript 2.4 KB

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