Skip to content

Commit f7ca659

Browse files
committed
Auto merge of #9905 - ehuss:wrong-output-error, r=alexcrichton
Improve "wrong output" error. The error message for an improperly formatted build script output was a bit abrupt and unhelpful. This adds some more details to the error message.
2 parents 70967da + c4e92ac commit f7ca659

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/cargo/core/compiler/custom_build.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,11 @@ impl BuildOutput {
566566
let (key, value) = match (key, value) {
567567
(Some(a), Some(b)) => (a, b.trim_end()),
568568
// Line started with `cargo:` but didn't match `key=value`.
569-
_ => bail!("Wrong output in {}: `{}`", whence, line),
569+
_ => bail!("invalid output in {}: `{}`\n\
570+
Expected a line with `cargo:key=value` with an `=` character, \
571+
but none was found.\n\
572+
See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
573+
for more information about build script outputs.", whence, line),
570574
};
571575

572576
// This will rewrite paths if the target directory has been moved.

tests/testsuite/build_script.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4942,3 +4942,31 @@ fn duplicate_script_with_extra_env() {
49424942
.run();
49434943
}
49444944
}
4945+
4946+
#[cargo_test]
4947+
fn wrong_output() {
4948+
let p = project()
4949+
.file("src/lib.rs", "")
4950+
.file(
4951+
"build.rs",
4952+
r#"
4953+
fn main() {
4954+
println!("cargo:example");
4955+
}
4956+
"#,
4957+
)
4958+
.build();
4959+
4960+
p.cargo("build")
4961+
.with_status(101)
4962+
.with_stderr(
4963+
"\
4964+
[COMPILING] foo [..]
4965+
error: invalid output in build script of `foo v0.0.1 ([ROOT]/foo)`: `cargo:example`
4966+
Expected a line with `cargo:key=value` with an `=` character, but none was found.
4967+
See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
4968+
for more information about build script outputs.
4969+
",
4970+
)
4971+
.run();
4972+
}

0 commit comments

Comments
 (0)