Add license check as part of make tidy and make check

This commit is contained in:
Brian Anderson 2013-04-04 17:50:04 -07:00
parent 3bf021a064
commit 0a8cb6703d
3 changed files with 174 additions and 2 deletions

View file

@ -31,9 +31,9 @@ DEPS_CHECK_TARGETS_FAST = $(addprefix check-,$(filter-out $(SLOW_TESTS),$(DEPS_C
.PHONY: check $(DEPS_CHECK_TARGETS_ALL) .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 check-servo: servo-test
./servo-test $(TESTNAME) ./servo-test $(TESTNAME)
@ -43,3 +43,6 @@ check-ref: reftest
check-content: contenttest check-content: contenttest
./contenttest --source-dir=$(S)/src/test/content $(TESTNAME) ./contenttest --source-dir=$(S)/src/test/content $(TESTNAME)
tidy:
python $(S)/src/etc/tidy.py $(S)/src

75
src/etc/licenseck.py Normal file
View file

@ -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

94
src/etc/tidy.py Normal file
View file

@ -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)