aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-09-07 18:30:15 +0200
committerAlex Auvolat <alex@adnab.me>2022-09-07 18:30:15 +0200
commitf310fce34b0273f9f75e7a6ea665f51003a1f795 (patch)
tree9480af39147f396f36fb8d73241ebcda6a468d4b /src
parent06df301de5ab2068ee55c8663eebafb0d9a26978 (diff)
downloadgarage-f310fce34b0273f9f75e7a6ea665f51003a1f795.tar.gz
garage-f310fce34b0273f9f75e7a6ea665f51003a1f795.zip
Inject GIT_VERSION even later
Diffstat (limited to 'src')
-rw-r--r--src/garage/main.rs9
-rw-r--r--src/model/version.rs17
2 files changed, 18 insertions, 8 deletions
diff --git a/src/garage/main.rs b/src/garage/main.rs
index 751dd941..1a4a939a 100644
--- a/src/garage/main.rs
+++ b/src/garage/main.rs
@@ -77,7 +77,7 @@ async fn main() {
std::process::abort();
}));
- // Parse opt
+ // Initialize version and features info
let features = &[
#[cfg(feature = "k2v")]
"k2v",
@@ -98,12 +98,17 @@ async fn main() {
#[cfg(feature = "system-libs")]
"system-libs",
][..];
+ if let Some(git_version) = option_env!("GIT_VERSION") {
+ garage_model::version::init_version(git_version);
+ }
+ garage_model::version::init_features(features);
+
+ // Parse arguments
let version = format!(
"{} [features: {}]",
garage_model::version::garage_version(),
features.join(", ")
);
- garage_model::version::init_features(features);
let opt = Opt::from_clap(&Opt::clap().version(version.as_str()).get_matches());
let res = match opt.cmd {
diff --git a/src/model/version.rs b/src/model/version.rs
index af6aa809..b515dccc 100644
--- a/src/model/version.rs
+++ b/src/model/version.rs
@@ -1,23 +1,28 @@
use std::sync::Arc;
-use arc_swap::ArcSwapOption;
+use arc_swap::{ArcSwap, ArcSwapOption};
lazy_static::lazy_static! {
+ static ref VERSION: ArcSwap<&'static str> = ArcSwap::new(Arc::new(git_version::git_version!(
+ prefix = "git:",
+ cargo_prefix = "cargo:",
+ fallback = "unknown"
+ )));
static ref FEATURES: ArcSwapOption<&'static [&'static str]> = ArcSwapOption::new(None);
}
pub fn garage_version() -> &'static str {
- option_env!("GIT_VERSION").unwrap_or(git_version::git_version!(
- prefix = "git:",
- cargo_prefix = "cargo:",
- fallback = "unknown"
- ))
+ &VERSION.load()
}
pub fn garage_features() -> Option<&'static [&'static str]> {
FEATURES.load().as_ref().map(|f| &f[..])
}
+pub fn init_version(version: &'static str) {
+ VERSION.store(Arc::new(version));
+}
+
pub fn init_features(features: &'static [&'static str]) {
FEATURES.store(Some(Arc::new(features)));
}