[llvm-lit] Improve the error message when make_paths_relative() fails
authorLouis Dionne <ldionne@apple.com>
Thu, 22 Oct 2020 20:34:19 +0000 (16:34 -0400)
committerLouis Dionne <ldionne@apple.com>
Wed, 28 Oct 2020 21:06:18 +0000 (17:06 -0400)
Previously, if make_paths_relative() failed due to some reason, it would
happily keep going and set the ${out_pathlist} to the standard output
of the command, which would be the empty string if the command failed.

This can lead to issues that are difficult to diagnose, since the calling
code will usually try to keep going with a variable that was set to the
empty string.

Differential Revision: https://reviews.llvm.org/D89985

llvm/cmake/modules/AddLLVM.cmake

index 4f11d2f..2bf071e 100644 (file)
@@ -1500,7 +1500,12 @@ if len(sys.argv) < 3: sys.exit(0)\n
 sys.stdout.write(';'.join(relpath(p) for p in sys.argv[2].split(';')))"
     ${basedir}
     ${pathlist_escaped}
-    OUTPUT_VARIABLE pathlist_relative)
+    OUTPUT_VARIABLE pathlist_relative
+    ERROR_VARIABLE error
+    RESULT_VARIABLE result)
+  if (NOT result EQUAL 0)
+    message(FATAL_ERROR "make_paths_relative() failed due to error '${result}', with stderr\n${error}")
+  endif()
   set(${out_pathlist} "${pathlist_relative}" PARENT_SCOPE)
 endfunction()