1 # Copyright 2010-2014 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 import sys, fileinput, subprocess, re
12 from licenseck import *
18 # Be careful to support Python 2.4, 2.6, and 3.x here!
19 config_proc=subprocess.Popen([ "git", "config", "core.autocrlf" ],
20 stdout=subprocess.PIPE)
21 result=config_proc.communicate()[0]
23 true="true".encode('utf8')
24 autocrlf=result.strip() == true if result is not None else False
26 def report_error_name_no(name, no, s):
28 print("%s:%d: %s" % (name, no, s))
32 report_error_name_no(fileinput.filename(), fileinput.filelineno(), s)
35 print("%s:%d: %s" % (fileinput.filename(),
36 fileinput.filelineno(),
39 def do_license_check(name, contents):
40 if not check_license(name, contents):
41 report_error_name_no(name, 1, "incorrect license")
44 file_names = [s for s in sys.argv[1:] if (not s.endswith("_gen.rs"))
51 for line in fileinput.input(file_names,
52 openhook=fileinput.hook_encoded("utf-8")):
54 if fileinput.filename().find("tidy.py") == -1:
55 if line.find("// XXX") != -1:
56 report_err("XXX is no longer necessary, use FIXME")
57 if line.find("TODO") != -1:
58 report_err("TODO is deprecated; use FIXME")
59 match = re.match(r'^.*//\s*(NOTE.*)$', line)
62 if "snap" in m.lower():
63 report_warn(match.group(1))
64 match = re.match(r'^.*//\s*SNAP\s+(\w+)', line)
67 date, rev = snapshot.curr_snapshot_rev()
68 if not hsh.startswith(rev):
69 report_err("snapshot out of date (" + date
73 report_warn("unmatched SNAP line: " + line)
75 if (line.find('\t') != -1 and
76 fileinput.filename().find("Makefile") == -1):
77 report_err("tab character")
78 if not autocrlf and line.find('\r') != -1:
79 report_err("CR character")
80 if line.endswith(" \n") or line.endswith("\t\n"):
81 report_err("trailing whitespace")
82 line_len = len(line)-2 if autocrlf else len(line)-1
85 report_err("line longer than %d chars" % cols)
87 if fileinput.isfirstline() and current_name != "":
88 do_license_check(current_name, current_contents)
90 if fileinput.isfirstline():
91 current_name = fileinput.filename()
94 current_contents += line
96 if current_name != "":
97 do_license_check(current_name, current_contents)
99 except UnicodeDecodeError, e:
100 report_err("UTF-8 decoding error " + str(e))