2013-03-26 07:14:19 +08:00
|
|
|
# CMake project that writes Subversion revision information to a header.
|
|
|
|
#
|
|
|
|
# Input variables:
|
[cmake] GetSVN.cmake takes a list of arguments
Summary:
GetSVN.cmake currently takes one or two pairs of <source directory path,
name>, then attempts to get the remote repository URL and source control
revision of the repositories at those one or two paths.
It takes two pairs in order for Clang to get the revision of both
itself, and its dependency LLVM.
For projects that rely upon both LLVM and Clang (Apple's Swift is one
example, but there are others), GetSVN.cmake is used to fetch *three*
revisions: Swift, Clang, and LLVM.
To support this use case, change GetSVN.cmake: instead of taking one or
two pairs (specified via `FIRST_SOURCE_DIR`/`FIRST_NAME`, have it take a list
of pairs (`SOURCE_DIRS`/`NAMES`).
In order to allow Clang to migrate, have GetSVN.cmake support both sets
of arguments for now. The old arguments can be removed once Clang begins
using the new arguments, and Swift can follow when it updates its
copy of LLVM.
Test Plan:
1. Perform a clean build of Clang, verify that `clang --version` still
prints the correct LLVM and Clang revision information.
2. Modify Clang's CMake to use the new arguments, then perform another
clean build. `clang --version` should still print the correct
revision information.
Reviewers: jordan_rose, beanz, probinson
Subscribers: echristo, chapuni, llvm-commits, mgorny
Differential Revision: https://reviews.llvm.org/D35132
llvm-svn: 308507
2017-07-20 02:37:02 +08:00
|
|
|
# SOURCE_DIRS - A list of source directories.
|
|
|
|
# NAMES - A list of macro prefixes for each of the source directories.
|
|
|
|
# HEADER_FILE - The header file to write
|
2014-11-20 06:03:21 +08:00
|
|
|
#
|
[cmake] GetSVN.cmake takes a list of arguments
Summary:
GetSVN.cmake currently takes one or two pairs of <source directory path,
name>, then attempts to get the remote repository URL and source control
revision of the repositories at those one or two paths.
It takes two pairs in order for Clang to get the revision of both
itself, and its dependency LLVM.
For projects that rely upon both LLVM and Clang (Apple's Swift is one
example, but there are others), GetSVN.cmake is used to fetch *three*
revisions: Swift, Clang, and LLVM.
To support this use case, change GetSVN.cmake: instead of taking one or
two pairs (specified via `FIRST_SOURCE_DIR`/`FIRST_NAME`, have it take a list
of pairs (`SOURCE_DIRS`/`NAMES`).
In order to allow Clang to migrate, have GetSVN.cmake support both sets
of arguments for now. The old arguments can be removed once Clang begins
using the new arguments, and Swift can follow when it updates its
copy of LLVM.
Test Plan:
1. Perform a clean build of Clang, verify that `clang --version` still
prints the correct LLVM and Clang revision information.
2. Modify Clang's CMake to use the new arguments, then perform another
clean build. `clang --version` should still print the correct
revision information.
Reviewers: jordan_rose, beanz, probinson
Subscribers: echristo, chapuni, llvm-commits, mgorny
Differential Revision: https://reviews.llvm.org/D35132
llvm-svn: 308507
2017-07-20 02:37:02 +08:00
|
|
|
# The output header will contain macros <NAME>_REPOSITORY and <NAME>_REVISION,
|
|
|
|
# where "<NAME>" and is substituted with the names specified in the input
|
|
|
|
# variables, for each of the SOURCE_DIRS given.
|
2014-11-20 06:03:21 +08:00
|
|
|
|
[cmake] GetSVN.cmake takes a list of arguments
Summary:
GetSVN.cmake currently takes one or two pairs of <source directory path,
name>, then attempts to get the remote repository URL and source control
revision of the repositories at those one or two paths.
It takes two pairs in order for Clang to get the revision of both
itself, and its dependency LLVM.
For projects that rely upon both LLVM and Clang (Apple's Swift is one
example, but there are others), GetSVN.cmake is used to fetch *three*
revisions: Swift, Clang, and LLVM.
To support this use case, change GetSVN.cmake: instead of taking one or
two pairs (specified via `FIRST_SOURCE_DIR`/`FIRST_NAME`, have it take a list
of pairs (`SOURCE_DIRS`/`NAMES`).
In order to allow Clang to migrate, have GetSVN.cmake support both sets
of arguments for now. The old arguments can be removed once Clang begins
using the new arguments, and Swift can follow when it updates its
copy of LLVM.
Test Plan:
1. Perform a clean build of Clang, verify that `clang --version` still
prints the correct LLVM and Clang revision information.
2. Modify Clang's CMake to use the new arguments, then perform another
clean build. `clang --version` should still print the correct
revision information.
Reviewers: jordan_rose, beanz, probinson
Subscribers: echristo, chapuni, llvm-commits, mgorny
Differential Revision: https://reviews.llvm.org/D35132
llvm-svn: 308507
2017-07-20 02:37:02 +08:00
|
|
|
# Chop off cmake/modules/GetSVN.cmake
|
2014-11-20 06:03:21 +08:00
|
|
|
get_filename_component(LLVM_DIR "${CMAKE_SCRIPT_MODE_FILE}" PATH)
|
|
|
|
get_filename_component(LLVM_DIR "${LLVM_DIR}" PATH)
|
|
|
|
get_filename_component(LLVM_DIR "${LLVM_DIR}" PATH)
|
|
|
|
|
|
|
|
# Handle strange terminals
|
|
|
|
set(ENV{TERM} "dumb")
|
2013-09-17 05:38:01 +08:00
|
|
|
|
2014-12-05 08:50:15 +08:00
|
|
|
macro(get_source_info_svn path revision repository)
|
2014-12-10 08:10:21 +08:00
|
|
|
# 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)
|
|
|
|
|
2014-12-05 08:50:15 +08:00
|
|
|
# FindSubversion does not work with symlinks. See PR 8437
|
|
|
|
if (NOT IS_SYMLINK "${path}")
|
|
|
|
find_package(Subversion)
|
|
|
|
endif()
|
|
|
|
if (Subversion_FOUND)
|
|
|
|
subversion_wc_info( ${path} 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()
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
macro(get_source_info_git_svn path revision repository)
|
|
|
|
find_program(git_executable NAMES git git.exe git.cmd)
|
|
|
|
if (git_executable)
|
|
|
|
execute_process(COMMAND ${git_executable} svn info
|
|
|
|
WORKING_DIRECTORY ${path}
|
|
|
|
TIMEOUT 5
|
|
|
|
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()
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
macro(get_source_info_git path revision repository)
|
|
|
|
find_program(git_executable NAMES git git.exe git.cmd)
|
|
|
|
if (git_executable)
|
|
|
|
execute_process(COMMAND ${git_executable} log -1 --pretty=format:%H
|
|
|
|
WORKING_DIRECTORY ${path}
|
|
|
|
TIMEOUT 5
|
|
|
|
RESULT_VARIABLE git_result
|
|
|
|
OUTPUT_VARIABLE git_output)
|
|
|
|
if (git_result EQUAL 0)
|
|
|
|
set(${revision} ${git_output} PARENT_SCOPE)
|
|
|
|
endif()
|
|
|
|
execute_process(COMMAND ${git_executable} remote -v
|
|
|
|
WORKING_DIRECTORY ${path}
|
|
|
|
TIMEOUT 5
|
|
|
|
RESULT_VARIABLE git_result
|
|
|
|
OUTPUT_VARIABLE git_output)
|
|
|
|
if (git_result EQUAL 0)
|
|
|
|
string(REGEX REPLACE "^(.*\n)?[^ \t]+[ \t]+([^ \t\n]+)[ \t]+\\(fetch\\).*"
|
|
|
|
"\\2" git_url "${git_output}")
|
|
|
|
set(${repository} "${git_url}" PARENT_SCOPE)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
function(get_source_info path revision repository)
|
|
|
|
if (EXISTS "${path}/.svn")
|
|
|
|
get_source_info_svn("${path}" revision repository)
|
[CMake] Update GetSVN.cmake to handle repo
Summary:
When repo is used with git, 'clang --version' option does not display
the correct revision information (i.e. git hash on TOP) as the following:
clang version 6.0.0 --->
clang version 6.0.0 (clang version) (llvm version)
This is because repo also creates .git/svn folder as git-svn does and
this makes repo with git uses "git svn info" command, which is only for
git-svn, to retrieve its revision information, making null for the info.
To correctly distinguish between git-svn and repo with git, the folder
hierarchy to specify for git-svn should be .git/svn/refs as the "git svn
info" command depends on the revision data in .git/svn/refs. This patch
in turn makes repo with git passes through to the third macro,
get_source_info_git, in get_source_info function, resulting in correctly
retrieving the revision information for repo with git using "git log ..."
command.
This patch is tested with git, svn, git-svn, and repo with git.
Reviewers: llvm-commits, probinson, rnk
Reviewed By: rnk
Subscribers: rnk, mehdi_amini, beanz, mgorny
Differential Revision: https://reviews.llvm.org/D35532
llvm-svn: 312864
2017-09-09 22:17:52 +08:00
|
|
|
elseif (EXISTS "${path}/.git/svn/refs")
|
2014-12-05 08:50:15 +08:00
|
|
|
get_source_info_git_svn("${path}" revision repository)
|
|
|
|
elseif (EXISTS "${path}/.git")
|
|
|
|
get_source_info_git("${path}" revision repository)
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2014-11-20 06:03:21 +08:00
|
|
|
function(append_info name path)
|
2014-12-05 08:50:15 +08:00
|
|
|
get_source_info("${path}" revision repository)
|
2014-11-20 06:03:21 +08:00
|
|
|
string(STRIP "${revision}" revision)
|
|
|
|
string(STRIP "${repository}" repository)
|
|
|
|
file(APPEND "${HEADER_FILE}.txt"
|
|
|
|
"#define ${name}_REVISION \"${revision}\"\n")
|
|
|
|
file(APPEND "${HEADER_FILE}.txt"
|
|
|
|
"#define ${name}_REPOSITORY \"${repository}\"\n")
|
|
|
|
endfunction()
|
2013-03-26 07:14:19 +08:00
|
|
|
|
[cmake] GetSVN.cmake takes a list of arguments
Summary:
GetSVN.cmake currently takes one or two pairs of <source directory path,
name>, then attempts to get the remote repository URL and source control
revision of the repositories at those one or two paths.
It takes two pairs in order for Clang to get the revision of both
itself, and its dependency LLVM.
For projects that rely upon both LLVM and Clang (Apple's Swift is one
example, but there are others), GetSVN.cmake is used to fetch *three*
revisions: Swift, Clang, and LLVM.
To support this use case, change GetSVN.cmake: instead of taking one or
two pairs (specified via `FIRST_SOURCE_DIR`/`FIRST_NAME`, have it take a list
of pairs (`SOURCE_DIRS`/`NAMES`).
In order to allow Clang to migrate, have GetSVN.cmake support both sets
of arguments for now. The old arguments can be removed once Clang begins
using the new arguments, and Swift can follow when it updates its
copy of LLVM.
Test Plan:
1. Perform a clean build of Clang, verify that `clang --version` still
prints the correct LLVM and Clang revision information.
2. Modify Clang's CMake to use the new arguments, then perform another
clean build. `clang --version` should still print the correct
revision information.
Reviewers: jordan_rose, beanz, probinson
Subscribers: echristo, chapuni, llvm-commits, mgorny
Differential Revision: https://reviews.llvm.org/D35132
llvm-svn: 308507
2017-07-20 02:37:02 +08:00
|
|
|
function(validate_inputs source_dirs names)
|
|
|
|
list(LENGTH source_dirs source_dirs_length)
|
|
|
|
list(LENGTH names names_length)
|
|
|
|
if (NOT source_dirs_length EQUAL names_length)
|
|
|
|
message(FATAL_ERROR
|
|
|
|
"GetSVN.cmake takes two arguments: a list of source directories, "
|
|
|
|
"and a list of names. Expected two lists must be of equal length, "
|
|
|
|
"but got ${source_dirs_length} source directories and "
|
|
|
|
"${names_length} names.")
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
if (DEFINED SOURCE_DIRS AND DEFINED NAMES)
|
|
|
|
validate_inputs("${SOURCE_DIRS}" "${NAMES}")
|
|
|
|
|
|
|
|
list(LENGTH SOURCE_DIRS source_dirs_length)
|
|
|
|
math(EXPR source_dirs_max_index ${source_dirs_length}-1)
|
|
|
|
foreach(index RANGE ${source_dirs_max_index})
|
|
|
|
list(GET SOURCE_DIRS ${index} source_dir)
|
|
|
|
list(GET NAMES ${index} name)
|
|
|
|
append_info(${name} ${source_dir})
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Allow -DFIRST_SOURCE_DIR arguments until Clang migrates to the new
|
|
|
|
# -DSOURCE_DIRS argument.
|
|
|
|
if(DEFINED FIRST_SOURCE_DIR)
|
|
|
|
append_info(${FIRST_NAME} "${FIRST_SOURCE_DIR}")
|
|
|
|
if(DEFINED SECOND_SOURCE_DIR)
|
|
|
|
append_info(${SECOND_NAME} "${SECOND_SOURCE_DIR}")
|
|
|
|
endif()
|
2013-03-26 07:14:19 +08:00
|
|
|
endif()
|
2014-11-20 06:03:21 +08:00
|
|
|
|
|
|
|
# Copy the file only if it has changed.
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
|
|
"${HEADER_FILE}.txt" "${HEADER_FILE}")
|
|
|
|
file(REMOVE "${HEADER_FILE}.txt")
|
|
|
|
|