Move waf into third_party/.
[obnox/samba/samba-obnox.git] / third_party / waf / wafadmin / 3rdparty / build_file_tracker.py
1 #! /usr/bin/env python
2 # encoding: utf-8
3 # Thomas Nagy, 2015
4
5 """
6 Force tasks to use file timestamps to force partial rebuilds when touch-ing build files
7
8 touch out/libfoo.a
9 ... rebuild what depends on libfoo.a
10
11 to use::
12     def options(opt):
13         opt.tool_options('build_file_tracker')
14 """
15
16 import os
17 import Task, Utils
18
19 def signature(self):
20         try: return self.cache_sig[0]
21         except AttributeError: pass
22
23         self.m = Utils.md5()
24
25         # explicit deps
26         exp_sig = self.sig_explicit_deps()
27
28         # env vars
29         var_sig = self.sig_vars()
30
31         # implicit deps
32         imp_sig = Task.SIG_NIL
33         if self.scan:
34                 try:
35                         imp_sig = self.sig_implicit_deps()
36                 except ValueError:
37                         return self.signature()
38
39         # timestamp dependency on build files only (source files are hashed)
40         buf = []
41         for k in self.inputs + getattr(self, 'dep_nodes', []) + self.generator.bld.node_deps.get(self.unique_id(), []):
42                 if k.id & 3 == 3:
43                         t = os.stat(k.abspath(self.env)).st_mtime
44                         buf.append(t)
45         self.m.update(str(buf))
46
47         # we now have the signature (first element) and the details (for debugging)
48         ret = self.m.digest()
49         self.cache_sig = (ret, exp_sig, imp_sig, var_sig)
50         return ret
51
52 Task.Task.signature_bak = Task.Task.signature # unused, kept just in case
53 Task.Task.signature = signature # overridden