build: strip newline from "git rev-parse" output

It works because a build command is line oriented, but it's technically
wrong to include "\n" in git_hash.
This commit is contained in:
Yuya Nishihara 2023-04-08 12:07:16 +09:00
parent 7a8903e5e7
commit 9e027c0aa2

View file

@ -13,6 +13,7 @@
// limitations under the License.
use std::process::Command;
use std::str;
use cargo_metadata::MetadataCommand;
@ -56,7 +57,8 @@ fn get_git_hash() -> Option<String> {
if let Ok(output) = Command::new("git").args(["rev-parse", "HEAD"]).output() {
if output.status.success() {
println!("cargo:rerun-if-changed=.git/HEAD");
return Some(String::from_utf8(output.stdout).unwrap());
let line = str::from_utf8(&output.stdout).unwrap();
return Some(line.trim_end().to_owned());
}
}