Skip to content

Commit

Permalink
chore(bin_version): don't concatenate GIT_REVISION if empty (#4535)
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez authored Dec 18, 2024
1 parent 70ac44c commit 5e221d5
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions crates/bin-version/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ pub mod _hidden {
///
/// Defines two global `const`s:
/// `GIT_REVISION`: The git revision as specified by the `GIT_REVISION` env
/// variable provided at compile time, or the current git revision as
/// discovered by running `git describe`.
/// variable provided at compile time, or the current git revision as discovered
/// by running `git describe`.
///
/// `VERSION`: The value of the `CARGO_PKG_VERSION` environment variable
/// concatenated with the value of `GIT_REVISION`.
/// concatenated with the value of `GIT_REVISION` if it is not empty.
///
/// Note: This macro must only be used from a binary, if used inside a library
/// this will fail to compile.
Expand All @@ -25,16 +25,19 @@ macro_rules! bin_version {
() => {
$crate::git_revision!();

const VERSION: &str =
$crate::_hidden::concat!(env!("CARGO_PKG_VERSION"), "-", GIT_REVISION);
const VERSION: &str = if GIT_REVISION.is_empty() {
env!("CARGO_PKG_VERSION")
} else {
$crate::_hidden::concat!(env!("CARGO_PKG_VERSION"), "-", GIT_REVISION)
};
};
}

/// Defines constant that holds the git revision at build time.
///
/// `GIT_REVISION`: The git revision as specified by the `GIT_REVISION` env
/// variable provided at compile time, or the current git revision as
/// discovered by running `git describe`.
/// variable provided at compile time, or the current git revision as discovered
/// by running `git describe`.
///
/// Note: This macro must only be used from a binary, if used inside a library
/// this will fail to compile.
Expand Down

0 comments on commit 5e221d5

Please sign in to comment.