2010-08-19 12:25:58 -05:00
|
|
|
#!/usr/bin/env python
|
2013-01-18 01:28:42 -06:00
|
|
|
# xfail-license
|
2010-06-23 23:03:09 -05:00
|
|
|
|
2012-06-21 18:44:10 -05:00
|
|
|
import sys, fileinput, subprocess, re
|
2013-01-18 01:28:42 -06:00
|
|
|
from licenseck import *
|
2010-06-23 23:03:09 -05:00
|
|
|
|
|
|
|
err=0
|
|
|
|
cols=78
|
|
|
|
|
2010-08-18 18:07:26 -05:00
|
|
|
# Be careful to support Python 2.4, 2.6, and 3.x here!
|
|
|
|
config_proc=subprocess.Popen([ "git", "config", "core.autocrlf" ],
|
2011-03-19 20:32:46 -05:00
|
|
|
stdout=subprocess.PIPE)
|
2010-08-18 18:07:26 -05:00
|
|
|
result=config_proc.communicate()[0]
|
|
|
|
|
|
|
|
true="true".encode('utf8')
|
|
|
|
autocrlf=result.strip() == true if result is not None else False
|
|
|
|
|
2013-01-18 01:28:42 -06:00
|
|
|
def report_error_name_no(name, no, s):
|
2010-06-23 23:03:09 -05:00
|
|
|
global err
|
2013-01-18 01:28:42 -06:00
|
|
|
print("%s:%d: %s" % (name, no, s))
|
2010-06-23 23:03:09 -05:00
|
|
|
err=1
|
|
|
|
|
2013-01-18 01:28:42 -06:00
|
|
|
def report_err(s):
|
|
|
|
report_error_name_no(fileinput.filename(), fileinput.filelineno(), s)
|
|
|
|
|
2013-01-25 00:03:29 -06:00
|
|
|
def report_warn(s):
|
|
|
|
print("%s:%d: %s" % (fileinput.filename(),
|
|
|
|
fileinput.filelineno(),
|
|
|
|
s))
|
|
|
|
|
2013-01-18 01:28:42 -06:00
|
|
|
def do_license_check(name, contents):
|
|
|
|
if not check_license(name, contents):
|
|
|
|
report_error_name_no(name, 1, "incorrect license")
|
|
|
|
|
|
|
|
|
2012-07-29 17:59:08 -05:00
|
|
|
file_names = [s for s in sys.argv[1:] if (not s.endswith("_gen.rs"))
|
2012-08-15 13:53:38 -05:00
|
|
|
and (not ".#" in s)]
|
2012-02-14 17:21:53 -06:00
|
|
|
|
2013-01-18 01:28:42 -06:00
|
|
|
current_name = ""
|
|
|
|
current_contents = ""
|
|
|
|
|
2012-01-06 21:56:33 -06:00
|
|
|
try:
|
2012-02-14 17:21:53 -06:00
|
|
|
for line in fileinput.input(file_names,
|
|
|
|
openhook=fileinput.hook_encoded("utf-8")):
|
2012-06-21 18:44:10 -05:00
|
|
|
|
|
|
|
if fileinput.filename().find("tidy.py") == -1:
|
|
|
|
if line.find("FIXME") != -1:
|
|
|
|
if re.search("FIXME.*#\d+", line) == None:
|
|
|
|
report_err("FIXME without issue number")
|
2012-07-12 20:20:22 -05:00
|
|
|
if line.find("TODO") != -1:
|
|
|
|
report_err("TODO is deprecated; use FIXME")
|
2013-01-25 00:03:29 -06:00
|
|
|
if line.find("// WARN") != -1:
|
|
|
|
mo = re.match("// WARN (.*)", line)
|
|
|
|
report_warn("WARN: " + mo.group(1))
|
2012-01-06 21:56:33 -06:00
|
|
|
if (line.find('\t') != -1 and
|
|
|
|
fileinput.filename().find("Makefile") == -1):
|
|
|
|
report_err("tab character")
|
|
|
|
if not autocrlf and line.find('\r') != -1:
|
|
|
|
report_err("CR character")
|
|
|
|
if line.endswith(" \n") or line.endswith("\t\n"):
|
|
|
|
report_err("trailing whitespace")
|
|
|
|
line_len = len(line)-2 if autocrlf else len(line)-1
|
2012-04-17 10:39:41 -05:00
|
|
|
|
2012-04-30 18:32:47 -05:00
|
|
|
if line_len > cols:
|
2012-01-06 21:56:33 -06:00
|
|
|
report_err("line longer than %d chars" % cols)
|
2013-01-18 01:28:42 -06:00
|
|
|
|
|
|
|
if fileinput.isfirstline() and current_name != "":
|
|
|
|
do_license_check(current_name, current_contents)
|
|
|
|
|
|
|
|
if fileinput.isfirstline():
|
|
|
|
current_name = fileinput.filename()
|
|
|
|
current_contents = ""
|
|
|
|
|
|
|
|
current_contents += line
|
|
|
|
|
|
|
|
if current_name != "":
|
|
|
|
do_license_check(current_name, current_contents)
|
|
|
|
|
2012-01-06 21:56:33 -06:00
|
|
|
except UnicodeDecodeError, e:
|
|
|
|
report_err("UTF-8 decoding error " + str(e))
|
2010-06-23 23:03:09 -05:00
|
|
|
|
|
|
|
|
|
|
|
sys.exit(err)
|
|
|
|
|