rebuild_check.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # This Source Code Form is subject to the terms of the Mozilla Public
  2. # License, v. 2.0. If a copy of the MPL was not distributed with this
  3. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. import os
  5. import errno
  6. def mtime(path):
  7. try:
  8. return os.stat(path).st_mtime
  9. except OSError as e:
  10. if e.errno == errno.ENOENT:
  11. return -1
  12. raise
  13. def rebuild_check(args):
  14. target = args[0]
  15. deps = args[1:]
  16. t = mtime(target)
  17. if t < 0:
  18. print target
  19. return
  20. newer = []
  21. removed = []
  22. for dep in deps:
  23. deptime = mtime(dep)
  24. if deptime < 0:
  25. removed.append(dep)
  26. elif mtime(dep) > t:
  27. newer.append(dep)
  28. if newer and removed:
  29. print 'Rebuilding %s because %s changed and %s was removed' % (target, ', '.join(newer), ', '.join(removed))
  30. elif newer:
  31. print 'Rebuilding %s because %s changed' % (target, ', '.join(newer))
  32. elif removed:
  33. print 'Rebuilding %s because %s was removed' % (target, ', '.join(removed))
  34. else:
  35. print 'Rebuilding %s for an unknown reason' % target
  36. if __name__ == '__main__':
  37. import sys
  38. rebuild_check(sys.argv[1:])