Skip to content

Commit

Permalink
Patch soci only once:
Browse files Browse the repository at this point in the history
* 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 XRPLF#3885
  • Loading branch information
guidovranken authored and ximinez committed Sep 8, 2021
1 parent aee422e commit c5c58d0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Builds/CMake/soci_patch.cmake
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit c5c58d0

Please sign in to comment.