Skip to content

Commit 3aaa0f5

Browse files
committedNov 4, 2023
Auto merge of #115274 - bjorn3:tidy_improvements, r=davidtwco
Run tidy license checker on more workspaces The license checker didn't run on several workspaces before this PR. The same applied to the "external package sources" check. There were also two missing lockfiles which I have added now.
·
1.90.01.75.0
2 parents f1b104f + af85d31 commit 3aaa0f5

File tree

5 files changed

+275
-82
lines changed

5 files changed

+275
-82
lines changed
 
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# This file is automatically @generated by Cargo.
2+
# It is not intended for manual editing.
3+
version = 3
4+
5+
[[package]]
6+
name = "r-efi"
7+
version = "4.2.0"
8+
source = "registry+https://github.com/rust-lang/crates.io-index"
9+
checksum = "575fc2d9b3da54adbdfaddf6eca48fec256d977c8630a1750b8991347d1ac911"
10+
11+
[[package]]
12+
name = "uefi_qemu_test"
13+
version = "0.0.0"
14+
dependencies = [
15+
"r-efi",
16+
]
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# This file is automatically @generated by Cargo.
2+
# It is not intended for manual editing.
3+
version = 3
4+
5+
[[package]]
6+
name = "cfg-if"
7+
version = "1.0.0"
8+
source = "registry+https://github.com/rust-lang/crates.io-index"
9+
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
10+
11+
[[package]]
12+
name = "getrandom"
13+
version = "0.2.10"
14+
source = "registry+https://github.com/rust-lang/crates.io-index"
15+
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
16+
dependencies = [
17+
"cfg-if",
18+
"libc",
19+
"wasi",
20+
]
21+
22+
[[package]]
23+
name = "libc"
24+
version = "0.2.147"
25+
source = "registry+https://github.com/rust-lang/crates.io-index"
26+
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
27+
28+
[[package]]
29+
name = "ppv-lite86"
30+
version = "0.2.17"
31+
source = "registry+https://github.com/rust-lang/crates.io-index"
32+
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
33+
34+
[[package]]
35+
name = "rand"
36+
version = "0.8.5"
37+
source = "registry+https://github.com/rust-lang/crates.io-index"
38+
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
39+
dependencies = [
40+
"libc",
41+
"rand_chacha",
42+
"rand_core",
43+
]
44+
45+
[[package]]
46+
name = "rand_chacha"
47+
version = "0.3.1"
48+
source = "registry+https://github.com/rust-lang/crates.io-index"
49+
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
50+
dependencies = [
51+
"ppv-lite86",
52+
"rand_core",
53+
]
54+
55+
[[package]]
56+
name = "rand_core"
57+
version = "0.6.4"
58+
source = "registry+https://github.com/rust-lang/crates.io-index"
59+
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
60+
dependencies = [
61+
"getrandom",
62+
]
63+
64+
[[package]]
65+
name = "test-float-parse"
66+
version = "0.1.0"
67+
dependencies = [
68+
"rand",
69+
]
70+
71+
[[package]]
72+
name = "wasi"
73+
version = "0.11.0+wasi-snapshot-preview1"
74+
source = "registry+https://github.com/rust-lang/crates.io-index"
75+
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"

‎src/etc/test-float-parse/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ publish = false
88
resolver = "1"
99

1010
[dependencies]
11-
rand = "0.4"
11+
rand = "0.8"
1212

1313
[lib]
1414
name = "test_float_parse"

‎src/tools/tidy/src/deps.rs‎

Lines changed: 161 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,49 @@ const LICENSES: &[&str] = &[
3131
// tidy-alphabetical-end
3232
];
3333

34+
type ExceptionList = &'static [(&'static str, &'static str)];
35+
36+
/// The workspaces to check for licensing and optionally permitted dependencies.
37+
///
38+
/// Each entry consists of a tuple with the following elements:
39+
///
40+
/// * The path to the workspace root Cargo.toml file.
41+
/// * The list of license exceptions.
42+
/// * Optionally a tuple of:
43+
/// * A list of crates for which dependencies need to be explicitly allowed.
44+
/// * The list of allowed dependencies.
45+
// FIXME auto detect all cargo workspaces
46+
pub(crate) const WORKSPACES: &[(&str, ExceptionList, Option<(&[&str], &[&str])>)] = &[
47+
// The root workspace has to be first for check_rustfix to work.
48+
(".", EXCEPTIONS, Some((&["rustc-main"], PERMITTED_RUSTC_DEPENDENCIES))),
49+
// Outside of the alphabetical section because rustfmt formats it using multiple lines.
50+
(
51+
"compiler/rustc_codegen_cranelift",
52+
EXCEPTIONS_CRANELIFT,
53+
Some((&["rustc_codegen_cranelift"], PERMITTED_CRANELIFT_DEPENDENCIES)),
54+
),
55+
// tidy-alphabetical-start
56+
//("compiler/rustc_codegen_gcc", EXCEPTIONS_GCC, None), // FIXME uncomment once all deps are vendored
57+
//("library/backtrace", &[], None), // FIXME uncomment once rust-lang/backtrace#562 has been synced back to the rust repo
58+
//("library/portable-simd", &[], None), // FIXME uncomment once rust-lang/portable-simd#363 has been synced back to the rust repo
59+
//("library/stdarch", EXCEPTIONS_STDARCH, None), // FIXME uncomment once rust-lang/stdarch#1462 has been synced back to the rust repo
60+
("src/bootstrap", EXCEPTIONS_BOOTSTRAP, None),
61+
("src/ci/docker/host-x86_64/test-various/uefi_qemu_test", EXCEPTIONS_UEFI_QEMU_TEST, None),
62+
//("src/etc/test-float-parse", &[], None), // FIXME uncomment once all deps are vendored
63+
("src/tools/cargo", EXCEPTIONS_CARGO, None),
64+
//("src/tools/miri/test-cargo-miri", &[], None), // FIXME uncomment once all deps are vendored
65+
//("src/tools/miri/test_dependencies", &[], None), // FIXME uncomment once all deps are vendored
66+
("src/tools/rust-analyzer", EXCEPTIONS_RUST_ANALYZER, None),
67+
("src/tools/x", &[], None),
68+
// tidy-alphabetical-end
69+
];
70+
3471
/// These are exceptions to Rust's permissive licensing policy, and
3572
/// should be considered bugs. Exceptions are only allowed in Rust
3673
/// tooling. It is _crucial_ that no exception crates be dependencies
3774
/// of the Rust runtime (std/test).
3875
#[rustfmt::skip]
39-
const EXCEPTIONS: &[(&str, &str)] = &[
76+
const EXCEPTIONS: ExceptionList = &[
4077
// tidy-alphabetical-start
4178
("ar_archive_writer", "Apache-2.0 WITH LLVM-exception"), // rustc
4279
("colored", "MPL-2.0"), // rustfmt
@@ -49,13 +86,24 @@ const EXCEPTIONS: &[(&str, &str)] = &[
4986
("openssl", "Apache-2.0"), // opt-dist
5087
("option-ext", "MPL-2.0"), // cargo-miri (via `directories`)
5188
("rustc_apfloat", "Apache-2.0 WITH LLVM-exception"), // rustc (license is the same as LLVM uses)
52-
("ryu", "Apache-2.0 OR BSL-1.0"), // cargo/... (because of serde)
89+
("ryu", "Apache-2.0 OR BSL-1.0"), // BSL is not acceptble, but we use it under Apache-2.0 // cargo/... (because of serde)
5390
("self_cell", "Apache-2.0"), // rustc (fluent translations)
5491
("snap", "BSD-3-Clause"), // rustc
5592
// tidy-alphabetical-end
5693
];
5794

58-
const EXCEPTIONS_CARGO: &[(&str, &str)] = &[
95+
// FIXME uncomment once rust-lang/stdarch#1462 lands
96+
/*
97+
const EXCEPTIONS_STDARCH: ExceptionList = &[
98+
// tidy-alphabetical-start
99+
("ryu", "Apache-2.0 OR BSL-1.0"), // BSL is not acceptble, but we use it under Apache-2.0
100+
("wasmparser", "Apache-2.0 WITH LLVM-exception"),
101+
("wasmprinter", "Apache-2.0 WITH LLVM-exception"),
102+
// tidy-alphabetical-end
103+
];
104+
*/
105+
106+
const EXCEPTIONS_CARGO: ExceptionList = &[
59107
// tidy-alphabetical-start
60108
("bitmaps", "MPL-2.0+"),
61109
("bytesize", "Apache-2.0"),
@@ -69,7 +117,7 @@ const EXCEPTIONS_CARGO: &[(&str, &str)] = &[
69117
("im-rc", "MPL-2.0+"),
70118
("normalize-line-endings", "Apache-2.0"),
71119
("openssl", "Apache-2.0"),
72-
("ryu", "Apache-2.0 OR BSL-1.0"),
120+
("ryu", "Apache-2.0 OR BSL-1.0"), // BSL is not acceptble, but we use it under Apache-2.0
73121
("sha1_smol", "BSD-3-Clause"),
74122
("similar", "Apache-2.0"),
75123
("sized-chunks", "MPL-2.0+"),
@@ -78,7 +126,20 @@ const EXCEPTIONS_CARGO: &[(&str, &str)] = &[
78126
// tidy-alphabetical-end
79127
];
80128

81-
const EXCEPTIONS_CRANELIFT: &[(&str, &str)] = &[
129+
const EXCEPTIONS_RUST_ANALYZER: ExceptionList = &[
130+
// tidy-alphabetical-start
131+
("anymap", "BlueOak-1.0.0 OR MIT OR Apache-2.0"), // BlueOak is not acceptable, but we use it under MIT OR Apache-2 .0
132+
("dissimilar", "Apache-2.0"),
133+
("instant", "BSD-3-Clause"),
134+
("notify", "CC0-1.0"),
135+
("pulldown-cmark-to-cmark", "Apache-2.0"),
136+
("ryu", "Apache-2.0 OR BSL-1.0"), // BSL is not acceptble, but we use it under Apache-2.0
137+
("scip", "Apache-2.0"),
138+
("snap", "BSD-3-Clause"),
139+
// tidy-alphabetical-end
140+
];
141+
142+
const EXCEPTIONS_CRANELIFT: ExceptionList = &[
82143
// tidy-alphabetical-start
83144
("cranelift-bforest", "Apache-2.0 WITH LLVM-exception"),
84145
("cranelift-codegen", "Apache-2.0 WITH LLVM-exception"),
@@ -99,8 +160,22 @@ const EXCEPTIONS_CRANELIFT: &[(&str, &str)] = &[
99160
// tidy-alphabetical-end
100161
];
101162

102-
const EXCEPTIONS_BOOTSTRAP: &[(&str, &str)] = &[
103-
("ryu", "Apache-2.0 OR BSL-1.0"), // through serde
163+
// FIXME uncomment once all deps are vendored
164+
/*
165+
const EXCEPTIONS_GCC: ExceptionList = &[
166+
// tidy-alphabetical-start
167+
("gccjit", "GPL-3.0"),
168+
("gccjit_sys", "GPL-3.0"),
169+
// tidy-alphabetical-end
170+
];
171+
*/
172+
173+
const EXCEPTIONS_BOOTSTRAP: ExceptionList = &[
174+
("ryu", "Apache-2.0 OR BSL-1.0"), // through serde. BSL is not acceptble, but we use it under Apache-2.0
175+
];
176+
177+
const EXCEPTIONS_UEFI_QEMU_TEST: ExceptionList = &[
178+
("r-efi", "MIT OR Apache-2.0 OR LGPL-2.1-or-later"), // LGPL is not acceptible, but we use it under MIT OR Apache-2.0
104179
];
105180

106181
/// These are the root crates that are part of the runtime. The licenses for
@@ -185,6 +260,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
185260
"is-terminal",
186261
"itertools",
187262
"itoa",
263+
"jemalloc-sys",
188264
"jobserver",
189265
"lazy_static",
190266
"libc",
@@ -383,65 +459,90 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[
383459
/// `root` is path to the directory with the root `Cargo.toml` (for the workspace). `cargo` is path
384460
/// to the cargo executable.
385461
pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
386-
let mut cmd = cargo_metadata::MetadataCommand::new();
387-
cmd.cargo_path(cargo)
388-
.manifest_path(root.join("Cargo.toml"))
389-
.features(cargo_metadata::CargoOpt::AllFeatures);
390-
let metadata = t!(cmd.exec());
391-
let runtime_ids = compute_runtime_crates(&metadata);
392-
check_license_exceptions(&metadata, EXCEPTIONS, runtime_ids, bad);
393-
check_permitted_dependencies(
394-
&metadata,
395-
"rustc",
396-
PERMITTED_RUSTC_DEPENDENCIES,
397-
&["rustc_driver", "rustc_codegen_llvm"],
398-
bad,
399-
);
400-
401-
// Check cargo independently as it has it's own workspace.
402-
let mut cmd = cargo_metadata::MetadataCommand::new();
403-
cmd.cargo_path(cargo)
404-
.manifest_path(root.join("src/tools/cargo/Cargo.toml"))
405-
.features(cargo_metadata::CargoOpt::AllFeatures);
406-
let cargo_metadata = t!(cmd.exec());
407-
let runtime_ids = HashSet::new();
408-
check_license_exceptions(&cargo_metadata, EXCEPTIONS_CARGO, runtime_ids, bad);
409-
check_rustfix(&metadata, &cargo_metadata, bad);
410-
411-
// Check rustc_codegen_cranelift independently as it has it's own workspace.
412-
let mut cmd = cargo_metadata::MetadataCommand::new();
413-
cmd.cargo_path(cargo)
414-
.manifest_path(root.join("compiler/rustc_codegen_cranelift/Cargo.toml"))
415-
.features(cargo_metadata::CargoOpt::AllFeatures);
416-
let metadata = t!(cmd.exec());
417-
let runtime_ids = HashSet::new();
418-
check_license_exceptions(&metadata, EXCEPTIONS_CRANELIFT, runtime_ids, bad);
419-
check_permitted_dependencies(
420-
&metadata,
421-
"cranelift",
422-
PERMITTED_CRANELIFT_DEPENDENCIES,
423-
&["rustc_codegen_cranelift"],
424-
bad,
425-
);
426-
427-
let mut cmd = cargo_metadata::MetadataCommand::new();
428-
cmd.cargo_path(cargo)
429-
.manifest_path(root.join("src/bootstrap/Cargo.toml"))
430-
.features(cargo_metadata::CargoOpt::AllFeatures);
431-
let metadata = t!(cmd.exec());
432-
let runtime_ids = HashSet::new();
433-
check_license_exceptions(&metadata, EXCEPTIONS_BOOTSTRAP, runtime_ids, bad);
462+
let mut checked_runtime_licenses = false;
463+
let mut rust_metadata = None;
464+
465+
for &(workspace, exceptions, permitted_deps) in WORKSPACES {
466+
if !root.join(workspace).join("Cargo.lock").exists() {
467+
tidy_error!(bad, "the `{workspace}` workspace doesn't have a Cargo.lock");
468+
continue;
469+
}
470+
471+
let mut cmd = cargo_metadata::MetadataCommand::new();
472+
cmd.cargo_path(cargo)
473+
.manifest_path(root.join(workspace).join("Cargo.toml"))
474+
.features(cargo_metadata::CargoOpt::AllFeatures)
475+
.other_options(vec!["--locked".to_owned()]);
476+
let metadata = t!(cmd.exec());
477+
478+
check_license_exceptions(&metadata, exceptions, bad);
479+
if let Some((crates, permitted_deps)) = permitted_deps {
480+
check_permitted_dependencies(&metadata, workspace, permitted_deps, crates, bad);
481+
}
482+
483+
if workspace == "." {
484+
let runtime_ids = compute_runtime_crates(&metadata);
485+
check_runtime_license_exceptions(&metadata, runtime_ids, bad);
486+
checked_runtime_licenses = true;
487+
rust_metadata = Some(metadata);
488+
} else if workspace == "src/tools/cargo" {
489+
check_rustfix(
490+
rust_metadata
491+
.as_ref()
492+
.expect("The root workspace should be the first to be checked"),
493+
&metadata,
494+
bad,
495+
);
496+
}
497+
}
498+
499+
// Sanity check to ensure we don't accidentally remove the workspace containing the runtime
500+
// crates.
501+
assert!(checked_runtime_licenses);
434502
}
435503

436-
/// Check that all licenses are in the valid list in `LICENSES`.
504+
/// Check that all licenses of runtime dependencies are in the valid list in `LICENSES`.
437505
///
438-
/// Packages listed in `exceptions` are allowed for tools.
439-
fn check_license_exceptions(
506+
/// Unlike for tools we don't allow exceptions to the `LICENSES` list for the runtime with the sole
507+
/// exception of `fortanix-sgx-abi` which is only used on x86_64-fortanix-unknown-sgx.
508+
fn check_runtime_license_exceptions(
440509
metadata: &Metadata,
441-
exceptions: &[(&str, &str)],
442510
runtime_ids: HashSet<&PackageId>,
443511
bad: &mut bool,
444512
) {
513+
for pkg in &metadata.packages {
514+
if !runtime_ids.contains(&pkg.id) {
515+
// Only checking dependencies of runtime libraries here.
516+
continue;
517+
}
518+
if pkg.source.is_none() {
519+
// No need to check local packages.
520+
continue;
521+
}
522+
let license = match &pkg.license {
523+
Some(license) => license,
524+
None => {
525+
tidy_error!(bad, "dependency `{}` does not define a license expression", pkg.id);
526+
continue;
527+
}
528+
};
529+
if !LICENSES.contains(&license.as_str()) {
530+
// This is a specific exception because SGX is considered "third party".
531+
// See https://github.com/rust-lang/rust/issues/62620 for more.
532+
// In general, these should never be added and this exception
533+
// should not be taken as precedent for any new target.
534+
if pkg.name == "fortanix-sgx-abi" && pkg.license.as_deref() == Some("MPL-2.0") {
535+
continue;
536+
}
537+
tidy_error!(bad, "invalid license `{}` in `{}`", license, pkg.id);
538+
}
539+
}
540+
}
541+
542+
/// Check that all licenses of tool dependencies are in the valid list in `LICENSES`.
543+
///
544+
/// Packages listed in `exceptions` are allowed for tools.
545+
fn check_license_exceptions(metadata: &Metadata, exceptions: &[(&str, &str)], bad: &mut bool) {
445546
// Validate the EXCEPTIONS list hasn't changed.
446547
for (name, license) in exceptions {
447548
// Check that the package actually exists.
@@ -483,7 +584,7 @@ fn check_license_exceptions(
483584
// No need to check local packages.
484585
continue;
485586
}
486-
if !runtime_ids.contains(&pkg.id) && exception_names.contains(&pkg.name.as_str()) {
587+
if exception_names.contains(&pkg.name.as_str()) {
487588
continue;
488589
}
489590
let license = match &pkg.license {
@@ -494,13 +595,6 @@ fn check_license_exceptions(
494595
}
495596
};
496597
if !LICENSES.contains(&license.as_str()) {
497-
if pkg.name == "fortanix-sgx-abi" {
498-
// This is a specific exception because SGX is considered
499-
// "third party". See
500-
// https://github.com/rust-lang/rust/issues/62620 for more. In
501-
// general, these should never be added.
502-
continue;
503-
}
504598
tidy_error!(bad, "invalid license `{}` in `{}`", license, pkg.id);
505599
}
506600
}

‎src/tools/tidy/src/extdeps.rs‎

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,33 @@ const ALLOWED_SOURCES: &[&str] = &["\"registry+https://github.com/rust-lang/crat
99
/// Checks for external package sources. `root` is the path to the directory that contains the
1010
/// workspace `Cargo.toml`.
1111
pub fn check(root: &Path, bad: &mut bool) {
12-
// `Cargo.lock` of rust.
13-
let path = root.join("Cargo.lock");
12+
for &(workspace, _, _) in crate::deps::WORKSPACES {
13+
// FIXME check other workspaces too
14+
// `Cargo.lock` of rust.
15+
let path = root.join(workspace).join("Cargo.lock");
1416

15-
// Open and read the whole file.
16-
let cargo_lock = t!(fs::read_to_string(&path));
17-
18-
// Process each line.
19-
for line in cargo_lock.lines() {
20-
// Consider only source entries.
21-
if !line.starts_with("source = ") {
17+
if !path.exists() {
18+
tidy_error!(bad, "the `{workspace}` workspace doesn't have a Cargo.lock");
2219
continue;
2320
}
2421

25-
// Extract source value.
26-
let source = line.split_once('=').unwrap().1.trim();
22+
// Open and read the whole file.
23+
let cargo_lock = t!(fs::read_to_string(&path));
24+
25+
// Process each line.
26+
for line in cargo_lock.lines() {
27+
// Consider only source entries.
28+
if !line.starts_with("source = ") {
29+
continue;
30+
}
31+
32+
// Extract source value.
33+
let source = line.split_once('=').unwrap().1.trim();
2734

28-
// Ensure source is allowed.
29-
if !ALLOWED_SOURCES.contains(&&*source) {
30-
tidy_error!(bad, "invalid source: {}", source);
35+
// Ensure source is allowed.
36+
if !ALLOWED_SOURCES.contains(&&*source) {
37+
tidy_error!(bad, "invalid source: {}", source);
38+
}
3139
}
3240
}
3341
}

0 commit comments

Comments
 (0)
Please sign in to comment.