Moved the stale files example to a single module

This commit is contained in:
Thomas Nagy 2014-10-25 01:57:13 +02:00
parent 9fa6e0aa95
commit a3e882dbba
No known key found for this signature in database
GPG Key ID: 67A565EDFDF90E64
2 changed files with 61 additions and 51 deletions

View File

@ -1,18 +1,10 @@
#! /usr/bin/env python
# encoding: utf-8
# Thomas Nagy, 2006-2010 (ita)
# Thomas Nagy, 2006-2014 (ita)
"""
Add a pre-build hook to remove all build files
which do not have a corresponding target
This can be used for example to remove the targets
that have changed name without performing
a full 'waf clean'
Of course, it will only work if there are no dynamically generated
nodes/tasks, in which case the method will have to be modified
to exclude some folders for example.
See waflib/extras/stale.py for more information.
Do not forget to reconfigure the proect after changing "configure" below
"""
VERSION='0.0.1'
@ -22,10 +14,9 @@ top = '.'
def options(opt):
opt.load('compiler_c')
opt.load('gnu_dirs')
def configure(conf):
conf.load('compiler_c')
conf.load('compiler_c stale')
def build(bld):
import random
@ -34,41 +25,3 @@ def build(bld):
else:
bld(rule='touch ${TGT}', target='bar.h')
from waflib import Logs
from waflib.Runner import Parallel
old = Parallel.refill_task_list
def refill_task_list(self):
iit = old(self)
bld = self.bld
if bld.options.targets and bld.options.targets != '*':
return iit
# execute only once
if getattr(self, 'clean', False):
return iit
self.clean = True
# obtain the nodes to use during the build
nodes = []
for i in range(len(bld.groups)):
tasks = bld.get_tasks_group(i)
for x in tasks:
try:
nodes.extend(x.outputs)
except:
pass
# recursion over the nodes to find the stale files
def iter(node):
if getattr(node, 'children', []):
for x in node.children.values():
iter(x)
else:
if not node in nodes:
Logs.warn("stale file found -> %s" % node.abspath())
node.delete()
iter(bld.bldnode)
return iit
Parallel.refill_task_list = refill_task_list

57
waflib/extras/stale.py Normal file
View File

@ -0,0 +1,57 @@
#! /usr/bin/env python
# encoding: UTF-8
# Thomas Nagy, 2006-2014 (ita)
"""
Add a pre-build hook to remove all build files
which do not have a corresponding target
This can be used for example to remove the targets
that have changed name without performing
a full 'waf clean'
Of course, it will only work if there are no dynamically generated
nodes/tasks, in which case the method will have to be modified
to exclude some folders for example.
"""
from waflib import Logs
from waflib.Runner import Parallel
old = Parallel.refill_task_list
def refill_task_list(self):
iit = old(self)
bld = self.bld
if bld.options.targets and bld.options.targets != '*':
return iit
# execute only once
if getattr(self, 'clean', False):
return iit
self.clean = True
# obtain the nodes to use during the build
nodes = []
for i in range(len(bld.groups)):
tasks = bld.get_tasks_group(i)
for x in tasks:
try:
nodes.extend(x.outputs)
except:
pass
# recursion over the nodes to find the stale files
def iter(node):
if getattr(node, 'children', []):
for x in node.children.values():
if x.name != "c4che":
iter(x)
else:
if not node in nodes:
Logs.warn("stale file found -> %s" % node.abspath())
node.delete()
iter(bld.bldnode)
return iit
Parallel.refill_task_list = refill_task_list