]> git.lizzy.rs Git - rust.git/blob - src/etc/errorck.py
cleanup: s/impl Copy/#[derive(Copy)]/g
[rust.git] / src / etc / errorck.py
1 # Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 # file at the top-level directory of this distribution and at
3 # http://rust-lang.org/COPYRIGHT.
4 #
5 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 # option. This file may not be copied, modified, or distributed
9 # except according to those terms.
10
11 # Digs error codes out of files named 'diagnostics.rs' across
12 # the tree, and ensures thare are no duplicates.
13
14 import sys, os, re
15
16 src_dir = sys.argv[1]
17 errcode_map = {}
18 error_re = re.compile("(E\d\d\d\d)")
19
20 for (dirpath, dirnames, filenames) in os.walk(src_dir):
21     if "src/test" in dirpath or "src/llvm" in dirpath:
22         # Short circuit for fast
23         continue
24
25     for filename in filenames:
26         if filename != "diagnostics.rs":
27             continue
28
29         path = os.path.join(dirpath, filename)
30
31         with open(path, 'r') as f:
32             for line_num, line in enumerate(f, start=1):
33                 match = error_re.search(line)
34                 if match:
35                     errcode = match.group(1)
36                     new_record = [(errcode, path, line_num, line)]
37                     existing = errcode_map.get(errcode)
38                     if existing is not None:
39                         # This is a dupe
40                         errcode_map[errcode] = existing + new_record
41                     else:
42                         errcode_map[errcode] = new_record
43
44 errors = False
45 all_errors = []
46
47 for errcode, entries in errcode_map.items():
48     all_errors.append(entries[0][0])
49     if len(entries) > 1:
50         print("error: duplicate error code " + errcode)
51         for entry in entries:
52             print("{1}: {2}\n{3}".format(*entry))
53         errors = True
54
55 print("{0} error codes".format(len(errcode_map)))
56 print("highest error code: " + max(all_errors))
57
58 if errors:
59     sys.exit(1)