From 4c999fb0c6d3c6f9de26ea87812b20abc75b2ccd Mon Sep 17 00:00:00 2001 From: bergmann Date: Thu, 1 Aug 2019 14:58:32 +0200 Subject: [PATCH] * Fixed bug in git helper: Do not fail if no tag could be read. --- git_helper.cmake | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/git_helper.cmake b/git_helper.cmake index 860af68..6d2a79d 100644 --- a/git_helper.cmake +++ b/git_helper.cmake @@ -1,5 +1,6 @@ # Execute git command and return the output -Function ( GitExecute COMMAND RESULT ) +Function ( GitExecute COMMAND FORCE OUT_RESULT OUT_SUCCESS ) + Set ( ${OUT_SUCCESS} 1 PARENT_SCOPE ) Execute_Process ( COMMAND bash -c "${COMMAND}" RESULT_VARIABLE @@ -11,9 +12,13 @@ Function ( GitExecute COMMAND RESULT ) If ( NOT ${GIT_RET} EQUAL 0 OR NOT "${GIT_ERR}" STREQUAL "" OR "${GIT_REV}" STREQUAL "" ) - Message ( FATAL_ERROR "Unable to execute git command (command=${COMMAND} out=${GIT_REV}; err=${GIT_ERR}; ret=${GIT_RET})" ) + If ( FORCE ) + Message ( FATAL_ERROR "Unable to execute git command (command=${COMMAND} out=${GIT_REV}; err=${GIT_ERR}; ret=${GIT_RET})" ) + Else ( ) + Set ( ${OUT_SUCCESS} 0 PARENT_SCOPE ) + EndIf ( ) EndIf ( ) - Set ( ${RESULT} "${GIT_REV}" PARENT_SCOPE ) + Set ( ${OUT_RESULT} "${GIT_REV}" PARENT_SCOPE ) EndFunction ( ) # Get the version by reading the git tag @@ -24,9 +29,20 @@ Function ( GitGetVersion GIT_ROOT OUT_MAJOR OUT_MINOR OUT_PATCH OUT_BUILD OUT_HA EndIf ( ) # Find the latest git tag - GitExecute ( "git describe --tags --abbrev=1 --match v[0-9].[0-9]* HEAD" TAG ) - GitExecute ( "git status -s -uall" DIRTY ) - GitExecute ( "git rev-parse HEAD" HASH ) + GitExecute ( "git describe --tags --abbrev=1 --match v[0-9].[0-9]* HEAD" False TAG SUCCESS ) + If ( NOT ${SUCCESS} ) + Return ( ) + EndIf ( ) + + GitExecute ( "git status -s -uall" True DIRTY SUCCESS ) + If ( NOT ${SUCCESS} ) + Return ( ) + EndIf ( ) + + GitExecute ( "git rev-parse HEAD" True HASH SUCCESS ) + If ( NOT ${SUCCESS} ) + Return ( ) + EndIf ( ) # Split the git revision string String ( REGEX REPLACE "^v" "" TAG "${TAG}" )