aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2013-04-04 17:50:04 -0700
committerBrian Anderson <banderson@mozilla.com>2013-04-04 19:41:42 -0700
commit0a8cb6703d6f70a76b5f17448a89efc51fbaf024 (patch)
tree411e6fd1b4fbeff5ede597c71c5b3947b12e403d
parent3bf021a064a29e9fb9ed3d8e24541468cc5c59d5 (diff)
downloadservo-0a8cb6703d6f70a76b5f17448a89efc51fbaf024.tar.gz
servo-0a8cb6703d6f70a76b5f17448a89efc51fbaf024.zip
Add license check as part of `make tidy` and `make check`
-rw-r--r--mk/check.mk7
-rw-r--r--src/etc/licenseck.py75
-rw-r--r--src/etc/tidy.py94
3 files changed, 174 insertions, 2 deletions
diff --git a/mk/check.mk b/mk/check.mk
index 03e6e49be3a..81bc3b2447a 100644
--- a/mk/check.mk
+++ b/mk/check.mk
@@ -31,9 +31,9 @@ DEPS_CHECK_TARGETS_FAST = $(addprefix check-,$(filter-out $(SLOW_TESTS),$(DEPS_C
.PHONY: check $(DEPS_CHECK_TARGETS_ALL)
-check: $(DEPS_CHECK_TARGETS_FAST) check-servo
+check: $(DEPS_CHECK_TARGETS_FAST) check-servo tidy
-check-all: $(DEPS_CHECK_TARGETS_ALL) check-servo
+check-all: $(DEPS_CHECK_TARGETS_ALL) check-servo tidy
check-servo: servo-test
./servo-test $(TESTNAME)
@@ -43,3 +43,6 @@ check-ref: reftest
check-content: contenttest
./contenttest --source-dir=$(S)/src/test/content $(TESTNAME)
+
+tidy:
+ python $(S)/src/etc/tidy.py $(S)/src
diff --git a/src/etc/licenseck.py b/src/etc/licenseck.py
new file mode 100644
index 00000000000..e6da0096d9e
--- /dev/null
+++ b/src/etc/licenseck.py
@@ -0,0 +1,75 @@
+# Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+# file at the top-level directory of this distribution.
+#
+# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+# option. This file may not be copied, modified, or distributed
+# except according to those terms.
+
+license0="""\
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"""
+
+license1="""\
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+"""
+
+license2="""\
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+"""
+
+license3 = """\
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+"""
+
+license4 = """\
+# Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+# file at the top-level directory of this distribution.
+#
+# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+# option. This file may not be copied, modified, or distributed
+# except according to those terms.
+"""
+
+licenses = [license0, license1, license2, license3, license4]
+
+exceptions = [
+ "rust-http-client/http_parser.c", # Joyent, BSD
+ "rust-http-client/http_parser.h", # Joyent, BSD
+ "rust-opengles/gl2.h", # Khronos, SGI Free Software B License Version 2.0
+]
+
+def check_license(name, contents):
+ valid_license = False
+ for a_valid_license in licenses:
+ if contents.startswith(a_valid_license):
+ valid_license = True
+ break
+ if valid_license:
+ return True
+
+ for exception in exceptions:
+ if name.endswith(exception):
+ return True
+
+ firstlineish = contents[:100]
+ if firstlineish.find("xfail-license") != -1:
+ return True
+
+ return False
diff --git a/src/etc/tidy.py b/src/etc/tidy.py
new file mode 100644
index 00000000000..b04194e30a9
--- /dev/null
+++ b/src/etc/tidy.py
@@ -0,0 +1,94 @@
+# Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+# file at the top-level directory of this distribution.
+#
+# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+# option. This file may not be copied, modified, or distributed
+# except according to those terms.
+
+#!/usr/bin/env python
+
+import fileinput, sys, os
+from licenseck import *
+
+err = 0
+
+def report_error_name_no(name, no, s):
+ global err
+ print("%s:%d: %s" % (name, no, s))
+ err=1
+
+def report_err(s):
+ report_error_name_no(fileinput.filename(), fileinput.filelineno(), s)
+
+def report_warn(s):
+ print("%s:%d: %s" % (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")
+
+exceptions = [
+ "src/cairo",
+ "src/libcss",
+ "src/libhubbub",
+ "src/libparserutils",
+ "src/libwapcaplet",
+ "src/mozjs",
+ "src/pixman",
+ "src/rust/",
+ "src/rust-azure/src",
+ "src/rust-azure/include",
+ "src/rust-harfbuzz/harfbuzz",
+ "src/skia",
+ "src/servo/dom/bindings/codegen",
+ "src/rust-opengles", # Need to contact copyright holders
+ "src/rust-stb-image", # "
+ "src/servo", # "
+ "src/servo-gfx", # "
+ "src/reftest", # "
+ "src/contenttest", # "
+]
+
+def should_check(name):
+ if ".#" in name:
+ return False
+ if not (name.endswith(".rs")
+ or name.endswith(".rc")
+ or name.endswith(".cpp")
+ or name.endswith(".c")
+ or name.endswith(".h")
+ or name.endswith(".py")):
+ return False
+ for exception in exceptions:
+ if exception in name:
+ return False
+ return True
+
+file_names = []
+for root, dirs, files in os.walk(sys.argv[1]):
+ for myfile in files:
+ file_name = root + "/" + myfile
+ if should_check(file_name):
+ file_names.append(file_name)
+
+current_name = ""
+current_contents = ""
+
+for line in fileinput.input(file_names):
+ 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)
+
+sys.exit(err)