wscript 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #! /usr/bin/env python
  2. # encoding: utf-8
  3. # Thomas Nagy, 2014-2015 (ita)
  4. """
  5. Climb dependencies without using build groups and without annotating them.
  6. In practice, one may want to avoid this:
  7. * This adds some overhead as the task generators have to be searched and processed
  8. * This is also unlikely to work in the real-world (complex targets, not all dependencies are file-based, etc)
  9. * This also makes the dependencies more complicated to understand when reading a wscript file (what requires what?)
  10. This example will create "d.txt" and all the required files but no "aa*.txt".
  11. The target "john" is hard-coded below, just call "waf", or comment the line to call "waf --targets=john"
  12. """
  13. VERSION='0.0.1'
  14. APPNAME='file_climbing'
  15. top = '.'
  16. out = 'build'
  17. def options(opt):
  18. return
  19. def configure(conf):
  20. return
  21. def build(bld):
  22. for i in range(10):
  23. bld(rule='cp ${SRC} ${TGT}', source='a.txt', target='aa%d.txt' % i)
  24. bld(rule='cp ${SRC} ${TGT}', source='a.txt', target='b.txt')
  25. bld(rule='cp ${SRC} ${TGT}', source='b.txt', target='c.txt')
  26. bld(rule='cp ${SRC} ${TGT}', source='c.txt', target='d.txt', name='john')
  27. # HERE
  28. bld.targets = 'john'
  29. import os
  30. from waflib import Utils
  31. from waflib.TaskGen import before_method, feature
  32. @feature('*')
  33. @before_method('process_source', 'process_rule')
  34. def post_other_task_generators_if_necessary(self):
  35. if not self.bld.targets:
  36. return
  37. if not getattr(self, 'source', None):
  38. return
  39. group = self.bld.get_group(self.bld.get_group_idx(self))
  40. for x in Utils.to_list(self.source):
  41. y = os.path.split(x)[1]
  42. for tg in group:
  43. if id(tg) == id(self):
  44. continue
  45. if getattr(tg, 'target', None):
  46. pass
  47. for target in Utils.to_list(tg.target):
  48. y2 = os.path.split(target)[1]
  49. if y == y2:
  50. tg.post()