summaryrefslogtreecommitdiff
path: root/third_party/waf/waflib/extras/why.py
blob: 1bb941f6c98d33c0c4d636cf52398bb36431d2cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#! /usr/bin/env python
# encoding: utf-8
# Thomas Nagy, 2010 (ita)

"""
This tool modifies the task signature scheme to store and obtain
information about the task execution (why it must run, etc)::

	def configure(conf):
		conf.load('why')

After adding the tool, a full rebuild is necessary:
waf clean build --zones=task
"""

from waflib import Task, Utils, Logs, Errors

def signature(self):
	# compute the result one time, and suppose the scan_signature will give the good result
	try:
		return self.cache_sig
	except AttributeError:
		pass

	self.m = Utils.md5()
	self.m.update(self.hcode)
	id_sig = self.m.digest()

	# explicit deps
	self.m = Utils.md5()
	self.sig_explicit_deps()
	exp_sig = self.m.digest()

	# env vars
	self.m = Utils.md5()
	self.sig_vars()
	var_sig = self.m.digest()

	# implicit deps / scanner results
	self.m = Utils.md5()
	if self.scan:
		try:
			self.sig_implicit_deps()
		except Errors.TaskRescan:
			return self.signature()
	impl_sig = self.m.digest()

	ret = self.cache_sig = impl_sig + id_sig + exp_sig + var_sig
	return ret


Task.Task.signature = signature

old = Task.Task.runnable_status
def runnable_status(self):
	ret = old(self)
	if ret == Task.RUN_ME:
		try:
			old_sigs = self.generator.bld.task_sigs[self.uid()]
		except (KeyError, AttributeError):
			Logs.debug("task: task must run as no previous signature exists")
		else:
			new_sigs = self.cache_sig
			def v(x):
				return Utils.to_hex(x)

			Logs.debug('Task %r', self)
			msgs = ['* Implicit or scanner dependency', '* Task code', '* Source file, explicit or manual dependency', '* Configuration data variable']
			tmp = 'task: -> %s: %s %s'
			for x in range(len(msgs)):
				l = len(Utils.SIG_NIL)
				a = new_sigs[x*l : (x+1)*l]
				b = old_sigs[x*l : (x+1)*l]
				if (a != b):
					Logs.debug(tmp, msgs[x].ljust(35), v(a), v(b))
	return ret
Task.Task.runnable_status = runnable_status