Skip to content

Commit

Permalink
Auto merge of #2723 - alexcrichton:override-errors, r=wycats
Browse files Browse the repository at this point in the history
Don't throw away errors with `-p` arguments

This was unfortunately ignoring errors which would helpfully tell you how to
rerun a command with a more precise specification.

Closes #2641
  • Loading branch information
bors committed May 20, 2016
2 parents 235e2c2 + ab9f64d commit f13ca72
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 19 deletions.
20 changes: 6 additions & 14 deletions src/cargo/ops/cargo_compile.rs
Expand Up @@ -167,23 +167,15 @@ pub fn compile_pkg<'a>(root_package: &Package,
no_default_features))
};

let mut invalid_spec = vec![];
let pkgids = if spec.len() > 0 {
spec.iter().filter_map(|p| {
match resolve_with_overrides.query(&p) {
Ok(p) => Some(p),
Err(..) => { invalid_spec.push(p.to_string()); None }
}
}).collect::<Vec<_>>()
let mut pkgids = Vec::new();
if spec.len() > 0 {
for p in spec {
pkgids.push(try!(resolve_with_overrides.query(&p)));
}
} else {
vec![root_package.package_id()]
pkgids.push(root_package.package_id());
};

if !spec.is_empty() && !invalid_spec.is_empty() {
bail!("could not find package matching spec `{}`",
invalid_spec.join(", "))
}

let to_builds = try!(pkgids.iter().map(|id| {
packages.get(id)
}).collect::<CargoResult<Vec<_>>>());
Expand Down
11 changes: 6 additions & 5 deletions tests/test_cargo_compile.rs
Expand Up @@ -2107,13 +2107,14 @@ test!(invalid_spec {
p.build();

assert_that(p.cargo_process("build").arg("-p").arg("notAValidDep"),
execs().with_status(101).with_stderr(&format!(
"[ERROR] could not find package matching spec `notAValidDep`")));
execs().with_status(101).with_stderr("\
[ERROR] package id specification `notAValidDep` matched no packages
"));

assert_that(p.cargo_process("build").arg("-p").arg("d1").arg("-p").arg("notAValidDep"),
execs().with_status(101).with_stderr(&format!(
"[ERROR] could not find package matching spec `notAValidDep`")));

execs().with_status(101).with_stderr("\
[ERROR] package id specification `notAValidDep` matched no packages
"));
});

test!(manifest_with_bom_is_ok {
Expand Down
38 changes: 38 additions & 0 deletions tests/test_cargo_overrides.rs
Expand Up @@ -526,3 +526,41 @@ error: overlapping replacement specifications found:
both specifications match: foo v0.1.0 ([..])
"));
});

test!(test_override_dep {
Package::new("foo", "0.1.0").publish();

let foo = git::repo(&paths::root().join("override"))
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.1.0"
authors = []
"#)
.file("src/lib.rs", "pub fn foo() {}");
foo.build();

let p = project("local")
.file("Cargo.toml", &format!(r#"
[package]
name = "local"
version = "0.0.1"
authors = []
[dependencies]
foo = "0.1.0"
[replace]
"foo:0.1.0" = {{ git = '{0}' }}
"#, foo.url()))
.file("src/lib.rs", "");

assert_that(p.cargo_process("test").arg("-p").arg("foo"),
execs().with_status(101)
.with_stderr_contains("\
error: There are multiple `foo` packages in your project, and the [..]
Please re-run this command with [..]
[..]#foo:0.1.0
[..]#foo:0.1.0
"));
});

0 comments on commit f13ca72

Please sign in to comment.