why.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #! /usr/bin/env python
  2. # encoding: utf-8
  3. # Thomas Nagy, 2010 (ita)
  4. """
  5. This tool modifies the task signature scheme to store and obtain
  6. information about the task execution (why it must run, etc)::
  7. def configure(conf):
  8. conf.load('why')
  9. After adding the tool, a full rebuild is necessary:
  10. waf clean build --zones=task
  11. """
  12. from waflib import Task, Utils, Logs, Errors
  13. def signature(self):
  14. # compute the result one time, and suppose the scan_signature will give the good result
  15. try:
  16. return self.cache_sig
  17. except AttributeError:
  18. pass
  19. self.m = Utils.md5()
  20. self.m.update(self.hcode)
  21. id_sig = self.m.digest()
  22. # explicit deps
  23. self.m = Utils.md5()
  24. self.sig_explicit_deps()
  25. exp_sig = self.m.digest()
  26. # env vars
  27. self.m = Utils.md5()
  28. self.sig_vars()
  29. var_sig = self.m.digest()
  30. # implicit deps / scanner results
  31. self.m = Utils.md5()
  32. if self.scan:
  33. try:
  34. self.sig_implicit_deps()
  35. except Errors.TaskRescan:
  36. return self.signature()
  37. impl_sig = self.m.digest()
  38. ret = self.cache_sig = impl_sig + id_sig + exp_sig + var_sig
  39. return ret
  40. Task.Task.signature = signature
  41. old = Task.Task.runnable_status
  42. def runnable_status(self):
  43. ret = old(self)
  44. if ret == Task.RUN_ME:
  45. try:
  46. old_sigs = self.generator.bld.task_sigs[self.uid()]
  47. except (KeyError, AttributeError):
  48. Logs.debug("task: task must run as no previous signature exists")
  49. else:
  50. new_sigs = self.cache_sig
  51. def v(x):
  52. return Utils.to_hex(x)
  53. Logs.debug('Task %r', self)
  54. msgs = ['* Implicit or scanner dependency', '* Task code', '* Source file, explicit or manual dependency', '* Configuration data variable']
  55. tmp = 'task: -> %s: %s %s'
  56. for x in range(len(msgs)):
  57. l = len(Utils.SIG_NIL)
  58. a = new_sigs[x*l : (x+1)*l]
  59. b = old_sigs[x*l : (x+1)*l]
  60. if (a != b):
  61. Logs.debug(tmp, msgs[x].ljust(35), v(a), v(b))
  62. return ret
  63. Task.Task.runnable_status = runnable_status