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

Determine Icinga 2 git version more reliably #10039

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ 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)
include(GetGitVersion)
git_get_version(GIT_VERSION)
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()
Expand Down
53 changes: 53 additions & 0 deletions cmake/GetGitVersion.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Icinga 2 | (c) 2024 Icinga GmbH | GPLv2+
#
# Determines the current Icinga 2 git version similar to a "git describe" command, but in a more reliable way.
function(git_get_version _var)
if (NOT GIT_FOUND)
find_package(Git QUIET)
if (NOT GIT_FOUND)
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
return()
endif ()
endif ()

# Determine the current git HEAD commit in "git rev-parse --show-superproject-working-tree --short @" manner.
execute_process(
COMMAND "${GIT_EXECUTABLE}" rev-parse --show-superproject-working-tree --short @
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE exitcode
OUTPUT_VARIABLE hash
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT exitcode EQUAL 0)
set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
return()
endif ()

execute_process(
COMMAND "${GIT_EXECUTABLE}" -c versionsort.suffix=- tag --list --sort=-version:refname
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE exitcode
OUTPUT_VARIABLE gittags
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT exitcode EQUAL 0)
set(${_var} "${exitcode}-TAGS-NOTFOUND" PARENT_SCOPE)
return()
endif ()

# We're only interested in the first/latest tag
string(REGEX REPLACE "\n.*" "" gittag "${gittags}")
string(STRIP "${gittag}" gittag)

execute_process(
COMMAND "${GIT_EXECUTABLE}" rev-list "${gittag}.." --count
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE exitcode
OUTPUT_VARIABLE commits
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT exitcode EQUAL 0)
# Something went wrong so just return the latest tag
set(${_var} "${gittag}" PARENT_SCOPE)
return()
endif ()

set(${_var} "${gittag}-${commits}-g${hash}" PARENT_SCOPE)
endfunction()
284 changes: 0 additions & 284 deletions third-party/cmake/GetGitRevisionDescription.cmake

This file was deleted.

43 changes: 0 additions & 43 deletions third-party/cmake/GetGitRevisionDescription.cmake.in

This file was deleted.

Loading