Skip to content

Commit c7abd4a

Browse files
committed
Extend the build directive syntax with cargo::metadata=
1 parent c9b89c6 commit c7abd4a

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

src/cargo/core/compiler/custom_build.rs

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -643,28 +643,55 @@ impl BuildOutput {
643643
Ok(line) => line.trim(),
644644
Err(..) => continue,
645645
};
646-
let mut iter = line.splitn(2, ':');
646+
let mut new_syntax = true;
647+
let mut iter = line.splitn(2, "::");
647648
if iter.next() != Some("cargo") {
648-
// skip this line since it doesn't start with "cargo:"
649-
continue;
649+
// For backwards compatibility, we also accept lines that start with "cargo:".
650+
new_syntax = false;
651+
iter = line.splitn(2, ":");
652+
if iter.next() != Some("cargo") {
653+
// skip this line since it doesn't start with "cargo:" or "cargo::".
654+
continue;
655+
}
650656
}
651657
let data = match iter.next() {
652658
Some(val) => val,
653659
None => continue,
654660
};
655661

656-
// getting the `key=value` part of the line
657-
let mut iter = data.splitn(2, '=');
662+
// getting the `key=value` part of the line]
663+
let n = if new_syntax {
664+
// cargo::metadata=key=value
665+
3
666+
} else {
667+
// cargo:key=value
668+
2
669+
};
670+
let mut iter = data.splitn(n, '=');
671+
if new_syntax {
672+
if iter.next() != Some("metadata") {
673+
// skip this line since it doesn't start with "cargo::metadata=".
674+
bail!("invalid output in {}: `{}`\n\
675+
Expected a line with `cargo::metadata=key=value` but it did not start with `cargo::metadata=`.\n\
676+
See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
677+
for more information about build script outputs.", whence, line);
678+
}
679+
}
658680
let key = iter.next();
659681
let value = iter.next();
660682
let (key, value) = match (key, value) {
661683
(Some(a), Some(b)) => (a, b.trim_end()),
662-
// Line started with `cargo:` but didn't match `key=value`.
684+
// Line started with `cargo:` or `cargo::metadata=` but didn't match `key=value`.
663685
_ => bail!("invalid output in {}: `{}`\n\
664-
Expected a line with `cargo:key=value` with an `=` character, \
665-
but none was found.\n\
686+
Expected a line with `{}` but it did not match `key=value`.\n\
666687
See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
667-
for more information about build script outputs.", whence, line),
688+
for more information about build script outputs.", whence, line,
689+
if new_syntax {
690+
"cargo::metadata=key=value"
691+
} else {
692+
"cargo:key=value"
693+
}
694+
),
668695
};
669696

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

0 commit comments

Comments
 (0)