diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-03-21 23:39:09 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-03-21 23:39:40 +0100 |
| commit | a6b63b96f9a5f07dabbe195b16d00d778d3246ff (patch) | |
| tree | 8ffacc8d1797a77bf1f3c9be13619cf192f7f4f2 /cli/build.rs | |
| parent | b934a2fd83d63fc115c01f959e888c7bc1aa87e4 (diff) | |
Fail gracefully if `git` does not exist
Diffstat (limited to 'cli/build.rs')
| -rw-r--r-- | cli/build.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/cli/build.rs b/cli/build.rs index f7b70e7f..afaed657 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -1,9 +1,11 @@ -use std::error::Error; use std::process::Command; -fn main() -> Result<(), Box<dyn Error>> { - let output = Command::new("git").args(&["rev-parse", "HEAD"]).output()?; - let hash = std::str::from_utf8(&output.stdout)?; - println!("cargo:rustc-env=TYPST_HASH={}", &hash[..8]); - Ok(()) +fn main() { + let version = Command::new("git") + .args(&["rev-parse", "HEAD"]) + .output() + .ok() + .and_then(|output| String::from_utf8(output.stdout[..8].into()).ok()) + .unwrap_or_else(|| "(unknown version)".into()); + println!("cargo:rustc-env=TYPST_VERSION={version}"); } |
