Provide node.exists() to increase filesystem abstraction

This commit is contained in:
Thomas Nagy 2015-12-24 18:03:58 +01:00
parent 72fda8ae36
commit 06c7c09681
3 changed files with 10 additions and 11 deletions

View File

@ -806,6 +806,9 @@ class Node(object):
"Build path without the file name"
return self.parent.bldpath()
def exists(self):
return os.path.exists(self.abspath())
@Utils.run_once
def get_bld_sig(self):
"""

View File

@ -191,7 +191,7 @@ class TaskBase(evil):
def process(self):
"""
Assume that the task has had a new attribute ``master`` which is an instance of :py:class:`waflib.Runner.Parallel`.
Assume that the task has had a ``master`` which is an instance of :py:class:`waflib.Runner.Parallel`.
Execute the task and then put it back in the queue :py:attr:`waflib.Runner.Parallel.out` (may be replaced by subclassing).
"""
m = self.master
@ -614,7 +614,7 @@ class Task(TaskBase):
if sig != key:
Logs.debug("task: task %r must run: an output node was produced by another task" % self)
return RUN_ME
if not os.path.exists(node.abspath()):
if not node.exists():
Logs.debug("task: task %r must run: an output node does not exist" % self)
return RUN_ME
@ -628,18 +628,14 @@ class Task(TaskBase):
The node signature is obtained from the task signature, but the output nodes may also get the signature
of their contents. See the class decorator :py:func:`waflib.Task.update_outputs` if you need this behaviour.
"""
bld = self.generator.bld
sig = self.signature()
dct = self.generator.bld.task_sigs
for node in self.outputs:
# check if the output actually exists
try:
os.stat(node.abspath())
except OSError:
if not node.exists():
self.hasrun = MISSING
self.err_msg = '-> missing file: %r' % node.abspath()
raise Errors.WafError(self.err_msg)
bld.task_sigs[node] = self.uid() # make sure this task produced the files in question
bld.task_sigs[self.uid()] = self.cache_sig
dct[node] = self.uid() # make sure this task produced the files in question
dct[self.uid()] = self.signature()
def sig_explicit_deps(self):
"""

View File

@ -68,7 +68,7 @@ class cython(Task.Task):
def post_run(self):
for x in self.outputs:
if x.name.endswith('.h'):
if not os.path.exists(x.abspath()):
if not x.exists():
if Logs.verbose:
Logs.warn('Expected %r' % x.abspath())
x.write('')