about summary refs log tree commit diff
path: root/src/etc/tidy.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/etc/tidy.py')
-rw-r--r--src/etc/tidy.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/etc/tidy.py b/src/etc/tidy.py
index 2c498b9283f..e866d80062d 100644
--- a/src/etc/tidy.py
+++ b/src/etc/tidy.py
@@ -1,6 +1,8 @@
 #!/usr/bin/env python
+# xfail-license
 
 import sys, fileinput, subprocess, re
+from licenseck import *
 
 err=0
 cols=78
@@ -13,14 +15,25 @@ result=config_proc.communicate()[0]
 true="true".encode('utf8')
 autocrlf=result.strip() == true if result is not None else False
 
-def report_err(s):
+def report_error_name_no(name, no, s):
     global err
-    print("%s:%d: %s" % (fileinput.filename(), fileinput.filelineno(), s))
+    print("%s:%d: %s" % (name, no, s))
     err=1
 
+def report_err(s):
+    report_error_name_no(fileinput.filename(), fileinput.filelineno(), s)
+
+def do_license_check(name, contents):
+    if not check_license(name, contents):
+        report_error_name_no(name, 1, "incorrect license")
+
+
 file_names = [s for s in sys.argv[1:] if (not s.endswith("_gen.rs"))
                                      and (not ".#" in s)]
 
+current_name = ""
+current_contents = ""
+
 try:
     for line in fileinput.input(file_names,
                                 openhook=fileinput.hook_encoded("utf-8")):
@@ -42,6 +55,19 @@ try:
 
         if line_len > cols:
             report_err("line longer than %d chars" % cols)
+
+        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)
+
 except UnicodeDecodeError, e:
     report_err("UTF-8 decoding error " + str(e))