third_party:waf: update to upstream 2.0.4 release
[sfrench/samba-autobuild/.git] / third_party / waf / waflib / Tools / md5_tstamp.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
8 """
9 Re-calculate md5 hashes of files only when the file times or the file
10 size have changed.
11
12 The hashes can also reflect either the file contents (STRONGEST=True) or the
13 file time and file size.
14
15 The performance benefits of this module are usually insignificant.
16 """
17
18 import os, stat
19 from waflib import Utils, Build, Node
20
21 STRONGEST = True
22
23 Build.SAVED_ATTRS.append('hashes_md5_tstamp')
24 def h_file(self):
25         filename = self.abspath()
26         st = os.stat(filename)
27
28         cache = self.ctx.hashes_md5_tstamp
29         if filename in cache and cache[filename][0] == st.st_mtime:
30                 return cache[filename][1]
31
32         if STRONGEST:
33                 ret = Utils.h_file(filename)
34         else:
35                 if stat.S_ISDIR(st[stat.ST_MODE]):
36                         raise IOError('Not a file')
37                 ret = Utils.md5(str((st.st_mtime, st.st_size)).encode()).digest()
38
39         cache[filename] = (st.st_mtime, ret)
40         return ret
41 h_file.__doc__ = Node.Node.h_file.__doc__
42 Node.Node.h_file = h_file
43