From 93fb90153f6babc23a5e8400f4666de953a66432 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 31 Jan 2020 09:00:40 +0200 Subject: [PATCH] Fix finding the latest tag distance. Switch to git. --- common.pri | 63 ++++++++++++++++++++++++++-------------- src/libs/vmisc/vmisc.pro | 20 ++----------- src/libs/vtest/vtest.pro | 16 ---------- 3 files changed, 44 insertions(+), 55 deletions(-) diff --git a/common.pri b/common.pri index 87f21b7e0..8a9f35321 100644 --- a/common.pri +++ b/common.pri @@ -258,37 +258,56 @@ defineReplace(enable_ccache){ } defineReplace(FindBuildRevision){ -CONFIG(debug, debug|release){ - # Debug mode - return(\\\"unknown\\\") -}else{ - # Release mode + CONFIG(debug, debug|release){ + # Debug mode + return(\\\"unknown\\\") + }else{ + # Release mode + macx{ + GIT = /usr/local/bin/git # Can't defeat PATH variable on Mac OS. + }else { + GIT = git # All other platforms are OK. + } - macx{ - HG = /usr/local/bin/hg # Can't defeat PATH variable on Mac OS. - }else { - HG = hg # All other platforms are OK. - } - - #build revision number for using in version - unix { - DVCS_HESH=$$system("$${HG} log -r. --template '{node|short}'") - } else { - # Use escape character before "|" on Windows - DVCS_HESH=$$system($${HG} log -r. --template "{node^|short}") - } - isEmpty(DVCS_HESH){ DVCS_HESH=$$system("git rev-parse --short HEAD") isEmpty(DVCS_HESH){ DVCS_HESH = \\\"unknown\\\" # if we can't find build revision left unknown. } else { DVCS_HESH=\\\"Git:$${DVCS_HESH}\\\" } - } else { - DVCS_HESH=\\\"Hg:$${DVCS_HESH}\\\" + return($${DVCS_HESH}) } - return($${DVCS_HESH}) } + +defineReplace(FindLatestTagDistance){ + CONFIG(debug, debug|release){ + # Debug mode + return(0) + }else{ + # Release mode + #get latest git tag and it's distance from HEAD + macx{ + GIT = /usr/local/bin/git # Can't defeat PATH variable on Mac OS. + }else { + GIT = GIT # All other platforms all OK. + } + + # tag is formatted as TAG-N-gSHA: + # 1. latest stable version is TAG, or vX.Y.Z + # 2. number of commits since latest stable version is N + # 3. latest commit is gSHA + tag_all = $$system(git describe --tags) + tag_split = $$split(tag_all, "-") #split at the dashes + GIT_DISTANCE = $$member(tag_split,1) #get 2nd element of results + + isEmpty(GIT_DISTANCE){ + GIT_DISTANCE = 0 # if we can't find local revision left 0. + } + + message("Latest tag distance:" $${GIT_DISTANCE}) + + return($${GIT_DISTANCE}) + } } # Default prefix. Use for creation install path. diff --git a/src/libs/vmisc/vmisc.pro b/src/libs/vmisc/vmisc.pro index 2de6d832a..38e39515b 100644 --- a/src/libs/vmisc/vmisc.pro +++ b/src/libs/vmisc/vmisc.pro @@ -69,9 +69,6 @@ include(warnings.pri) CONFIG(debug, debug|release){ # Debug mode - #Calculate latest tag distance and build revision only in release mode. Change number each time requare - #recompilation precompiled headers file. - DEFINES += "LATEST_TAG_DISTANCE=0" }else{ # Release mode !*msvc*:CONFIG += silent @@ -90,20 +87,9 @@ CONFIG(debug, debug|release){ QMAKE_CFLAGS_RELEASE += -g -gdwarf-3 QMAKE_LFLAGS_RELEASE = } - } - - macx{ - HG = /usr/local/bin/hg # Can't defeat PATH variable on Mac OS. - }else { - HG = hg # All other platforms all OK. - } - #latest tag distance number for using in version - HG_DISTANCE=$$system($${HG} log -r. --template '{latesttagdistance}') - isEmpty(HG_DISTANCE){ - HG_DISTANCE = 0 # if we can't find local revision left 0. - } - message("Latest tag distance:" $${HG_DISTANCE}) - DEFINES += "LATEST_TAG_DISTANCE=$${HG_DISTANCE}" # Make available latest tag distance number in sources. + } } +DEFINES += "LATEST_TAG_DISTANCE=$$FindLatestTagDistance()" # Make available latest tag distance number in sources. + include (../libs.pri) diff --git a/src/libs/vtest/vtest.pro b/src/libs/vtest/vtest.pro index 51f8052b0..d4addab71 100644 --- a/src/libs/vtest/vtest.pro +++ b/src/libs/vtest/vtest.pro @@ -62,9 +62,6 @@ include(warnings.pri) CONFIG(debug, debug|release){ # Debug mode - #Calculate latest tag distance and build revision only in release mode. Change number each time requare - #recompilation precompiled headers file. - DEFINES += "LATEST_TAG_DISTANCE=0" }else{ # Release mode !*msvc*:CONFIG += silent @@ -84,19 +81,6 @@ CONFIG(debug, debug|release){ QMAKE_LFLAGS_RELEASE = } } - - macx{ - HG = /usr/local/bin/hg # Can't defeat PATH variable on Mac OS. - }else { - HG = hg # All other platforms all OK. - } - #latest tag distance number for using in version - HG_DISTANCE=$$system($${HG} log -r. --template '{latesttagdistance}') - isEmpty(HG_DISTANCE){ - HG_DISTANCE = 0 # if we can't find local revision left 0. - } - message("Latest tag distance:" $${HG_DISTANCE}) - DEFINES += "LATEST_TAG_DISTANCE=$${HG_DISTANCE}" # Make available latest tag distance number in sources. } include (../libs.pri)