Skip to content

Commit 0bbfc5e

Browse files
committed
Auto merge of #10191 - weihanglo:issue-9881, r=alexcrichton
Improve I/O error message for fingerprint of build script It is a bit rough but I don't think there is a network I/O error in `pkg_fingerprint`. Checking only `io::Error` type should be fine. Resolves #9881
2 parents 1ee19f3 + 760ff62 commit 0bbfc5e

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/cargo/core/compiler/fingerprint.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ use std::collections::hash_map::{Entry, HashMap};
316316
use std::convert::TryInto;
317317
use std::env;
318318
use std::hash::{self, Hash, Hasher};
319+
use std::io;
319320
use std::path::{Path, PathBuf};
320321
use std::str;
321322
use std::sync::{Arc, Mutex};
@@ -1366,11 +1367,19 @@ fn calculate_run_custom_build(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoRes
13661367
let local = (gen_local)(
13671368
deps,
13681369
Some(&|| {
1369-
pkg_fingerprint(cx.bcx, &unit.pkg).with_context(|| {
1370-
format!(
1371-
"failed to determine package fingerprint for build script for {}",
1372-
unit.pkg
1373-
)
1370+
const IO_ERR_MESSAGE: &str = "\
1371+
An I/O error happened. Please make sure you can access the file.
1372+
1373+
By default, if your project contains a build script, cargo scans all files in
1374+
it to determine whether a rebuild is needed. If you don't expect to access the
1375+
file, specify `rerun-if-changed` in your build script.
1376+
See https://doc.rust-lang.org/cargo/reference/build-scripts.html#rerun-if-changed for more information.";
1377+
pkg_fingerprint(cx.bcx, &unit.pkg).map_err(|err| {
1378+
let mut message = format!("failed to determine package fingerprint for build script for {}", unit.pkg);
1379+
if err.root_cause().is::<io::Error>() {
1380+
message = format!("{}\n{}", message, IO_ERR_MESSAGE)
1381+
}
1382+
err.context(message)
13741383
})
13751384
}),
13761385
)?

tests/testsuite/build_script.rs

+6
Original file line numberDiff line numberDiff line change
@@ -4639,6 +4639,12 @@ fn build_script_scan_eacces() {
46394639
.with_stderr(
46404640
"\
46414641
[ERROR] failed to determine package fingerprint for build script for foo v0.0.1 ([..]/foo)
4642+
An I/O error happened[..]
4643+
4644+
By default[..]
4645+
it to[..]
4646+
file[..]
4647+
See[..]
46424648
46434649
Caused by:
46444650
failed to determine the most recently modified file in [..]/foo

0 commit comments

Comments
 (0)