Browse Source

Merge topic 'rpath-unrecognized-format'

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 <[email protected]>
Acked-by: buildbot <[email protected]>
Merge-request: !6779
Brad King 3 years ago
parent
commit
57349a4851

+ 21 - 4
Source/cmSystemTools.cxx

@@ -2855,6 +2855,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;
 }
 
@@ -2869,6 +2877,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;
 }
 
@@ -3198,7 +3214,8 @@ bool cmSystemTools::RemoveRPath(std::string const& file, std::string* emsg,
   if (cm::optional<bool> 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,
@@ -3238,9 +3255,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)

+ 11 - 0
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)

+ 1 - 0
Tests/RunCMake/file-RPATH/TextChange-result.txt

@@ -0,0 +1 @@
+1

+ 12 - 0
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\.$

+ 3 - 0
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")

+ 3 - 0
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 "")

+ 6 - 0
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()

+ 6 - 0
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()

+ 3 - 0
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}")

+ 1 - 0
Tests/RunCMake/file-RPATH/TextSet-result.txt

@@ -0,0 +1 @@
+1

+ 12 - 0
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\.$

+ 3 - 0
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")

+ 3 - 0
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 "")