misc: add git commit hash to --version when not on tag v${VERSION} (#590)

This commit is contained in:
Maximilian Seidler 2024-12-20 18:41:06 +00:00 committed by GitHub
parent d12b4a7fba
commit ee37e41723
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 2 deletions

View file

@ -28,9 +28,28 @@ set(CMAKE_CXX_STANDARD 23)
add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-unused-value
-Wno-missing-field-initializers -Wno-narrowing)
# get git commit
execute_process(
OUTPUT_VARIABLE GIT_SHORT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND git rev-parse --short HEAD
)
# get git commit of v$VERSION
execute_process(
OUTPUT_VARIABLE GIT_TAG_SHORT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND git rev-parse --short v${VERSION}
)
add_compile_definitions(HYPRLOCK_VERSION="${VERSION}")
add_compile_definitions(HYPRLOCK_COMMIT="${GIT_SHORT_HASH}")
add_compile_definitions(HYPRLOCK_VERSION_COMMIT="${GIT_TAG_SHORT_HASH}")
# position independent build: __FILE__
add_compile_options(-fmacro-prefix-map=${CMAKE_SOURCE_DIR}/=)
add_compile_definitions(HYPRLOCK_VERSION="${VERSION}")
# dependencies
message(STATUS "Checking deps...")

View file

@ -4,6 +4,7 @@
#include "src/helpers/Log.hpp"
#include <cstddef>
#include <iostream>
#include <string_view>
void help() {
std::cout << "Usage: hyprlock [options]\n\n"
@ -46,7 +47,12 @@ int main(int argc, char** argv, char** envp) {
}
if (arg == "--version" || arg == "-V") {
std::cout << "Hyprlock version " << HYPRLOCK_VERSION << "\n";
constexpr bool ISTAGGEDRELEASE = std::string_view(HYPRLOCK_COMMIT) == HYPRLOCK_VERSION_COMMIT;
std::cout << "Hyprlock version v" << HYPRLOCK_VERSION;
if (!ISTAGGEDRELEASE)
std::cout << " (commit " << HYPRLOCK_COMMIT << ")";
std::cout << std::endl;
return 0;
}