Bug 1684593 [wpt PR 27023] - Update wpt metadata, a=testonly
[gecko.git] / config / rebuild_check.py
blobcea589a6a34ecdf65cf41f5a4d1a07af05a62951
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/.
5 from __future__ import absolute_import, print_function, unicode_literals
6 import os
7 import errno
10 def mtime(path):
11 try:
12 return os.stat(path).st_mtime
13 except OSError as e:
14 if e.errno == errno.ENOENT:
15 return -1
16 raise
19 def rebuild_check(args):
20 target = args[0]
21 deps = args[1:]
22 t = mtime(target)
23 if t < 0:
24 print(target)
25 return
27 newer = []
28 removed = []
29 for dep in deps:
30 deptime = mtime(dep)
31 if deptime < 0:
32 removed.append(dep)
33 elif deptime > t:
34 newer.append(dep)
36 def format_filelist(filelist):
37 if not filelist:
38 return None
40 limit = 5
41 length = len(filelist)
42 if length < limit:
43 return ", ".join(filelist)
45 truncated = filelist[:limit]
46 remaining = length - limit
48 return "%s (and %d other files)" % (", ".join(truncated), remaining)
50 newer = format_filelist(newer)
51 removed = format_filelist(removed)
53 if newer and removed:
54 print(
55 "Rebuilding %s because %s changed and %s was removed"
56 % (target, newer, removed)
58 elif newer:
59 print("Rebuilding %s because %s changed" % (target, newer))
60 elif removed:
61 print("Rebuilding %s because %s was removed" % (target, removed))
62 else:
63 print("Rebuilding %s for an unknown reason" % target)
66 if __name__ == "__main__":
67 import sys
69 rebuild_check(sys.argv[1:])