third_party: Update waf to version 2.0.17
[vlendec/samba-autobuild/.git] / third_party / waf / waflib / Tools / md5_tstamp.py
1 #! /usr/bin/env python
2 # encoding: utf-8
3
4 """
5 Re-calculate md5 hashes of files only when the file time have changed::
6
7         def options(opt):
8                 opt.load('md5_tstamp')
9
10 The hashes can also reflect either the file contents (STRONGEST=True) or the
11 file time and file size.
12
13 The performance benefits of this module are usually insignificant.
14 """
15
16 import os, stat
17 from waflib import Utils, Build, Node
18
19 STRONGEST = True
20
21 Build.SAVED_ATTRS.append('hashes_md5_tstamp')
22 def h_file(self):
23         filename = self.abspath()
24         st = os.stat(filename)
25
26         cache = self.ctx.hashes_md5_tstamp
27         if filename in cache and cache[filename][0] == st.st_mtime:
28                 return cache[filename][1]
29
30         if STRONGEST:
31                 ret = Utils.h_file(filename)
32         else:
33                 if stat.S_ISDIR(st[stat.ST_MODE]):
34                         raise IOError('Not a file')
35                 ret = Utils.md5(str((st.st_mtime, st.st_size)).encode()).digest()
36
37         cache[filename] = (st.st_mtime, ret)
38         return ret
39 h_file.__doc__ = Node.Node.h_file.__doc__
40 Node.Node.h_file = h_file
41