From 6b6acde972bfd646e5b8a3eeaabd613c44d1028c Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 17 Jan 2013 23:28:42 -0800 Subject: [PATCH] Add a license check to tidy. #4018 --- src/etc/check-summary.py | 1 + src/etc/combine-tests.py | 1 + src/etc/extract-tests.py | 2 + src/etc/extract_grammar.py | 1 + src/etc/get-snapshot.py | 1 + src/etc/latest-unix-snaps.py | 1 + src/etc/licenseck.py | 72 ++++++++++++++++++++++++++++++++ src/etc/make-snapshot.py | 1 + src/etc/mirror-all-snapshots.py | 1 + src/etc/snapshot.py | 2 + src/etc/sugarise-doc-comments.py | 1 + src/etc/tidy.py | 30 ++++++++++++- src/etc/unicode.py | 1 + src/libcargo/cargo.rc | 1 - src/libcore/bool.rs | 1 - src/libcore/os.rs | 2 +- src/libcore/prelude.rs | 10 +++++ src/libfuzzer/fuzzer.rc | 1 - src/librustc/driver/driver.rs | 1 - src/librustc/rustc.rc | 1 - src/libstd/bigint.rs | 10 +++++ src/libstd/flatpipes.rs | 10 +++++ src/libstd/priority_queue.rs | 9 ++++ src/rt/arch/arm/context.cpp | 1 + src/rt/arch/arm/context.h | 1 + src/rt/arch/arm/gpr.cpp | 2 + src/rt/arch/arm/gpr.h | 1 + src/rt/arch/arm/regs.h | 2 + src/rt/arch/i386/context.h | 1 - src/rt/arch/x86_64/context.h | 1 - src/rt/rust_kernel.h | 1 - src/rt/rust_log.h | 1 - src/rt/sync/lock_and_signal.h | 1 - src/rt/sync/sync.h | 1 - src/rt/util/array_list.h | 1 - src/rt/util/hash_map.h | 1 - src/rt/util/indexed_list.h | 1 - 37 files changed, 160 insertions(+), 17 deletions(-) create mode 100644 src/etc/licenseck.py diff --git a/src/etc/check-summary.py b/src/etc/check-summary.py index 7faacbfbb26ba..272bbc6fbbd6c 100755 --- a/src/etc/check-summary.py +++ b/src/etc/check-summary.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# xfail-license import sys diff --git a/src/etc/combine-tests.py b/src/etc/combine-tests.py index 1e3c0bcfbfc3e..d6efcbc464298 100755 --- a/src/etc/combine-tests.py +++ b/src/etc/combine-tests.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# xfail-license # this combines all the working run-pass tests into a single large crate so we # can run it "fast": spawning zillions of windows processes is our major build diff --git a/src/etc/extract-tests.py b/src/etc/extract-tests.py index 891e8674f887b..9d9b7817f4b03 100644 --- a/src/etc/extract-tests.py +++ b/src/etc/extract-tests.py @@ -1,3 +1,5 @@ +# xfail-license + # Script for extracting compilable fragments from markdown # documentation. See prep.js for a description of the format # recognized by this tool. Expects a directory fragements/ to exist diff --git a/src/etc/extract_grammar.py b/src/etc/extract_grammar.py index 63e89563464f3..58d1975c042b7 100755 --- a/src/etc/extract_grammar.py +++ b/src/etc/extract_grammar.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# xfail-license # This script is for extracting the grammar from the rust docs. diff --git a/src/etc/get-snapshot.py b/src/etc/get-snapshot.py index 7d390c8c9aafb..130ace64ce47a 100755 --- a/src/etc/get-snapshot.py +++ b/src/etc/get-snapshot.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# xfail-license import os, tarfile, re, shutil, sys from snapshot import * diff --git a/src/etc/latest-unix-snaps.py b/src/etc/latest-unix-snaps.py index 01d9edddf788f..7a2ddba3a16aa 100755 --- a/src/etc/latest-unix-snaps.py +++ b/src/etc/latest-unix-snaps.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# xfail-license import os, tarfile, hashlib, re, shutil, sys from snapshot import * diff --git a/src/etc/licenseck.py b/src/etc/licenseck.py new file mode 100644 index 0000000000000..14d00e8c2cbb9 --- /dev/null +++ b/src/etc/licenseck.py @@ -0,0 +1,72 @@ +# Copyright 2013 The Rust Project Developers. See the COPYRIGHT +# file at the top-level directory of this distribution and at +# http://rust-lang.org/COPYRIGHT. +# +# Licensed under the Apache License, Version 2.0 or the MIT license +# , at your +# option. This file may not be copied, modified, or distributed +# except according to those terms. + +license1 = """// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +""" + +license2 = """// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +""" + +license3 = """# Copyright 2013 The Rust Project Developers. See the COPYRIGHT +# file at the top-level directory of this distribution and at +# http://rust-lang.org/COPYRIGHT. +# +# Licensed under the Apache License, Version 2.0 or the MIT license +# , at your +# option. This file may not be copied, modified, or distributed +# except according to those terms. +""" + +licenses = [license1, license2, license3] + +exceptions = [ + "rt/rust_android_dummy.cpp", # BSD, chromium + "rt/rust_android_dummy.h", # BSD, chromium + "rt/isaac/randport.cpp", # public domain + "rt/isaac/rand.h", # public domain + "rt/isaac/standard.h", # public domain +] + +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/make-snapshot.py b/src/etc/make-snapshot.py index 4c2950af1cc33..27d17c2ff16f3 100755 --- a/src/etc/make-snapshot.py +++ b/src/etc/make-snapshot.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# xfail-license import snapshot, sys diff --git a/src/etc/mirror-all-snapshots.py b/src/etc/mirror-all-snapshots.py index f4bb8c042eadd..f1fce7a94b5b6 100644 --- a/src/etc/mirror-all-snapshots.py +++ b/src/etc/mirror-all-snapshots.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# xfail-license import os, tarfile, hashlib, re, shutil from snapshot import * diff --git a/src/etc/snapshot.py b/src/etc/snapshot.py index b19a44e968df5..123987d4b1ead 100644 --- a/src/etc/snapshot.py +++ b/src/etc/snapshot.py @@ -1,3 +1,5 @@ +# xfail-license + import re, os, sys, glob, tarfile, shutil, subprocess, tempfile try: diff --git a/src/etc/sugarise-doc-comments.py b/src/etc/sugarise-doc-comments.py index bd21447ffcc50..6399cff6b880d 100755 --- a/src/etc/sugarise-doc-comments.py +++ b/src/etc/sugarise-doc-comments.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# xfail-license # # this script attempts to turn doc comment attributes (#[doc = "..."]) diff --git a/src/etc/tidy.py b/src/etc/tidy.py index 2c498b9283ff7..e866d80062d51 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 @@ 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 @@ def report_err(s): 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)) diff --git a/src/etc/unicode.py b/src/etc/unicode.py index ff9f75e996e22..5dabf34953b01 100755 --- a/src/etc/unicode.py +++ b/src/etc/unicode.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# xfail-license # This digests UnicodeData.txt and DerivedCoreProperties.txt and emits rust # code covering the core properties. Since this is a pretty rare event we diff --git a/src/libcargo/cargo.rc b/src/libcargo/cargo.rc index ea67d0ea858d1..29a7af2bfdbd5 100644 --- a/src/libcargo/cargo.rc +++ b/src/libcargo/cargo.rc @@ -1,4 +1,3 @@ -// -*- rust -*- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. diff --git a/src/libcore/bool.rs b/src/libcore/bool.rs index 3e7b88b7b78f7..2f3a53ea504f4 100644 --- a/src/libcore/bool.rs +++ b/src/libcore/bool.rs @@ -1,4 +1,3 @@ -// -*- rust -*- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. diff --git a/src/libcore/os.rs b/src/libcore/os.rs index ff3253a8223ff..ffd41bc05b11b 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers.src/libcore/os.rs +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // diff --git a/src/libcore/prelude.rs b/src/libcore/prelude.rs index de23feceea590..63b7628f119e5 100644 --- a/src/libcore/prelude.rs +++ b/src/libcore/prelude.rs @@ -1,3 +1,13 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + // This file is imported into every module by default. /* Reexported core operators */ diff --git a/src/libfuzzer/fuzzer.rc b/src/libfuzzer/fuzzer.rc index 3f37b6d17944e..b7ec10e1a4f3f 100644 --- a/src/libfuzzer/fuzzer.rc +++ b/src/libfuzzer/fuzzer.rc @@ -1,4 +1,3 @@ -// -*- rust -*- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 740cc52631098..70cad499e4cb7 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -1,4 +1,3 @@ -// -*- rust -*- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. diff --git a/src/librustc/rustc.rc b/src/librustc/rustc.rc index 56a228991939b..4e101eb5bb708 100644 --- a/src/librustc/rustc.rc +++ b/src/librustc/rustc.rc @@ -1,4 +1,3 @@ -// -*- rust -*- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. diff --git a/src/libstd/bigint.rs b/src/libstd/bigint.rs index 303129c2849e1..678565ee325c2 100644 --- a/src/libstd/bigint.rs +++ b/src/libstd/bigint.rs @@ -1,3 +1,13 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + /*! A Big integer (signed version: BigInt, unsigned version: BigUint). diff --git a/src/libstd/flatpipes.rs b/src/libstd/flatpipes.rs index 0607055db5c03..534f1b7d47916 100644 --- a/src/libstd/flatpipes.rs +++ b/src/libstd/flatpipes.rs @@ -1,3 +1,13 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + /*! Generic communication channels for things that can be represented as, diff --git a/src/libstd/priority_queue.rs b/src/libstd/priority_queue.rs index 4d341d737f602..b9c040de42a20 100644 --- a/src/libstd/priority_queue.rs +++ b/src/libstd/priority_queue.rs @@ -1,3 +1,12 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! A priority queue implemented with a binary heap diff --git a/src/rt/arch/arm/context.cpp b/src/rt/arch/arm/context.cpp index dbf06a532a878..2c735e410fa4a 100644 --- a/src/rt/arch/arm/context.cpp +++ b/src/rt/arch/arm/context.cpp @@ -1,3 +1,4 @@ +// xfail-license #include "context.h" #include "../../rust_globals.h" diff --git a/src/rt/arch/arm/context.h b/src/rt/arch/arm/context.h index 6c7db766d6a7e..54f0df7de3144 100644 --- a/src/rt/arch/arm/context.h +++ b/src/rt/arch/arm/context.h @@ -1,4 +1,5 @@ // -*- mode: c++ -*- +// xfail-license #ifndef CONTEXT_H #define CONTEXT_H diff --git a/src/rt/arch/arm/gpr.cpp b/src/rt/arch/arm/gpr.cpp index 32a68d0732ab3..6dd385fb33025 100644 --- a/src/rt/arch/arm/gpr.cpp +++ b/src/rt/arch/arm/gpr.cpp @@ -1,3 +1,5 @@ +// xfail-license + #include "gpr.h" #define LOAD(rn) do { \ diff --git a/src/rt/arch/arm/gpr.h b/src/rt/arch/arm/gpr.h index 472c8a05e35e4..49db1429903d9 100644 --- a/src/rt/arch/arm/gpr.h +++ b/src/rt/arch/arm/gpr.h @@ -1,3 +1,4 @@ +// xfail-license // General-purpose registers. This structure is used during stack crawling. #ifndef GPR_H diff --git a/src/rt/arch/arm/regs.h b/src/rt/arch/arm/regs.h index a49fcab1184c5..2b44bd3af357d 100644 --- a/src/rt/arch/arm/regs.h +++ b/src/rt/arch/arm/regs.h @@ -1,3 +1,5 @@ +// xfail-license + #define RUSTRT_RBX 0 #define RUSTRT_RSP 1 #define RUSTRT_RBP 2 diff --git a/src/rt/arch/i386/context.h b/src/rt/arch/i386/context.h index 99d633ebff27c..33352b4a5562d 100644 --- a/src/rt/arch/i386/context.h +++ b/src/rt/arch/i386/context.h @@ -1,4 +1,3 @@ -// -*- mode: c++ -*- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. diff --git a/src/rt/arch/x86_64/context.h b/src/rt/arch/x86_64/context.h index f78c92e365a2b..b768a1fb7b089 100644 --- a/src/rt/arch/x86_64/context.h +++ b/src/rt/arch/x86_64/context.h @@ -1,4 +1,3 @@ -// -*- mode: c++ -*- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. diff --git a/src/rt/rust_kernel.h b/src/rt/rust_kernel.h index cd52bfae8d3f4..48522b57d5c0d 100644 --- a/src/rt/rust_kernel.h +++ b/src/rt/rust_kernel.h @@ -1,4 +1,3 @@ -// -*- c++ -*- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. diff --git a/src/rt/rust_log.h b/src/rt/rust_log.h index 8b32b1cc91077..b98d8477dbc08 100644 --- a/src/rt/rust_log.h +++ b/src/rt/rust_log.h @@ -1,4 +1,3 @@ -// -*- c++ -*- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. diff --git a/src/rt/sync/lock_and_signal.h b/src/rt/sync/lock_and_signal.h index 1ed494a77ae56..5a0eb83a3943c 100644 --- a/src/rt/sync/lock_and_signal.h +++ b/src/rt/sync/lock_and_signal.h @@ -1,4 +1,3 @@ -// -*- c++ -*- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. diff --git a/src/rt/sync/sync.h b/src/rt/sync/sync.h index 13d11a550216f..6ac97d5793362 100644 --- a/src/rt/sync/sync.h +++ b/src/rt/sync/sync.h @@ -1,4 +1,3 @@ -// -*- c++ -*- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. diff --git a/src/rt/util/array_list.h b/src/rt/util/array_list.h index 4bef26750db3c..0852cf9497e2b 100644 --- a/src/rt/util/array_list.h +++ b/src/rt/util/array_list.h @@ -1,4 +1,3 @@ -// -*- c++ -*- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. diff --git a/src/rt/util/hash_map.h b/src/rt/util/hash_map.h index 253a7a06fb7b7..e5bef45c1c3c5 100644 --- a/src/rt/util/hash_map.h +++ b/src/rt/util/hash_map.h @@ -1,4 +1,3 @@ -// -*- c++ -*- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. diff --git a/src/rt/util/indexed_list.h b/src/rt/util/indexed_list.h index 88f4f2776186b..4673e9e27e31b 100644 --- a/src/rt/util/indexed_list.h +++ b/src/rt/util/indexed_list.h @@ -1,4 +1,3 @@ -// -*- c++ -*- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT.