From 7a6a3e4160d2a472febd2122248f21ae7dfb0c90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Sun, 22 Mar 2020 16:13:34 +0100 Subject: [PATCH] Set the cargo version and allow changing it during build time with BWRS_VERSION. Also renamed GIT_VERSION because that's not the only source anymore. --- build.rs | 16 ++++++++++++---- src/api/admin.rs | 2 +- src/main.rs | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/build.rs b/build.rs index ac92dbd9..0eeb4767 100644 --- a/build.rs +++ b/build.rs @@ -1,4 +1,5 @@ use std::process::Command; +use std::env; fn main() { #[cfg(all(feature = "sqlite", feature = "mysql"))] @@ -10,8 +11,13 @@ fn main() { #[cfg(not(any(feature = "sqlite", feature = "mysql", feature = "postgresql")))] compile_error!("You need to enable one DB backend. To build with previous defaults do: cargo build --features sqlite"); - - read_git_info().ok(); + + if let Ok(version) = env::var("BWRS_VERSION") { + println!("cargo:rustc-env=BWRS_VERSION={}", version); + println!("cargo:rustc-env=CARGO_PKG_VERSION={}", version); + } else { + read_git_info().ok(); + } } fn run(args: &[&str]) -> Result { @@ -54,14 +60,16 @@ fn read_git_info() -> Result<(), std::io::Error> { } else { format!("{}-{}", last_tag, rev_short) }; - println!("cargo:rustc-env=GIT_VERSION={}", version); + + println!("cargo:rustc-env=BWRS_VERSION={}", version); + println!("cargo:rustc-env=CARGO_PKG_VERSION={}", version); // To access these values, use: // env!("GIT_EXACT_TAG") // env!("GIT_LAST_TAG") // env!("GIT_BRANCH") // env!("GIT_REV") - // env!("GIT_VERSION") + // env!("BWRS_VERSION") Ok(()) } diff --git a/src/api/admin.rs b/src/api/admin.rs index 23bc65fe..7014c43c 100644 --- a/src/api/admin.rs +++ b/src/api/admin.rs @@ -51,7 +51,7 @@ const COOKIE_NAME: &str = "BWRS_ADMIN"; const ADMIN_PATH: &str = "/admin"; const BASE_TEMPLATE: &str = "admin/base"; -const VERSION: Option<&str> = option_env!("GIT_VERSION"); +const VERSION: Option<&str> = option_env!("BWRS_VERSION"); fn admin_path() -> String { format!("{}{}", CONFIG.domain_path(), ADMIN_PATH) diff --git a/src/main.rs b/src/main.rs index 85e9d286..1a8cb971 100644 --- a/src/main.rs +++ b/src/main.rs @@ -88,7 +88,7 @@ fn main() { fn parse_args() { let opt = Opt::from_args(); if opt.version { - if let Some(version) = option_env!("GIT_VERSION") { + if let Some(version) = option_env!("BWRS_VERSION") { println!("bitwarden_rs {}", version); } else { println!("bitwarden_rs (Version info from Git not present)"); @@ -101,7 +101,7 @@ fn launch_info() { println!("/--------------------------------------------------------------------\\"); println!("| Starting Bitwarden_RS |"); - if let Some(version) = option_env!("GIT_VERSION") { + if let Some(version) = option_env!("BWRS_VERSION") { println!("|{:^68}|", format!("Version {}", version)); }