Skip to content

Commit 350bd8d

Browse files
committed
Don't intermingle targets between packages
When loading targets to compile, be sure to use the targets from the package that's being passed down to the compilation step, not the one that was passed in which is overridden. Closes #1404
1 parent 66849de commit 350bd8d

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/cargo/ops/cargo_compile.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,11 @@ pub fn compile_pkg(package: &Package, options: &CompileOptions)
131131
(packages, resolved_with_overrides, registry.move_sources())
132132
};
133133

134-
let to_build = match spec {
135-
Some(spec) => {
136-
let pkgid = try!(resolve_with_overrides.query(spec));
137-
packages.iter().find(|p| p.package_id() == pkgid).unwrap()
138-
}
139-
None => package,
134+
let pkgid = match spec {
135+
Some(spec) => try!(resolve_with_overrides.query(spec)),
136+
None => package.package_id(),
140137
};
141-
138+
let to_build = packages.iter().find(|p| p.package_id() == pkgid).unwrap();
142139
let targets = to_build.targets().iter().filter(|target| {
143140
target.profile().is_custom_build() || match env {
144141
// doc-all == document everything, so look for doc targets

tests/test_cargo_package.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,21 @@ test!(include {
244244
{archiving} [..]
245245
", packaging = PACKAGING, archiving = ARCHIVING).as_slice()));
246246
});
247+
248+
test!(package_lib_with_bin {
249+
let p = project("foo")
250+
.file("Cargo.toml", r#"
251+
[project]
252+
name = "foo"
253+
version = "0.0.1"
254+
authors = []
255+
"#)
256+
.file("src/main.rs", r#"
257+
extern crate foo;
258+
fn main() {}
259+
"#)
260+
.file("src/lib.rs", "");
261+
262+
assert_that(p.cargo_process("package").arg("-v"),
263+
execs().with_status(0));
264+
});

0 commit comments

Comments
 (0)