summaryrefslogtreecommitdiff
path: root/third_party/waf/wafadmin/3rdparty/build_file_tracker.py
blob: 5fc73581ec25fb4b6fb65ca41d62fb3b1ce7318d (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
#! /usr/bin/env python
# encoding: utf-8
# Thomas Nagy, 2015

"""
Force tasks to use file timestamps to force partial rebuilds when touch-ing build files

touch out/libfoo.a
... rebuild what depends on libfoo.a

to use::
    def options(opt):
        opt.tool_options('build_file_tracker')
"""

import os
import Task, Utils

def signature(self):
	try: return self.cache_sig[0]
	except AttributeError: pass

	self.m = Utils.md5()

	# explicit deps
	exp_sig = self.sig_explicit_deps()

	# env vars
	var_sig = self.sig_vars()

	# implicit deps
	imp_sig = Task.SIG_NIL
	if self.scan:
		try:
			imp_sig = self.sig_implicit_deps()
		except ValueError:
			return self.signature()

	# timestamp dependency on build files only (source files are hashed)
	buf = []
	for k in self.inputs + getattr(self, 'dep_nodes', []) + self.generator.bld.node_deps.get(self.unique_id(), []):
		if k.id & 3 == 3:
			t = os.stat(k.abspath(self.env)).st_mtime
			buf.append(t)
	self.m.update(str(buf))

	# we now have the signature (first element) and the details (for debugging)
	ret = self.m.digest()
	self.cache_sig = (ret, exp_sig, imp_sig, var_sig)
	return ret

Task.Task.signature_bak = Task.Task.signature # unused, kept just in case
Task.Task.signature = signature # overridden