mirror of
https://github.com/rust-lang/cargo
synced 2024-10-13 03:02:45 +00:00
Add parse_metadata to prase metadata
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
This commit is contained in:
parent
9ebe3b332a
commit
56fdb1d0b6
|
@ -734,6 +734,25 @@ impl BuildOutput {
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_metadata<'a>(
|
||||
whence: &str,
|
||||
line: &str,
|
||||
data: &'a str,
|
||||
) -> CargoResult<(&'a str, &'a str)> {
|
||||
let mut iter = data.splitn(2, "=");
|
||||
let key = iter.next();
|
||||
let value = iter.next();
|
||||
match (key, value) {
|
||||
(Some(a), Some(b)) => Ok((a, b.trim_end())),
|
||||
_ => bail!(
|
||||
"invalid output in {whence}: `{line}`\n\
|
||||
Expected a line with `cargo::metadata=KEY=VALUE` with an `=` character, \
|
||||
but none was found.\n\
|
||||
{DOCS_LINK_SUGGESTION}",
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
for line in input.split(|b| *b == b'\n') {
|
||||
let line = match str::from_utf8(line) {
|
||||
Ok(line) => line.trim(),
|
||||
|
@ -910,7 +929,7 @@ impl BuildOutput {
|
|||
"rerun-if-changed" => rerun_if_changed.push(PathBuf::from(value)),
|
||||
"rerun-if-env-changed" => rerun_if_env_changed.push(value.to_string()),
|
||||
"metadata" => {
|
||||
let (key, value) = parse_directive(whence.as_str(), line, &value)?;
|
||||
let (key, value) = parse_metadata(whence.as_str(), line, &value)?;
|
||||
metadata.push((key.to_owned(), value.to_owned()));
|
||||
}
|
||||
_ => bail!(
|
||||
|
|
|
@ -5169,7 +5169,7 @@ fn wrong_output() {
|
|||
"\
|
||||
[COMPILING] foo [..]
|
||||
error: invalid output in build script of `foo v0.0.1 ([ROOT]/foo)`: `cargo:example`
|
||||
Expected a line with `cargo::KEY=VALUE` with an `=` character, but none was found.
|
||||
Expected a line with `cargo::metadata=KEY=VALUE` with an `=` character, but none was found.
|
||||
See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
|
||||
for more information about build script outputs.
|
||||
",
|
||||
|
|
Loading…
Reference in a new issue