|
8 | 8 | # option. This file may not be copied, modified, or distributed
|
9 | 9 | # except according to those terms.
|
10 | 10 |
|
11 |
| -license1 = """// Copyright """ |
12 |
| -license2 = """ The Rust Project Developers. See the COPYRIGHT |
13 |
| -// file at the top-level directory of this distribution and at |
14 |
| -// http://rust-lang.org/COPYRIGHT. |
15 |
| -// |
16 |
| -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
17 |
| -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
18 |
| -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
19 |
| -// option. This file may not be copied, modified, or distributed |
20 |
| -// except according to those terms. |
21 |
| -""" |
| 11 | +import re |
22 | 12 |
|
23 |
| -license3 = """# Copyright """ |
24 |
| -license4 = """ The Rust Project Developers. See the COPYRIGHT |
25 |
| -# file at the top-level directory of this distribution and at |
26 |
| -# http://rust-lang.org/COPYRIGHT. |
27 |
| -# |
28 |
| -# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
29 |
| -# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
30 |
| -# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
31 |
| -# option. This file may not be copied, modified, or distributed |
32 |
| -# except according to those terms. |
33 |
| -""" |
| 13 | +license_re = re.compile( |
| 14 | +u"""(#|//) Copyright .* The Rust Project Developers. See the COPYRIGHT |
| 15 | +\\1 file at the top-level directory of this distribution and at |
| 16 | +\\1 http://rust-lang.org/COPYRIGHT. |
| 17 | +\\1 |
| 18 | +\\1 Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 19 | +\\1 http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 20 | +\\1 <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 21 | +\\1 option. This file may not be copied, modified, or distributed |
| 22 | +\\1 except according to those terms.""") |
34 | 23 |
|
35 | 24 | exceptions = [
|
36 | 25 | "rt/rust_android_dummy.cpp", # BSD, chromium
|
|
57 | 46 |
|
58 | 47 | def check_license(name, contents):
|
59 | 48 | # Whitelist check
|
60 |
| - for exception in exceptions: |
61 |
| - if name.endswith(exception): |
62 |
| - return True |
| 49 | + if any(name.endswith(e) for e in exceptions): |
| 50 | + return True |
63 | 51 |
|
64 | 52 | # Xfail check
|
65 | 53 | firstlineish = contents[:100]
|
66 |
| - if firstlineish.find("ignore-license") != -1: |
| 54 | + if "ignore-license" in firstlineish: |
67 | 55 | return True
|
68 | 56 |
|
69 | 57 | # License check
|
70 | 58 | boilerplate = contents[:500]
|
71 |
| - if (boilerplate.find(license1) == -1 or boilerplate.find(license2) == -1) and \ |
72 |
| - (boilerplate.find(license3) == -1 or boilerplate.find(license4) == -1): |
73 |
| - return False |
74 |
| - return True |
| 59 | + return bool(license_re.search(boilerplate)) |
0 commit comments