Blacklist binary target names

Some binary targets caused problems as
the directory names exist in target/debug. When
the compilation step fails, the error
message was also not descriptive.

This commit adds a blacklist and a more
descriptive error message.

See #1618.
This commit is contained in:
Yoong Kang Lim 2015-06-03 23:35:44 +10:00
parent 69c2af26cf
commit 82aeaf744a
2 changed files with 32 additions and 0 deletions

View file

@ -423,6 +423,15 @@ impl TomlManifest {
None => inferred_bin_targets(&project.name, layout)
};
let blacklist = vec!["build", "deps", "examples", "native"];
for bin in bins.iter() {
if blacklist.iter().find(|&x| *x == bin.name) != None {
return Err(human(&format!("the binary target name `{}` is forbidden",
bin.name)));
}
}
let examples = match self.example {
Some(ref examples) => examples.clone(),
None => inferred_example_targets(layout),

View file

@ -158,6 +158,29 @@ Caused by:
"))
});
test!(cargo_compile_with_forbidden_bin_target_name {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
authors = []
version = "0.0.0"
[[bin]]
name = "build"
"#);
assert_that(p.cargo_process("build"),
execs()
.with_status(101)
.with_stderr("\
failed to parse manifest at `[..]`
Caused by:
the binary target name `build` is forbidden
"))
});
test!(cargo_compile_with_invalid_lib_target_name {
let p = project("foo")
.file("Cargo.toml", r#"