From 1d30fcaccf6886190d635304cfa120fdf4b938ff Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Sat, 16 Apr 2016 07:33:14 +0000 Subject: [PATCH] Add SVN version to libLLVMLTO Summary: For Incremental LTO, we need to make sure that an old cache entry is not used when incrementally re-linking with a new libLTO. Adding a global LLVM_REVISION in llvm-config.h would for to rebuild/relink the world for every "git pull"/"svn update". So instead only libLTO is made dependent on the VCS and will be rebuilt (and the dependent binaries relinked, i.e. as of today: libLTO.dylib and llvm-lto). Reviewers: beanz Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D18987 From: Mehdi Amini llvm-svn: 266523 --- llvm/cmake/modules/GenerateVersionFromCVS.cmake | 39 +++++++++++++++++++ llvm/cmake/modules/VersionFromVCS.cmake | 24 +++++++----- llvm/lib/LTO/CMakeLists.txt | 50 +++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 llvm/cmake/modules/GenerateVersionFromCVS.cmake diff --git a/llvm/cmake/modules/GenerateVersionFromCVS.cmake b/llvm/cmake/modules/GenerateVersionFromCVS.cmake new file mode 100644 index 0000000..6b1c719 --- /dev/null +++ b/llvm/cmake/modules/GenerateVersionFromCVS.cmake @@ -0,0 +1,39 @@ +# CMake project that writes Subversion revision information to a header. +# +# Input variables: +# SRC - Source directory +# HEADER_FILE - The header file to write +# +# The output header will contain macros FIRST_REPOSITORY and FIRST_REVISION, +# and SECOND_REPOSITORY and SECOND_REVISION if requested, where "FIRST" and +# "SECOND" are substituted with the names specified in the input variables. + + + +# Chop off cmake/modules/GetSVN.cmake +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) + +set(CMAKE_MODULE_PATH + ${CMAKE_MODULE_PATH} + "${LLVM_DIR}/cmake/modules") +include(VersionFromVCS) + +# Handle strange terminals +set(ENV{TERM} "dumb") + +function(append_info name path) + add_version_info_from_vcs(REVISION ${path}) + string(STRIP "${REVISION}" REVISION) + file(APPEND "${HEADER_FILE}.txt" + "#define ${name} \"${REVISION}\"\n") +endfunction() + +append_info(${NAME} "${SOURCE_DIR}") + +# 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") + diff --git a/llvm/cmake/modules/VersionFromVCS.cmake b/llvm/cmake/modules/VersionFromVCS.cmake index 6be4daa..8d56b66 100644 --- a/llvm/cmake/modules/VersionFromVCS.cmake +++ b/llvm/cmake/modules/VersionFromVCS.cmake @@ -1,17 +1,22 @@ # 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. +# existence of certain subdirectories under SOURCE_DIR (if provided as an +# extra argument, otherwise uses CMAKE_CURRENT_SOURCE_DIR). function(add_version_info_from_vcs VERS) + SET(SOURCE_DIR ${ARGV1}) + if("${SOURCE_DIR}" STREQUAL "") + SET(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) + endif() 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(result "${result}-r${Project_WC_REVISION}") @@ -20,16 +25,16 @@ function(add_version_info_from_vcs VERS) set(LLVM_REPOSITORY ${Project_WC_URL} PARENT_SCOPE) 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 ) + if( EXISTS ${SOURCE_DIR}/.git/svn ) find_program(git_executable NAMES git git.exe git.cmd) if( git_executable ) set(is_git_svn_rev_exact false) execute_process(COMMAND ${git_executable} svn info - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + WORKING_DIRECTORY ${SOURCE_DIR} TIMEOUT 5 RESULT_VARIABLE git_result OUTPUT_VARIABLE git_output) @@ -46,7 +51,7 @@ function(add_version_info_from_vcs VERS) # 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) @@ -61,10 +66,11 @@ function(add_version_info_from_vcs VERS) endif() execute_process(COMMAND ${git_executable} rev-parse --short HEAD - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + 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) diff --git a/llvm/lib/LTO/CMakeLists.txt b/llvm/lib/LTO/CMakeLists.txt index 1a592f0..cf6a7d1 100644 --- a/llvm/lib/LTO/CMakeLists.txt +++ b/llvm/lib/LTO/CMakeLists.txt @@ -1,8 +1,58 @@ +# 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_first_existing_file(${out_var} + "${path}/.git/logs/HEAD" # Git + "${path}/.svn/wc.db" # SVN 1.7 + "${path}/.svn/entries" # SVN 1.6 + ) +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}/LLVMLTORevision.h") + +set(get_svn_script "${LLVM_MAIN_SRC_DIR}/cmake/modules/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) + + # Tell Version.cpp that it needs to build with -DHAVE_SVN_VERSION_INC. + set_source_files_properties(Version.cpp + PROPERTIES COMPILE_DEFINITIONS "HAVE_SVN_VERSION_INC") +else() + # Not producing a VC revision include. + set(version_inc) +endif() + + add_llvm_library(LLVMLTO LTOModule.cpp LTOCodeGenerator.cpp UpdateCompilerUsed.cpp ThinLTOCodeGenerator.cpp + ${version_inc} ADDITIONAL_HEADER_DIRS ${LLVM_MAIN_INCLUDE_DIR}/llvm/LTO -- 2.7.4