Bug 1838272 [wpt PR 40523] - Further DOM Parts hierarchy reorg, and connect Document...
[gecko.git] / config / rebuild_check.py
bloba906fdc304f8b73d1e73d4a32227b43ed0f2bd6d
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 import errno
6 import os
9 def mtime(path):
10 try:
11 return os.stat(path).st_mtime
12 except OSError as e:
13 if e.errno == errno.ENOENT:
14 return -1
15 raise
18 def rebuild_check(args):
19 target = args[0]
20 deps = args[1:]
21 t = mtime(target)
22 if t < 0:
23 print(target)
24 return
26 newer = []
27 removed = []
28 for dep in deps:
29 deptime = mtime(dep)
30 if deptime < 0:
31 removed.append(dep)
32 elif deptime > t:
33 newer.append(dep)
35 def format_filelist(filelist):
36 if not filelist:
37 return None
39 limit = 5
40 length = len(filelist)
41 if length < limit:
42 return ", ".join(filelist)
44 truncated = filelist[:limit]
45 remaining = length - limit
47 return "%s (and %d other files)" % (", ".join(truncated), remaining)
49 newer = format_filelist(newer)
50 removed = format_filelist(removed)
52 if newer and removed:
53 print(
54 "Rebuilding %s because %s changed and %s was removed"
55 % (target, newer, removed)
57 elif newer:
58 print("Rebuilding %s because %s changed" % (target, newer))
59 elif removed:
60 print("Rebuilding %s because %s was removed" % (target, removed))
61 else:
62 print("Rebuilding %s for an unknown reason" % target)
65 if __name__ == "__main__":
66 import sys
68 rebuild_check(sys.argv[1:])