[PATCH] CMake: extend add_version_info_from_vcs
Adam Strzelecki
ono at java.pl
Wed May 28 03:13:26 PDT 2014
Adds version control information to the variables prefixed with VAR_PREFIX:
${VAR_PREFIX}_VERSION, ${VAR_PREFIX}_SVN_REVISION,
${VAR_PREFIX}_SVN_REPOSITORY, ${VAR_PREFIX}_GIT_COMMIT
Inspects the existence of certain subdirectories under SOURCE_DIR (2nd arg).
It also tries now to figure out repository URL and revision on Git mirror
parsing git-svn-id: footer from last commit (if present).
This will be used by Clang to show full build information when
LLVM_APPEND_VC_REV is enabled and LLVM/Clang are built from Git.
---
CMakeLists.txt | 2 +-
cmake/modules/VersionFromVCS.cmake | 76 +++++++++++++++++++++++++-------------
2 files changed, 51 insertions(+), 27 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0d6eead..d9fedb3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,7 +46,7 @@ option(LLVM_APPEND_VC_REV
"Append the version control system revision id to LLVM version" OFF)
if( LLVM_APPEND_VC_REV )
- add_version_info_from_vcs(PACKAGE_VERSION)
+ add_version_info_from_vcs(PACKAGE ${CMAKE_CURRENT_SOURCE_DIR})
endif()
set(PACKAGE_NAME LLVM)
diff --git a/cmake/modules/VersionFromVCS.cmake b/cmake/modules/VersionFromVCS.cmake
index 26314d4..6604bc3 100644
--- a/cmake/modules/VersionFromVCS.cmake
+++ b/cmake/modules/VersionFromVCS.cmake
@@ -1,31 +1,33 @@
-# Adds version control information to the variable VERS. For
-# determining the Version Control System used (if any) it inspects the
-# existence of certain subdirectories under CMAKE_CURRENT_SOURCE_DIR.
+# Adds version control information to the variables prefixed with VAR_PREFIX:
+# ${VAR_PREFIX}_VERSION, ${VAR_PREFIX}_SVN_REVISION,
+# ${VAR_PREFIX}_SVN_REPOSITORY, ${VAR_PREFIX}_GIT_COMMIT
+# Inspects the existence of certain subdirectories under SOURCE_DIR.
-function(add_version_info_from_vcs VERS)
- string(REPLACE "svn" "" result "${${VERS}}")
- if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.svn" )
+function(add_version_info_from_vcs VAR_PREFIX SOURCE_DIR)
+ string(REPLACE "svn" "" result "${${VAR_PREFIX}_VERSION}")
+ if( EXISTS "${SOURCE_DIR}/.svn" )
set(result "${result}svn")
# FindSubversion does not work with symlinks. See PR 8437
- if( NOT IS_SYMLINK "${CMAKE_CURRENT_SOURCE_DIR}" )
+ if( NOT IS_SYMLINK "${SOURCE_DIR}" )
find_package(Subversion)
endif()
if( Subversion_FOUND )
- subversion_wc_info( ${CMAKE_CURRENT_SOURCE_DIR} Project )
+ subversion_wc_info( ${SOURCE_DIR} Project )
if( Project_WC_REVISION )
set(SVN_REVISION ${Project_WC_REVISION} PARENT_SCOPE)
+ set(SVN_REPOSITORY ${Project_WC_URL} PARENT_SCOPE)
set(result "${result}-r${Project_WC_REVISION}")
endif()
endif()
- elseif( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git )
+ elseif( EXISTS ${SOURCE_DIR}/.git )
set(result "${result}git")
- # Try to get a ref-id
- if( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/svn )
- find_program(git_executable NAMES git git.exe git.cmd)
- if( git_executable )
+ find_program(git_executable NAMES git git.exe git.cmd)
+ if( git_executable )
+ # Try to get a ref-id
+ if( EXISTS ${SOURCE_DIR}/.git/svn )
set(is_git_svn_rev_exact false)
execute_process(COMMAND ${git_executable} svn log --limit=1 --oneline
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ WORKING_DIRECTORY ${SOURCE_DIR}
TIMEOUT 5
RESULT_VARIABLE git_result
OUTPUT_VARIABLE git_output)
@@ -36,10 +38,19 @@ function(add_version_info_from_vcs VERS)
string(SUBSTRING "${git_svn_rev}" 1 ${rev_length} git_svn_rev_number)
set(SVN_REVISION ${git_svn_rev_number} PARENT_SCOPE)
set(git_svn_rev "-svn-${git_svn_rev}")
-
+ # Get repository URL
+ execute_process(COMMAND ${git_executable} svn info --url
+ WORKING_DIRECTORY ${SOURCE_DIR}
+ TIMEOUT 5
+ RESULT_VARIABLE git_result
+ OUTPUT_VARIABLE git_output)
+ if( git_result EQUAL 0 )
+ string(STRIP "${git_output}" git_svn_info_url)
+ set(${VAR_PREFIX}_SVN_REPOSITORY ${git_svn_info_url} PARENT_SCOPE)
+ endif()
# Determine if the HEAD points directly at a subversion revision.
execute_process(COMMAND ${git_executable} svn find-rev HEAD
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ WORKING_DIRECTORY ${SOURCE_DIR}
TIMEOUT 5
RESULT_VARIABLE git_result
OUTPUT_VARIABLE git_output)
@@ -52,21 +63,34 @@ function(add_version_info_from_vcs VERS)
else()
set(git_svn_rev "")
endif()
- execute_process(COMMAND
- ${git_executable} rev-parse --short HEAD
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ else() # Figure out revision and URL from last commit footer
+ execute_process(COMMAND ${git_executable} log -1 --pretty=format:%b
+ WORKING_DIRECTORY ${SOURCE_DIR}
TIMEOUT 5
RESULT_VARIABLE git_result
OUTPUT_VARIABLE git_output)
- if( git_result EQUAL 0 AND NOT is_git_svn_rev_exact )
- string(STRIP "${git_output}" git_ref_id)
- set(GIT_COMMIT ${git_ref_id} PARENT_SCOPE)
- set(result "${result}${git_svn_rev}-${git_ref_id}")
- else()
- set(result "${result}${git_svn_rev}")
+ if( git_result EQUAL 0 AND
+ git_output MATCHES "^(.*\n)?git-svn-id: ([^@]*)@([0-9]+)" )
+ set(${VAR_PREFIX}_SVN_REVISION ${CMAKE_MATCH_3} PARENT_SCOPE)
+ set(${VAR_PREFIX}_SVN_REPOSITORY ${CMAKE_MATCH_2} PARENT_SCOPE)
+ set(git_svn_rev "-svn-r${CMAKE_MATCH_3}")
+ set(is_git_svn_rev_exact true)
endif()
endif()
+ execute_process(COMMAND
+ ${git_executable} rev-parse --short HEAD
+ WORKING_DIRECTORY ${SOURCE_DIR}
+ TIMEOUT 5
+ RESULT_VARIABLE git_result
+ OUTPUT_VARIABLE git_output)
+ if( git_result EQUAL 0 AND NOT is_git_svn_rev_exact )
+ string(STRIP "${git_output}" git_ref_id)
+ set(${VAR_PREFIX}_GIT_COMMIT ${git_ref_id} PARENT_SCOPE)
+ set(result "${result}${git_svn_rev}-${git_ref_id}")
+ else()
+ set(result "${result}${git_svn_rev}")
+ endif()
endif()
endif()
- set(${VERS} ${result} PARENT_SCOPE)
+ set(${VAR_PREFIX}_VERSION ${result} PARENT_SCOPE)
endfunction(add_version_info_from_vcs)
--
1.8.5.2 (Apple Git-48)
More information about the llvm-commits
mailing list