Skip to content

Commit

Permalink
dirty_reason.rs: Remove "From" and "To" statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
dnbln committed Nov 25, 2022
1 parent 1966436 commit e08848c
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 139 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 3 additions & 4 deletions crates/cargo-test-support/src/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -755,9 +753,10 @@ B", false,
true,
);
case(
"",
"\n",
"\
[DIRTY-MSVC] a",
[DIRTY-MSVC] a
",
false,
);

Expand Down
123 changes: 15 additions & 108 deletions src/cargo/core/compiler/fingerprint/dirty_reason.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use super::*;
use crate::core::Shell;

use crate::Config;
use dissimilar::Chunk;
use itertools::Itertools;
use std::fmt;

#[derive(Debug)]
Expand Down Expand Up @@ -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<DepFingerprint>,
pub(super) new: Vec<DepFingerprint>,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(())
}

Expand All @@ -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(())
}
Expand All @@ -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"),
Expand All @@ -463,60 +399,39 @@ 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 { .. } => {
s.dirty_because(unit, "the environment variables changed")?;

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("<missing>", String::as_str),
new_value.as_ref().map_or("<missing>", String::as_str),
)?;

Ok(())
}
DirtyReason::LocalFingerprintTypeChanged { old, new } => {
DirtyReason::LocalFingerprintTypeChanged { .. } => {
s.dirty_because(unit, "the local fingerprint type changed")?;
s.changed(old, new)?;

Ok(())
}
Expand Down Expand Up @@ -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("<missing>", String::as_str),
current.as_ref().map_or("<missing>", String::as_str),
)?;
Ok(())
}
},
Expand Down
8 changes: 0 additions & 8 deletions tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [..]`
Expand Down Expand Up @@ -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 [..]`
Expand Down Expand Up @@ -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 [..]
Expand Down Expand Up @@ -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 [..]
Expand Down
2 changes: 0 additions & 2 deletions tests/testsuite/config_include.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] [..]
Expand Down
10 changes: 0 additions & 10 deletions tests/testsuite/freshness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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[..]
Expand Down Expand Up @@ -2138,8 +2136,6 @@ fn rerun_if_changes() {
.with_stderr(
"\
[DIRTY] foo [..]: the env variable FOO changed
[FROM] <missing>
[TO] 1
[COMPILING] foo [..]
[RUNNING] `[..]build-script-build`
[RUNNING] `rustc [..]
Expand All @@ -2158,8 +2154,6 @@ fn rerun_if_changes() {
.with_stderr(
"\
[DIRTY] foo [..]: the env variable BAR changed
[FROM] <missing>
[TO] 1
[COMPILING] foo [..]
[RUNNING] `[..]build-script-build`
[RUNNING] `rustc [..]
Expand All @@ -2178,8 +2172,6 @@ fn rerun_if_changes() {
.with_stderr(
"\
[DIRTY] foo [..]: the env variable FOO changed
[FROM] 1
[TO] <missing>
[COMPILING] foo [..]
[RUNNING] `[..]build-script-build`
[RUNNING] `rustc [..]
Expand Down Expand Up @@ -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] [..]
Expand Down
2 changes: 0 additions & 2 deletions tests/testsuite/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [..]`
Expand Down
4 changes: 0 additions & 4 deletions tests/testsuite/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] [..]
Expand All @@ -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[..]
Expand Down

0 comments on commit e08848c

Please sign in to comment.