jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.3KB

  1. #! /usr/bin/env python
  2. # encoding: UTF-8
  3. # Thomas Nagy, 2006-2015 (ita)
  4. """
  5. Add a pre-build hook to remove build files (declared in the system)
  6. that do not have a corresponding target
  7. This can be used for example to remove the targets
  8. that have changed name without performing
  9. a full 'waf clean'
  10. Of course, it will only work if there are no dynamically generated
  11. nodes/tasks, in which case the method will have to be modified
  12. to exclude some folders for example.
  13. """
  14. from waflib import Logs, Build
  15. from waflib.Runner import Parallel
  16. DYNAMIC_EXT = [] # add your non-cleanable files/extensions here
  17. MOC_H_EXTS = '.cpp .cxx .hpp .hxx .h'.split()
  18. def can_delete(node):
  19. """Imperfect moc cleanup which does not look for a Q_OBJECT macro in the files"""
  20. if not node.name.endswith('.moc'):
  21. return True
  22. base = node.name[:-4]
  23. p1 = node.parent.get_src()
  24. p2 = node.parent.get_bld()
  25. for k in MOC_H_EXTS:
  26. h_name = base + k
  27. n = p1.search_node(h_name)
  28. if n:
  29. return False
  30. n = p2.search_node(h_name)
  31. if n:
  32. return False
  33. # foo.cpp.moc, foo.h.moc, etc.
  34. if base.endswith(k):
  35. return False
  36. return True
  37. # recursion over the nodes to find the stale files
  38. def stale_rec(node, nodes):
  39. if node.abspath() in node.ctx.env[Build.CFG_FILES]:
  40. return
  41. if getattr(node, 'children', []):
  42. for x in node.children.values():
  43. if x.name != "c4che":
  44. stale_rec(x, nodes)
  45. else:
  46. for ext in DYNAMIC_EXT:
  47. if node.name.endswith(ext):
  48. break
  49. else:
  50. if not node in nodes:
  51. if can_delete(node):
  52. Logs.warn("Removing stale file -> %s" % node.abspath())
  53. node.delete()
  54. old = Parallel.refill_task_list
  55. def refill_task_list(self):
  56. iit = old(self)
  57. bld = self.bld
  58. # execute this operation only once
  59. if getattr(self, 'stale_done', False):
  60. return iit
  61. self.stale_done = True
  62. # this does not work in partial builds
  63. if hasattr(bld, 'options') and bld.options.targets and bld.options.targets != '*':
  64. return iit
  65. # this does not work in dynamic builds
  66. if not hasattr(bld, 'post_mode') or bld.post_mode == Build.POST_LAZY:
  67. return iit
  68. # obtain the nodes to use during the build
  69. nodes = []
  70. for i in range(len(bld.groups)):
  71. tasks = bld.get_tasks_group(i)
  72. for x in tasks:
  73. try:
  74. nodes.extend(x.outputs)
  75. except:
  76. pass
  77. stale_rec(bld.bldnode, nodes)
  78. return iit
  79. Parallel.refill_task_list = refill_task_list