Skip to content

Commit 98a7339

Browse files
committed
fix: verify source before recompile
This fixes a regression introduced by #11407, which Cargo should always verify a source before it recompiles.
1 parent 419a56f commit 98a7339

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/cargo/core/compiler/fingerprint.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,17 +391,21 @@ pub fn prepare_target(cx: &mut Context<'_, '_>, unit: &Unit, force: bool) -> Car
391391
let compare = compare_old_fingerprint(&loc, &*fingerprint, mtime_on_use);
392392
log_compare(unit, &compare);
393393

394-
// If our comparison failed (e.g., we're going to trigger a rebuild of this
395-
// crate), then we also ensure the source of the crate passes all
396-
// verification checks before we build it.
394+
// If our comparison failed or reported dirty (e.g., we're going to trigger
395+
// a rebuild of this crate), then we also ensure the source of the crate
396+
// passes all verification checks before we build it.
397397
//
398398
// The `Source::verify` method is intended to allow sources to execute
399399
// pre-build checks to ensure that the relevant source code is all
400400
// up-to-date and as expected. This is currently used primarily for
401401
// directory sources which will use this hook to perform an integrity check
402402
// on all files in the source to ensure they haven't changed. If they have
403403
// changed then an error is issued.
404-
if compare.is_err() {
404+
if compare
405+
.as_ref()
406+
.map(|dirty| dirty.is_some())
407+
.unwrap_or(true)
408+
{
405409
let source_id = unit.pkg.package_id().source_id();
406410
let sources = bcx.packages.sources();
407411
let source = sources

tests/testsuite/freshness.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2800,10 +2800,17 @@ fn verify_source_before_recompile() {
28002800
//
28012801
// Cargo should refuse to build because of checksum verfication failure.
28022802
// Cargo shouldn't recompile dependency `bar`.
2803-
// TODO: fix this wrong behaviour
28042803
p.cargo("check --verbose")
28052804
.env("RUSTFLAGS", "-W warnings")
28062805
.with_status(101)
2807-
.with_stderr_contains("[..]error: You shall not pass![..]")
2806+
.with_stderr(
2807+
"\
2808+
error: the listed checksum of `[CWD]/vendor/bar/src/lib.rs` has changed:
2809+
expected: [..]
2810+
actual: [..]
2811+
2812+
directory sources are not [..]
2813+
",
2814+
)
28082815
.run();
28092816
}

0 commit comments

Comments
 (0)