2
0
mirror of https://gitlab.com/ita1024/waf.git synced 2024-11-22 18:07:12 +01:00

Update the example that cleans any non-declared file #2415

This commit is contained in:
Waf Project 2023-09-15 18:37:44 +02:00
parent ad7b733fc6
commit fb6f0549c4

View File

@ -14,9 +14,16 @@ Of course, it will only work if there are no dynamically generated
nodes/tasks, in which case the method will have to be modified nodes/tasks, in which case the method will have to be modified
to exclude some folders for example. to exclude some folders for example.
Make sure to set bld.post_mode = waflib.Build.POST_AT_ONCE Make sure to specify bld.post_mode = waflib.Build.POST_AT_ONCE::
def build(bld):
bld.load('stale')
import waflib.Build
bld.post_mode = waflib.Build.POST_AT_ONCE
""" """
import os
from waflib import Logs, Build from waflib import Logs, Build
from waflib.Runner import Parallel from waflib.Runner import Parallel
@ -26,7 +33,7 @@ MOC_H_EXTS = '.cpp .cxx .hpp .hxx .h'.split()
def can_delete(node): def can_delete(node):
"""Imperfect moc cleanup which does not look for a Q_OBJECT macro in the files""" """Imperfect moc cleanup which does not look for a Q_OBJECT macro in the files"""
if not node.name.endswith('.moc'): if not node.name.endswith('.moc'):
return True return os.path.isfile(node.abspath())
base = node.name[:-4] base = node.name[:-4]
p1 = node.parent.get_src() p1 = node.parent.get_src()
p2 = node.parent.get_bld() p2 = node.parent.get_bld()
@ -51,7 +58,7 @@ def stale_rec(node, nodes):
return return
if getattr(node, 'children', []): if getattr(node, 'children', []):
for x in node.children.values(): for x in list(node.children.values()):
if x.name != "c4che": if x.name != "c4che":
stale_rec(x, nodes) stale_rec(x, nodes)
else: else:
@ -75,21 +82,26 @@ def refill_task_list(self):
self.stale_done = True self.stale_done = True
# this does not work in partial builds # this does not work in partial builds
if bld.targets != '*': if bld.targets not in ('', '*'):
return iit return iit
# this does not work in dynamic builds # this does not work in dynamic builds
if getattr(bld, 'post_mode') == Build.POST_AT_ONCE: if getattr(bld, 'post_mode') != Build.POST_AT_ONCE:
Logs.warn('waflib.extras.stale is incompatible with dynamic builds')
return iit return iit
# obtain the nodes to use during the build # obtain the nodes to use during the build
nodes = [] nodes = []
for tasks in bld.groups: for group in bld.groups:
for x in tasks: for tg in group:
try: try:
nodes.extend(x.outputs) nodes.extend(tg.outputs)
except AttributeError: except AttributeError:
pass for task in tg.tasks:
try:
nodes.extend(task.outputs)
except AttributeError:
pass
stale_rec(bld.bldnode, nodes) stale_rec(bld.bldnode, nodes)
return iit return iit