[PATCH] CMake: extend add_version_info_from_vcs
Tilmann Scheller
t.scheller at samsung.com
Fri May 16 00:11:28 PDT 2014
Hi Adam,
Patch looks good, thanks :)
CCing Chandler who is the code owner of the CMake files to get the final
sign off.
The clang side of the patch is at:
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20140512/105438.h
tml
Regards,
Tilmann
-----Original Message-----
From: llvm-commits-bounces at cs.uiuc.edu
[mailto:llvm-commits-bounces at cs.uiuc.edu] On Behalf Of Adam Strzelecki
Sent: Thursday, May 15, 2014 12:09 AM
To: llvm-commits at cs.uiuc.edu
Subject: [PATCH] CMake: extend add_version_info_from_vcs
CMake add_version_info_from_vcs function now requires 2nd SOURCE_DIR
argument specifying where to lookup repository information.
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 | 73
+++++++++++++++++++++++++-------------
2 files changed, 50 insertions(+), 25 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ec3e33..bc91b00 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_VERSION
+ ${CMAKE_CURRENT_SOURCE_DIR})
endif()
set(PACKAGE_NAME LLVM)
diff --git a/cmake/modules/VersionFromVCS.cmake
b/cmake/modules/VersionFromVCS.cmake
index 26314d4..867331f 100644
--- a/cmake/modules/VersionFromVCS.cmake
+++ b/cmake/modules/VersionFromVCS.cmake
@@ -1,31 +1,34 @@
-# 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 variable VERS. For
+determining the # Version Control System used (if any) it inspects the
+existence of certain # subdirectories under SOURCE_DIR.
+# Additionaly sets SVN_REVISION and SVN_REPOSITORY parent scope
+variables to # source code revision and repository URL.
-function(add_version_info_from_vcs VERS)
+function(add_version_info_from_vcs VERS SOURCE_DIR)
string(REPLACE "svn" "" result "${${VERS}}")
- if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.svn" )
+ 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 +39,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(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,20 +64,33 @@
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(SVN_REVISION ${CMAKE_MATCH_3} PARENT_SCOPE)
+ set(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(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)
--
1.8.5.2 (Apple Git-48)
_______________________________________________
llvm-commits mailing list
llvm-commits at cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list