Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 31 additions & 20 deletions influxdb3_process/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,40 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}

fn get_git_hash() -> String {
let git_hash = {
let output = Command::new("git")
// We used `git describe`, but when you tag a build the commit hash goes missing when
// using describe. So, switching it to use `rev-parse` which is consistent with the
// `get_git_hash_short` below as well.
//
// And we already have cargo version appearing as a separate string so using `git
// describe` looks redundant on tagged release builds
.args(["rev-parse", "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") {
Ok(v) => v,
Err(_) => {
let output = Command::new("git")
// We used `git describe`, but when you tag a build the commit hash goes missing when
// using describe. So, switching it to use `rev-parse` which is consistent with the
// `get_git_hash_short` below as well.
//
// And we already have cargo version appearing as a separate string so using `git
// describe` looks redundant on tagged release builds
.args(["rev-parse", "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!(!git_hash.is_empty(), "attempting to embed empty git hash");
git_hash
assert!(!out.is_empty(), "attempting to embed empty git hash");
out
}

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
}
Loading