2011-09-10 11:13:51 +02:00
|
|
|
#! /usr/bin/env python
|
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
"""
|
2012-04-02 01:36:52 +02:00
|
|
|
This module assumes that only one build context is running at a given time, which
|
|
|
|
is not the case if you want to execute configuration tests in parallel.
|
|
|
|
|
2011-09-10 11:13:51 +02:00
|
|
|
Store some values on the buildcontext mapping file paths to
|
|
|
|
stat values and md5 values (timestamp + md5)
|
|
|
|
this way the md5 hashes are computed only when timestamp change (can be faster)
|
|
|
|
There is usually little or no gain from enabling this, but it can be used to enable
|
|
|
|
the second level cache with timestamps (WAFCACHE)
|
|
|
|
|
|
|
|
You may have to run distclean or to remove the build directory before enabling/disabling
|
|
|
|
this hashing scheme
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os, stat
|
|
|
|
try: import cPickle
|
|
|
|
except: import pickle as cPickle
|
|
|
|
from waflib import Utils, Build, Context
|
|
|
|
|
2011-10-17 18:52:01 +02:00
|
|
|
STRONGEST = True
|
2011-09-10 11:13:51 +02:00
|
|
|
|
2012-04-02 01:36:52 +02:00
|
|
|
try:
|
|
|
|
Build.BuildContext.store_real
|
|
|
|
except AttributeError:
|
2011-09-10 11:13:51 +02:00
|
|
|
|
2012-04-02 01:36:52 +02:00
|
|
|
Context.DBFILE += '_md5tstamp'
|
2011-09-10 11:13:51 +02:00
|
|
|
|
2012-04-02 01:36:52 +02:00
|
|
|
Build.hashes_md5_tstamp = {}
|
|
|
|
Build.SAVED_ATTRS.append('hashes_md5_tstamp')
|
|
|
|
def store(self):
|
|
|
|
# save the hash cache as part of the default pickle file
|
|
|
|
self.hashes_md5_tstamp = Build.hashes_md5_tstamp
|
|
|
|
self.store_real()
|
|
|
|
Build.BuildContext.store_real = Build.BuildContext.store
|
|
|
|
Build.BuildContext.store = store
|
2011-10-17 18:52:01 +02:00
|
|
|
|
2012-04-02 01:36:52 +02:00
|
|
|
def restore(self):
|
|
|
|
# we need a module variable for h_file below
|
|
|
|
self.restore_real()
|
2011-10-17 18:52:01 +02:00
|
|
|
try:
|
2012-04-02 01:36:52 +02:00
|
|
|
Build.hashes_md5_tstamp = self.hashes_md5_tstamp or {}
|
|
|
|
except Exception as e:
|
|
|
|
Build.hashes_md5_tstamp = {}
|
|
|
|
Build.BuildContext.restore_real = Build.BuildContext.restore
|
|
|
|
Build.BuildContext.restore = restore
|
|
|
|
|
|
|
|
def h_file(filename):
|
|
|
|
st = os.stat(filename)
|
|
|
|
if stat.S_ISDIR(st[stat.ST_MODE]): raise IOError('not a file')
|
|
|
|
|
|
|
|
if filename in Build.hashes_md5_tstamp:
|
|
|
|
if Build.hashes_md5_tstamp[filename][0] == str(st.st_mtime):
|
|
|
|
return Build.hashes_md5_tstamp[filename][1]
|
|
|
|
if STRONGEST:
|
2012-05-19 10:26:34 +02:00
|
|
|
ret = Utils.h_file_no_md5(filename)
|
|
|
|
Build.hashes_md5_tstamp[filename] = (str(st.st_mtime), ret)
|
|
|
|
return ret
|
2012-04-02 01:36:52 +02:00
|
|
|
else:
|
2012-05-19 10:26:34 +02:00
|
|
|
m = Utils.md5()
|
2012-04-02 01:36:52 +02:00
|
|
|
m.update(str(st.st_mtime))
|
|
|
|
m.update(str(st.st_size))
|
|
|
|
m.update(filename)
|
2012-05-19 10:26:34 +02:00
|
|
|
Build.hashes_md5_tstamp[filename] = (str(st.st_mtime), m.digest())
|
|
|
|
return m.digest()
|
|
|
|
Utils.h_file_no_md5 = Utils.h_file
|
2012-04-02 01:36:52 +02:00
|
|
|
Utils.h_file = h_file
|
2011-09-10 11:13:51 +02:00
|
|
|
|