diff --git a/Cargo.toml b/Cargo.toml index 5f5fdf81c96f..d3352269b625 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,6 @@ cargo-util = { path = "crates/cargo-util", version = "0.2.3" } crates-io = { path = "crates/crates-io", version = "0.35.0" } curl = { version = "0.4.44", features = ["http2"] } curl-sys = "0.4.59" -dissimilar = "1.0" env_logger = "0.10.0" pretty_env_logger = { version = "0.4", optional = true } anyhow = "1.0.47" diff --git a/crates/cargo-test-support/src/compare.rs b/crates/cargo-test-support/src/compare.rs index d645e9f79d95..eff9696ba3de 100644 --- a/crates/cargo-test-support/src/compare.rs +++ b/crates/cargo-test-support/src/compare.rs @@ -196,8 +196,6 @@ fn substitute_macros(input: &str) -> String { ("[SCRAPING]", " Scraping"), ("[FRESH]", " Fresh"), ("[DIRTY]", " Dirty"), - ("[FROM]", " From"), - ("[TO]", " To"), ("[UPDATING]", " Updating"), ("[ADDING]", " Adding"), ("[REMOVING]", " Removing"), @@ -755,9 +753,10 @@ B", false, true, ); case( - "", + "\n", "\ -[DIRTY-MSVC] a", +[DIRTY-MSVC] a +", false, ); diff --git a/src/cargo/core/compiler/fingerprint/dirty_reason.rs b/src/cargo/core/compiler/fingerprint/dirty_reason.rs index 454bff6c2873..025aa8ee1c2b 100644 --- a/src/cargo/core/compiler/fingerprint/dirty_reason.rs +++ b/src/cargo/core/compiler/fingerprint/dirty_reason.rs @@ -2,8 +2,6 @@ use super::*; use crate::core::Shell; use crate::Config; -use dissimilar::Chunk; -use itertools::Itertools; use std::fmt; #[derive(Debug)] @@ -77,11 +75,16 @@ pub enum DirtyReason { } impl DirtyReason { - pub fn presentation<'a>(&'a self, unit: &'a Unit, config: &'a Config) -> DirtyReasonPrettyPresentation<'a> { + pub fn presentation<'a>( + &'a self, + unit: &'a Unit, + config: &'a Config, + ) -> DirtyReasonPrettyPresentation<'a> { DirtyReasonPrettyPresentation(self, unit, config) } } +#[allow(dead_code)] // fields to be used in the future pub struct DirtyReasonDeps { pub(super) old: Vec, pub(super) new: Vec, @@ -269,73 +272,14 @@ impl std::error::Error for DirtyReason {} pub struct DirtyReasonPrettyPresentation<'a>(&'a DirtyReason, &'a Unit, &'a Config); -pub fn diffed(a: &str, b: &str) -> (String, String) { - let mut s1 = String::new(); - let mut s2 = String::new(); - - for chunk in dissimilar::diff(a, b) { - match chunk { - Chunk::Equal(s) => { - s1.push_str(s); - s2.push_str(s); - } - Chunk::Delete(s) => { - s1.push_str(s); - s2.push_str(&" ".repeat(s.len())); - } - Chunk::Insert(s) => { - s1.push_str(&" ".repeat(s.len())); - s2.push_str(s); - } - } - } - - (s1, s2) -} - trait ShellExt { fn dirty_because(&mut self, unit: &Unit, s: impl fmt::Display) -> CargoResult<()>; - fn from(&mut self, s: impl fmt::Display) -> CargoResult<()>; - fn to(&mut self, s: impl fmt::Display) -> CargoResult<()>; - - fn changed(&mut self, old: impl fmt::Display, new: impl fmt::Display) -> CargoResult<()>; - fn changed_diffed(&mut self, old: impl fmt::Display, new: impl fmt::Display) - -> CargoResult<()>; } impl ShellExt for Shell { fn dirty_because(&mut self, unit: &Unit, s: impl fmt::Display) -> CargoResult<()> { self.status("Dirty", format!("{}: {s}", &unit.pkg)) } - - fn from(&mut self, s: impl fmt::Display) -> CargoResult<()> { - self.status("From", s) - } - - fn to(&mut self, s: impl fmt::Display) -> CargoResult<()> { - self.status("To", s) - } - - fn changed(&mut self, old: impl fmt::Display, new: impl fmt::Display) -> CargoResult<()> { - self.verbose(|s| { - s.from(&old)?; - s.to(&new)?; - - Ok(()) - }) - } - - fn changed_diffed( - &mut self, - old: impl fmt::Display, - new: impl fmt::Display, - ) -> CargoResult<()> { - self.verbose(|s| { - let (old_pretty, new_pretty) = diffed(&old.to_string(), &new.to_string()); - - s.changed(old_pretty, new_pretty) - }) - } } struct FileTimeDiff { @@ -396,15 +340,10 @@ impl<'a> DirtyReasonPrettyPresentation<'a> { fn present_dependency_diffs( s: &mut Shell, unit: &Unit, - deps: &DirtyReasonDeps, + _deps: &DirtyReasonDeps, ) -> CargoResult<()> { s.dirty_because(unit, "the list of dependencies changed")?; - let old_deps = deps.old.iter().map(|it| &it.name).sorted().join(", "); - let new_deps = deps.new.iter().map(|it| &it.name).sorted().join(", "); - - s.changed_diffed(old_deps, new_deps)?; - Ok(()) } @@ -426,9 +365,8 @@ impl<'a> DirtyReasonPrettyPresentation<'a> { match &self.0 { DirtyReason::RustcChanged => s.dirty_because(unit, "the toolchain changed"), - DirtyReason::FeaturesChanged { old, new } => { + DirtyReason::FeaturesChanged { .. } => { s.dirty_because(unit, "the list of features changed")?; - s.changed_diffed(old, new)?; Ok(()) } @@ -441,11 +379,9 @@ impl<'a> DirtyReasonPrettyPresentation<'a> { DirtyReason::ProfileConfigurationChanged => { s.dirty_because(unit, "the profile configuration changed") } - DirtyReason::RustflagsChanged { old, new } => { + DirtyReason::RustflagsChanged { .. } => { s.dirty_because(unit, "the rustflags changed")?; - s.changed_diffed(&old.join(" "), &new.join(" "))?; - Ok(()) } DirtyReason::MetadataChanged => s.dirty_because(unit, "the metadata changed"), @@ -463,37 +399,25 @@ impl<'a> DirtyReasonPrettyPresentation<'a> { Ok(()) } - DirtyReason::PrecalculatedComponentsChanged { old, new } => { + DirtyReason::PrecalculatedComponentsChanged { .. } => { s.dirty_because(unit, "the precalculated components changed")?; - s.changed(old, new)?; Ok(()) } DirtyReason::DepInfoOutputChanged { .. } => { s.dirty_because(unit, "the dependency info output changed") } - DirtyReason::RerunIfChangedOutputRootChanged { old, new } => { + DirtyReason::RerunIfChangedOutputRootChanged { .. } => { s.dirty_because( unit, "the working directories for `rerun-if-changed` instructions changed", )?; - s.changed(old.display(), new.display())?; - Ok(()) } - DirtyReason::RerunIfChangedOutputChanged { old, new } => { + DirtyReason::RerunIfChangedOutputChanged { .. } => { s.dirty_because(unit, "the rerun-if-changed instructions changed")?; - s.verbose(|s| { - let old_str = old.iter().map(|it| format!("{it:?}")).join(", "); - let new_str = new.iter().map(|it| format!("{it:?}")).join(", "); - - s.changed_diffed(old_str, new_str)?; - - Ok(()) - })?; - Ok(()) } DirtyReason::EnvVarsChanged { .. } => { @@ -501,22 +425,13 @@ impl<'a> DirtyReasonPrettyPresentation<'a> { Ok(()) } - DirtyReason::EnvVarChanged { - name, - old_value, - new_value, - } => { + DirtyReason::EnvVarChanged { name, .. } => { s.dirty_because(unit, format!("the env variable {name} changed"))?; - s.changed( - old_value.as_ref().map_or("", String::as_str), - new_value.as_ref().map_or("", String::as_str), - )?; Ok(()) } - DirtyReason::LocalFingerprintTypeChanged { old, new } => { + DirtyReason::LocalFingerprintTypeChanged { .. } => { s.dirty_because(unit, "the local fingerprint type changed")?; - s.changed(old, new)?; Ok(()) } @@ -552,16 +467,8 @@ impl<'a> DirtyReasonPrettyPresentation<'a> { ), ) } - StaleItem::ChangedEnv { - var, - previous, - current, - } => { + StaleItem::ChangedEnv { var, .. } => { s.dirty_because(unit, format!("the environment variable {var} changed"))?; - s.changed( - previous.as_ref().map_or("", String::as_str), - current.as_ref().map_or("", String::as_str), - )?; Ok(()) } }, diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index ecaedc908994..7fd28081283c 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -1215,8 +1215,6 @@ fn only_rerun_build_script() { .with_stderr( "\ [DIRTY] foo v0.5.0 ([CWD]): the precalculated components changed -[FROM] [..] -[TO] [..] [COMPILING] foo v0.5.0 ([CWD]) [RUNNING] `[..]/build-script-build` [RUNNING] `rustc --crate-name foo [..]` @@ -1324,8 +1322,6 @@ fn testing_and_such() { .with_stderr( "\ [DIRTY] foo v0.5.0 ([CWD]): the precalculated components changed -[FROM] [..] -[TO] [..] [COMPILING] foo v0.5.0 ([CWD]) [RUNNING] `[..]/build-script-build` [RUNNING] `rustc --crate-name foo [..]` @@ -1749,8 +1745,6 @@ fn out_dir_is_preserved() { .with_stderr( "\ [DIRTY] foo [..]: the precalculated components changed -[FROM] [..] -[TO] [..] [COMPILING] foo [..] [RUNNING] `[..]build-script-build` [RUNNING] `rustc --crate-name foo [..] @@ -3016,8 +3010,6 @@ fn changing_an_override_invalidates() { .with_stderr( "\ [DIRTY] foo v0.5.0 ([..]): the precalculated components changed -[FROM] [..] -[TO] [..] [COMPILING] foo v0.5.0 ([..] [RUNNING] `rustc [..] -L native=bar` [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] diff --git a/tests/testsuite/config_include.rs b/tests/testsuite/config_include.rs index 27e02455ea52..26167ad26205 100644 --- a/tests/testsuite/config_include.rs +++ b/tests/testsuite/config_include.rs @@ -75,8 +75,6 @@ fn works_with_cli() { .with_stderr( "\ [DIRTY] foo v0.0.1 ([..]): the rustflags changed -[FROM] -W unused -[TO] -W unsafe-code -W unused [COMPILING] foo v0.0.1 [..] [RUNNING] `rustc [..]-W unsafe-code -W unused` [FINISHED] [..] diff --git a/tests/testsuite/freshness.rs b/tests/testsuite/freshness.rs index fba1515337a9..2d142a3d8797 100644 --- a/tests/testsuite/freshness.rs +++ b/tests/testsuite/freshness.rs @@ -1904,8 +1904,6 @@ fn simulated_docker_deps_stay_cached() { [FRESH] regdep_old_style [..] [FRESH] regdep_rerun [..] [DIRTY] foo [..]: the precalculated components changed -[FROM] [..] -[TO] [..] [COMPILING] foo [..] [RUNNING] [..]/foo-[..]/build-script-build[..] [RUNNING] `rustc --crate-name foo[..] @@ -2138,8 +2136,6 @@ fn rerun_if_changes() { .with_stderr( "\ [DIRTY] foo [..]: the env variable FOO changed -[FROM] -[TO] 1 [COMPILING] foo [..] [RUNNING] `[..]build-script-build` [RUNNING] `rustc [..] @@ -2158,8 +2154,6 @@ fn rerun_if_changes() { .with_stderr( "\ [DIRTY] foo [..]: the env variable BAR changed -[FROM] -[TO] 1 [COMPILING] foo [..] [RUNNING] `[..]build-script-build` [RUNNING] `rustc [..] @@ -2178,8 +2172,6 @@ fn rerun_if_changes() { .with_stderr( "\ [DIRTY] foo [..]: the env variable FOO changed -[FROM] 1 -[TO] [COMPILING] foo [..] [RUNNING] `[..]build-script-build` [RUNNING] `rustc [..] @@ -2667,8 +2659,6 @@ fn cargo_env_changes() { .with_stderr( "\ [DIRTY] foo v1.0.0 ([..]): the environment variable CARGO changed -[FROM] [..] -[TO] [..] [CHECKING] foo [..] [RUNNING] `rustc [..] [FINISHED] [..] diff --git a/tests/testsuite/git.rs b/tests/testsuite/git.rs index 3577d8307553..db8d36fc9225 100644 --- a/tests/testsuite/git.rs +++ b/tests/testsuite/git.rs @@ -2522,8 +2522,6 @@ fn include_overrides_gitignore() { .with_stderr( "\ [DIRTY] foo v0.5.0 ([..]): the precalculated components changed -[FROM] [..] -[TO] [..] [COMPILING] foo v0.5.0 ([..]) [RUNNING] `[..]build-script-build[..]` [RUNNING] `rustc --crate-name foo src/lib.rs [..]` diff --git a/tests/testsuite/lto.rs b/tests/testsuite/lto.rs index 8547e5650f5b..d812b4eb90c2 100644 --- a/tests/testsuite/lto.rs +++ b/tests/testsuite/lto.rs @@ -596,8 +596,6 @@ fn dylib() { [FRESH] registry v0.0.1 [RUNNING] `rustc --crate-name registry_shared [..]-C embed-bitcode=no[..] [DIRTY] bar v0.0.0 ([..]): the list of dependencies changed -[FROM] registry, registry_shared -[TO] registry, registry_shared [COMPILING] bar [..] [RUNNING] `rustc --crate-name bar [..]--crate-type dylib [..]-C embed-bitcode=no[..] [FINISHED] [..] @@ -616,8 +614,6 @@ fn dylib() { [COMPILING] registry v0.0.1 [RUNNING] `rustc --crate-name registry [..] [DIRTY] bar v0.0.0 ([..]): the list of dependencies changed -[FROM] registry, registry_shared -[TO] registry, registry_shared [COMPILING] bar [..] [RUNNING] `rustc --crate-name bar [..]--crate-type dylib [..]-C embed-bitcode=no[..] [RUNNING] `rustc --crate-name bar [..]-C lto [..]--test[..]