jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.1KB

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