From 544fb30751b606e125ec81c34f010a03c1947c99 Mon Sep 17 00:00:00 2001 From: Guido Vranken Date: Tue, 20 Jul 2021 20:43:08 +0200 Subject: [PATCH] Patch soci only once: * Patch the soci unsigned-types.h file. If no changes are made, delete the patched file and exit. If there are changes, backup the original and replace it with the patched file. * Fixes #3885 Patch Rocksdb only once: * The repeated patches do not appear to affect build times, but avoiding unnecessary copies is good for its own sake. --- Builds/CMake/deps/Rocksdb.cmake | 2 +- Builds/CMake/soci_patch.cmake | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Builds/CMake/deps/Rocksdb.cmake b/Builds/CMake/deps/Rocksdb.cmake index eed6cefe162..5437bea9115 100644 --- a/Builds/CMake/deps/Rocksdb.cmake +++ b/Builds/CMake/deps/Rocksdb.cmake @@ -63,7 +63,7 @@ if (local_rocksdb) GIT_TAG v6.7.3 PATCH_COMMAND # only used by windows build - ${CMAKE_COMMAND} -E copy + ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/Builds/CMake/rocks_thirdparty.inc /thirdparty.inc COMMAND diff --git a/Builds/CMake/soci_patch.cmake b/Builds/CMake/soci_patch.cmake index 7d0f9eb8487..57c46e58219 100644 --- a/Builds/CMake/soci_patch.cmake +++ b/Builds/CMake/soci_patch.cmake @@ -1,13 +1,30 @@ # This patches unsigned-types.h in the soci official sources # so as to remove type range check exceptions that cause # us trouble when using boost::optional to select int values + +# Some versions of CMake erroneously patch external projects on every build. +# If the patch makes no changes, skip it. This workaround can be +# removed once we stop supporting vulnerable versions of CMake. +# https://gitlab.kitware.com/cmake/cmake/-/issues/21086 file (STRINGS include/soci/unsigned-types.h sourcecode) +# Delete the .patched file if it exists, so it doesn't end up duplicated. +# Trying to remove a file that does not exist is not a problem. +file (REMOVE include/soci/unsigned-types.h.patched) foreach (line_ ${sourcecode}) if (line_ MATCHES "^[ \\t]+throw[ ]+soci_error[ ]*\\([ ]*\"Value outside of allowed.+$") set (line_ "//${CMAKE_MATCH_0}") endif () file (APPEND include/soci/unsigned-types.h.patched "${line_}\n") endforeach () +execute_process( COMMAND ${CMAKE_COMMAND} -E compare_files + include/soci/unsigned-types.h include/soci/unsigned-types.h.patched + RESULT_VARIABLE compare_result +) +if( compare_result EQUAL 0) + message(DEBUG "The soci source and patch files are identical. Make no changes.") + file (REMOVE include/soci/unsigned-types.h.patched) + return() +endif() file (RENAME include/soci/unsigned-types.h include/soci/unsigned-types.h.orig) file (RENAME include/soci/unsigned-types.h.patched include/soci/unsigned-types.h) # also fix Boost.cmake so that it just returns when we override the Boost_FOUND var