Skip to content

inconsistencies build.rs and git hash handling #25266

@darix

Description

@darix
  1. the main function checks for different environment variables than the get_git_hash* functions
  2. get_git_hash checks for the wrong variable compared to main
  3. get_git_hash_short doesnt even check for the environment variable before trying to run git.
diff --git a/influxdb3_process/build.rs b/influxdb3_process/build.rs
index e4b4f992ff..33343f989b 100644
--- a/influxdb3_process/build.rs
+++ b/influxdb3_process/build.rs
@@ -15,7 +15,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
 }
 
 fn get_git_hash() -> String {
-    let out = match std::env::var("VERSION_HASH") {
+    let out = match std::env::var("GIT_HASH") {
         Ok(v) => v,
         Err(_) => {
             let output = Command::new("git")
@@ -32,9 +32,17 @@ fn get_git_hash() -> String {
 }
 
 fn get_git_hash_short() -> String {
-    let output = Command::new("git")
-        .args(["rev-parse", "--short", "HEAD"])
-        .output()
-        .expect("failed to execute git rev-parse to read the current git hash");
-    String::from_utf8(output.stdout).expect("non-utf8 found in git hash")
+    let out = match std::env::var("GIT_HASH_SHORT") {
+        Ok(v) => v,
+        Err(_) => {
+            let output = Command::new("git")
+                .args(["rev-parse", "--short", "HEAD"])
+                .output()
+                .expect("failed to execute git rev-parse to read the current git hash");
+            String::from_utf8(output.stdout).expect("non-utf8 found in git hash")
+        }
+    };
+
+    assert!(!out.is_empty(), "attempting to embed empty git hash");
+    out
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions