third_party:waf: update to upstream 2.0.4 release
[bbaumbach/samba-autobuild/.git] / third_party / waf / waflib / extras / why.py
1 #! /usr/bin/env python
2 # encoding: utf-8
3 # WARNING! Do not edit! https://waf.io/book/index.html#_obtaining_the_waf_file
4
5 #! /usr/bin/env python
6 # encoding: utf-8
7 # Thomas Nagy, 2010 (ita)
8
9 """
10 This tool modifies the task signature scheme to store and obtain
11 information about the task execution (why it must run, etc)::
12
13         def configure(conf):
14                 conf.load('why')
15
16 After adding the tool, a full rebuild is necessary:
17 waf clean build --zones=task
18 """
19
20 from waflib import Task, Utils, Logs, Errors
21
22 def signature(self):
23         # compute the result one time, and suppose the scan_signature will give the good result
24         try:
25                 return self.cache_sig
26         except AttributeError:
27                 pass
28
29         self.m = Utils.md5()
30         self.m.update(self.hcode)
31         id_sig = self.m.digest()
32
33         # explicit deps
34         self.m = Utils.md5()
35         self.sig_explicit_deps()
36         exp_sig = self.m.digest()
37
38         # env vars
39         self.m = Utils.md5()
40         self.sig_vars()
41         var_sig = self.m.digest()
42
43         # implicit deps / scanner results
44         self.m = Utils.md5()
45         if self.scan:
46                 try:
47                         self.sig_implicit_deps()
48                 except Errors.TaskRescan:
49                         return self.signature()
50         impl_sig = self.m.digest()
51
52         ret = self.cache_sig = impl_sig + id_sig + exp_sig + var_sig
53         return ret
54
55
56 Task.Task.signature = signature
57
58 old = Task.Task.runnable_status
59 def runnable_status(self):
60         ret = old(self)
61         if ret == Task.RUN_ME:
62                 try:
63                         old_sigs = self.generator.bld.task_sigs[self.uid()]
64                 except (KeyError, AttributeError):
65                         Logs.debug("task: task must run as no previous signature exists")
66                 else:
67                         new_sigs = self.cache_sig
68                         def v(x):
69                                 return Utils.to_hex(x)
70
71                         Logs.debug('Task %r', self)
72                         msgs = ['* Implicit or scanner dependency', '* Task code', '* Source file, explicit or manual dependency', '* Configuration data variable']
73                         tmp = 'task: -> %s: %s %s'
74                         for x in range(len(msgs)):
75                                 l = len(Utils.SIG_NIL)
76                                 a = new_sigs[x*l : (x+1)*l]
77                                 b = old_sigs[x*l : (x+1)*l]
78                                 if (a != b):
79                                         Logs.debug(tmp, msgs[x].ljust(35), v(a), v(b))
80         return ret
81 Task.Task.runnable_status = runnable_status
82