diff --git a/build.rs b/build.rs new file mode 100644 index 00000000000..31619ef07f3 --- /dev/null +++ b/build.rs @@ -0,0 +1,17 @@ +use std::process::Command; + +fn main() { + let version = Command::new(if cfg!(windows) { "git.exe" } else { "git" }) + .args(["describe", "--match=v*\\.*\\.*"]) + .output() + .ok() + .and_then(|out| parse_describe(&out.stdout)) + .unwrap_or_else(|| env!("CARGO_PKG_VERSION").into()); + + println!("cargo:rustc-env=GITOXIDE_VERSION={version}"); +} + +fn parse_describe(input: &[u8]) -> Option { + let input = std::str::from_utf8(input).ok()?; + input.trim().to_owned().into() +} diff --git a/cargo-smart-release/build.rs b/cargo-smart-release/build.rs new file mode 100644 index 00000000000..20ecf3f7c0e --- /dev/null +++ b/cargo-smart-release/build.rs @@ -0,0 +1,17 @@ +use std::process::Command; + +fn main() { + let version = Command::new(if cfg!(windows) { "git.exe" } else { "git" }) + .args(["describe", "--match=cargo-smart-release-*"]) + .output() + .ok() + .and_then(|out| parse_describe(&out.stdout)) + .unwrap_or_else(|| env!("CARGO_PKG_VERSION").into()); + + println!("cargo:rustc-env=CARGO_SMART_RELEASE_VERSION={version}"); +} + +fn parse_describe(input: &[u8]) -> Option { + let input = std::str::from_utf8(input).ok()?; + input.trim().to_owned().into() +} diff --git a/cargo-smart-release/src/cli/options.rs b/cargo-smart-release/src/cli/options.rs index d1617c89eff..026900d2ce1 100644 --- a/cargo-smart-release/src/cli/options.rs +++ b/cargo-smart-release/src/cli/options.rs @@ -13,7 +13,7 @@ pub struct Args { #[derive(clap::Parser)] pub enum SubCommands { - #[clap(name = "smart-release", version = clap::crate_version!())] + #[clap(name = "smart-release", version = env!("CARGO_SMART_RELEASE_VERSION"))] /// Release workspace crates fearlessly. /// /// Use --execute to actually perform the operation. @@ -162,7 +162,7 @@ pub enum SubCommands { #[clap(long, help_heading = Some("CHANGELOG"))] capitalize_commit: bool, }, - #[clap(name = "changelog", version = clap::crate_version!())] + #[clap(name = "changelog", version = env!("CARGO_SMART_RELEASE_VERSION"))] /// Generate changelogs from commit histories, non-destructively. /// /// Use --write to actually write generated changelogs diff --git a/src/plumbing/options/mod.rs b/src/plumbing/options/mod.rs index a58492d8fe5..627c75a9cd7 100644 --- a/src/plumbing/options/mod.rs +++ b/src/plumbing/options/mod.rs @@ -4,7 +4,7 @@ use gitoxide_core as core; use gix::bstr::BString; #[derive(Debug, clap::Parser)] -#[clap(name = "gix-plumbing", about = "The git underworld", version = clap::crate_version!())] +#[clap(name = "gix", about = "The git underworld", version = env!("GITOXIDE_VERSION"))] #[clap(subcommand_required = true)] #[clap(arg_required_else_help = true)] pub struct Args { @@ -129,10 +129,7 @@ pub mod corpus { use std::path::PathBuf; #[derive(Debug, clap::Parser)] - #[command( - about = "run algorithms on a corpus of git repositories and store their results for later analysis", - version = clap::crate_version!(), // TODO: make this an actual version that is git describe, leverage `gix` - )] + #[command(about = "run algorithms on a corpus of git repositories and store their results for later analysis")] pub struct Platform { /// The path to the database to read and write depending on the sub-command. #[arg(long, default_value = "corpus.db")] diff --git a/src/porcelain/options.rs b/src/porcelain/options.rs index 1ae734bf8c0..784e112a0f2 100644 --- a/src/porcelain/options.rs +++ b/src/porcelain/options.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; #[derive(Debug, clap::Parser)] -#[clap(about = "The rusty git", version = clap::crate_version!())] +#[clap(about = "The rusty git", version = env!("GITOXIDE_VERSION"))] #[clap(subcommand_required = true)] pub struct Args { /// Do not display verbose messages and progress information @@ -94,7 +94,6 @@ pub mod tools { #[derive(Debug, clap::Parser)] #[command( about = "a database accelerated engine to extract information and query it", - version = clap::crate_version!(), visible_alias = "q" )] pub struct Query { @@ -135,7 +134,6 @@ pub mod tools { #[clap( about = "Estimate hours worked based on a commit history", long_about = "See https://github.com/kimmobrunfeldt/git-hours#how-it-works for details", - version = clap::crate_version!(), visible_alias = "h", visible_alias = "hours" )]