From 3883b11edbb983c72f0d1f2f13ad29fd8a630514 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 2 Dec 2021 16:45:16 +0000 Subject: [PATCH] Merge topic 'rpath-unrecognized-format' into release-3.22 643fc46bdc file(RPATH): Restore tolerance of unknown formats if new RPATH is empty 5596cba7dc cmSystemTools: Remove unnecessary mark-as-used casts to void Acked-by: Kitware Robot Acked-by: buildbot Merge-request: !6779 --- Source/cmSystemTools.cxx | 25 +++++++++++++++++++++---- Tests/RunCMake/file-RPATH/RunCMakeTest.cmake | 11 +++++++++++ Tests/RunCMake/file-RPATH/TextChange-result.txt | 1 + Tests/RunCMake/file-RPATH/TextChange-stderr.txt | 12 ++++++++++++ Tests/RunCMake/file-RPATH/TextChange.cmake | 3 +++ Tests/RunCMake/file-RPATH/TextChangeEmpty.cmake | 3 +++ Tests/RunCMake/file-RPATH/TextCheck.cmake | 6 ++++++ Tests/RunCMake/file-RPATH/TextCheckEmpty.cmake | 6 ++++++ Tests/RunCMake/file-RPATH/TextRemove.cmake | 3 +++ Tests/RunCMake/file-RPATH/TextSet-result.txt | 1 + Tests/RunCMake/file-RPATH/TextSet-stderr.txt | 12 ++++++++++++ Tests/RunCMake/file-RPATH/TextSet.cmake | 3 +++ Tests/RunCMake/file-RPATH/TextSetEmpty.cmake | 3 +++ 13 files changed, 85 insertions(+), 4 deletions(-) diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 75a5a8d878..1934393bb0 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -2869,6 +2869,14 @@ bool cmSystemTools::ChangeRPath(std::string const& file, file, oldRPath, newRPath, removeEnvironmentRPath, emsg, changed)) { return result.value(); } + // The file format is not recognized. Assume it has no RPATH. + if (newRPath.empty()) { + // The caller wanted no RPATH anyway. + return true; + } + if (emsg) { + *emsg = "The file format is not recognized."; + } return false; } @@ -2883,6 +2891,14 @@ bool cmSystemTools::SetRPath(std::string const& file, SetRPathXCOFF(file, newRPath, emsg, changed)) { return result.value(); } + // The file format is not recognized. Assume it has no RPATH. + if (newRPath.empty()) { + // The caller wanted no RPATH anyway. + return true; + } + if (emsg) { + *emsg = "The file format is not recognized."; + } return false; } @@ -3212,7 +3228,8 @@ bool cmSystemTools::RemoveRPath(std::string const& file, std::string* emsg, if (cm::optional result = RemoveRPathXCOFF(file, emsg, removed)) { return result.value(); } - return false; + // The file format is not recognized. Assume it has no RPATH. + return true; } bool cmSystemTools::CheckRPath(std::string const& file, @@ -3252,9 +3269,9 @@ bool cmSystemTools::CheckRPath(std::string const& file, return false; } #endif - (void)file; - (void)newRPath; - return false; + // The file format is not recognized. Assume it has no RPATH. + // Therefore we succeed if the new rpath is empty anyway. + return newRPath.empty(); } bool cmSystemTools::RepeatedRemoveDirectory(const std::string& dir) diff --git a/Tests/RunCMake/file-RPATH/RunCMakeTest.cmake b/Tests/RunCMake/file-RPATH/RunCMakeTest.cmake index 1ca2e757a6..525df09c3e 100644 --- a/Tests/RunCMake/file-RPATH/RunCMakeTest.cmake +++ b/Tests/RunCMake/file-RPATH/RunCMakeTest.cmake @@ -5,3 +5,14 @@ run_cmake_command(ELF ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/ELF.cmake) if(CMAKE_SYSTEM_NAME STREQUAL "AIX") run_cmake_command(XCOFF ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/XCOFF.cmake) endif() + +run_cmake_command(TextCheck ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/TextCheck.cmake) +run_cmake_command(TextCheckEmpty ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/TextCheckEmpty.cmake) + +run_cmake_command(TextChange ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/TextChange.cmake) +run_cmake_command(TextChangeEmpty ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/TextChangeEmpty.cmake) + +run_cmake_command(TextSet ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/TextSet.cmake) +run_cmake_command(TextSetEmpty ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/TextSetEmpty.cmake) + +run_cmake_command(TextRemove ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/TextRemove.cmake) diff --git a/Tests/RunCMake/file-RPATH/TextChange-result.txt b/Tests/RunCMake/file-RPATH/TextChange-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/file-RPATH/TextChange-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/file-RPATH/TextChange-stderr.txt b/Tests/RunCMake/file-RPATH/TextChange-stderr.txt new file mode 100644 index 0000000000..48a1bf599f --- /dev/null +++ b/Tests/RunCMake/file-RPATH/TextChange-stderr.txt @@ -0,0 +1,12 @@ +^CMake Error at [^ +]*/Tests/RunCMake/file-RPATH/TextChange.cmake:[0-9]+ \(file\): + file RPATH_CHANGE could not write new RPATH: + + /new/rpath + + to the file: + + [^ +]*/Tests/RunCMake/file-RPATH/TextChange-build/not_a_binary.txt + + The file format is not recognized\.$ diff --git a/Tests/RunCMake/file-RPATH/TextChange.cmake b/Tests/RunCMake/file-RPATH/TextChange.cmake new file mode 100644 index 0000000000..5c599eca27 --- /dev/null +++ b/Tests/RunCMake/file-RPATH/TextChange.cmake @@ -0,0 +1,3 @@ +set(f "${CMAKE_CURRENT_BINARY_DIR}/not_a_binary.txt") +file(WRITE "${f}" "Not a binary.\n") +file(RPATH_CHANGE FILE "${f}" OLD_RPATH "/old/rpath" NEW_RPATH "/new/rpath") diff --git a/Tests/RunCMake/file-RPATH/TextChangeEmpty.cmake b/Tests/RunCMake/file-RPATH/TextChangeEmpty.cmake new file mode 100644 index 0000000000..8f855d9477 --- /dev/null +++ b/Tests/RunCMake/file-RPATH/TextChangeEmpty.cmake @@ -0,0 +1,3 @@ +set(f "${CMAKE_CURRENT_BINARY_DIR}/not_a_binary.txt") +file(WRITE "${f}" "Not a binary.\n") +file(RPATH_CHANGE FILE "${f}" OLD_RPATH "/old/rpath" NEW_RPATH "") diff --git a/Tests/RunCMake/file-RPATH/TextCheck.cmake b/Tests/RunCMake/file-RPATH/TextCheck.cmake new file mode 100644 index 0000000000..1f21ba73cd --- /dev/null +++ b/Tests/RunCMake/file-RPATH/TextCheck.cmake @@ -0,0 +1,6 @@ +set(f "${CMAKE_CURRENT_BINARY_DIR}/not_a_binary.txt") +file(WRITE "${f}" "Not a binary.\n") +file(RPATH_CHECK FILE "${f}" RPATH "/some/rpath") +if(EXISTS "${f}") + message(FATAL_ERROR "RPATH_CHECK did not remove\n ${f}\nfor non-empty RPATH") +endif() diff --git a/Tests/RunCMake/file-RPATH/TextCheckEmpty.cmake b/Tests/RunCMake/file-RPATH/TextCheckEmpty.cmake new file mode 100644 index 0000000000..806c73dae7 --- /dev/null +++ b/Tests/RunCMake/file-RPATH/TextCheckEmpty.cmake @@ -0,0 +1,6 @@ +set(f "${CMAKE_CURRENT_BINARY_DIR}/not_a_binary.txt") +file(WRITE "${f}" "Not a binary.\n") +file(RPATH_CHECK FILE "${f}" RPATH "") +if(NOT EXISTS "${f}") + message(FATAL_ERROR "RPATH_CHECK removed\n ${f}\nfor empty RPATH") +endif() diff --git a/Tests/RunCMake/file-RPATH/TextRemove.cmake b/Tests/RunCMake/file-RPATH/TextRemove.cmake new file mode 100644 index 0000000000..aecaf6f436 --- /dev/null +++ b/Tests/RunCMake/file-RPATH/TextRemove.cmake @@ -0,0 +1,3 @@ +set(f "${CMAKE_CURRENT_BINARY_DIR}/not_a_binary.txt") +file(WRITE "${f}" "Not a binary.\n") +file(RPATH_REMOVE FILE "${f}") diff --git a/Tests/RunCMake/file-RPATH/TextSet-result.txt b/Tests/RunCMake/file-RPATH/TextSet-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/file-RPATH/TextSet-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/file-RPATH/TextSet-stderr.txt b/Tests/RunCMake/file-RPATH/TextSet-stderr.txt new file mode 100644 index 0000000000..811c9a5bfc --- /dev/null +++ b/Tests/RunCMake/file-RPATH/TextSet-stderr.txt @@ -0,0 +1,12 @@ +^CMake Error at [^ +]*/Tests/RunCMake/file-RPATH/TextSet.cmake:[0-9]+ \(file\): + file RPATH_SET could not write new RPATH: + + /new/rpath + + to the file: + + [^ +]*/Tests/RunCMake/file-RPATH/TextSet-build/not_a_binary.txt + + The file format is not recognized\.$ diff --git a/Tests/RunCMake/file-RPATH/TextSet.cmake b/Tests/RunCMake/file-RPATH/TextSet.cmake new file mode 100644 index 0000000000..f4b09d248c --- /dev/null +++ b/Tests/RunCMake/file-RPATH/TextSet.cmake @@ -0,0 +1,3 @@ +set(f "${CMAKE_CURRENT_BINARY_DIR}/not_a_binary.txt") +file(WRITE "${f}" "Not a binary.\n") +file(RPATH_SET FILE "${f}" NEW_RPATH "/new/rpath") diff --git a/Tests/RunCMake/file-RPATH/TextSetEmpty.cmake b/Tests/RunCMake/file-RPATH/TextSetEmpty.cmake new file mode 100644 index 0000000000..d9517e08c6 --- /dev/null +++ b/Tests/RunCMake/file-RPATH/TextSetEmpty.cmake @@ -0,0 +1,3 @@ +set(f "${CMAKE_CURRENT_BINARY_DIR}/not_a_binary.txt") +file(WRITE "${f}" "Not a binary.\n") +file(RPATH_SET FILE "${f}" NEW_RPATH "")