Add path to the failure to load a dependency.

This commit is contained in:
Eric Huss 2020-02-27 08:17:18 -08:00
parent a07fec1b7b
commit 1eca786d7f
13 changed files with 86 additions and 20 deletions

View File

@ -16,6 +16,8 @@ use std::rc::Rc;
use log::debug;
use crate::core::interning::InternedString;
use crate::core::resolver::context::Context;
use crate::core::resolver::errors::describe_path;
use crate::core::{Dependency, FeatureValue, PackageId, PackageIdSpec, Registry, Summary};
use crate::util::errors::{CargoResult, CargoResultExt};
@ -197,6 +199,7 @@ impl<'a> RegistryQueryer<'a> {
/// next obvious question.
pub fn build_deps(
&mut self,
cx: &Context,
parent: Option<PackageId>,
candidate: &Summary,
opts: &ResolveOpts,
@ -222,9 +225,9 @@ impl<'a> RegistryQueryer<'a> {
.map(|(dep, features)| {
let candidates = self.query(&dep).chain_err(|| {
anyhow::format_err!(
"failed to get `{}` as a dependency of `{}`",
"failed to get `{}` as a dependency of {}",
dep.package_name(),
candidate.package_id(),
describe_path(&cx.parents.path_to_bottom(&candidate.package_id())),
)
})?;
Ok((dep, candidates, features))

View File

@ -656,7 +656,7 @@ fn activate(
let now = Instant::now();
let (used_features, deps) =
&*registry.build_deps(parent.map(|p| p.0.package_id()), &candidate, &opts)?;
&*registry.build_deps(cx, parent.map(|p| p.0.package_id()), &candidate, &opts)?;
// Record what list of features is active for this package.
if !used_features.is_empty() {

View File

@ -368,7 +368,7 @@ fn bad_git_dependency() {
.with_stderr(
"\
[UPDATING] git repository `file:///`
[ERROR] failed to get `foo` as a dependency of `foo v0.0.0 [..]`
[ERROR] failed to get `foo` as a dependency of package `foo v0.0.0 [..]`
Caused by:
failed to load source for dependency `foo`
@ -904,7 +904,7 @@ fn bad_source_config2() {
.with_status(101)
.with_stderr(
"\
[ERROR] failed to get `bar` as a dependency of `foo v0.0.0 [..]`
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.0 [..]`
Caused by:
failed to load source for dependency `bar`
@ -950,7 +950,7 @@ fn bad_source_config3() {
.with_status(101)
.with_stderr(
"\
[ERROR] failed to get `bar` as a dependency of `foo v0.0.0 [..]`
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.0 [..]`
Caused by:
failed to load source for dependency `bar`
@ -998,7 +998,7 @@ fn bad_source_config4() {
.with_status(101)
.with_stderr(
"\
[ERROR] failed to get `bar` as a dependency of `foo v0.0.0 ([..])`
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.0 ([..])`
Caused by:
failed to load source for dependency `bar`

View File

@ -199,7 +199,7 @@ fn nightly_feature_requires_nightly_in_dep() {
.with_status(101)
.with_stderr(
"\
[ERROR] failed to get `a` as a dependency of `b v0.0.1 ([..])`
[ERROR] failed to get `a` as a dependency of package `b v0.0.1 ([..])`
Caused by:
failed to load source for dependency `a`

View File

@ -652,7 +652,7 @@ fn git_override_requires_lockfile() {
.with_status(101)
.with_stderr(
"\
[ERROR] failed to get `git` as a dependency of `foo v0.0.1 ([..])`
[ERROR] failed to get `git` as a dependency of package `foo v0.0.1 ([..])`
Caused by:
failed to load source for dependency `git`

View File

@ -931,7 +931,7 @@ fn dep_with_bad_submodule() {
let expected = format!(
"\
[UPDATING] git repository [..]
[ERROR] failed to get `dep1` as a dependency of `foo v0.5.0 [..]`
[ERROR] failed to get `dep1` as a dependency of package `foo v0.5.0 [..]`
Caused by:
failed to load source for dependency `dep1`
@ -2387,7 +2387,7 @@ fn invalid_git_dependency_manifest() {
.with_stderr(&format!(
"\
[UPDATING] git repository `{}`
[ERROR] failed to get `dep1` as a dependency of `foo v0.5.0 ([..])`
[ERROR] failed to get `dep1` as a dependency of package `foo v0.5.0 ([..])`
Caused by:
failed to load source for dependency `dep1`

View File

@ -133,7 +133,7 @@ fn http_auth_offered() {
.with_stderr_contains(&format!(
"\
[UPDATING] git repository `http://{addr}/foo/bar`
[ERROR] failed to get `bar` as a dependency of `foo v0.0.1 [..]`
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 [..]`
Caused by:
failed to load source for dependency `bar`

View File

@ -360,7 +360,7 @@ fn invalid_dir_bad() {
.with_status(101)
.with_stderr(
"\
[ERROR] failed to get `bar` as a dependency of `foo v0.0.1 [..]`
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 [..]`
Caused by:
failed to load source for dependency `bar`

View File

@ -270,7 +270,7 @@ fn cargo_compile_forbird_git_httpsrepo_offline() {
.build();
p.cargo("build --offline").with_status(101).with_stderr("\
[ERROR] failed to get `dep1` as a dependency of `foo v0.5.0 [..]`
[ERROR] failed to get `dep1` as a dependency of package `foo v0.5.0 [..]`
Caused by:
failed to load source for dependency `dep1`

View File

@ -521,7 +521,7 @@ fn error_message_for_missing_manifest() {
.with_status(101)
.with_stderr(
"\
[ERROR] failed to get `bar` as a dependency of `foo v0.5.0 [..]`
[ERROR] failed to get `bar` as a dependency of package `foo v0.5.0 [..]`
Caused by:
failed to load source for dependency `bar`
@ -1020,3 +1020,66 @@ fn workspace_produces_rlib() {
assert!(p.root().join("target/debug/libtop.rlib").is_file());
assert!(!p.root().join("target/debug/libfoo.rlib").is_file());
}
#[cargo_test]
fn deep_path_error() {
// Test for an error loading a path deep in the dependency graph.
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
[dependencies]
a = {path="a"}
"#,
)
.file("src/lib.rs", "")
.file(
"a/Cargo.toml",
r#"
[package]
name = "a"
version = "0.1.0"
[dependencies]
b = {path="../b"}
"#,
)
.file("a/src/lib.rs", "")
.file(
"b/Cargo.toml",
r#"
[package]
name = "b"
version = "0.1.0"
[dependencies]
c = {path="../c"}
"#,
)
.file("b/src/lib.rs", "")
.build();
p.cargo("check")
.with_status(101)
.with_stderr(
"\
[ERROR] failed to get `c` as a dependency of package `b v0.1.0 [..]`
... which is depended on by `a v0.1.0 [..]`
... which is depended on by `foo v0.1.0 [..]`
Caused by:
failed to load source for dependency `c`
Caused by:
Unable to update [..]/foo/c
Caused by:
failed to read `[..]/foo/c/Cargo.toml`
Caused by:
[..]
",
)
.run();
}

View File

@ -1558,7 +1558,7 @@ fn disallow_network() {
.with_status(101)
.with_stderr(
"\
[ERROR] failed to get `foo` as a dependency of `bar v0.5.0 [..]`
[ERROR] failed to get `foo` as a dependency of package `bar v0.5.0 [..]`
Caused by:
failed to load source for dependency `foo`

View File

@ -544,7 +544,7 @@ fn override_wrong_name() {
"\
[UPDATING] [..] index
[UPDATING] git repository [..]
[ERROR] failed to get `baz` as a dependency of `foo v0.0.1 ([..])`
[ERROR] failed to get `baz` as a dependency of package `foo v0.0.1 ([..])`
Caused by:
no matching package for override `[..]baz:0.1.0` found
@ -591,7 +591,7 @@ fn override_with_nothing() {
"\
[UPDATING] [..] index
[UPDATING] git repository [..]
[ERROR] failed to get `bar` as a dependency of `foo v0.0.1 ([..])`
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([..])`
Caused by:
failed to load source for dependency `bar`
@ -677,7 +677,7 @@ fn multiple_specs() {
"\
[UPDATING] [..] index
[UPDATING] git repository [..]
[ERROR] failed to get `bar` as a dependency of `foo v0.0.1 ([..])`
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([..])`
Caused by:
overlapping replacement specifications found:

View File

@ -2223,7 +2223,7 @@ fn invalid_missing() {
.with_status(101)
.with_stderr(
"\
[ERROR] failed to get `x` as a dependency of `foo v0.1.0 [..]`
[ERROR] failed to get `x` as a dependency of package `foo v0.1.0 [..]`
Caused by:
failed to load source for dependency `x`