Make cargo:rustc-link-arg-bin without the = an error.

This commit is contained in:
Eric Huss 2021-05-29 16:12:11 -07:00
parent f676b49e52
commit 836e537bc0
2 changed files with 42 additions and 22 deletions

View File

@ -599,29 +599,32 @@ impl BuildOutput {
}
"rustc-link-arg-bin" => {
if extra_link_arg {
let parts = value.splitn(2, "=").collect::<Vec<_>>();
if parts.len() == 2 {
let bin_name = parts[0].to_string();
if !targets
.iter()
.any(|target| target.is_bin() && target.name() == bin_name)
{
bail!(
"invalid instruction `cargo:{}` from {}\n\
The package {} does not have a bin target with the name `{}`.",
key,
whence,
pkg_descr,
bin_name
);
}
linker_args.push((LinkType::SingleBin(bin_name), parts[1].to_string()));
} else {
warnings.push(format!(
"cargo:{} has invalid syntax: expected `cargo:{}=BIN=ARG`",
key, key
));
let mut parts = value.splitn(2, '=');
let bin_name = parts.next().unwrap().to_string();
let arg = parts.next().ok_or_else(|| {
anyhow::format_err!(
"invalid instruction `cargo:{}={}` from {}\n\
The instruction should have the form cargo:{}=BIN=ARG",
key,
value,
whence,
key
)
})?;
if !targets
.iter()
.any(|target| target.is_bin() && target.name() == bin_name)
{
bail!(
"invalid instruction `cargo:{}` from {}\n\
The package {} does not have a bin target with the name `{}`.",
key,
whence,
pkg_descr,
bin_name
);
}
linker_args.push((LinkType::SingleBin(bin_name), arg.to_string()));
} else {
warnings.push(format!("cargo:{} requires -Zextra-link-arg flag", key));
}

View File

@ -162,6 +162,23 @@ The package foo v0.0.1 ([ROOT]/foo) does not have a bin target.
[COMPILING] foo [..]
error: invalid instruction `cargo:rustc-link-arg-bin` from build script of `foo v0.0.1 ([ROOT]/foo)`
The package foo v0.0.1 ([ROOT]/foo) does not have a bin target with the name `abc`.
",
)
.run();
p.change_file(
"build.rs",
r#"fn main() { println!("cargo:rustc-link-arg-bin=abc"); }"#,
);
p.cargo("check -Zextra-link-arg")
.masquerade_as_nightly_cargo()
.with_status(101)
.with_stderr(
"\
[COMPILING] foo [..]
error: invalid instruction `cargo:rustc-link-arg-bin=abc` from build script of `foo v0.0.1 ([ROOT]/foo)`
The instruction should have the form cargo:rustc-link-arg-bin=BIN=ARG
",
)
.run();