2010-08-19 10:25:58 -07:00
|
|
|
#!/usr/bin/env python
|
2013-01-17 23:28:42 -08:00
|
|
|
# xfail-license
|
2010-06-23 21:03:09 -07:00
|
|
|
|
2012-06-21 16:44:10 -07:00
|
|
|
import sys, fileinput, subprocess, re
|
2013-01-17 23:28:42 -08:00
|
|
|
from licenseck import *
|
2010-06-23 21:03:09 -07:00
|
|
|
|
|
|
|
err=0
|
2013-03-12 10:55:39 -07:00
|
|
|
cols=100
|
2010-06-23 21:03:09 -07:00
|
|
|
|
2010-08-18 16:07:26 -07: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 18:32:46 -07:00
|
|
|
stdout=subprocess.PIPE)
|
2010-08-18 16:07:26 -07:00
|
|
|
result=config_proc.communicate()[0]
|
|
|
|
|
|
|
|
true="true".encode('utf8')
|
|
|
|
autocrlf=result.strip() == true if result is not None else False
|
|
|
|
|
2013-01-17 23:28:42 -08:00
|
|
|
def report_error_name_no(name, no, s):
|
2010-06-23 21:03:09 -07:00
|
|
|
global err
|
2013-01-17 23:28:42 -08:00
|
|
|
print("%s:%d: %s" % (name, no, s))
|
2010-06-23 21:03:09 -07:00
|
|
|
err=1
|
|
|
|
|
2013-01-17 23:28:42 -08:00
|
|
|
def report_err(s):
|
|
|
|
report_error_name_no(fileinput.filename(), fileinput.filelineno(), s)
|
|
|
|
|
2013-01-24 22:03:29 -08:00
|
|
|
def report_warn(s):
|
|
|
|
print("%s:%d: %s" % (fileinput.filename(),
|
|
|
|
fileinput.filelineno(),
|
|
|
|
s))
|
|
|
|
|
2013-01-17 23:28:42 -08:00
|
|
|
def do_license_check(name, contents):
|
|
|
|
if not check_license(name, contents):
|
|
|
|
report_error_name_no(name, 1, "incorrect license")
|
|
|
|
|
|
|
|
|
2012-07-29 15:59:08 -07:00
|
|
|
file_names = [s for s in sys.argv[1:] if (not s.endswith("_gen.rs"))
|
2012-08-15 11:53:38 -07:00
|
|
|
and (not ".#" in s)]
|
2012-02-14 15:21:53 -08:00
|
|
|
|
2013-01-17 23:28:42 -08:00
|
|
|
current_name = ""
|
|
|
|
current_contents = ""
|
|
|
|
|
2012-01-06 19:56:33 -08:00
|
|
|
try:
|
2012-02-14 15:21:53 -08:00
|
|
|
for line in fileinput.input(file_names,
|
|
|
|
openhook=fileinput.hook_encoded("utf-8")):
|
2012-06-21 16:44:10 -07: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 18:20:22 -07:00
|
|
|
if line.find("TODO") != -1:
|
|
|
|
report_err("TODO is deprecated; use FIXME")
|
2013-01-28 09:59:58 -08:00
|
|
|
idx = line.find("// NOTE")
|
2013-01-25 06:27:32 -08:00
|
|
|
if idx != -1:
|
2013-01-10 10:59:58 -08:00
|
|
|
report_warn("NOTE" + line[idx + len("// NOTE"):])
|
2012-01-06 19:56:33 -08: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 08:39:41 -07:00
|
|
|
|
2012-04-30 16:32:47 -07:00
|
|
|
if line_len > cols:
|
2012-01-06 19:56:33 -08:00
|
|
|
report_err("line longer than %d chars" % cols)
|
2013-01-17 23:28:42 -08: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 19:56:33 -08:00
|
|
|
except UnicodeDecodeError, e:
|
|
|
|
report_err("UTF-8 decoding error " + str(e))
|
2010-06-23 21:03:09 -07:00
|
|
|
|
|
|
|
|
|
|
|
sys.exit(err)
|