Skip to content

Commit 1966436

Browse files
committed
dirty_reason.rs: put everything behind verbose
1 parent ef581f3 commit 1966436

19 files changed

+51
-134
lines changed

crates/cargo-test-support/src/compare.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ fn replace_dirty_msvc_impl(s: &str, is_msvc: bool) -> String {
145145
fn replace_dirty_msvc(s: &str) -> String {
146146
replace_dirty_msvc_impl(s, cfg!(target_env = "msvc"))
147147
}
148+
148149
/// Normalizes text for both actual and expected strings on Windows.
149150
fn normalize_windows(text: &str, cwd: Option<&Path>) -> String {
150151
// Let's not deal with / vs \ (windows...)

src/cargo/core/compiler/fingerprint/dirty_reason.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::*;
2-
use crate::core::{Shell, Verbosity};
2+
use crate::core::Shell;
33

4+
use crate::Config;
45
use dissimilar::Chunk;
56
use itertools::Itertools;
67
use std::fmt;
@@ -76,8 +77,8 @@ pub enum DirtyReason {
7677
}
7778

7879
impl DirtyReason {
79-
pub fn presentation(&self) -> DirtyReasonPrettyPresentation<'_> {
80-
DirtyReasonPrettyPresentation(self)
80+
pub fn presentation<'a>(&'a self, unit: &'a Unit, config: &'a Config) -> DirtyReasonPrettyPresentation<'a> {
81+
DirtyReasonPrettyPresentation(self, unit, config)
8182
}
8283
}
8384

@@ -266,7 +267,7 @@ impl fmt::Display for DirtyReason {
266267

267268
impl std::error::Error for DirtyReason {}
268269

269-
pub struct DirtyReasonPrettyPresentation<'a>(&'a DirtyReason);
270+
pub struct DirtyReasonPrettyPresentation<'a>(&'a DirtyReason, &'a Unit, &'a Config);
270271

271272
pub fn diffed(a: &str, b: &str) -> (String, String) {
272273
let mut s1 = String::new();
@@ -415,7 +416,14 @@ impl<'a> DirtyReasonPrettyPresentation<'a> {
415416
}
416417
}
417418

418-
pub fn present_to(&self, s: &mut Shell, unit: &Unit, root: &Path) -> CargoResult<()> {
419+
pub fn present_to(&self, s: &mut Shell) -> CargoResult<()> {
420+
let unit = self.1;
421+
let ws_roots = self.2.ws_roots.borrow();
422+
let root: &Path = ws_roots
423+
.values()
424+
.next()
425+
.map_or_else(|| self.2.cwd(), |it| it.inheritable().ws_root().as_ref());
426+
419427
match &self.0 {
420428
DirtyReason::RustcChanged => s.dirty_because(unit, "the toolchain changed"),
421429
DirtyReason::FeaturesChanged { old, new } => {
@@ -449,11 +457,9 @@ impl<'a> DirtyReasonPrettyPresentation<'a> {
449457
}
450458
DirtyReason::LocalLengthsChanged => {
451459
s.dirty_because(unit, "the local lengths changed")?;
452-
s.verbose(|s| {
453-
s.note(
460+
s.note(
454461
"This could happen because of added/removed `cargo:rerun-if` instructions in the build script",
455-
)
456-
})?;
462+
)?;
457463

458464
Ok(())
459465
}
@@ -537,20 +543,14 @@ impl<'a> DirtyReasonPrettyPresentation<'a> {
537543
..
538544
} => {
539545
let file = stale.strip_prefix(root).unwrap_or(&stale);
540-
match s.verbosity() {
541-
Verbosity::Verbose => s.dirty_because(
542-
unit,
543-
format!(
544-
"the file `{}` has changed({})",
545-
file.display(),
546-
Self::after(*reference_mtime, *stale_mtime, "last build"),
547-
),
548-
),
549-
_ => s.dirty_because(
550-
unit,
551-
format!("the file `{}` has changed", file.display()),
546+
s.dirty_because(
547+
unit,
548+
format!(
549+
"the file `{}` has changed ({})",
550+
file.display(),
551+
Self::after(*reference_mtime, *stale_mtime, "last build"),
552552
),
553-
}
553+
)
554554
}
555555
StaleItem::ChangedEnv {
556556
var,
@@ -571,14 +571,14 @@ impl<'a> DirtyReasonPrettyPresentation<'a> {
571571
max_mtime,
572572
..
573573
} => {
574-
let message = match (dep_mtime, s.verbosity()) {
575-
(Some(dep_mtime), Verbosity::Verbose) => {
574+
let message = match dep_mtime {
575+
Some(dep_mtime) => {
576576
format!(
577577
"the dependency {name} was rebuilt ({})",
578578
Self::after(*max_mtime, *dep_mtime, "last build"),
579579
)
580580
}
581-
(None, _) | (Some(_), _) => {
581+
None => {
582582
format!("the dependency {name} was rebuilt")
583583
}
584584
};

src/cargo/core/compiler/job_queue.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ use crate::core::compiler::future_incompat::{
7676
self, FutureBreakageItem, FutureIncompatReportPackage,
7777
};
7878
use crate::core::resolver::ResolveBehavior;
79-
use crate::core::{PackageId, Shell, TargetKind, WorkspaceRootConfig};
79+
use crate::core::{PackageId, Shell, TargetKind};
8080
use crate::util::diagnostic_server::{self, DiagnosticPrinter};
8181
use crate::util::errors::AlreadyPrintedError;
8282
use crate::util::machine_message::{self, Message as _};
@@ -1370,16 +1370,9 @@ impl<'cfg> DrainState<'cfg> {
13701370
self.compiled.insert(unit.pkg.package_id());
13711371

13721372
if let Some(reason) = dirty_reason {
1373-
// FIXME: multiple workspace roots???
1374-
let roots = config.ws_roots.borrow();
1375-
let ws_root = roots.values().next().map_or(
1376-
config.cwd(), // FIXME: use a correct root when ws_roots is empty
1377-
|root: &WorkspaceRootConfig| root.inheritable().ws_root(),
1378-
);
1379-
1380-
reason
1381-
.presentation()
1382-
.present_to(&mut config.shell(), unit, ws_root)?;
1373+
config
1374+
.shell()
1375+
.verbose(|shell| reason.presentation(unit, config).present_to(shell))?;
13831376
}
13841377

13851378
if unit.mode.is_check() {

tests/testsuite/artifact_dep.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2321,7 +2321,7 @@ fn calc_bin_artifact_fingerprint() {
23212321
.masquerade_as_nightly_cargo(&["bindeps"])
23222322
.with_stderr(
23232323
"\
2324-
[DIRTY] bar v0.5.0 ([CWD]/bar): the file `bar/src/main.rs` has changed([..])
2324+
[DIRTY] bar v0.5.0 ([CWD]/bar): the file `bar/src/main.rs` has changed ([..])
23252325
[COMPILING] bar v0.5.0 ([CWD]/bar)
23262326
[RUNNING] `rustc --crate-name bar [..]`
23272327
[DIRTY] foo v0.1.0 ([CWD]): the dependency bar was rebuilt

tests/testsuite/build.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2829,7 +2829,6 @@ fn rebuild_preserves_out_dir() {
28292829
foo.cargo("build")
28302830
.with_stderr(
28312831
"\
2832-
[DIRTY] foo v0.0.0 ([CWD]): the precalculated components changed
28332832
[COMPILING] foo v0.0.0 ([CWD])
28342833
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
28352834
",

tests/testsuite/build_script.rs

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,6 @@ fn testing_and_such() {
13541354
p.cargo("run")
13551355
.with_stderr(
13561356
"\
1357-
[DIRTY] foo v0.5.0 ([CWD]): the precalculated components changed
13581357
[COMPILING] foo v0.5.0 ([CWD])
13591358
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
13601359
[RUNNING] `target/debug/foo[EXE]`
@@ -1724,7 +1723,7 @@ fn out_dir_is_preserved() {
17241723
p.cargo("build -v")
17251724
.with_stderr(
17261725
"\
1727-
[DIRTY] foo [..]: the file `build.rs` has changed([..])
1726+
[DIRTY] foo [..]: the file `build.rs` has changed ([..])
17281727
[COMPILING] foo [..]
17291728
[RUNNING] `rustc --crate-name build_script_build [..]
17301729
[RUNNING] `[..]/build-script-build`
@@ -3328,7 +3327,7 @@ fn rebuild_only_on_explicit_paths() {
33283327
p.cargo("build -v")
33293328
.with_stderr(
33303329
"\
3331-
[DIRTY] foo v0.5.0 ([..]): the file `foo` has changed([..])
3330+
[DIRTY] foo v0.5.0 ([..]): the file `foo` has changed ([..])
33323331
[COMPILING] foo v0.5.0 ([..])
33333332
[RUNNING] `[..]/build-script-build`
33343333
[RUNNING] `rustc [..] src/lib.rs [..]`
@@ -3367,7 +3366,7 @@ fn rebuild_only_on_explicit_paths() {
33673366
p.cargo("build -v")
33683367
.with_stderr(
33693368
"\
3370-
[DIRTY] foo v0.5.0 ([..]): the file `foo` has changed([..])
3369+
[DIRTY] foo v0.5.0 ([..]): the file `foo` has changed ([..])
33713370
[COMPILING] foo v0.5.0 ([..])
33723371
[RUNNING] `[..]/build-script-build`
33733372
[RUNNING] `rustc [..] src/lib.rs [..]`
@@ -4710,18 +4709,7 @@ fn rerun_if_directory() {
47104709
)
47114710
.build();
47124711

4713-
let dirty = |reason: &str| {
4714-
p.cargo("check")
4715-
.with_stderr(format!(
4716-
"\
4717-
[DIRTY] foo [..]: {reason}
4718-
[COMPILING] foo [..]
4719-
[FINISHED] [..]",
4720-
))
4721-
.run();
4722-
};
4723-
4724-
let dirty_first = || {
4712+
let dirty = || {
47254713
p.cargo("check")
47264714
.with_stderr(format!(
47274715
"\
@@ -4736,18 +4724,18 @@ fn rerun_if_directory() {
47364724
};
47374725

47384726
// Start with a missing directory.
4739-
dirty_first();
4727+
dirty();
47404728
// Because the directory doesn't exist, it will trigger a rebuild every time.
47414729
// https://github.com/rust-lang/cargo/issues/6003
4742-
dirty("the file `somedir` is missing");
4730+
dirty();
47434731

47444732
if is_coarse_mtime() {
47454733
sleep_ms(1000);
47464734
}
47474735

47484736
// Empty directory.
47494737
fs::create_dir(p.root().join("somedir")).unwrap();
4750-
dirty("the file `somedir` has changed");
4738+
dirty();
47514739
fresh();
47524740

47534741
if is_coarse_mtime() {
@@ -4757,7 +4745,7 @@ fn rerun_if_directory() {
47574745
// Add a file.
47584746
p.change_file("somedir/foo", "");
47594747
p.change_file("somedir/bar", "");
4760-
dirty("the file `somedir` has changed");
4748+
dirty();
47614749
fresh();
47624750

47634751
if is_coarse_mtime() {
@@ -4766,7 +4754,7 @@ fn rerun_if_directory() {
47664754

47674755
// Add a symlink.
47684756
p.symlink("foo", "somedir/link");
4769-
dirty("the file `somedir` has changed");
4757+
dirty();
47704758
fresh();
47714759

47724760
if is_coarse_mtime() {
@@ -4776,7 +4764,7 @@ fn rerun_if_directory() {
47764764
// Move the symlink.
47774765
fs::remove_file(p.root().join("somedir/link")).unwrap();
47784766
p.symlink("bar", "somedir/link");
4779-
dirty("the file `somedir` has changed");
4767+
dirty();
47804768
fresh();
47814769

47824770
if is_coarse_mtime() {
@@ -4785,7 +4773,7 @@ fn rerun_if_directory() {
47854773

47864774
// Remove a file.
47874775
fs::remove_file(p.root().join("somedir/foo")).unwrap();
4788-
dirty("the file `somedir` has changed");
4776+
dirty();
47894777
fresh();
47904778
}
47914779

tests/testsuite/build_script_env.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ fn rerun_if_env_changes() {
3030
.env("FOO", "bar")
3131
.with_stderr(
3232
"\
33-
[DIRTY] foo v0.0.1 ([..]): the env variable FOO changed
3433
[COMPILING] foo v0.0.1 ([..])
3534
[FINISHED] [..]
3635
",
@@ -40,7 +39,6 @@ fn rerun_if_env_changes() {
4039
.env("FOO", "baz")
4140
.with_stderr(
4241
"\
43-
[DIRTY] foo v0.0.1 ([..]): the env variable FOO changed
4442
[COMPILING] foo v0.0.1 ([..])
4543
[FINISHED] [..]
4644
",
@@ -53,7 +51,6 @@ fn rerun_if_env_changes() {
5351
p.cargo("build")
5452
.with_stderr(
5553
"\
56-
[DIRTY] foo v0.0.1 ([..]): the env variable FOO changed
5754
[COMPILING] foo v0.0.1 ([..])
5855
[FINISHED] [..]
5956
",
@@ -89,7 +86,6 @@ fn rerun_if_env_or_file_changes() {
8986
.env("FOO", "bar")
9087
.with_stderr(
9188
"\
92-
[DIRTY] foo v0.0.1 ([..]): the env variable FOO changed
9389
[COMPILING] foo v0.0.1 ([..])
9490
[FINISHED] [..]
9591
",
@@ -105,7 +101,6 @@ fn rerun_if_env_or_file_changes() {
105101
.env("FOO", "bar")
106102
.with_stderr(
107103
"\
108-
[DIRTY] foo v0.0.1 ([..]): the file `foo` has changed
109104
[COMPILING] foo v0.0.1 ([..])
110105
[FINISHED] [..]
111106
",

tests/testsuite/build_script_extra_link_arg.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ The package foo v0.0.1 ([ROOT]/foo) does not have a bin target.
140140
.with_status(101)
141141
.with_stderr(
142142
"\
143-
[DIRTY] foo [..]: the file `build.rs` has changed
144143
[COMPILING] foo [..]
145144
error: invalid instruction `cargo:rustc-link-arg-bin` from build script of `foo v0.0.1 ([ROOT]/foo)`
146145
The package foo v0.0.1 ([ROOT]/foo) does not have a bin target with the name `abc`.
@@ -157,7 +156,6 @@ The package foo v0.0.1 ([ROOT]/foo) does not have a bin target with the name `ab
157156
.with_status(101)
158157
.with_stderr(
159158
"\
160-
[DIRTY] foo [..]: the file `build.rs` has changed
161159
[COMPILING] foo [..]
162160
error: invalid instruction `cargo:rustc-link-arg-bin=abc` from build script of `foo v0.0.1 ([ROOT]/foo)`
163161
The instruction should have the form cargo:rustc-link-arg-bin=BIN=ARG

tests/testsuite/cache_messages.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ fn clears_cache_after_fix() {
176176
.with_stdout("")
177177
.with_stderr(
178178
"\
179-
[DIRTY] foo [..]: the file `src/lib.rs` has changed
180179
[CHECKING] foo [..]
181180
[FINISHED] [..]
182181
",

tests/testsuite/directory.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,7 @@ fn crates_io_then_directory() {
379379
p.cargo("build")
380380
.with_stderr(
381381
"\
382-
[DIRTY] bar v0.1.0: the path to the source changed
383382
[COMPILING] bar v0.1.0
384-
[DIRTY] foo v0.1.0 ([CWD]): the list of dependencies changed
385383
[COMPILING] foo v0.1.0 ([CWD])
386384
[FINISHED] [..]
387385
",
@@ -603,9 +601,7 @@ fn git_lock_file_doesnt_change() {
603601
p.cargo("build")
604602
.with_stderr(
605603
"\
606-
[DIRTY] git v0.5.0 ([..]): the path to the source changed
607604
[COMPILING] [..]
608-
[DIRTY] foo v0.0.1 ([..]): the list of dependencies changed
609605
[COMPILING] [..]
610606
[FINISHED] [..]
611607
",

tests/testsuite/features.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,6 @@ fn no_feature_doesnt_build() {
484484
.with_stderr(
485485
"\
486486
[COMPILING] bar v0.0.1 ([CWD]/bar)
487-
[DIRTY-MSVC] foo v0.0.1 ([CWD]): the list of features changed
488487
[COMPILING] foo v0.0.1 ([CWD])
489488
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
490489
",
@@ -542,7 +541,6 @@ fn default_feature_pulled_in() {
542541
p.cargo("build --no-default-features")
543542
.with_stderr(
544543
"\
545-
[DIRTY-MSVC] foo v0.0.1 ([CWD]): the list of features changed
546544
[COMPILING] foo v0.0.1 ([CWD])
547545
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
548546
",

tests/testsuite/features_namespaced.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ fn namespaced_same_name() {
328328
[DOWNLOADING] crates ...
329329
[DOWNLOADED] baz v0.1.0 [..]
330330
[COMPILING] baz v0.1.0
331-
[DIRTY-MSVC] foo v0.0.1 ([..]): the list of features changed
332331
[COMPILING] foo v0.0.1 [..]
333332
[FINISHED] [..]
334333
[RUNNING] [..]
@@ -391,7 +390,6 @@ fn no_implicit_feature() {
391390
[DOWNLOADED] lazy_static v1.0.0 [..]
392391
[COMPILING] regex v1.0.0
393392
[COMPILING] lazy_static v1.0.0
394-
[DIRTY-MSVC] foo v0.1.0 ([..]): the list of features changed
395393
[COMPILING] foo v0.1.0 [..]
396394
[FINISHED] [..]
397395
[RUNNING] `target/debug/foo[EXE]`

tests/testsuite/fix.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,6 @@ fn doesnt_rebuild_dependencies() {
12021202
.with_stdout("")
12031203
.with_stderr(
12041204
"\
1205-
[DIRTY] foo v0.1.0 ([..]): forced
12061205
[CHECKING] foo v0.1.0 ([..])
12071206
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
12081207
",

0 commit comments

Comments
 (0)