File: VersionFromVCS.cmake

package info (click to toggle)
llvm-toolchain-9 1%3A9.0.1-16.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 882,388 kB
  • sloc: cpp: 4,167,636; ansic: 714,256; asm: 457,610; python: 155,927; objc: 65,094; sh: 42,856; lisp: 26,908; perl: 7,786; pascal: 7,722; makefile: 6,881; ml: 5,581; awk: 3,648; cs: 2,027; xml: 888; javascript: 381; ruby: 156
file content (94 lines) | stat: -rw-r--r-- 3,592 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# 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 (if provided as an
# extra argument, otherwise uses CMAKE_CURRENT_SOURCE_DIR).

function(get_source_info_svn path revision repository)
  # If svn is a bat file, find_program(Subversion) doesn't find it.
  # Explicitly search for that here; Subversion_SVN_EXECUTABLE will override
  # the find_program call in FindSubversion.cmake.
  find_program(Subversion_SVN_EXECUTABLE NAMES svn svn.bat)
  find_package(Subversion)

  # Subversion module does not work with symlinks, see PR8437.
  get_filename_component(realpath ${path} REALPATH)
  if(Subversion_FOUND)
    subversion_wc_info(${realpath} Project)
    if(Project_WC_REVISION)
      set(${revision} ${Project_WC_REVISION} PARENT_SCOPE)
    endif()
    if(Project_WC_URL)
      set(${repository} ${Project_WC_URL} PARENT_SCOPE)
    endif()
  endif()
endfunction()

function(get_source_info_git path revision repository)
  find_package(Git)
  if(GIT_FOUND)
    execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --git-dir
      WORKING_DIRECTORY ${path}
      RESULT_VARIABLE git_result
      OUTPUT_VARIABLE git_output
      ERROR_QUIET)
    if(git_result EQUAL 0)
      string(STRIP "${git_output}" git_output)
      get_filename_component(git_dir ${git_output} ABSOLUTE BASE_DIR ${path})
      if(EXISTS "${git_dir}/svn/refs")
        execute_process(COMMAND ${GIT_EXECUTABLE} svn info
          WORKING_DIRECTORY ${path}
          RESULT_VARIABLE git_result
          OUTPUT_VARIABLE git_output)
        if(git_result EQUAL 0)
          string(REGEX REPLACE "^(.*\n)?Revision: ([^\n]+).*"
            "\\2" git_svn_rev "${git_output}")
          set(${revision} ${git_svn_rev} PARENT_SCOPE)
          string(REGEX REPLACE "^(.*\n)?URL: ([^\n]+).*"
            "\\2" git_url "${git_output}")
          set(${repository} ${git_url} PARENT_SCOPE)
        endif()
      else()
        execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
          WORKING_DIRECTORY ${path}
          RESULT_VARIABLE git_result
          OUTPUT_VARIABLE git_output)
        if(git_result EQUAL 0)
          string(STRIP "${git_output}" git_output)
          set(${revision} ${git_output} PARENT_SCOPE)
        endif()
        execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref --symbolic-full-name @{upstream}
          WORKING_DIRECTORY ${path}
          RESULT_VARIABLE git_result
          OUTPUT_VARIABLE git_output
          ERROR_QUIET)
        if(git_result EQUAL 0)
          string(REPLACE "/" ";" branch ${git_output})
          list(GET branch 0 remote)
        else()
          set(remote "origin")
        endif()
        execute_process(COMMAND ${GIT_EXECUTABLE} remote get-url ${remote}
          WORKING_DIRECTORY ${path}
          RESULT_VARIABLE git_result
          OUTPUT_VARIABLE git_output
          ERROR_QUIET)
        if(git_result EQUAL 0)
          string(STRIP "${git_output}" git_output)
          set(${repository} ${git_output} PARENT_SCOPE)
        else()
          set(${repository} ${path} PARENT_SCOPE)
        endif()
      endif()
    endif()
  endif()
endfunction()

function(get_source_info path revision repository)
  if(EXISTS "${path}/.svn")
    get_source_info_svn("${path}" revision_info repository_info)
  else()
    get_source_info_git("${path}" revision_info repository_info)
  endif()
  set(${repository} "${repository_info}" PARENT_SCOPE)
  set(${revision} "${revision_info}" PARENT_SCOPE)
endfunction()