Skip to content

Commit 6b6acde

Browse files
committed
Add a license check to tidy. rust-lang#4018
1 parent 1244c0b commit 6b6acde

37 files changed

+160
-17
lines changed

src/etc/check-summary.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
# xfail-license
23

34
import sys
45

src/etc/combine-tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
# xfail-license
23

34
# this combines all the working run-pass tests into a single large crate so we
45
# can run it "fast": spawning zillions of windows processes is our major build

src/etc/extract-tests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# xfail-license
2+
13
# Script for extracting compilable fragments from markdown
24
# documentation. See prep.js for a description of the format
35
# recognized by this tool. Expects a directory fragements/ to exist

src/etc/extract_grammar.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
# xfail-license
23

34
# This script is for extracting the grammar from the rust docs.
45

src/etc/get-snapshot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
# xfail-license
23

34
import os, tarfile, re, shutil, sys
45
from snapshot import *

src/etc/latest-unix-snaps.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
# xfail-license
23

34
import os, tarfile, hashlib, re, shutil, sys
45
from snapshot import *

src/etc/licenseck.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
# file at the top-level directory of this distribution and at
3+
# http://rust-lang.org/COPYRIGHT.
4+
#
5+
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
# option. This file may not be copied, modified, or distributed
9+
# except according to those terms.
10+
11+
license1 = """// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
12+
// file at the top-level directory of this distribution and at
13+
// http://rust-lang.org/COPYRIGHT.
14+
//
15+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
16+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
17+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
18+
// option. This file may not be copied, modified, or distributed
19+
// except according to those terms.
20+
"""
21+
22+
license2 = """// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
23+
// file at the top-level directory of this distribution and at
24+
// http://rust-lang.org/COPYRIGHT.
25+
//
26+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
27+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
28+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
29+
// option. This file may not be copied, modified, or distributed
30+
// except according to those terms.
31+
"""
32+
33+
license3 = """# Copyright 2013 The Rust Project Developers. See the COPYRIGHT
34+
# file at the top-level directory of this distribution and at
35+
# http://rust-lang.org/COPYRIGHT.
36+
#
37+
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
38+
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
39+
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
40+
# option. This file may not be copied, modified, or distributed
41+
# except according to those terms.
42+
"""
43+
44+
licenses = [license1, license2, license3]
45+
46+
exceptions = [
47+
"rt/rust_android_dummy.cpp", # BSD, chromium
48+
"rt/rust_android_dummy.h", # BSD, chromium
49+
"rt/isaac/randport.cpp", # public domain
50+
"rt/isaac/rand.h", # public domain
51+
"rt/isaac/standard.h", # public domain
52+
]
53+
54+
def check_license(name, contents):
55+
valid_license = False
56+
for a_valid_license in licenses:
57+
if contents.startswith(a_valid_license):
58+
valid_license = True
59+
break
60+
if valid_license:
61+
return True
62+
63+
for exception in exceptions:
64+
if name.endswith(exception):
65+
return True
66+
67+
firstlineish = contents[:100]
68+
if firstlineish.find("xfail-license") != -1:
69+
return True
70+
71+
return False
72+

src/etc/make-snapshot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
# xfail-license
23

34
import snapshot, sys
45

src/etc/mirror-all-snapshots.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
# xfail-license
23

34
import os, tarfile, hashlib, re, shutil
45
from snapshot import *

src/etc/snapshot.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# xfail-license
2+
13
import re, os, sys, glob, tarfile, shutil, subprocess, tempfile
24

35
try:

src/etc/sugarise-doc-comments.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
# xfail-license
23

34
#
45
# this script attempts to turn doc comment attributes (#[doc = "..."])

src/etc/tidy.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env python
2+
# xfail-license
23

34
import sys, fileinput, subprocess, re
5+
from licenseck import *
46

57
err=0
68
cols=78
@@ -13,14 +15,25 @@
1315
true="true".encode('utf8')
1416
autocrlf=result.strip() == true if result is not None else False
1517

16-
def report_err(s):
18+
def report_error_name_no(name, no, s):
1719
global err
18-
print("%s:%d: %s" % (fileinput.filename(), fileinput.filelineno(), s))
20+
print("%s:%d: %s" % (name, no, s))
1921
err=1
2022

23+
def report_err(s):
24+
report_error_name_no(fileinput.filename(), fileinput.filelineno(), s)
25+
26+
def do_license_check(name, contents):
27+
if not check_license(name, contents):
28+
report_error_name_no(name, 1, "incorrect license")
29+
30+
2131
file_names = [s for s in sys.argv[1:] if (not s.endswith("_gen.rs"))
2232
and (not ".#" in s)]
2333

34+
current_name = ""
35+
current_contents = ""
36+
2437
try:
2538
for line in fileinput.input(file_names,
2639
openhook=fileinput.hook_encoded("utf-8")):
@@ -42,6 +55,19 @@ def report_err(s):
4255

4356
if line_len > cols:
4457
report_err("line longer than %d chars" % cols)
58+
59+
if fileinput.isfirstline() and current_name != "":
60+
do_license_check(current_name, current_contents)
61+
62+
if fileinput.isfirstline():
63+
current_name = fileinput.filename()
64+
current_contents = ""
65+
66+
current_contents += line
67+
68+
if current_name != "":
69+
do_license_check(current_name, current_contents)
70+
4571
except UnicodeDecodeError, e:
4672
report_err("UTF-8 decoding error " + str(e))
4773

src/etc/unicode.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
# xfail-license
23

34
# This digests UnicodeData.txt and DerivedCoreProperties.txt and emits rust
45
# code covering the core properties. Since this is a pretty rare event we

src/libcargo/cargo.rc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// -*- rust -*-
21
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
32
// file at the top-level directory of this distribution and at
43
// http://rust-lang.org/COPYRIGHT.

src/libcore/bool.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// -*- rust -*-
21
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
32
// file at the top-level directory of this distribution and at
43
// http://rust-lang.org/COPYRIGHT.

src/libcore/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers.src/libcore/os.rs
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/libcore/prelude.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
111
// This file is imported into every module by default.
212

313
/* Reexported core operators */

src/libfuzzer/fuzzer.rc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// -*- rust -*-
21
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
32
// file at the top-level directory of this distribution and at
43
// http://rust-lang.org/COPYRIGHT.

src/librustc/driver/driver.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// -*- rust -*-
21
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
32
// file at the top-level directory of this distribution and at
43
// http://rust-lang.org/COPYRIGHT.

src/librustc/rustc.rc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// -*- rust -*-
21
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
32
// file at the top-level directory of this distribution and at
43
// http://rust-lang.org/COPYRIGHT.

src/libstd/bigint.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
111
/*!
212
313
A Big integer (signed version: BigInt, unsigned version: BigUint).

src/libstd/flatpipes.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
111
/*!
212
313
Generic communication channels for things that can be represented as,

src/libstd/priority_queue.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
110

211
//! A priority queue implemented with a binary heap
312

src/rt/arch/arm/context.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// xfail-license
12

23
#include "context.h"
34
#include "../../rust_globals.h"

src/rt/arch/arm/context.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// -*- mode: c++ -*-
2+
// xfail-license
23

34
#ifndef CONTEXT_H
45
#define CONTEXT_H

src/rt/arch/arm/gpr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// xfail-license
2+
13
#include "gpr.h"
24

35
#define LOAD(rn) do { \

src/rt/arch/arm/gpr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// xfail-license
12
// General-purpose registers. This structure is used during stack crawling.
23

34
#ifndef GPR_H

src/rt/arch/arm/regs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// xfail-license
2+
13
#define RUSTRT_RBX 0
24
#define RUSTRT_RSP 1
35
#define RUSTRT_RBP 2

src/rt/arch/i386/context.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// -*- mode: c++ -*-
21
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
32
// file at the top-level directory of this distribution and at
43
// http://rust-lang.org/COPYRIGHT.

src/rt/arch/x86_64/context.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// -*- mode: c++ -*-
21
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
32
// file at the top-level directory of this distribution and at
43
// http://rust-lang.org/COPYRIGHT.

src/rt/rust_kernel.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// -*- c++ -*-
21
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
32
// file at the top-level directory of this distribution and at
43
// http://rust-lang.org/COPYRIGHT.

src/rt/rust_log.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// -*- c++ -*-
21
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
32
// file at the top-level directory of this distribution and at
43
// http://rust-lang.org/COPYRIGHT.

src/rt/sync/lock_and_signal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// -*- c++ -*-
21
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
32
// file at the top-level directory of this distribution and at
43
// http://rust-lang.org/COPYRIGHT.

src/rt/sync/sync.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// -*- c++ -*-
21
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
32
// file at the top-level directory of this distribution and at
43
// http://rust-lang.org/COPYRIGHT.

src/rt/util/array_list.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// -*- c++ -*-
21
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
32
// file at the top-level directory of this distribution and at
43
// http://rust-lang.org/COPYRIGHT.

src/rt/util/hash_map.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// -*- c++ -*-
21
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
32
// file at the top-level directory of this distribution and at
43
// http://rust-lang.org/COPYRIGHT.

src/rt/util/indexed_list.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// -*- c++ -*-
21
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
32
// file at the top-level directory of this distribution and at
43
// http://rust-lang.org/COPYRIGHT.

0 commit comments

Comments
 (0)