Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject manifest with duplicate dependencies in different targets #2491

Merged
merged 1 commit into from
Mar 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/cargo/util/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,18 @@ impl TomlManifest {
}
}

{
let mut names_sources = HashMap::new();
for dep in deps.iter() {
let name = dep.name();
let prev = names_sources.insert(name, dep.source_id());
if prev.is_some() && prev != Some(dep.source_id()) {
bail!("found duplicate dependency name {}, but all \
dependencies must have a unique name", name);
}
}
}

let exclude = project.exclude.clone().unwrap_or(Vec::new());
let include = project.include.clone().unwrap_or(Vec::new());

Expand Down
44 changes: 44 additions & 0 deletions tests/test_bad_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,50 @@ Caused by:
error = ERROR)));
});

test!(duplicate_deps {
let foo = project("foo")
.file("shim-bar/Cargo.toml", r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
"#)
.file("shim-bar/src/lib.rs", r#"
pub fn a() {}
"#)
.file("linux-bar/Cargo.toml", r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
"#)
.file("linux-bar/src/lib.rs", r#"
pub fn a() {}
"#)
.file("Cargo.toml", r#"
[package]
name = "qqq"
version = "0.0.1"
authors = []

[dependencies]
bar = { path = "shim-bar" }

[target.x86_64-unknown-linux-gnu.dependencies]
bar = { path = "linux-bar" }
"#)
.file("src/main.rs", r#"fn main () {}"#);

assert_that(foo.cargo_process("build"),
execs().with_status(101).with_stderr(&format!("\
{error} failed to parse manifest at `[..]`

Caused by:
found duplicate dependency name bar, but all dependencies must have a unique name
",
error = ERROR)));
});

test!(unused_keys {
let foo = project("foo")
.file("Cargo.toml", r#"
Expand Down