Permalink
Browse files
Auto merge of #4054 - alexcrichton:beta-next, r=alexcrichton
[beta] Change inferring bin's name logic
This is a backport of #4046
- Loading branch information...
Showing
with
78 additions
and
2 deletions.
-
+16
−2
src/cargo/util/toml.rs
-
+62
−0
tests/build.rs
|
|
@@ -1431,11 +1431,25 @@ fn inferred_bin_path(bin: &TomlBinTarget, |
|
|
|
} |
|
|
|
|
|
|
|
return Path::new("src").join("bin").join(&format!("main.rs")).to_path_buf() |
|
|
|
} |
|
|
|
|
|
|
|
// bin_len > 1 |
|
|
|
let path = Path::new("src").join("bin").join(&format!("{}.rs", bin.name())); |
|
|
|
if package_root.join(&path).exists() { |
|
|
|
return path.to_path_buf() |
|
|
|
} |
|
|
|
|
|
|
|
let path = Path::new("src").join(&format!("{}.rs", bin.name())); |
|
|
|
if package_root.join(&path).exists() { |
|
|
|
return path.to_path_buf() |
|
|
|
} |
|
|
|
|
|
|
|
let path = Path::new("src").join("bin").join(&format!("main.rs")); |
|
|
|
if package_root.join(&path).exists() { |
|
|
|
return path.to_path_buf() |
|
|
|
} |
|
|
|
|
|
|
|
// here we have multiple bins, so they are expected to be located inside src/bin |
|
|
|
Path::new("src").join("bin").join(&format!("{}.rs", bin.name())).to_path_buf() |
|
|
|
return Path::new("src").join(&format!("main.rs")).to_path_buf() |
|
|
|
} |
|
|
|
|
|
|
|
fn build_profiles(profiles: &Option<TomlProfiles>) -> Profiles { |
|
|
|
|
|
@@ -2870,6 +2870,68 @@ fn run_proper_binary_main_rs() { |
|
|
|
execs().with_status(0)); |
|
|
|
} |
|
|
|
|
|
|
|
#[test] |
|
|
|
fn run_proper_alias_binary_from_src() { |
|
|
|
let p = project("foo") |
|
|
|
.file("Cargo.toml", r#" |
|
|
|
[package] |
|
|
|
name = "foo" |
|
|
|
authors = [] |
|
|
|
version = "0.0.0" |
|
|
|
[[bin]] |
|
|
|
name = "foo" |
|
|
|
[[bin]] |
|
|
|
name = "bar" |
|
|
|
"#) |
|
|
|
.file("src/foo.rs", r#" |
|
|
|
fn main() { |
|
|
|
println!("foo"); |
|
|
|
} |
|
|
|
"#).file("src/bar.rs", r#" |
|
|
|
fn main() { |
|
|
|
println!("bar"); |
|
|
|
} |
|
|
|
"#); |
|
|
|
|
|
|
|
assert_that(p.cargo_process("build") |
|
|
|
.arg("--all"), |
|
|
|
execs().with_status(0) |
|
|
|
); |
|
|
|
assert_that(process(&p.bin("foo")), |
|
|
|
execs().with_status(0).with_stdout("foo\n")); |
|
|
|
assert_that(process(&p.bin("bar")), |
|
|
|
execs().with_status(0).with_stdout("bar\n")); |
|
|
|
} |
|
|
|
|
|
|
|
#[test] |
|
|
|
fn run_proper_alias_binary_main_rs() { |
|
|
|
let p = project("foo") |
|
|
|
.file("Cargo.toml", r#" |
|
|
|
[package] |
|
|
|
name = "foo" |
|
|
|
authors = [] |
|
|
|
version = "0.0.0" |
|
|
|
[[bin]] |
|
|
|
name = "foo" |
|
|
|
[[bin]] |
|
|
|
name = "bar" |
|
|
|
"#) |
|
|
|
.file("src/main.rs", r#" |
|
|
|
fn main() { |
|
|
|
println!("main"); |
|
|
|
} |
|
|
|
"#); |
|
|
|
|
|
|
|
assert_that(p.cargo_process("build") |
|
|
|
.arg("--all"), |
|
|
|
execs().with_status(0) |
|
|
|
); |
|
|
|
assert_that(process(&p.bin("foo")), |
|
|
|
execs().with_status(0).with_stdout("main\n")); |
|
|
|
assert_that(process(&p.bin("bar")), |
|
|
|
execs().with_status(0).with_stdout("main\n")); |
|
|
|
} |
|
|
|
|
|
|
|
#[test] |
|
|
|
fn run_proper_binary_main_rs_as_foo() { |
|
|
|
let p = project("foo") |
|
|
|
0 comments on commit
28d1d60