Don't search for SVN revision when calculating version

This commit is contained in:
Mike Gelfand 2016-09-02 22:45:03 +03:00
parent 95e12a3a0a
commit b2c5a9ce63
2 changed files with 13 additions and 43 deletions

View File

@ -57,20 +57,11 @@ else()
endif()
set(TR_VCS_REVISION_FILE "${CMAKE_SOURCE_DIR}/REVISION")
set(TR_VCS_REVISION_RELIABLE ON)
if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/.svn)
if(NOT "$ENV{JENKINS_URL}" STREQUAL "" AND NOT "$ENV{VCS_REVISION}" STREQUAL "")
# Jenkins automated build, use the set environment variables to avoid
# version mismatches between java's svn and command line's svn
set(TR_VCS_REVISION "$ENV{VCS_REVISION}")
else()
find_package(Subversion)
if(Subversion_FOUND)
Subversion_WC_INFO(${CMAKE_SOURCE_DIR} TR_SVN)
set(TR_VCS_REVISION "${TR_SVN_WC_REVISION}")
endif()
endif()
if(NOT "$ENV{JENKINS_URL}" STREQUAL "" AND NOT "$ENV{VCS_REVISION}" STREQUAL "")
# Jenkins automated build, use the set environment variables to avoid
# version mismatches between java's svn and command line's svn
set(TR_VCS_REVISION "$ENV{VCS_REVISION}")
elseif(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/.git)
find_package(Git)
if(GIT_FOUND)
@ -91,27 +82,11 @@ if("${TR_VCS_REVISION}" STREQUAL "" AND EXISTS "${TR_VCS_REVISION_FILE}")
string(STRIP "${TR_VCS_REVISION}" TR_VCS_REVISION)
endif()
if("${TR_VCS_REVISION}" STREQUAL "")
# Give up and check the source files
set(TR_VCS_REVISION 0)
set(TR_VCS_REVISION_RELIABLE OFF)
file(GLOB_RECURSE TR_ALL_SOURCES RELATIVE ${CMAKE_SOURCE_DIR} *.cc *.[chm] *.po)
foreach(F ${TR_ALL_SOURCES})
file(STRINGS ${F} F_ID REGEX "\\$Id:")
if(F_ID MATCHES "\\$Id: [^ ]+ ([0-9]+) " AND CMAKE_MATCH_1 GREATER TR_VCS_REVISION)
set(TR_VCS_REVISION ${CMAKE_MATCH_1})
endif()
endforeach()
endif()
if("${TR_VCS_REVISION}" STREQUAL "")
set(TR_VCS_REVISION 0)
if(NOT "${TR_VCS_REVISION}" STREQUAL "")
file(WRITE "${TR_VCS_REVISION_FILE}" "${TR_VCS_REVISION}")
else()
if(TR_VCS_REVISION_RELIABLE)
file(WRITE "${TR_VCS_REVISION_FILE}" "${TR_VCS_REVISION}")
else()
file(REMOVE "${TR_VCS_REVISION_FILE}")
endif()
set(TR_VCS_REVISION 0)
file(REMOVE "${TR_VCS_REVISION_FILE}")
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

View File

@ -20,28 +20,23 @@ peer_id_prefix=`grep m4_define configure.ac | sed "s/[][)(]/,/g" | grep peer_id_
major_version=`echo ${user_agent_prefix} | awk -F . '{print $1}'`
minor_version=`echo ${user_agent_prefix} | awk -F . '{print $2 + 0}'`
vcs_revision=
vcs_revision_file=REVISION
vcs_revision_reliable=true
if [ -n "$JENKINS_URL" -a -n "$VCS_REVISION" ]; then
# Jenkins automated build, use the set environment variables to avoid
# version mismatches between java's svn and command line's svn
vcs_revision=$VCS_REVISION
elif [ -d ".svn" ] && type svnversion >/dev/null 2>&1; then
# If this is a svn tree, and svnversion is available in PATH, use it to
# grab the version.
vcs_revision=`svnversion -n . | cut -d: -f1 | cut -dM -f1 | cut -dS -f1`
elif [ -d ".git" ] && type git >/dev/null 2>&1; then
vcs_revision=`git rev-list --max-count=1 --abbrev-commit HEAD`
elif [ -f "$vcs_revision_file" ]; then
vcs_revision=`cat "$vcs_revision_file"`
else
# Give up and check the source files
vcs_revision=`awk '/\\$Id: /{ if ($4>i) i=$4 } END {print i}' */*.cc */*.[chm] */*.po`
vcs_revision_reliable=false
fi
if $vcs_revision_reliable; then
if [ -n "$vcs_revision" ]; then
[ -f "$vcs_revision_file" ] && [ "`cat "$vcs_revision_file"`" = "$vcs_revision" ] || echo "$vcs_revision" > "$vcs_revision_file"
else
vcs_revision=0
rm -f "$vcs_revision_file"
fi