llvm.org GIT mirror llvm / cc946df
CMake: Clean up VersionFromVCS.cmake Summary: Fix a few problems in VersionFromVCS.cmake to make it more reliable: - Stop using git svn info to retrieve the svn revision. I am unable to determine what the svn revision returned by this command means. During my testing this command returned a revision from a month ago which was not the HEAD of any of my local branches. Also, this revision was never actually added to the version string due to a typo in the script. All it was used for was to reject the revision number returned by git svn find-rev HEAD when the revision numbers didn't match. - Populate GIT_COMMIT even when we detect a git repo without any svn information. Reviewers: mehdi_amini, beanz Reviewed By: beanz Subscribers: mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D30092 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296829 91177308-0d34-0410-b5e6-96231b3b80d8 Tom Stellard 3 years ago
1 changed file(s) with 30 addition(s) and 34 deletion(s). Raw diff Collapse all Expand all
2727 elseif( EXISTS ${SOURCE_DIR}/.git )
2828 set(result "${result}git")
2929 # Try to get a ref-id
30 if( EXISTS ${SOURCE_DIR}/.git/svn )
31 find_program(git_executable NAMES git git.exe git.cmd)
32 if( git_executable )
33 set(is_git_svn_rev_exact false)
30 find_program(git_executable NAMES git git.exe git.cmd)
31
32 if( git_executable )
33 if( EXISTS ${SOURCE_DIR}/.git/svn )
34 # Get the repository URL
3435 execute_process(COMMAND
3536 ${git_executable} svn info
3637 WORKING_DIRECTORY ${SOURCE_DIR}
4243 if(svn_url)
4344 set(LLVM_REPOSITORY ${CMAKE_MATCH_1} PARENT_SCOPE)
4445 endif()
46 endif()
4547
46 string(REGEX REPLACE "^(.*\n)?Revision: ([^\n]+).*"
47 "\\2" git_svn_rev_number "${git_output}")
48 set(SVN_REVISION ${git_svn_rev_number} PARENT_SCOPE)
49 set(git_svn_rev "-svn-${git_svn_rev}")
50
51 # Determine if the HEAD points directly at a subversion revision.
52 execute_process(COMMAND ${git_executable} svn find-rev HEAD
53 WORKING_DIRECTORY ${SOURCE_DIR}
54 TIMEOUT 5
55 RESULT_VARIABLE git_result
56 OUTPUT_VARIABLE git_output)
57 if( git_result EQUAL 0 )
58 string(STRIP "${git_output}" git_head_svn_rev_number)
59 if( git_head_svn_rev_number EQUAL git_svn_rev_number )
60 set(is_git_svn_rev_exact true)
61 endif()
62 endif()
48 # Get the svn revision number for this git commit if one exists.
49 execute_process(COMMAND ${git_executable} svn find-rev HEAD
50 WORKING_DIRECTORY ${SOURCE_DIR}
51 TIMEOUT 5
52 RESULT_VARIABLE git_result
53 OUTPUT_VARIABLE git_head_svn_rev_number
54 OUTPUT_STRIP_TRAILING_WHITESPACE)
55 if( git_result EQUAL 0 AND git_output)
56 set(SVN_REVISION ${git_head_svn_rev_number} PARENT_SCOPE)
57 set(git_svn_rev "-svn-${git_head_svn_rev_number}")
6358 else()
6459 set(git_svn_rev "")
6560 endif()
66 execute_process(COMMAND
67 ${git_executable} rev-parse --short HEAD
68 WORKING_DIRECTORY ${SOURCE_DIR}
69 TIMEOUT 5
70 RESULT_VARIABLE git_result
71 OUTPUT_VARIABLE git_output)
61 endif()
7262
73 if( git_result EQUAL 0 AND NOT is_git_svn_rev_exact )
74 string(STRIP "${git_output}" git_ref_id)
75 set(GIT_COMMIT ${git_ref_id} PARENT_SCOPE)
76 set(result "${result}${git_svn_rev}-${git_ref_id}")
77 else()
78 set(result "${result}${git_svn_rev}")
79 endif()
63 # Get the git ref id
64 execute_process(COMMAND
65 ${git_executable} rev-parse --short HEAD
66 WORKING_DIRECTORY ${SOURCE_DIR}
67 TIMEOUT 5
68 RESULT_VARIABLE git_result
69 OUTPUT_VARIABLE git_ref_id
70 OUTPUT_STRIP_TRAILING_WHITESPACE)
8071
72 if( git_result EQUAL 0 )
73 set(GIT_COMMIT ${git_ref_id} PARENT_SCOPE)
74 set(result "${result}${git_svn_rev}-${git_ref_id}")
75 else()
76 set(result "${result}${git_svn_rev}")
8177 endif()
8278 endif()
8379 endif()