llvm.org GIT mirror llvm / 8b69529
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 Peter Collingbourne 2 years ago
6 changed file(s) with 109 addition(s) and 97 deletion(s). Raw diff Collapse all Expand all
2424 set(LLVM_REPOSITORY ${Project_WC_URL} PARENT_SCOPE)
2525 endif()
2626 endif()
27 elseif( EXISTS ${SOURCE_DIR}/.git )
28 set(result "${result}git")
29 # Try to get a ref-id
27 else()
3028 find_program(git_executable NAMES git git.exe git.cmd)
3129
3230 if( git_executable )
33 if( EXISTS ${SOURCE_DIR}/.git/svn )
34 # Get the repository URL
31 # Run from a subdirectory to force git to print an absoute path.
32 execute_process(COMMAND ${git_executable} rev-parse --git-dir
33 WORKING_DIRECTORY ${SOURCE_DIR}/cmake
34 RESULT_VARIABLE git_result
35 OUTPUT_VARIABLE git_dir)
36 if(git_result EQUAL 0)
37 # Try to get a ref-id
38 string(STRIP "${git_dir}" git_dir)
39 set(result "${result}git")
40 if( EXISTS ${git_dir}/svn )
41 # Get the repository URL
42 execute_process(COMMAND
43 ${git_executable} svn info
44 WORKING_DIRECTORY ${SOURCE_DIR}
45 TIMEOUT 5
46 RESULT_VARIABLE git_result
47 OUTPUT_VARIABLE git_output)
48 if( git_result EQUAL 0 )
49 string(REGEX MATCH "URL: ([^ \n]*)" svn_url ${git_output})
50 if(svn_url)
51 set(LLVM_REPOSITORY ${CMAKE_MATCH_1} PARENT_SCOPE)
52 endif()
53 endif()
54
55 # Get the svn revision number for this git commit if one exists.
56 execute_process(COMMAND ${git_executable} svn find-rev HEAD
57 WORKING_DIRECTORY ${SOURCE_DIR}
58 TIMEOUT 5
59 RESULT_VARIABLE git_result
60 OUTPUT_VARIABLE git_head_svn_rev_number
61 OUTPUT_STRIP_TRAILING_WHITESPACE)
62 if( git_result EQUAL 0 AND git_output)
63 set(SVN_REVISION ${git_head_svn_rev_number} PARENT_SCOPE)
64 set(git_svn_rev "-svn-${git_head_svn_rev_number}")
65 else()
66 set(git_svn_rev "")
67 endif()
68 endif()
69
70 # Get the git ref id
3571 execute_process(COMMAND
36 ${git_executable} svn info
72 ${git_executable} rev-parse --short HEAD
3773 WORKING_DIRECTORY ${SOURCE_DIR}
3874 TIMEOUT 5
3975 RESULT_VARIABLE git_result
40 OUTPUT_VARIABLE git_output)
76 OUTPUT_VARIABLE git_ref_id
77 OUTPUT_STRIP_TRAILING_WHITESPACE)
78
4179 if( git_result EQUAL 0 )
42 string(REGEX MATCH "URL: ([^ \n]*)" svn_url ${git_output})
43 if(svn_url)
44 set(LLVM_REPOSITORY ${CMAKE_MATCH_1} PARENT_SCOPE)
45 endif()
80 set(GIT_COMMIT ${git_ref_id} PARENT_SCOPE)
81 set(result "${result}${git_svn_rev}-${git_ref_id}")
82 else()
83 set(result "${result}${git_svn_rev}")
4684 endif()
47
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}")
58 else()
59 set(git_svn_rev "")
60 endif()
61 endif()
62
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)
71
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}")
7785 endif()
7886 endif()
7987 endif()
0 add_subdirectory(IR)
1 add_subdirectory(Support)
12
23 # If we're doing an out-of-tree build, copy a module map for generated
34 # header files into the build area.
0 # Figure out if we can track VC revisions.
1 function(find_first_existing_file out_var)
2 foreach(file ${ARGN})
3 if(EXISTS "${file}")
4 set(${out_var} "${file}" PARENT_SCOPE)
5 return()
6 endif()
7 endforeach()
8 endfunction()
9
10 macro(find_first_existing_vc_file out_var path)
11 find_program(git_executable NAMES git git.exe git.cmd)
12 # Run from a subdirectory to force git to print an absolute path.
13 execute_process(COMMAND ${git_executable} rev-parse --git-dir
14 WORKING_DIRECTORY ${path}/cmake
15 RESULT_VARIABLE git_result
16 OUTPUT_VARIABLE git_dir)
17 if(git_result EQUAL 0)
18 string(STRIP "${git_dir}" git_dir)
19 set(${out_var} "${git_dir}/logs/HEAD")
20 else()
21 find_first_existing_file(${out_var}
22 "${path}/.svn/wc.db" # SVN 1.7
23 "${path}/.svn/entries" # SVN 1.6
24 )
25 endif()
26 endmacro()
27
28 find_first_existing_vc_file(llvm_vc "${LLVM_MAIN_SRC_DIR}")
29
30 # The VC revision include that we want to generate.
31 set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSRevision.h")
32
33 set(get_svn_script "${LLVM_CMAKE_PATH}/GenerateVersionFromCVS.cmake")
34
35 if(DEFINED llvm_vc)
36 # Create custom target to generate the VC revision include.
37 add_custom_command(OUTPUT "${version_inc}"
38 DEPENDS "${llvm_vc}" "${get_svn_script}"
39 COMMAND
40 ${CMAKE_COMMAND} "-DSOURCE_DIR=${LLVM_MAIN_SRC_DIR}"
41 "-DNAME=LLVM_REVISION"
42 "-DHEADER_FILE=${version_inc}"
43 -P "${get_svn_script}")
44
45 # Mark the generated header as being generated.
46 set_source_files_properties("${version_inc}"
47 PROPERTIES GENERATED TRUE
48 HEADER_FILE_ONLY TRUE)
49 else()
50 file(WRITE "${version_inc}" "")
51 endif()
52
53 add_custom_target(llvm_vcsrevision_h DEPENDS "${version_inc}")
None # Figure out if we can track VC revisions.
1 function(find_first_existing_file out_var)
2 foreach(file ${ARGN})
3 if(EXISTS "${file}")
4 set(${out_var} "${file}" PARENT_SCOPE)
5 return()
6 endif()
7 endforeach()
8 endfunction()
9
10 macro(find_first_existing_vc_file out_var path)
11 find_first_existing_file(${out_var}
12 "${path}/.git/logs/HEAD" # Git
13 "${path}/.svn/wc.db" # SVN 1.7
14 "${path}/.svn/entries" # SVN 1.6
15 )
16 endmacro()
17
18 find_first_existing_vc_file(llvm_vc "${LLVM_MAIN_SRC_DIR}")
19
20 # The VC revision include that we want to generate.
21 set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/LLVMLTORevision.h")
22
23 set(get_svn_script "${LLVM_CMAKE_PATH}/GenerateVersionFromCVS.cmake")
24
25 if(DEFINED llvm_vc)
26 # Create custom target to generate the VC revision include.
27 add_custom_command(OUTPUT "${version_inc}"
28 DEPENDS "${llvm_vc}" "${get_svn_script}"
29 COMMAND
30 ${CMAKE_COMMAND} "-DSOURCE_DIR=${LLVM_MAIN_SRC_DIR}"
31 "-DNAME=LLVM_REVISION"
32 "-DHEADER_FILE=${version_inc}"
33 -P "${get_svn_script}")
34
35 # Mark the generated header as being generated.
36 set_source_files_properties("${version_inc}"
37 PROPERTIES GENERATED TRUE
38 HEADER_FILE_ONLY TRUE)
39
40 # Tell Version.cpp that it needs to build with -DHAVE_SVN_VERSION_INC.
41 set_source_files_properties(Version.cpp
42 PROPERTIES COMPILE_DEFINITIONS "HAVE_SVN_VERSION_INC")
43 else()
44 # Not producing a VC revision include.
45 set(version_inc)
46 endif()
47
48
49 add_llvm_library(LLVMLTO
501 Caching.cpp
512 LTO.cpp
545 LTOCodeGenerator.cpp
556 UpdateCompilerUsed.cpp
567 ThinLTOCodeGenerator.cpp
57 ${version_inc}
588
599 ADDITIONAL_HEADER_DIRS
6010 ${LLVM_MAIN_INCLUDE_DIR}/llvm/LTO
6111
6212 DEPENDS
6313 intrinsics_gen
14 llvm_vcsrevision_h
6415 )
3434 #include "llvm/Support/TargetRegistry.h"
3535 #include "llvm/Support/ThreadPool.h"
3636 #include "llvm/Support/Threading.h"
37 #include "llvm/Support/VCSRevision.h"
3738 #include "llvm/Support/raw_ostream.h"
3839 #include "llvm/Target/TargetMachine.h"
3940 #include "llvm/Target/TargetOptions.h"
7374
7475 // Start with the compiler revision
7576 Hasher.update(LLVM_VERSION_STRING);
76 #ifdef HAVE_LLVM_REVISION
77 #ifdef LLVM_REVISION
7778 Hasher.update(LLVM_REVISION);
7879 #endif
7980
1212 //===----------------------------------------------------------------------===//
1313
1414 #include "llvm/LTO/legacy/ThinLTOCodeGenerator.h"
15
16 #ifdef HAVE_LLVM_REVISION
17 #include "LLVMLTORevision.h"
18 #endif
1915
2016 #include "llvm/ADT/Statistic.h"
2117 #include "llvm/ADT/StringExtras.h"
4642 #include "llvm/Support/ThreadPool.h"
4743 #include "llvm/Support/Threading.h"
4844 #include "llvm/Support/ToolOutputFile.h"
45 #include "llvm/Support/VCSRevision.h"
4946 #include "llvm/Target/TargetMachine.h"
5047 #include "llvm/Transforms/IPO.h"
5148 #include "llvm/Transforms/IPO/FunctionImport.h"
303300
304301 // Start with the compiler revision
305302 Hasher.update(LLVM_VERSION_STRING);
306 #ifdef HAVE_LLVM_REVISION
303 #ifdef LLVM_REVISION
307304 Hasher.update(LLVM_REVISION);
308305 #endif
309306