mirror of https://gitlab.com/ita1024/waf.git
Clean orphan Qt files
This commit is contained in:
parent
7ffd53b803
commit
2fa4078c47
|
@ -3,8 +3,8 @@
|
|||
# Thomas Nagy, 2006-2014 (ita)
|
||||
|
||||
"""
|
||||
Add a pre-build hook to remove all build files
|
||||
which do not have a corresponding target
|
||||
Add a pre-build hook to remove build files (declared in the system)
|
||||
that do not have a corresponding target
|
||||
|
||||
This can be used for example to remove the targets
|
||||
that have changed name without performing
|
||||
|
@ -18,7 +18,49 @@ to exclude some folders for example.
|
|||
from waflib import Logs, Build
|
||||
from waflib.Runner import Parallel
|
||||
|
||||
DYNAMIC_EXT = ['.moc']
|
||||
DYNAMIC_EXT = [] # add your non-cleanable files/extensions here
|
||||
MOC_H_EXTS = '.cpp .cxx .hpp .hxx .h'.split()
|
||||
|
||||
def can_delete(node):
|
||||
"""Imperfect moc cleanup which does not look for a Q_OBJECT macro in the files"""
|
||||
if not node.name.endswith('.moc'):
|
||||
return True
|
||||
base = node.name[:-4]
|
||||
p1 = node.parent.get_src()
|
||||
p2 = node.parent.get_bld()
|
||||
for k in MOC_H_EXTS:
|
||||
h_name = base + k
|
||||
n = p1.search_node(h_name)
|
||||
if n:
|
||||
return False
|
||||
n = p2.search_node(h_name)
|
||||
if n:
|
||||
return False
|
||||
|
||||
# foo.cpp.moc, foo.h.moc, etc.
|
||||
if base.endswith(k):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
# recursion over the nodes to find the stale files
|
||||
def stale_rec(node, nodes):
|
||||
if node.abspath() in node.ctx.env[Build.CFG_FILES]:
|
||||
return
|
||||
|
||||
if getattr(node, 'children', []):
|
||||
for x in node.children.values():
|
||||
if x.name != "c4che":
|
||||
stale_rec(x, nodes)
|
||||
else:
|
||||
for ext in DYNAMIC_EXT:
|
||||
if node.name.endswith(ext):
|
||||
break
|
||||
else:
|
||||
if not node in nodes:
|
||||
if can_delete(node):
|
||||
Logs.warn("Removing stale file -> %s" % node.abspath())
|
||||
node.delete()
|
||||
|
||||
old = Parallel.refill_task_list
|
||||
def refill_task_list(self):
|
||||
|
@ -48,25 +90,7 @@ def refill_task_list(self):
|
|||
except:
|
||||
pass
|
||||
|
||||
# recursion over the nodes to find the stale files
|
||||
def iter(node):
|
||||
|
||||
if node.abspath() in bld.env[Build.CFG_FILES]:
|
||||
return
|
||||
|
||||
if getattr(node, 'children', []):
|
||||
for x in node.children.values():
|
||||
if x.name != "c4che":
|
||||
iter(x)
|
||||
else:
|
||||
for ext in DYNAMIC_EXT:
|
||||
if node.name.endswith(ext):
|
||||
break
|
||||
else:
|
||||
if not node in nodes:
|
||||
Logs.warn("Removing stale file -> %s" % node.abspath())
|
||||
node.delete()
|
||||
iter(bld.bldnode)
|
||||
stale_rec(bld.bldnode, nodes)
|
||||
return iit
|
||||
|
||||
Parallel.refill_task_list = refill_task_list
|
||||
|
|
Loading…
Reference in New Issue