Description: Make GIT_HASH optional for long version
Author: Abhinaba Rakshit <abhinaba.rakshit@oss.qualcomm.com>
Origin: upstream, https://github.com/quic/mink-idl-compiler/pull/33
Bug: https://github.com/quic/mink-idl-compiler/issues/32
Forwarded: https://github.com/quic/mink-idl-compiler/pull/33
Last-Update: 2026-04-23
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
Index: mink-idl-compiler/idlc/build.rs
===================================================================
--- mink-idl-compiler.orig/idlc/build.rs
+++ mink-idl-compiler/idlc/build.rs
@@ -6,8 +6,14 @@ use std::process::Command;
 pub fn main() {
     let output = Command::new("git")
         .args(["describe", "--always", "--abbrev=40", "--dirty"])
-        .output()
-        .unwrap();
-    let git_hash = std::str::from_utf8(&output.stdout).unwrap();
+        .output();
+
+    let git_hash = match output {
+        Ok(output) if output.status.success() => {
+            std::str::from_utf8(&output.stdout).unwrap().to_string()
+        }
+        _ => "unknown".to_string(),
+    };
+
     println!("cargo:rustc-env=GIT_HASH={git_hash}");
 }
Index: mink-idl-compiler/idlc/src/main.rs
===================================================================
--- mink-idl-compiler.orig/idlc/src/main.rs
+++ mink-idl-compiler/idlc/src/main.rs
@@ -25,12 +25,18 @@ use idlc_mir_passes::{interface_verifier
 use idlc_codegen::{Generator, SplitInvokeGenerator};
 
 fn long_version() -> &'static str {
-    format!(
-        "{}\nCompiled from (git hash): {}",
-        env!("CARGO_PKG_VERSION"),
-        env!("GIT_HASH")
-    )
-    .leak()
+    let git_hash = env!("GIT_HASH");
+
+    if git_hash == "unknown" {
+        env!("CARGO_PKG_VERSION")
+    } else {
+        format!(
+            "{}\nCompiled from (git hash): {}",
+            env!("CARGO_PKG_VERSION"),
+            git_hash
+        )
+        .leak()
+    }
 }
 
 #[derive(clap::Parser)]
