From a6b63b96f9a5f07dabbe195b16d00d778d3246ff Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 21 Mar 2023 23:39:09 +0100 Subject: [PATCH] Fail gracefully if `git` does not exist --- cli/build.rs | 14 ++++++++------ cli/src/main.rs | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cli/build.rs b/cli/build.rs index f7b70e7f8..afaed6578 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> { - 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}"); } diff --git a/cli/src/main.rs b/cli/src/main.rs index 3f41ac782..dfb13aaa1 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -156,7 +156,7 @@ fn print_help(help: &'static str) -> ! { /// Print the version hash and quit. fn print_version() -> ! { - println!("typst {}", env!("TYPST_HASH")); + println!("typst {}", env!("TYPST_VERSION")); std::process::exit(0); }