fakecc.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #! /usr/bin/env python
  2. # encoding: utf-8
  3. # DC 2008
  4. # Thomas Nagy 2010 (ita)
  5. import re
  6. from waflib import Utils, Task, TaskGen, Logs
  7. from TaskGen import feature, before, after, extension
  8. from waflib.Tools import ccroot
  9. IS_MODULE_R = re.compile('module ([a-z]*)')
  10. USE_MODULE_R = re.compile('use ([a-z]*)')
  11. @extension('.a')
  12. def hook(self, node):
  13. self.create_compiled_task('fakecc', node)
  14. def ismodule(node):
  15. deps = []
  16. for l in node.read().splitlines():
  17. m = IS_MODULE_R.match(l)
  18. if m:
  19. deps.append(m.group(1) + '.mod')
  20. return deps
  21. def usemodule(node):
  22. deps = []
  23. for l in node.read().splitlines():
  24. m = USE_MODULE_R.match(l)
  25. if m:
  26. deps.append(m.group(1) + '.mod')
  27. return deps
  28. def compile(tsk):
  29. tsk.outputs[0].write('compiled')
  30. m = ismodule(tsk.inputs[0])
  31. if m:
  32. print("%s declares module %s" % (tsk.inputs[0], m[0]))
  33. t2 = open(m[0], 'w')
  34. try:
  35. t2.write('module compiled')
  36. finally:
  37. t2.close()
  38. class fakecc(Task.Task):
  39. color = 'YELLOW'
  40. def run(self):
  41. cmd = []
  42. if not len(self.outputs) == len(self.inputs) == 1:
  43. pass
  44. bnodes = self.outputs
  45. m = usemodule(self.inputs[0])
  46. if m:
  47. print("%s requires module %s" % (self.inputs[0].abspath(), m[0]))
  48. #bnodes.append(self.generator.bld.bldnode.exclusive_build_node(m[0]))
  49. compile(self)