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.
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.
11 # Digs error codes out of files named 'diagnostics.rs' across
12 # the tree, and ensures thare are no duplicates.
19 print "usage: errorck.py <src-dir>"
24 error_re = re.compile("(E\d\d\d\d)")
26 for (dirpath, dirnames, filenames) in os.walk(src_dir):
27 if "src/test" in dirpath or "src/llvm" in dirpath:
28 # Short circuit for fast
31 for filename in filenames:
32 if filename != "diagnostics.rs":
35 path = os.path.join(dirpath, filename)
37 with open(path, 'r') as f:
38 for line_num, line in enumerate(f, start=1):
39 match = error_re.search(line)
41 errcode = match.group(1)
42 new_record = [(errcode, path, line_num, line)]
43 existing = errcode_map.get(errcode)
44 if existing is not None:
46 errcode_map[errcode] = existing + new_record
48 errcode_map[errcode] = new_record
53 for errcode, entries in errcode_map.items():
54 all_errors.append(entries[0][0])
56 print("error: duplicate error code " + errcode)
58 print("{1}: {2}\n{3}".format(*entry))
62 print("* {0} error codes".format(len(errcode_map)))
63 print("* highest error code: " + max(all_errors))