fix: verify source before recompile

This fixes a regression introduced by #11407,
which Cargo should always verify a source before it recompiles.
This commit is contained in:
Weihang Lo 2023-02-03 14:14:39 +00:00
parent 419a56f617
commit 98a73394f1
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7
2 changed files with 17 additions and 6 deletions

View File

@ -391,9 +391,9 @@ pub fn prepare_target(cx: &mut Context<'_, '_>, unit: &Unit, force: bool) -> Car
let compare = compare_old_fingerprint(&loc, &*fingerprint, mtime_on_use);
log_compare(unit, &compare);
// If our comparison failed (e.g., we're going to trigger a rebuild of this
// crate), then we also ensure the source of the crate passes all
// verification checks before we build it.
// If our comparison failed or reported dirty (e.g., we're going to trigger
// a rebuild of this crate), then we also ensure the source of the crate
// passes all verification checks before we build it.
//
// The `Source::verify` method is intended to allow sources to execute
// pre-build checks to ensure that the relevant source code is all
@ -401,7 +401,11 @@ pub fn prepare_target(cx: &mut Context<'_, '_>, unit: &Unit, force: bool) -> Car
// directory sources which will use this hook to perform an integrity check
// on all files in the source to ensure they haven't changed. If they have
// changed then an error is issued.
if compare.is_err() {
if compare
.as_ref()
.map(|dirty| dirty.is_some())
.unwrap_or(true)
{
let source_id = unit.pkg.package_id().source_id();
let sources = bcx.packages.sources();
let source = sources

View File

@ -2800,10 +2800,17 @@ fn verify_source_before_recompile() {
//
// Cargo should refuse to build because of checksum verfication failure.
// Cargo shouldn't recompile dependency `bar`.
// TODO: fix this wrong behaviour
p.cargo("check --verbose")
.env("RUSTFLAGS", "-W warnings")
.with_status(101)
.with_stderr_contains("[..]error: You shall not pass![..]")
.with_stderr(
"\
error: the listed checksum of `[CWD]/vendor/bar/src/lib.rs` has changed:
expected: [..]
actual: [..]
directory sources are not [..]
",
)
.run();
}