Skip to content

Commit 5246a6d

Browse files
author
Yoshiki Takashima
authored
Changed copyright check to the new standard from PR 1422. (rust-lang#1447)
* Changed copyright check to the new standard PR 1422. * Fixed debug print. * Added doc comment. * Changed to proper doc-comment * reverted test cases * Changed generator test cases to new format. * Added check that above our license is empty or comments * Fixed merge fail * Escaped backslash. * Allowed empty 2nd line pattern discussed in rust-lang#1422 * Test case for maybe empty lines above. * Changed from list to generator.
1 parent 27e037b commit 5246a6d

21 files changed

+80
-65
lines changed

scripts/ci/copyright_check.py

+19-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
import sys
66
import os.path as path
77
from enum import Enum
8+
from itertools import chain
9+
10+
11+
COMMENT_OR_EMPTY_PATTERN = '^(//.*$|#.*$|\\s*$)'
812

913
STANDARD_HEADER_PATTERN_1 = '(//|#) Copyright Kani Contributors'
1014
STANDARD_HEADER_PATTERN_2 = '(//|#) SPDX-License-Identifier: Apache-2.0 OR MIT'
1115

1216
MODIFIED_HEADER_PATTERN_1 = '(//|#) SPDX-License-Identifier: Apache-2.0 OR MIT'
13-
MODIFIED_HEADER_PATTERN_2 = '(//|#)'
17+
MODIFIED_HEADER_PATTERN_2 = COMMENT_OR_EMPTY_PATTERN
1418
MODIFIED_HEADER_PATTERN_3 = '(//|#) Modifications Copyright Kani Contributors'
1519
MODIFIED_HEADER_PATTERN_4 = '(//|#) See GitHub history for details.'
1620

@@ -28,6 +32,19 @@ def get_header(has_shebang, regexes):
2832
indices = range(init_idx, init_idx + len(regexes))
2933
return zip(regexes, indices)
3034

35+
def match_somewhere(regexes, lines, empty_or_comment_regex):
36+
""" Matches all MODIFIED_HEADER patterns within the file. This is used
37+
when the license is not at the top header, and there are licenses of
38+
external libraries. """
39+
maybe_match_head_index = [index for index, line in enumerate(lines) if regexes[0].search(line)][:1]
40+
if maybe_match_head_index and maybe_match_head_index[0] + len(regexes) <= len(lines):
41+
match_head_index = maybe_match_head_index[0]
42+
matches_pre_license = (empty_or_comment_regex.search(lines[index]) for index in range(match_head_index))
43+
matches_license = (regex.search(lines[match_head_index + index]) for index, regex in enumerate(regexes))
44+
return all(chain(matches_license, matches_pre_license))
45+
else:
46+
return False
47+
3148
def result_into_bool(result):
3249
if result == CheckResult.FAIL:
3350
return False
@@ -81,9 +98,7 @@ def copyright_check(filename):
8198
regexes.append(re.compile(MODIFIED_HEADER_PATTERN_3))
8299
regexes.append(re.compile(MODIFIED_HEADER_PATTERN_4))
83100

84-
header = get_header(has_shebang, regexes)
85-
86-
if matches_header_lines(header, lines):
101+
if match_somewhere(regexes, lines, re.compile(COMMENT_OR_EMPTY_PATTERN)):
87102
return CheckResult.PASS_MODIFIED
88103

89104
# We fail if there were no matches

tests/kani/Generator/rustc-generator-tests/conditional-drop.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
// Copyright rustc Contributors
2+
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/conditional-drop.rs
3+
14
// SPDX-License-Identifier: Apache-2.0 OR MIT
2-
//
5+
36
// Modifications Copyright Kani Contributors
47
// See GitHub history for details.
58

6-
// Copyright rustc Contributors
7-
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/conditional-drop.rs
8-
99
// run-pass
1010

1111
// revisions: default nomiropt

tests/kani/Generator/rustc-generator-tests/control-flow.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
// Copyright rustc Contributors
2+
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/control-flow.rs
3+
//
14
// SPDX-License-Identifier: Apache-2.0 OR MIT
25
//
36
// Modifications Copyright Kani Contributors
47
// See GitHub history for details.
58

6-
// Copyright rustc Contributors
7-
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/control-flow.rs
8-
99
// run-pass
1010

1111
// revisions: default nomiropt

tests/kani/Generator/rustc-generator-tests/discriminant_fixme.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
// Copyright rustc Contributors
2+
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/discriminant.rs
3+
//
14
// SPDX-License-Identifier: Apache-2.0 OR MIT
25
//
36
// Modifications Copyright Kani Contributors
47
// See GitHub history for details.
58

6-
// Copyright rustc Contributors
7-
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/discriminant.rs
8-
99
// This test creates some large generators with around 256 variants, some of them need a u16 discriminant instead of u8.
1010
// This test ensures that we use the right discriminant type.
1111

tests/kani/Generator/rustc-generator-tests/env-drop.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
// Copyright rustc Contributors
2+
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/env-drop.rs
3+
//
14
// SPDX-License-Identifier: Apache-2.0 OR MIT
25
//
36
// Modifications Copyright Kani Contributors
47
// See GitHub history for details.
58

6-
// Copyright rustc Contributors
7-
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/env-drop.rs
8-
99
// run-pass
1010

1111
// revisions: default nomiropt

tests/kani/Generator/rustc-generator-tests/iterator-count.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
// Copyright rustc Contributors
2+
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/iterator-count.rs
3+
//
14
// SPDX-License-Identifier: Apache-2.0 OR MIT
25
//
36
// Modifications Copyright Kani Contributors
47
// See GitHub history for details.
58

6-
// Copyright rustc Contributors
7-
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/iterator-count.rs
8-
99
// run-pass
1010

1111
#![feature(generators, generator_trait)]

tests/kani/Generator/rustc-generator-tests/live-upvar-across-yield.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
// Copyright rustc Contributors
2+
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/live-upvar-across-yield.rs
3+
//
14
// SPDX-License-Identifier: Apache-2.0 OR MIT
25
//
36
// Modifications Copyright Kani Contributors
47
// See GitHub history for details.
58

6-
// Copyright rustc Contributors
7-
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/live-upvar-across-yield.rs
8-
99
// run-pass
1010

1111
#![feature(generators, generator_trait)]

tests/kani/Generator/rustc-generator-tests/nested-generators.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
// Copyright rustc Contributors
2+
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/nested-generators.rs
3+
//
14
// SPDX-License-Identifier: Apache-2.0 OR MIT
25
//
36
// Modifications Copyright Kani Contributors
47
// See GitHub history for details.
58

6-
// Copyright rustc Contributors
7-
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/nested-generators.rs
8-
99
// run-pass
1010

1111
#![feature(generators, generator_trait)]

tests/kani/Generator/rustc-generator-tests/niche-in-generator.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
// Copyright rustc Contributors
2+
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/niche-in-generator.rs
3+
//
14
// SPDX-License-Identifier: Apache-2.0 OR MIT
25
//
36
// Modifications Copyright Kani Contributors
47
// See GitHub history for details.
58

6-
// Copyright rustc Contributors
7-
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/niche-in-generator.rs
8-
99
// Test that niche finding works with captured generator upvars.
1010

1111
// run-pass

tests/kani/Generator/rustc-generator-tests/niche-in-generator_fixme.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
// Copyright rustc Contributors
2+
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/niche-in-generator.rs
3+
//
14
// SPDX-License-Identifier: Apache-2.0 OR MIT
25
//
36
// Modifications Copyright Kani Contributors
47
// See GitHub history for details.
58

6-
// Copyright rustc Contributors
7-
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/niche-in-generator.rs
8-
99
// Test that niche finding works with captured generator upvars.
1010

1111
// run-pass

tests/kani/Generator/rustc-generator-tests/overlap-locals.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
// Copyright rustc Contributors
2+
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/overlap-locals.rs
3+
//
14
// SPDX-License-Identifier: Apache-2.0 OR MIT
25
//
36
// Modifications Copyright Kani Contributors
47
// See GitHub history for details.
58

6-
// Copyright rustc Contributors
7-
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/overlap-locals.rs
8-
99
// run-pass
1010

1111
#![feature(generators, generator_trait)]

tests/kani/Generator/rustc-generator-tests/overlap-locals_fixme.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
// Copyright rustc Contributors
2+
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/overlap-locals.rs
3+
//
14
// SPDX-License-Identifier: Apache-2.0 OR MIT
25
//
36
// Modifications Copyright Kani Contributors
47
// See GitHub history for details.
58

6-
// Copyright rustc Contributors
7-
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/overlap-locals.rs
8-
99
// run-pass
1010

1111
#![feature(generators)]

tests/kani/Generator/rustc-generator-tests/resume-arg-size_fixme.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
// Copyright rustc Contributors
2+
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/resume-arg-size.rs
3+
//
14
// SPDX-License-Identifier: Apache-2.0 OR MIT
25
//
36
// Modifications Copyright Kani Contributors
47
// See GitHub history for details.
58

6-
// Copyright rustc Contributors
7-
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/resume-arg-size.rs
8-
99
#![feature(generators)]
1010

1111
// run-pass

tests/kani/Generator/rustc-generator-tests/resume-arg.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
// Copyright rustc Contributors
2+
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/resume-arg-size.rs
3+
//
14
// SPDX-License-Identifier: Apache-2.0 OR MIT
25
//
36
// Modifications Copyright Kani Contributors
47
// See GitHub history for details.
58

6-
// Copyright rustc Contributors
7-
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/resume-arg-size.rs
8-
99
#![feature(generators, generator_trait)]
1010

1111
use std::ops::{Generator, GeneratorState};

tests/kani/Generator/rustc-generator-tests/resume-live-across-yield.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
// Copyright rustc Contributors
2+
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/resume-live-across-yield.rs
3+
//
14
// SPDX-License-Identifier: Apache-2.0 OR MIT
25
//
36
// Modifications Copyright Kani Contributors
47
// See GitHub history for details.
58

6-
// Copyright rustc Contributors
7-
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/resume-live-across-yield.rs
8-
99
// run-pass
1010

1111
#![feature(generators, generator_trait)]

tests/kani/Generator/rustc-generator-tests/size-moved-locals.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
// Copyright rustc Contributors
2+
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/size-moved-locals.rs
3+
//
14
// SPDX-License-Identifier: Apache-2.0 OR MIT
25
//
36
// Modifications Copyright Kani Contributors
47
// See GitHub history for details.
58

6-
// Copyright rustc Contributors
7-
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/size-moved-locals.rs
8-
99
// run-pass
1010
// Test that we don't duplicate storage for a variable that is moved to another
1111
// binding. This used to happen in the presence of unwind and drop edges (see

tests/kani/Generator/rustc-generator-tests/size-moved-locals_fixme.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
// Copyright rustc Contributors
2+
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/size-moved-locals.rs
3+
//
14
// SPDX-License-Identifier: Apache-2.0 OR MIT
25
//
36
// Modifications Copyright Kani Contributors
47
// See GitHub history for details.
58

6-
// Copyright rustc Contributors
7-
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/size-moved-locals.rs
8-
99
// run-pass
1010
// Test that we don't duplicate storage for a variable that is moved to another
1111
// binding. This used to happen in the presence of unwind and drop edges (see

tests/kani/Generator/rustc-generator-tests/smoke-resume-args.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
// Copyright rustc Contributors
2+
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/smoke-resume-args.rs
3+
//
14
// SPDX-License-Identifier: Apache-2.0 OR MIT
25
//
36
// Modifications Copyright Kani Contributors
47
// See GitHub history for details.
58

6-
// Copyright rustc Contributors
7-
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/smoke-resume-args.rs
8-
99
// run-pass
1010

1111
// revisions: default nomiropt

tests/kani/Generator/rustc-generator-tests/smoke.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
// Copyright rustc Contributors
2+
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/smoke.rs
3+
//
14
// SPDX-License-Identifier: Apache-2.0 OR MIT
25
//
36
// Modifications Copyright Kani Contributors
47
// See GitHub history for details.
58

6-
// Copyright rustc Contributors
7-
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/smoke.rs
8-
99
// run-pass
1010

1111
// revisions: default nomiropt

tests/kani/Generator/rustc-generator-tests/static-generator.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
// Copyright rustc Contributors
2+
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/static-generator.rs
3+
//
14
// SPDX-License-Identifier: Apache-2.0 OR MIT
25
//
36
// Modifications Copyright Kani Contributors
47
// See GitHub history for details.
58

6-
// Copyright rustc Contributors
7-
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/static-generator.rs
8-
99
// run-pass
1010

1111
#![feature(generators, generator_trait)]

tests/kani/Generator/rustc-generator-tests/yield-in-box.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
// Copyright rustc Contributors
2+
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/yield-in-box.rs
3+
14
// SPDX-License-Identifier: Apache-2.0 OR MIT
25
//
36
// Modifications Copyright Kani Contributors
47
// See GitHub history for details.
58

6-
// Copyright rustc Contributors
7-
// Adapted from rustc: https://github.com/rust-lang/rust/tree/5f98537eb7b5f42c246a52c550813c3cff336069/src/test/ui/generator/yield-in-box.rs
8-
99
// run-pass
1010
// Test that box-statements with yields in them work.
1111

0 commit comments

Comments
 (0)