From 9ea3534a5147ee9fba6cbbdcd0ebaafd7d4afc65 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 23 Feb 2023 16:20:27 +0100 Subject: [PATCH 1/2] Prefer git archive generated version if any --- .git-archive-version | 2 ++ .gitattributes | 3 +++ CMakeLists.txt | 10 ++++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .git-archive-version diff --git a/.git-archive-version b/.git-archive-version new file mode 100644 index 000000000..15db4cfd4 --- /dev/null +++ b/.git-archive-version @@ -0,0 +1,2 @@ +# Becomes like v2.13.0-555-g11e37a0bd if git-archived, is kept as-is otherwise +$Format:%(describe)$ diff --git a/.gitattributes b/.gitattributes index a6ab5f7a5..398024b46 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,5 @@ debian/ export-ignore .gitattributes export-ignore + +# Include version information on `git archive' +/.git-archive-version export-subst diff --git a/CMakeLists.txt b/CMakeLists.txt index fce41f411..43079de67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,8 +105,14 @@ string(SUBSTRING ${SPEC_VERSION} 9 ${SPEC_VERSION_LENGTH} SPEC_VERSION) configure_file(icinga-spec-version.h.cmake icinga-spec-version.h) -include(GetGitRevisionDescription) -git_describe(GIT_VERSION --tags) +file(STRINGS .git-archive-version GIT_ARCHIVE_VERSION REGEX "^[^#]") +if(GIT_ARCHIVE_VERSION MATCHES "Format") + include(GetGitRevisionDescription) + git_describe(GIT_VERSION --tags) +else() + set(GIT_VERSION "${GIT_ARCHIVE_VERSION}") +endif() + if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/icinga-version.h.force) configure_file(icinga-version.h.force ${CMAKE_CURRENT_BINARY_DIR}/icinga-version.h COPYONLY) else() From 2b1e5a429f84796b8293e53deadf25db9ac249a0 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 22 Feb 2023 11:38:31 +0100 Subject: [PATCH 2/2] Override v2.13.0-555-g11e37a0bd from git describe with 2.13.7 from ./ICINGA2_VERSION -> v2.13.7-555-g11e37a0bd --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 43079de67..1f6826683 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,6 +125,10 @@ else() set(GIT_VERSION "r${SPEC_VERSION}-${SPEC_REVISION}") set(ICINGA2_VERSION "${SPEC_VERSION}") else() + if(GIT_VERSION MATCHES "-g") + # Override v2.13.0-555-g11e37a0bd from git describe with 2.13.7 from ./ICINGA2_VERSION -> v2.13.7-555-g11e37a0bd + string(REGEX REPLACE ^[v0-9.]+ "v${SPEC_VERSION}" GIT_VERSION "${GIT_VERSION}") + endif() # use GIT version as ICINGA2_VERSION string(REGEX REPLACE "^[rv]" "" ICINGA2_VERSION "${GIT_VERSION}") endif()