From 4c777710c6f5996e0967fe5b9d2924684c646626 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Mon, 20 Mar 2023 11:42:54 +0800 Subject: [PATCH] tidy: `check_crate_duplicate` is no longer useful After cargo becomes a workspace, no one uses `check_crate_duplicate` to check if cargo is a dependency anymore. --- src/tools/tidy/src/deps.rs | 55 ++++++-------------------------------- 1 file changed, 8 insertions(+), 47 deletions(-) diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index c80557fb757..0e0a517ae49 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -335,13 +335,6 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[ "windows_x86_64_msvc", ]; -const FORBIDDEN_TO_HAVE_DUPLICATES: &[&str] = &[ - // This crate takes quite a long time to build, so don't allow two versions of them - // to accidentally sneak into our dependency graph, in order to ensure we keep our CI times - // under control. - "cargo", -]; - /// Dependency checks. /// /// `root` is path to the directory with the root `Cargo.toml` (for the workspace). `cargo` is path @@ -361,7 +354,6 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) { &["rustc_driver", "rustc_codegen_llvm"], bad, ); - check_crate_duplicate(&metadata, &[], bad); // Check cargo independently as it has it's own workspace. let mut cmd = cargo_metadata::MetadataCommand::new(); @@ -371,7 +363,6 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) { let cargo_metadata = t!(cmd.exec()); let runtime_ids = HashSet::new(); check_license_exceptions(&cargo_metadata, EXCEPTIONS_CARGO, runtime_ids, bad); - check_crate_duplicate(&cargo_metadata, FORBIDDEN_TO_HAVE_DUPLICATES, bad); check_rustfix(&metadata, &cargo_metadata, bad); // Check rustc_codegen_cranelift independently as it has it's own workspace. @@ -389,7 +380,6 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) { &["rustc_codegen_cranelift"], bad, ); - check_crate_duplicate(&metadata, &[], bad); let mut cmd = cargo_metadata::MetadataCommand::new(); cmd.cargo_path(cargo) @@ -535,40 +525,6 @@ fn check_permitted_dependencies( } } -/// Prevents multiple versions of some expensive crates. -fn check_crate_duplicate( - metadata: &Metadata, - forbidden_to_have_duplicates: &[&str], - bad: &mut bool, -) { - for &name in forbidden_to_have_duplicates { - let matches: Vec<_> = metadata.packages.iter().filter(|pkg| pkg.name == name).collect(); - match matches.len() { - 0 => { - tidy_error!( - bad, - "crate `{}` is missing, update `check_crate_duplicate` \ - if it is no longer used", - name - ); - } - 1 => {} - _ => { - tidy_error!( - bad, - "crate `{}` is duplicated in `Cargo.lock`, \ - it is too expensive to build multiple times, \ - so make sure only one version appears across all dependencies", - name - ); - for pkg in matches { - println!(" * {}", pkg.id); - } - } - } - } -} - /// Finds a package with the given name. fn pkg_from_name<'a>(metadata: &'a Metadata, name: &'static str) -> &'a Package { let mut i = metadata.packages.iter().filter(|p| p.name == name); @@ -618,7 +574,10 @@ fn deps_of_filtered<'a>( } } -fn direct_deps_of<'a>(metadata: &'a Metadata, pkg_id: &'a PackageId) -> impl Iterator { +fn direct_deps_of<'a>( + metadata: &'a Metadata, + pkg_id: &'a PackageId, +) -> impl Iterator { let resolve = metadata.resolve.as_ref().unwrap(); let node = resolve.nodes.iter().find(|n| &n.id == pkg_id).unwrap(); node.deps.iter().map(|dep| pkg_from_id(metadata, &dep.pkg)) @@ -626,10 +585,12 @@ fn direct_deps_of<'a>(metadata: &'a Metadata, pkg_id: &'a PackageId) -> impl Ite fn check_rustfix(rust_metadata: &Metadata, cargo_metadata: &Metadata, bad: &mut bool) { let cargo = pkg_from_name(cargo_metadata, "cargo"); - let cargo_rustfix = direct_deps_of(cargo_metadata, &cargo.id).find(|p| p.name == "rustfix").unwrap(); + let cargo_rustfix = + direct_deps_of(cargo_metadata, &cargo.id).find(|p| p.name == "rustfix").unwrap(); let compiletest = pkg_from_name(rust_metadata, "compiletest"); - let compiletest_rustfix = direct_deps_of(rust_metadata, &compiletest.id).find(|p| p.name == "rustfix").unwrap(); + let compiletest_rustfix = + direct_deps_of(rust_metadata, &compiletest.id).find(|p| p.name == "rustfix").unwrap(); if cargo_rustfix.version != compiletest_rustfix.version { tidy_error!(