Skip to content

Commit 56fdb1d

Browse files
committed
Add parse_metadata to prase metadata
Signed-off-by: hi-rustin <[email protected]>
1 parent 9ebe3b3 commit 56fdb1d

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/cargo/core/compiler/custom_build.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,25 @@ impl BuildOutput {
734734
}
735735
}
736736

737+
fn parse_metadata<'a>(
738+
whence: &str,
739+
line: &str,
740+
data: &'a str,
741+
) -> CargoResult<(&'a str, &'a str)> {
742+
let mut iter = data.splitn(2, "=");
743+
let key = iter.next();
744+
let value = iter.next();
745+
match (key, value) {
746+
(Some(a), Some(b)) => Ok((a, b.trim_end())),
747+
_ => bail!(
748+
"invalid output in {whence}: `{line}`\n\
749+
Expected a line with `cargo::metadata=KEY=VALUE` with an `=` character, \
750+
but none was found.\n\
751+
{DOCS_LINK_SUGGESTION}",
752+
),
753+
}
754+
}
755+
737756
for line in input.split(|b| *b == b'\n') {
738757
let line = match str::from_utf8(line) {
739758
Ok(line) => line.trim(),
@@ -910,7 +929,7 @@ impl BuildOutput {
910929
"rerun-if-changed" => rerun_if_changed.push(PathBuf::from(value)),
911930
"rerun-if-env-changed" => rerun_if_env_changed.push(value.to_string()),
912931
"metadata" => {
913-
let (key, value) = parse_directive(whence.as_str(), line, &value)?;
932+
let (key, value) = parse_metadata(whence.as_str(), line, &value)?;
914933
metadata.push((key.to_owned(), value.to_owned()));
915934
}
916935
_ => bail!(

tests/testsuite/build_script.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5169,7 +5169,7 @@ fn wrong_output() {
51695169
"\
51705170
[COMPILING] foo [..]
51715171
error: invalid output in build script of `foo v0.0.1 ([ROOT]/foo)`: `cargo:example`
5172-
Expected a line with `cargo::KEY=VALUE` with an `=` character, but none was found.
5172+
Expected a line with `cargo::metadata=KEY=VALUE` with an `=` character, but none was found.
51735173
See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
51745174
for more information about build script outputs.
51755175
",

0 commit comments

Comments
 (0)