Skip to content

Commit 30488fb

Browse files
committed
Fix tidy
1 parent 3bef430 commit 30488fb

File tree

3 files changed

+70
-38
lines changed

3 files changed

+70
-38
lines changed

library/Cargo.lock

+2-9
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ dependencies = [
3232
"rand_xorshift",
3333
]
3434

35-
[[package]]
36-
name = "autocfg"
37-
version = "1.0.1"
38-
source = "registry+https://github.com/rust-lang/crates.io-index"
39-
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
40-
4135
[[package]]
4236
name = "cc"
4337
version = "1.0.59"
@@ -127,11 +121,10 @@ dependencies = [
127121

128122
[[package]]
129123
name = "hashbrown"
130-
version = "0.8.2"
124+
version = "0.9.0"
131125
source = "registry+https://github.com/rust-lang/crates.io-index"
132-
checksum = "e91b62f79061a0bc2e046024cb7ba44b08419ed238ecbd9adbd787434b9e8c25"
126+
checksum = "00d63df3d41950fb462ed38308eea019113ad1508da725bbedcd0fa5a85ef5f7"
133127
dependencies = [
134-
"autocfg",
135128
"compiler_builtins",
136129
"rustc-std-workspace-alloc",
137130
"rustc-std-workspace-core",

src/tools/tidy/src/deps.rs

+64-14
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ const EXCEPTIONS: &[(&str, &str)] = &[
4343
("arrayref", "BSD-2-Clause"), // cargo-miri/directories/.../rust-argon2 (redox)
4444
("instant", "BSD-3-Clause"), // rustc_driver/tracing-subscriber/parking_lot
4545
("snap", "BSD-3-Clause"), // rustc
46+
];
47+
48+
const RUNTIME_EXCEPTIONS: &[(&str, &str)] = &[
4649
// FIXME: this dependency violates the documentation comment above:
4750
("fortanix-sgx-abi", "MPL-2.0"), // libstd but only for `sgx` target
4851
];
@@ -79,7 +82,6 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
7982
"chalk-ir",
8083
"cloudabi",
8184
"cmake",
82-
"compiler_builtins",
8385
"crc32fast",
8486
"crossbeam-deque",
8587
"crossbeam-epoch",
@@ -88,15 +90,13 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
8890
"datafrog",
8991
"difference",
9092
"digest",
91-
"dlmalloc",
9293
"either",
9394
"ena",
9495
"env_logger",
9596
"expect-test",
9697
"fake-simd",
9798
"filetime",
9899
"flate2",
99-
"fortanix-sgx-abi",
100100
"fuchsia-zircon",
101101
"fuchsia-zircon-sys",
102102
"generic-array",
@@ -144,7 +144,6 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
144144
"rand_core",
145145
"rand_hc",
146146
"rand_pcg",
147-
"rand_xorshift",
148147
"redox_syscall",
149148
"regex",
150149
"regex-syntax",
@@ -190,6 +189,37 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
190189
"winapi-x86_64-pc-windows-gnu",
191190
];
192191

192+
/// Crates the runtime is allowed to depend on. Avoid adding to the list if possible.
193+
///
194+
/// This list is here to provide a speed-bump to adding a new dependency to
195+
/// the runtime. Please check with the compiler team before adding an entry.
196+
const PERMITTED_RUNTIME_DEPENDENCIES: &[&str] = &[
197+
"addr2line",
198+
"adler",
199+
"cc",
200+
"cfg-if",
201+
"compiler_builtins",
202+
"dlmalloc",
203+
"fortanix-sgx-abi",
204+
"getopts",
205+
"getrandom",
206+
"gimli",
207+
"hashbrown",
208+
"hermit-abi",
209+
"libc",
210+
"miniz_oxide",
211+
"object",
212+
"ppv-lite86",
213+
"rand",
214+
"rand_chacha",
215+
"rand_core",
216+
"rand_hc",
217+
"rand_xorshift",
218+
"rustc-demangle",
219+
"unicode-width",
220+
"wasi",
221+
];
222+
193223
/// Dependency checks.
194224
///
195225
/// `root` is path to the directory with the root `Cargo.toml` (for the workspace). `cargo` is path
@@ -200,17 +230,32 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
200230
.manifest_path(root.join("Cargo.toml"))
201231
.features(cargo_metadata::CargoOpt::AllFeatures);
202232
let metadata = t!(cmd.exec());
203-
check_exceptions(&metadata, bad);
204-
check_dependencies(&metadata, bad);
233+
check_exceptions(&metadata, EXCEPTIONS, false, bad);
234+
check_dependencies(&metadata, PERMITTED_DEPENDENCIES, RESTRICTED_DEPENDENCY_CRATES, bad);
205235
check_crate_duplicate(&metadata, bad);
236+
237+
let mut cmd = cargo_metadata::MetadataCommand::new();
238+
cmd.cargo_path(cargo)
239+
.manifest_path(root.join("library").join("Cargo.toml"))
240+
.features(cargo_metadata::CargoOpt::AllFeatures);
241+
let metadata = t!(cmd.exec());
242+
check_exceptions(&metadata, RUNTIME_EXCEPTIONS, true, bad);
243+
check_dependencies(&metadata, PERMITTED_RUNTIME_DEPENDENCIES, RUNTIME_CRATES, bad);
244+
// Not running `check_crate_duplicate`, as the crates that don't allow duplicates are not used
245+
// by the runtime.
206246
}
207247

208248
/// Check that all licenses are in the valid list in `LICENSES`.
209249
///
210250
/// Packages listed in `EXCEPTIONS` are allowed for tools.
211-
fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
251+
fn check_exceptions(
252+
metadata: &Metadata,
253+
exceptions: &[(&str, &str)],
254+
is_runtime: bool,
255+
bad: &mut bool,
256+
) {
212257
// Validate the EXCEPTIONS list hasn't changed.
213-
for (name, license) in EXCEPTIONS {
258+
for (name, license) in exceptions {
214259
// Check that the package actually exists.
215260
if !metadata.packages.iter().any(|p| p.name == *name) {
216261
println!(
@@ -257,8 +302,8 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
257302
}
258303
}
259304

260-
let exception_names: Vec<_> = EXCEPTIONS.iter().map(|(name, _license)| *name).collect();
261-
let runtime_ids = compute_runtime_crates(metadata);
305+
let exception_names: Vec<_> = exceptions.iter().map(|(name, _license)| *name).collect();
306+
let runtime_ids = if is_runtime { compute_runtime_crates(metadata) } else { HashSet::new() };
262307

263308
// Check if any package does not have a valid license.
264309
for pkg in &metadata.packages {
@@ -295,9 +340,14 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
295340
/// `true` if a check failed.
296341
///
297342
/// Specifically, this checks that the dependencies are on the `PERMITTED_DEPENDENCIES`.
298-
fn check_dependencies(metadata: &Metadata, bad: &mut bool) {
343+
fn check_dependencies(
344+
metadata: &Metadata,
345+
permitted: &[&'static str],
346+
restricted_dependency_crates: &[&'static str],
347+
bad: &mut bool,
348+
) {
299349
// Check that the PERMITTED_DEPENDENCIES does not have unused entries.
300-
for name in PERMITTED_DEPENDENCIES {
350+
for name in permitted {
301351
if !metadata.packages.iter().any(|p| p.name == *name) {
302352
println!(
303353
"could not find allowed package `{}`\n\
@@ -308,12 +358,12 @@ fn check_dependencies(metadata: &Metadata, bad: &mut bool) {
308358
}
309359
}
310360
// Get the list in a convenient form.
311-
let permitted_dependencies: HashSet<_> = PERMITTED_DEPENDENCIES.iter().cloned().collect();
361+
let permitted_dependencies: HashSet<_> = permitted.iter().cloned().collect();
312362

313363
// Check dependencies.
314364
let mut visited = BTreeSet::new();
315365
let mut unapproved = BTreeSet::new();
316-
for &krate in RESTRICTED_DEPENDENCY_CRATES.iter() {
366+
for &krate in restricted_dependency_crates.iter() {
317367
let pkg = pkg_from_name(metadata, krate);
318368
let mut bad =
319369
check_crate_dependencies(&permitted_dependencies, metadata, &mut visited, pkg);

src/tools/tidy/src/edition.rs

+4-15
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,6 @@
22
33
use std::path::Path;
44

5-
fn filter_dirs(path: &Path) -> bool {
6-
// FIXME: just use super::filter_dirs after the submodules are updated.
7-
if super::filter_dirs(path) {
8-
return true;
9-
}
10-
let skip = [
11-
"src/doc/book/second-edition",
12-
"src/doc/book/2018-edition",
13-
"src/doc/book/ci/stable-check",
14-
"src/doc/reference/stable-check",
15-
];
16-
skip.iter().any(|p| path.ends_with(p))
17-
}
18-
195
fn is_edition_2018(mut line: &str) -> bool {
206
line = line.trim();
217
line == "edition = \"2018\"" || line == "edition = \'2018\'"
@@ -24,13 +10,16 @@ fn is_edition_2018(mut line: &str) -> bool {
2410
pub fn check(path: &Path, bad: &mut bool) {
2511
super::walk(
2612
path,
27-
&mut |path| filter_dirs(path) || path.ends_with("src/test"),
13+
&mut |path| super::filter_dirs(path) || path.ends_with("src/test"),
2814
&mut |entry, contents| {
2915
let file = entry.path();
3016
let filename = file.file_name().unwrap();
3117
if filename != "Cargo.toml" {
3218
return;
3319
}
20+
if file.ends_with("library/Cargo.toml") {
21+
return;
22+
}
3423
let has_edition = contents.lines().any(is_edition_2018);
3524
if !has_edition {
3625
tidy_error!(

0 commit comments

Comments
 (0)