Adam Strzelecki
2014-May-13 17:14 UTC
[LLVMdev] [PATCH] CMake add_version_info_from_vcs SVN_REPOSITORY
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. Also try to figure-out repository URL and revision from Git mirror parsing git-svn-id: footer from last commit (if present). --- cmake/modules/VersionFromVCS.cmake | 55 ++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/cmake/modules/VersionFromVCS.cmake b/cmake/modules/VersionFromVCS.cmake index 26314d4..4e140e9 100644 --- a/cmake/modules/VersionFromVCS.cmake +++ b/cmake/modules/VersionFromVCS.cmake @@ -1,9 +1,13 @@ # 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. +# existence of certain subdirectories under CMAKE_CURRENT_SOURCE_DIR +# or optional 2nd argument. function(add_version_info_from_vcs VERS) string(REPLACE "svn" "" result "${${VERS}}") + if( ARGV1 ) + set(CMAKE_CURRENT_SOURCE_DIR "${ARGV1}") + endif() if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.svn" ) set(result "${result}svn") # FindSubversion does not work with symlinks. See PR 8437 @@ -14,15 +18,16 @@ function(add_version_info_from_vcs VERS) subversion_wc_info( ${CMAKE_CURRENT_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 ) 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 ${CMAKE_CURRENT_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} @@ -36,7 +41,16 @@ 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 ${CMAKE_CURRENT_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} @@ -52,20 +66,33 @@ function(add_version_info_from_vcs VERS) else() set(git_svn_rev "") endif() - execute_process(COMMAND - ${git_executable} rev-parse --short HEAD + else() # Figure out revision and URL from last commit footer + execute_process(COMMAND ${git_executable} log -1 --pretty=format:%b WORKING_DIRECTORY ${CMAKE_CURRENT_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 ${CMAKE_CURRENT_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)
Robinson, Paul
2014-May-13 19:16 UTC
[LLVMdev] [PATCH] CMake add_version_info_from_vcs SVN_REPOSITORY
LLVM patches should go to the llvm-commits list, not llvmdev. --paulr> -----Original Message----- > From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] > On Behalf Of Adam Strzelecki > Sent: Tuesday, May 13, 2014 10:15 AM > To: llvmdev at cs.uiuc.edu > Subject: [LLVMdev] [PATCH] CMake add_version_info_from_vcs > SVN_REPOSITORY > > 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. > > Also try to figure-out repository URL and revision from Git mirror > parsing > git-svn-id: footer from last commit (if present). > --- > cmake/modules/VersionFromVCS.cmake | 55 ++++++++++++++++++++++++++++--- > ------- > 1 file changed, 41 insertions(+), 14 deletions(-) > > diff --git a/cmake/modules/VersionFromVCS.cmake > b/cmake/modules/VersionFromVCS.cmake > index 26314d4..4e140e9 100644 > --- a/cmake/modules/VersionFromVCS.cmake > +++ b/cmake/modules/VersionFromVCS.cmake > @@ -1,9 +1,13 @@ > # 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. > +# existence of certain subdirectories under CMAKE_CURRENT_SOURCE_DIR > +# or optional 2nd argument. > > function(add_version_info_from_vcs VERS) > string(REPLACE "svn" "" result "${${VERS}}") > + if( ARGV1 ) > + set(CMAKE_CURRENT_SOURCE_DIR "${ARGV1}") > + endif() > if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.svn" ) > set(result "${result}svn") > # FindSubversion does not work with symlinks. See PR 8437 > @@ -14,15 +18,16 @@ function(add_version_info_from_vcs VERS) > subversion_wc_info( ${CMAKE_CURRENT_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 ) > 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 ${CMAKE_CURRENT_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} > @@ -36,7 +41,16 @@ 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 ${CMAKE_CURRENT_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} > @@ -52,20 +66,33 @@ function(add_version_info_from_vcs VERS) > else() > set(git_svn_rev "") > endif() > - execute_process(COMMAND > - ${git_executable} rev-parse --short HEAD > + else() # Figure out revision and URL from last commit footer > + execute_process(COMMAND ${git_executable} log -1 -- > pretty=format:%b > WORKING_DIRECTORY ${CMAKE_CURRENT_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 ${CMAKE_CURRENT_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 Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Adam Strzelecki
2014-May-13 20:20 UTC
[LLVMdev] [PATCH] CMake add_version_info_from_vcs SVN_REPOSITORY
> LLVM patches should go to the llvm-commits list, not llvmdev.Paul, thank you for pointing that out. Next time I will be more careful about reading submitting guidelines. Cheers, -- Adam