Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(bin_version): don't concatenate GIT_REVISION if empty #4535

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading