#5934: Generate REVISION file and use it in case of missing reliable source

This commit is contained in:
Mike Gelfand 2015-04-24 19:14:56 +00:00
parent b5eee9b0fc
commit a1393e7b35
5 changed files with 48 additions and 13 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
/.depend
/REVISION
Transmission.xcodeproj/*.mode*
Transmission.xcodeproj/*.pbxuser
Transmission.xcodeproj/*.xcworkspace

View File

@ -56,23 +56,15 @@ else()
set(TR_STABLE_RELEASE 1)
endif()
set(TR_SCM_REVISION_FILE "${CMAKE_SOURCE_DIR}/REVISION")
set(TR_SCM_REVISION_RELIABLE ON)
if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/.svn)
find_package(Subversion)
if(Subversion_FOUND)
Subversion_WC_INFO(${CMAKE_SOURCE_DIR} TR_SVN)
set(TR_SCM_REVISION "${TR_SVN_WC_REVISION}")
endif()
if("${TR_SCM_REVISION}" STREQUAL "")
file(GLOB_RECURSE TR_ALL_SOURCES RELATIVE ${CMAKE_SOURCE_DIR} *.cc *.[chm] *.po)
set(TR_SCM_REVISION 0)
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_SCM_REVISION)
set(TR_SCM_REVISION ${CMAKE_MATCH_1})
endif()
endforeach()
endif()
elseif(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/.git)
find_package(Git)
if(GIT_FOUND)
@ -88,8 +80,32 @@ elseif(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/.git)
endif()
endif()
if("${TR_SCM_REVISION}" STREQUAL "" AND EXISTS "${TR_SCM_REVISION_FILE}")
file(READ "${TR_SCM_REVISION_FILE}" TR_SCM_REVISION)
string(STRIP "${TR_SCM_REVISION}" TR_SCM_REVISION)
endif()
if("${TR_SCM_REVISION}" STREQUAL "")
# Give up and check the source files
set(TR_SCM_REVISION 0)
set(TR_SCM_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_SCM_REVISION)
set(TR_SCM_REVISION ${CMAKE_MATCH_1})
endif()
endforeach()
endif()
if("${TR_SCM_REVISION}" STREQUAL "")
set(TR_SCM_REVISION 0)
else()
if(TR_SCM_REVISION_RELIABLE)
file(WRITE "${TR_SCM_REVISION_FILE}" "${TR_SCM_REVISION}")
else()
file(REMOVE "${TR_SCM_REVISION_FILE}")
endif()
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

View File

@ -47,17 +47,22 @@ EXTRA_DIST += \
po/CMakeLists.txt \
qt/CMakeLists.txt \
third-party/b64-01-newline.patch \
third-party/b64-02-unsigned-char.patch \
third-party/b64.cmake \
third-party/dht.cmake \
third-party/event2.cmake \
third-party/natpmp.cmake \
third-party/utp-01-ticket-5002.patch \
third-party/utp.cmake \
third-party/utp_config.h \
utils/CMakeLists.txt
dist-hook:
rm -rf `find $(distdir)/qt -name .svn`
if HAVE_REVISION_FILE
EXTRA_DIST += REVISION
endif
dist-hook:
find "$(distdir)/qt" "$(distdir)/cmake" -name .svn -exec rm -rf '{}' '+' -prune
DISTCLEANFILES = \
intltool-extract \

View File

@ -31,6 +31,7 @@ else
fi
fi
AM_CONDITIONAL(TR_UNSTABLE, test "x$supported_build" = "xno")
AM_CONDITIONAL(HAVE_REVISION_FILE, test -f REVISION)
##
##

View File

@ -20,6 +20,9 @@ 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}'`
svn_revision_file=REVISION
svn_revision_reliable=true
if [ -n "$JENKINS_URL" -a -n "$SVN_REVISION" ]; then
# Jenkins automated build, use the set environment variables to avoid
# version mismatches between java's svn and command line's svn
@ -28,9 +31,18 @@ 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.
svn_revision=`svnversion -n . | cut -d: -f1 | cut -dM -f1 | cut -dS -f1`
elif [ -f "$svn_revision_file" ]; then
svn_revision=`cat "$svn_revision_file"`
else
# Give up and check the source files
svn_revision=`awk '/\\$Id: /{ if ($4>i) i=$4 } END {print i}' */*.cc */*.[chm] */*.po`
svn_revision_reliable=false
fi
if $svn_revision_reliable; then
[ -f "$svn_revision_file" ] && [ "`cat "$svn_revision_file"`" -eq "$svn_revision" ] || echo "$svn_revision" > "$svn_revision_file"
else
rm -f "$svn_revision_file"
fi
cat > libtransmission/version.h.new << EOF