Skip to content

Commit 9ed56ca

Browse files
committed
Add some more context to errors walking path sources.
1 parent 8751eb3 commit 9ed56ca

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

src/cargo/core/compiler/fingerprint.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,12 @@ fn calculate_normal(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Finger
12091209
let target_root = target_root(cx);
12101210
let local = if unit.mode.is_doc() {
12111211
// rustdoc does not have dep-info files.
1212-
let fingerprint = pkg_fingerprint(cx.bcx, &unit.pkg)?;
1212+
let fingerprint = pkg_fingerprint(cx.bcx, &unit.pkg).chain_err(|| {
1213+
format!(
1214+
"failed to determine package fingerprint for documenting {}",
1215+
unit.pkg
1216+
)
1217+
})?;
12131218
vec![LocalFingerprint::Precalculated(fingerprint)]
12141219
} else {
12151220
let dep_info = dep_info_loc(cx, unit);
@@ -1270,7 +1275,18 @@ fn calculate_run_custom_build(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoRes
12701275
// the whole crate.
12711276
let (gen_local, overridden) = build_script_local_fingerprints(cx, unit);
12721277
let deps = &cx.build_explicit_deps[unit];
1273-
let local = (gen_local)(deps, Some(&|| pkg_fingerprint(cx.bcx, &unit.pkg)))?.unwrap();
1278+
let local = (gen_local)(
1279+
deps,
1280+
Some(&|| {
1281+
pkg_fingerprint(cx.bcx, &unit.pkg).chain_err(|| {
1282+
format!(
1283+
"failed to determine package fingerprint for build script for {}",
1284+
unit.pkg
1285+
)
1286+
})
1287+
}),
1288+
)?
1289+
.unwrap();
12741290
let output = deps.build_script_output.clone();
12751291

12761292
// Include any dependencies of our execution, which is typically just the

src/cargo/sources/path.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ impl<'cfg> PathSource<'cfg> {
9696
/// are relevant for building this package, but it also contains logic to
9797
/// use other methods like .gitignore to filter the list of files.
9898
pub fn list_files(&self, pkg: &Package) -> CargoResult<Vec<PathBuf>> {
99+
self._list_files(pkg).chain_err(|| {
100+
format!(
101+
"failed to determine list of files in {}",
102+
pkg.root().display()
103+
)
104+
})
105+
}
106+
107+
fn _list_files(&self, pkg: &Package) -> CargoResult<Vec<PathBuf>> {
99108
let root = pkg.root();
100109
let no_include_option = pkg.manifest().include().is_empty();
101110

@@ -415,7 +424,12 @@ impl<'cfg> PathSource<'cfg> {
415424

416425
let mut max = FileTime::zero();
417426
let mut max_path = PathBuf::new();
418-
for file in self.list_files(pkg)? {
427+
for file in self.list_files(pkg).chain_err(|| {
428+
format!(
429+
"failed to determine the most recently modified file in {}",
430+
pkg.root().display()
431+
)
432+
})? {
419433
// An `fs::stat` error here is either because path is a
420434
// broken symlink, a permissions error, or a race
421435
// condition where this path was `rm`-ed -- either way,

tests/testsuite/build_script.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3985,12 +3985,21 @@ fn build_script_scan_eacces() {
39853985
.build();
39863986
let path = p.root().join("secrets");
39873987
fs::set_permissions(&path, fs::Permissions::from_mode(0)).unwrap();
3988-
// "Caused by" is a string from libc such as the following:
3988+
// The last "Caused by" is a string from libc such as the following:
39893989
// Permission denied (os error 13)
39903990
p.cargo("build")
39913991
.with_stderr(
39923992
"\
3993-
[ERROR] cannot read \"[..]/foo/secrets\"
3993+
[ERROR] failed to determine package fingerprint for build script for foo v0.0.1 ([..]/foo)
3994+
3995+
Caused by:
3996+
failed to determine the most recently modified file in [..]/foo
3997+
3998+
Caused by:
3999+
failed to determine list of files in [..]/foo
4000+
4001+
Caused by:
4002+
cannot read \"[..]/foo/secrets\"
39944003
39954004
Caused by:
39964005
[..]

0 commit comments

Comments
 (0)