From 9e027c0aa2cd9a8c8f52996c9f4fe247e1e4c360 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sat, 8 Apr 2023 12:07:16 +0900 Subject: [PATCH] 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. --- build.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 5549e3cf9..15469379c 100644 --- a/build.rs +++ b/build.rs @@ -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 { 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()); } }