[llvm] r266523 - Add SVN version to libLLVMLTO
Mehdi Amini via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 16 00:33:15 PDT 2016
Author: mehdi_amini
Date: Sat Apr 16 02:33:14 2016
New Revision: 266523
URL: http://llvm.org/viewvc/llvm-project?rev=266523&view=rev
Log:
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 <mehdi.amini at apple.com>
Added:
llvm/trunk/cmake/modules/GenerateVersionFromCVS.cmake
Modified:
llvm/trunk/cmake/modules/VersionFromVCS.cmake
llvm/trunk/lib/LTO/CMakeLists.txt
Added: llvm/trunk/cmake/modules/GenerateVersionFromCVS.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/GenerateVersionFromCVS.cmake?rev=266523&view=auto
==============================================================================
--- llvm/trunk/cmake/modules/GenerateVersionFromCVS.cmake (added)
+++ llvm/trunk/cmake/modules/GenerateVersionFromCVS.cmake Sat Apr 16 02:33:14 2016
@@ -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")
+
Modified: llvm/trunk/cmake/modules/VersionFromVCS.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/VersionFromVCS.cmake?rev=266523&r1=266522&r2=266523&view=diff
==============================================================================
--- llvm/trunk/cmake/modules/VersionFromVCS.cmake (original)
+++ llvm/trunk/cmake/modules/VersionFromVCS.cmake Sat Apr 16 02:33:14 2016
@@ -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)
Modified: llvm/trunk/lib/LTO/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/CMakeLists.txt?rev=266523&r1=266522&r2=266523&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/CMakeLists.txt (original)
+++ llvm/trunk/lib/LTO/CMakeLists.txt Sat Apr 16 02:33:14 2016
@@ -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
More information about the llvm-commits
mailing list