[PATCH] D60051: [build] Only rewrite TableGen files if they've changed
Harlan Haskins via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 31 16:22:13 PDT 2019
harlanhaskins created this revision.
harlanhaskins added a reviewer: beanz.
Herald added subscribers: llvm-commits, mgorny.
Herald added a project: LLVM.
Previously, re-running CMake caused all the TableGen files to be rebuilt, which
invalidated headers that used them. Instead, only overwrite files if they've
changed.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D60051
Files:
llvm/cmake/modules/TableGen.cmake
Index: llvm/cmake/modules/TableGen.cmake
===================================================================
--- llvm/cmake/modules/TableGen.cmake
+++ llvm/cmake/modules/TableGen.cmake
@@ -14,6 +14,8 @@
message(FATAL_ERROR "${project}_TABLEGEN_EXE not set")
endif()
+ set(output_path)
+
# Use depfile instead of globbing arbitrary *.td(s)
# DEPFILE is available for Ninja Generator with CMake>=3.7.
if(CMAKE_GENERATOR STREQUAL "Ninja" AND NOT CMAKE_VERSION VERSION_LESS 3.7)
@@ -24,8 +26,8 @@
# Note that tblgen is executed on ${CMAKE_BINARY_DIR} as working directory.
file(RELATIVE_PATH ofn_rel
${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${ofn})
+ set(output_path ${ofn_rel})
set(additional_cmdline
- -o ${ofn_rel}
-d ${ofn_rel}.d
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.d
@@ -35,9 +37,8 @@
else()
file(GLOB local_tds "*.td")
file(GLOB_RECURSE global_tds "${LLVM_MAIN_INCLUDE_DIR}/llvm/*.td")
- set(additional_cmdline
- -o ${CMAKE_CURRENT_BINARY_DIR}/${ofn}
- )
+ set(output_path ${CMAKE_CURRENT_BINARY_DIR}/${ofn})
+ set(additiona_cmdline)
endif()
if (IS_ABSOLUTE ${LLVM_TARGET_DEFINITIONS})
@@ -70,10 +71,18 @@
# ("${${project}_TABLEGEN_TARGET}" STREQUAL "${${project}_TABLEGEN_EXE}")
# but lets us having smaller and cleaner code here.
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${ofn}
+ # Because we don't want to affect modification time of tablegen targets
+ # that have not changed, emit the tablegen output to a temp file and only
+ # overwrite an existing file if the output has changed.
COMMAND ${${project}_TABLEGEN_EXE} ${ARGN} -I ${CMAKE_CURRENT_SOURCE_DIR}
- ${LLVM_TABLEGEN_FLAGS}
- ${LLVM_TARGET_DEFINITIONS_ABSOLUTE}
- ${additional_cmdline}
+ -o ${output_path}.tmp
+ ${LLVM_TABLEGEN_FLAGS}
+ ${LLVM_TARGET_DEFINITIONS_ABSOLUTE}
+ ${additional_cmdline}
+ COMMAND
+ ${CMAKE_COMMAND} -E copy_if_different ${output_path}.tmp ${output_path}
+ COMMAND
+ ${CMAKE_COMMAND} -E remove ${output_path}.tmp
# The file in LLVM_TARGET_DEFINITIONS may be not in the current
# directory and local_tds may not contain it, so we must
# explicitly list it here:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60051.193030.patch
Type: text/x-patch
Size: 2311 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190331/e5e13112/attachment.bin>
More information about the llvm-commits
mailing list