forked from llvm-mirror/llvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support: Add a VCSRevision.h header file.
This is a magic header file supported by the build system that provides a single definition, LLVM_REVISION, containing an LLVM revision identifier, if available. This functionality previously lived in the LTO library, but I am moving it out to lib/Support because I want to also start using it in lib/Object to create the IR symbol table. This change also fixes a bug where LLVM_REVISION was never actually being used in lib/LTO because the macro HAS_LLVM_REVISION was never defined (it was misspelled as HAVE_SVN_VERSION_INC in lib/LTO/CMakeLists.txt, and was only being defined in a non-existent file Version.cpp). I also changed the code to use "git rev-parse --git-dir" to locate the .git directory, instead of looking for it in the LLVM source root directory, which makes this compatible with monorepos as well as git worktrees. Differential Revision: https://reviews.llvm.org/D31985 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300160 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
Showing
6 changed files
with
106 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Figure out if we can track VC revisions. | ||
function(find_first_existing_file out_var) | ||
foreach(file ${ARGN}) | ||
if(EXISTS "${file}") | ||
set(${out_var} "${file}" PARENT_SCOPE) | ||
return() | ||
endif() | ||
endforeach() | ||
endfunction() | ||
|
||
macro(find_first_existing_vc_file out_var path) | ||
find_program(git_executable NAMES git git.exe git.cmd) | ||
# Run from a subdirectory to force git to print an absolute path. | ||
execute_process(COMMAND ${git_executable} rev-parse --git-dir | ||
WORKING_DIRECTORY ${path}/cmake | ||
RESULT_VARIABLE git_result | ||
OUTPUT_VARIABLE git_dir) | ||
if(git_result EQUAL 0) | ||
string(STRIP "${git_dir}" git_dir) | ||
set(${out_var} "${git_dir}/logs/HEAD") | ||
else() | ||
find_first_existing_file(${out_var} | ||
"${path}/.svn/wc.db" # SVN 1.7 | ||
"${path}/.svn/entries" # SVN 1.6 | ||
) | ||
endif() | ||
endmacro() | ||
|
||
find_first_existing_vc_file(llvm_vc "${LLVM_MAIN_SRC_DIR}") | ||
|
||
# The VC revision include that we want to generate. | ||
set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSRevision.h") | ||
|
||
set(get_svn_script "${LLVM_CMAKE_PATH}/GenerateVersionFromCVS.cmake") | ||
|
||
if(DEFINED llvm_vc) | ||
# Create custom target to generate the VC revision include. | ||
add_custom_command(OUTPUT "${version_inc}" | ||
DEPENDS "${llvm_vc}" "${get_svn_script}" | ||
COMMAND | ||
${CMAKE_COMMAND} "-DSOURCE_DIR=${LLVM_MAIN_SRC_DIR}" | ||
"-DNAME=LLVM_REVISION" | ||
"-DHEADER_FILE=${version_inc}" | ||
-P "${get_svn_script}") | ||
|
||
# Mark the generated header as being generated. | ||
set_source_files_properties("${version_inc}" | ||
PROPERTIES GENERATED TRUE | ||
HEADER_FILE_ONLY TRUE) | ||
else() | ||
file(WRITE "${version_inc}" "") | ||
endif() | ||
|
||
add_custom_target(llvm_vcsrevision_h DEPENDS "${version_inc}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters