build:wafsamba: Remove unnecessary parameters to cmd_and_log
[nivanova/samba-autobuild/.git] / third_party / waf / waflib / extras / md5_tstamp.py
1 #! /usr/bin/env python
2 # encoding: utf-8
3
4 """
5 This module assumes that only one build context is running at a given time, which
6 is not the case if you want to execute configuration tests in parallel.
7
8 Store some values on the buildcontext mapping file paths to
9 stat values and md5 values (timestamp + md5)
10 this way the md5 hashes are computed only when timestamp change (can be faster)
11 There is usually little or no gain from enabling this, but it can be used to enable
12 the second level cache with timestamps (WAFCACHE)
13
14 You may have to run distclean or to remove the build directory before enabling/disabling
15 this hashing scheme
16 """
17
18 import os, stat
19 from waflib import Utils, Build, Context
20
21 STRONGEST = True
22
23 try:
24         Build.BuildContext.store_real
25 except AttributeError:
26
27         Context.DBFILE += '_md5tstamp'
28
29         Build.hashes_md5_tstamp = {}
30         Build.SAVED_ATTRS.append('hashes_md5_tstamp')
31         def store(self):
32                 # save the hash cache as part of the default pickle file
33                 self.hashes_md5_tstamp = Build.hashes_md5_tstamp
34                 self.store_real()
35         Build.BuildContext.store_real = Build.BuildContext.store
36         Build.BuildContext.store      = store
37
38         def restore(self):
39                 # we need a module variable for h_file below
40                 self.restore_real()
41                 try:
42                         Build.hashes_md5_tstamp = self.hashes_md5_tstamp or {}
43                 except AttributeError:
44                         Build.hashes_md5_tstamp = {}
45         Build.BuildContext.restore_real = Build.BuildContext.restore
46         Build.BuildContext.restore      = restore
47
48         def h_file(filename):
49                 st = os.stat(filename)
50                 if stat.S_ISDIR(st[stat.ST_MODE]): raise IOError('not a file')
51
52                 if filename in Build.hashes_md5_tstamp:
53                         if Build.hashes_md5_tstamp[filename][0] == str(st.st_mtime):
54                                 return Build.hashes_md5_tstamp[filename][1]
55                 if STRONGEST:
56                         ret = Utils.h_file_no_md5(filename)
57                         Build.hashes_md5_tstamp[filename] = (str(st.st_mtime), ret)
58                         return ret
59                 else:
60                         m = Utils.md5()
61                         m.update(str(st.st_mtime))
62                         m.update(str(st.st_size))
63                         m.update(filename)
64                         Build.hashes_md5_tstamp[filename] = (str(st.st_mtime), m.digest())
65                         return m.digest()
66         Utils.h_file_no_md5 = Utils.h_file
67         Utils.h_file = h_file