Skip to content

Commit 0c563c1

Browse files
committed
Add build.rs to log git sha on init
1 parent be9d51c commit 0c563c1

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ RUST_SOEXT.freebsd=so
134134
RUST_SOEXT.macos=dylib
135135

136136
build:
137-
CARGO_FLAGS = cargo:rustc-env=GITHASH=$(git rev-parse HEAD); $(CARGO_FLAGS)
138137
ifeq ($(SAN),)
139138
export RUSTFLAGS=$(RUSTFLAGS) ;\
140139
cargo build --all --all-targets $(CARGO_FLAGS)

build.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use std::process::Command;
2+
3+
fn main() {
4+
// Expose GIT_SHA env var
5+
let gitsha = Command::new("git").args(&["rev-parse", "HEAD"]).output();
6+
if let Ok(sha) = gitsha {
7+
let sha = String::from_utf8(sha.stdout).unwrap();
8+
println!("cargo:rustc-env=GIT_SHA={}", sha);
9+
}
10+
}

src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ pub mod manager;
2727
mod nodevisitor;
2828
pub mod redisjson;
2929

30+
pub const GIT_SHA: Option<&'static str> = std::option_env!("GIT_SHA");
31+
3032
pub const REDIS_JSON_TYPE_VERSION: i32 = 3;
3133

3234
pub static REDIS_JSON_TYPE: RedisType = RedisType::new(
@@ -400,10 +402,7 @@ macro_rules! redis_json_module_create {(
400402
}
401403

402404
fn intialize(ctx: &Context, args: &Vec<RedisString>) -> Status {
403-
ctx.log_notice(format!("git_sha={}",
404-
option_env!("GITHASH")
405-
.unwrap_or("unknown")
406-
));
405+
ctx.log_notice(&format!("git sha: {}", match GIT_SHA { Some(sha) => sha, _ => "unknown"}));
407406
export_shared_api(ctx);
408407
ctx.set_module_options(ModuleOptions::HANDLE_IO_ERRORS);
409408
ctx.log_notice("Enabled diskless replication");

0 commit comments

Comments
 (0)