[PATCH] CMake: extend add_version_info_from_vcs

Chandler Carruth chandlerc at google.com
Mon May 26 22:10:04 PDT 2014


On Wed, May 14, 2014 at 3:08 PM, Adam Strzelecki <ono at java.pl> wrote:

> CMake add_version_info_from_vcs function now requires 2nd SOURCE_DIR
> argument
> specifying where to lookup repository information.
>

I'm curious, why not just call this from the right position? I'm not really
opposed to using a SOURCE_DIR, but it seems not unreasonable that each
subproject would call this from its top-most CMakeLists.txt only, and set
up variables to be used from there down.


> 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 seems like strict goodness. Should it be separated into its own patch?

Also, you seem to be making a large number of cleanups to the function
while there. This is nice, but should be mentioned.


>
> 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.
>

It's good to clarify that this function is mucking with the parent scope,
but I really wish it just *didn't* muck with the parent scope.

If you're interested in this area, the correct interface (IMO) is accept a
variable *prefix*, and then to set prefixed variables so I could write:

add_version_info_from_vcs(FOO)
message("Foo version: ${FOO_VERSION}")
message("Foo svn revision: ${FOO_SVN_REVISION}")
message("Foo svn repository: ${FOO_SVN_REPOSITORY}")
message("Foo git commit: ${FOO_GIT_COMMIT}")

(Or something like this... It's just pseudo-CMake but you get the idea I
suspect)

This will also require some changes throughout LLVM and Clang's existing
setup, but will make your subsequent patch make a lot more sense because
then we'll have LLVM_SVN_REVISION from the beginning, and not have any name
conflicts.

Also, we've been really lax about exactly how to represent the N revision
numbers that apply to a single clang binary. We should be more careful
about this, but it just hasn't come up thus far.... We should at least
clearly separate the revision of LLVM and the revision of Clang...


>
> -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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140526/9311a5e1/attachment.html>


More information about the llvm-commits mailing list