1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2025-10-06 05:36:58 +02:00

build: emit warning if git is missing during build

Closes #3057
This commit is contained in:
kevichi7
2025-05-29 20:33:35 +08:00
committed by Andrew Gallant
parent 2ebd768d40
commit 00e501b529

View File

@@ -37,10 +37,25 @@ fn set_git_revision_hash() {
use std::process::Command;
let args = &["rev-parse", "--short=10", "HEAD"];
let Ok(output) = Command::new("git").args(args).output() else { return };
let rev = String::from_utf8_lossy(&output.stdout).trim().to_string();
if rev.is_empty() {
return;
let output = Command::new("git").args(args).output();
match output {
Ok(output) => {
let rev =
String::from_utf8_lossy(&output.stdout).trim().to_string();
if rev.is_empty() {
println!(
"cargo:warning=output from `git rev-parse` is empty, \
so skipping embedding of commit hash"
);
return;
}
println!("cargo:rustc-env=RIPGREP_BUILD_GIT_HASH={rev}");
}
Err(e) => {
println!(
"cargo:warning=failed to run `git rev-parse`, \
so skipping embedding of commit hash: {e}"
);
}
}
println!("cargo:rustc-env=RIPGREP_BUILD_GIT_HASH={rev}");
}