]> granicus.if.org Git - clang/commitdiff
[MSVC] If unable to find link.exe from a MSVC installation, look for link.exe next...
authorMartin Storsjo <martin@martin.st>
Fri, 19 Apr 2019 19:04:22 +0000 (19:04 +0000)
committerMartin Storsjo <martin@martin.st>
Fri, 19 Apr 2019 19:04:22 +0000 (19:04 +0000)
Previously, if the MSVC installation isn't detected properly, clang
will later just fail to execute link.exe.

This improves using clang in msvc mode on linux, where one intentionally
might not want to point clang to the MSVC installation itself (which
isn't executable as such), but where a link.exe named wine wrapper is
available in the path next to a cl.exe named wine wrapper.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@358778 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/ToolChains/MSVC.cpp

index e3801c55a98cc4756bd04653630059b5b5718b40..3a789627c5519eb1ab32296baabe8e61f456f09c 100644 (file)
@@ -488,8 +488,18 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
     // their own link.exe which may come first.
     linkPath = FindVisualStudioExecutable(TC, "link.exe");
 
-    if (!TC.FoundMSVCInstall() && !llvm::sys::fs::can_execute(linkPath))
-      C.getDriver().Diag(clang::diag::warn_drv_msvc_not_found);
+    if (!TC.FoundMSVCInstall() && !llvm::sys::fs::can_execute(linkPath)) {
+      llvm::SmallString<128> ClPath;
+      ClPath = TC.GetProgramPath("cl.exe");
+      if (llvm::sys::fs::can_execute(ClPath)) {
+        linkPath = llvm::sys::path::parent_path(ClPath);
+        llvm::sys::path::append(linkPath, "link.exe");
+        if (!llvm::sys::fs::can_execute(linkPath))
+          C.getDriver().Diag(clang::diag::warn_drv_msvc_not_found);
+      } else {
+        C.getDriver().Diag(clang::diag::warn_drv_msvc_not_found);
+      }
+    }
 
 #ifdef _WIN32
     // When cross-compiling with VS2017 or newer, link.exe expects to have