|
| 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 | + |
| 18 | +errcode_map = { } |
| 19 | + |
| 20 | +for (dirpath, dirnames, filenames) in os.walk(src_dir): |
| 21 | + |
| 22 | + if "src/test" in dirpath or "src/llvm" in dirpath: |
| 23 | + # Short circuit for fast |
| 24 | + continue |
| 25 | + |
| 26 | + for filename in filenames: |
| 27 | + if filename != "diagnostics.rs": |
| 28 | + continue |
| 29 | + |
| 30 | + path = os.path.join(dirpath, filename) |
| 31 | + line_num = 1 |
| 32 | + with open(path, 'r') as f: |
| 33 | + for line in f: |
| 34 | + |
| 35 | + p = re.compile("(E\d\d\d\d)") |
| 36 | + m = p.search(line) |
| 37 | + if not m is None: |
| 38 | + errcode = m.group(1) |
| 39 | + |
| 40 | + new_record = [(errcode, path, line_num, line)] |
| 41 | + existing = errcode_map.get(errcode) |
| 42 | + if existing is not None: |
| 43 | + # This is a dupe |
| 44 | + errcode_map[errcode] = existing + new_record |
| 45 | + else: |
| 46 | + errcode_map[errcode] = new_record |
| 47 | + |
| 48 | + line_num += 1 |
| 49 | + |
| 50 | +errors = False |
| 51 | +all_errors = [] |
| 52 | +for errcode in errcode_map: |
| 53 | + entries = errcode_map[errcode] |
| 54 | + all_errors += [entries[0][0]] |
| 55 | + if len(entries) > 1: |
| 56 | + print "error: duplicate error code " + errcode |
| 57 | + for entry in entries: |
| 58 | + print entry[1] + ": " + str(entry[2]) |
| 59 | + print entry[3] |
| 60 | + errors = True |
| 61 | + |
| 62 | +print str(len(errcode_map)) + " error codes" |
| 63 | + |
| 64 | +all_errors.sort() |
| 65 | +all_errors.reverse() |
| 66 | + |
| 67 | +print "highest error code: " + all_errors[0] |
| 68 | + |
| 69 | +if errors: |
| 70 | + sys.exit(1) |
0 commit comments