Skip to content

Commit

Permalink
Update version info
Browse files Browse the repository at this point in the history
  • Loading branch information
akiomik committed Jan 14, 2024
1 parent cb24c32 commit cbec720
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
16 changes: 1 addition & 15 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,8 @@ fn main() {
let git_info = git_output
.as_ref()
.and_then(|output| std::str::from_utf8(&output.stdout).ok().map(str::trim));
let cargo_pkg_version = env!("CARGO_PKG_VERSION");

// Default git_describe to cargo_pkg_version
let mut git_describe = String::from(cargo_pkg_version);

if let Some(git_info) = git_info {
// If the `git_info` contains `CARGO_PKG_VERSION`, we simply use `git_info` as it is.
// Otherwise, prepend `CARGO_PKG_VERSION` to `git_info`.
if git_info.contains(cargo_pkg_version) {
// Remove the 'g' before the commit sha
let git_info = &git_info.replace('g', "");
git_describe = git_info.to_string();
} else {
git_describe = format!("v{}-{}", cargo_pkg_version, git_info);
}
println!("cargo:rustc-env=_GIT_INFO={}", git_info);
}

println!("cargo:rustc-env=_GIT_INFO={}", git_describe);
}
12 changes: 8 additions & 4 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use tracing_subscriber::{

use crate::tui::Tui;

pub static GIT_COMMIT_HASH: &str = env!("_GIT_INFO");

lazy_static! {
pub static ref PROJECT_NAME: String = env!("CARGO_CRATE_NAME").to_uppercase().to_string();
pub static ref DATA_FOLDER: Option<PathBuf> =
Expand Down Expand Up @@ -159,15 +157,21 @@ macro_rules! trace_dbg {
pub fn version() -> String {
let author = clap::crate_authors!();

let commit_hash = GIT_COMMIT_HASH;
let pkg_version = format!("v{}", env!("CARGO_PKG_VERSION"));
let commit_hash = option_env!("_GIT_INFO");
let version = if let Some(hash) = commit_hash {
format!("{pkg_version}-{hash}")
} else {
pkg_version
};

// let current_exe_path = PathBuf::from(clap::crate_name!()).display().to_string();
let config_dir_path = get_config_dir().display().to_string();
let data_dir_path = get_data_dir().display().to_string();

format!(
"\
{commit_hash}
{version}
Authors: {author}
Expand Down

0 comments on commit cbec720

Please sign in to comment.