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/.
|
|
|
|
|
2020-05-05 22:53:22 +03:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
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)
|
2019-11-06 00:26:33 +03:00
|
|
|
elif deptime > t:
|
2013-08-10 10:57:09 +04:00
|
|
|
newer.append(dep)
|
|
|
|
|
2019-11-06 00:26:33 +03:00
|
|
|
def format_filelist(filelist):
|
|
|
|
if not filelist:
|
|
|
|
return None
|
|
|
|
|
|
|
|
limit = 5
|
|
|
|
length = len(filelist)
|
|
|
|
if length < limit:
|
|
|
|
return ', '.join(filelist)
|
|
|
|
|
|
|
|
truncated = filelist[:limit]
|
|
|
|
remaining = length - limit
|
|
|
|
|
|
|
|
return '%s (and %d other files)' % (', '.join(truncated), remaining)
|
|
|
|
|
|
|
|
newer = format_filelist(newer)
|
|
|
|
removed = format_filelist(removed)
|
|
|
|
|
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' % (
|
2019-11-06 00:26:33 +03:00
|
|
|
target, newer, removed))
|
2013-08-15 18:45:07 +04:00
|
|
|
elif newer:
|
2019-11-06 00:26:33 +03:00
|
|
|
print('Rebuilding %s because %s changed' % (target, 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' % (
|
2019-11-06 00:26:33 +03:00
|
|
|
target, 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:])
|