Skip to content

Commit

Permalink
a build script to set a gitoxide version according to what's in git
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jun 14, 2023
1 parent d9e74ff commit 83f6466
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
17 changes: 17 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -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<String> {
let input = std::str::from_utf8(input).ok()?;
input.trim().to_owned().into()
}
17 changes: 17 additions & 0 deletions cargo-smart-release/build.rs
Original file line number Diff line number Diff line change
@@ -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<String> {
let input = std::str::from_utf8(input).ok()?;
input.trim().to_owned().into()
}
4 changes: 2 additions & 2 deletions cargo-smart-release/src/cli/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions src/plumbing/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")]
Expand Down
4 changes: 1 addition & 3 deletions src/porcelain/options.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
)]
Expand Down

0 comments on commit 83f6466

Please sign in to comment.