mirror of
https://github.com/irlserver/srtla_send.git
synced 2026-07-04 14:46:45 +00:00
49 lines
1.5 KiB
Rust
49 lines
1.5 KiB
Rust
use std::process::Command;
|
|
|
|
fn main() {
|
|
// Get git commit hash
|
|
let git_hash = Command::new("git")
|
|
.args(["rev-parse", "--short", "HEAD"])
|
|
.output()
|
|
.ok()
|
|
.and_then(|output| {
|
|
if output.status.success() {
|
|
Some(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
|
} else {
|
|
None
|
|
}
|
|
})
|
|
.unwrap_or_else(|| "unknown".to_string());
|
|
|
|
// Get git branch
|
|
let git_branch = Command::new("git")
|
|
.args(["rev-parse", "--abbrev-ref", "HEAD"])
|
|
.output()
|
|
.ok()
|
|
.and_then(|output| {
|
|
if output.status.success() {
|
|
Some(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
|
} else {
|
|
None
|
|
}
|
|
})
|
|
.unwrap_or_else(|| "unknown".to_string());
|
|
|
|
// Check if working directory is dirty
|
|
let git_dirty = Command::new("git")
|
|
.args(["diff", "--quiet"])
|
|
.status()
|
|
.map(|status| !status.success())
|
|
.unwrap_or(false);
|
|
|
|
let git_dirty_suffix = if git_dirty { "-dirty" } else { "" };
|
|
|
|
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
|
|
println!("cargo:rustc-env=GIT_BRANCH={}", git_branch);
|
|
println!("cargo:rustc-env=GIT_DIRTY={}", git_dirty_suffix);
|
|
|
|
// Tell Cargo to re-run this build script if git files change
|
|
println!("cargo:rerun-if-changed=.git/HEAD");
|
|
println!("cargo:rerun-if-changed=.git/refs/heads");
|
|
}
|