Bug 1669129 - [devtools] Enable devtools.overflow.debugging.enabled. r=jdescottes
[gecko.git] / config / rebuild_check.py
blob0bb2a6612d43efee101858e35381658e2537ba16
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('Rebuilding %s because %s changed and %s was removed' % (
55 target, newer, removed))
56 elif newer:
57 print('Rebuilding %s because %s changed' % (target, newer))
58 elif removed:
59 print('Rebuilding %s because %s was removed' % (
60 target, removed))
61 else:
62 print('Rebuilding %s for an unknown reason' % target)
65 if __name__ == '__main__':
66 import sys
67 rebuild_check(sys.argv[1:])