2013-08-10 10:57:09 +04:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2019-07-08 20:30:34 +03:00
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import print_function
|
2013-08-10 10:57:09 +04:00
|
|
|
import os
|
2013-08-15 18:45:07 +04:00
|
|
|
import errno
|
2013-08-10 10:57:09 +04:00
|
|
|
|
2018-05-22 01:01:01 +03:00
|
|
|
|
2013-08-10 10:57:09 +04:00
|
|
|
def mtime(path):
|
2013-08-15 18:45:07 +04:00
|
|
|
try:
|
|
|
|
return os.stat(path).st_mtime
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno == errno.ENOENT:
|
|
|
|
return -1
|
|
|
|
raise
|
2013-08-10 10:57:09 +04:00
|
|
|
|
2018-05-22 01:01:01 +03:00
|
|
|
|
2013-08-10 10:57:09 +04:00
|
|
|
def rebuild_check(args):
|
|
|
|
target = args[0]
|
|
|
|
deps = args[1:]
|
2013-08-15 18:45:07 +04:00
|
|
|
t = mtime(target)
|
|
|
|
if t < 0:
|
2018-05-22 16:22:46 +03:00
|
|
|
print(target)
|
2013-08-10 10:57:09 +04:00
|
|
|
return
|
|
|
|
|
|
|
|
newer = []
|
2013-08-15 18:45:07 +04:00
|
|
|
removed = []
|
2013-08-10 10:57:09 +04:00
|
|
|
for dep in deps:
|
2013-08-15 18:45:07 +04:00
|
|
|
deptime = mtime(dep)
|
|
|
|
if deptime < 0:
|
|
|
|
removed.append(dep)
|
|
|
|
elif mtime(dep) > t:
|
2013-08-10 10:57:09 +04:00
|
|
|
newer.append(dep)
|
|
|
|
|
2013-08-15 18:45:07 +04:00
|
|
|
if newer and removed:
|
2018-05-22 16:22:46 +03:00
|
|
|
print('Rebuilding %s because %s changed and %s was removed' % (
|
|
|
|
target, ', '.join(newer), ', '.join(removed)))
|
2013-08-15 18:45:07 +04:00
|
|
|
elif newer:
|
2018-05-22 16:22:46 +03:00
|
|
|
print('Rebuilding %s because %s changed' % (target, ', '.join(newer)))
|
2013-08-15 18:45:07 +04:00
|
|
|
elif removed:
|
2018-05-22 16:22:46 +03:00
|
|
|
print('Rebuilding %s because %s was removed' % (
|
|
|
|
target, ', '.join(removed)))
|
2013-08-10 10:57:09 +04:00
|
|
|
else:
|
2018-05-22 16:22:46 +03:00
|
|
|
print('Rebuilding %s for an unknown reason' % target)
|
2013-08-10 10:57:09 +04:00
|
|
|
|
2018-05-22 01:01:01 +03:00
|
|
|
|
2013-08-10 10:57:09 +04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
rebuild_check(sys.argv[1:])
|