michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: import os michael@0: import errno michael@0: michael@0: def mtime(path): michael@0: try: michael@0: return os.stat(path).st_mtime michael@0: except OSError as e: michael@0: if e.errno == errno.ENOENT: michael@0: return -1 michael@0: raise michael@0: michael@0: def rebuild_check(args): michael@0: target = args[0] michael@0: deps = args[1:] michael@0: t = mtime(target) michael@0: if t < 0: michael@0: print target michael@0: return michael@0: michael@0: newer = [] michael@0: removed = [] michael@0: for dep in deps: michael@0: deptime = mtime(dep) michael@0: if deptime < 0: michael@0: removed.append(dep) michael@0: elif mtime(dep) > t: michael@0: newer.append(dep) michael@0: michael@0: if newer and removed: michael@0: print 'Rebuilding %s because %s changed and %s was removed' % (target, ', '.join(newer), ', '.join(removed)) michael@0: elif newer: michael@0: print 'Rebuilding %s because %s changed' % (target, ', '.join(newer)) michael@0: elif removed: michael@0: print 'Rebuilding %s because %s was removed' % (target, ', '.join(removed)) michael@0: else: michael@0: print 'Rebuilding %s for an unknown reason' % target michael@0: michael@0: if __name__ == '__main__': michael@0: import sys michael@0: rebuild_check(sys.argv[1:])