[PATCH] D15006: Driver: Better detection of mingw-gcc

Martell Malone via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 14 06:45:29 PDT 2017


martell updated this revision to Diff 95292.
martell edited the summary of this revision.
martell added a reviewer: yaron.keren.
martell added a subscriber: yaron.keren.
martell added a comment.

After the revert I left this patch go to pick up some other patch work.
Seen as we are not anywhere near the next release this seem like a good time to pick it up again.
Also got a reminder when yaron resigned

Updated to master.
@ismail can you confirm this update works for your custom opensuse setup on master.
@yaron.keren I can't do a non flaky test case for this it seems because on windows we need .exe extension and not on unix.
Also we need the test case to be able to set the PATH variable to be able to test this fully.

I would like to consider this as working because it passes all the existing Driver testcases in `test/Driver/mingw.cpp`


Repository:
  rL LLVM

https://reviews.llvm.org/D15006

Files:
  lib/Driver/ToolChains/MinGW.cpp
  lib/Driver/ToolChains/MinGW.h


Index: lib/Driver/ToolChains/MinGW.h
===================================================================
--- lib/Driver/ToolChains/MinGW.h
+++ lib/Driver/ToolChains/MinGW.h
@@ -93,6 +93,7 @@
   mutable std::unique_ptr<tools::gcc::Preprocessor> Preprocessor;
   mutable std::unique_ptr<tools::gcc::Compiler> Compiler;
   void findGccLibDir();
+  llvm::ErrorOr<std::string> findGcc();
 };
 
 } // end namespace toolchains
Index: lib/Driver/ToolChains/MinGW.cpp
===================================================================
--- lib/Driver/ToolChains/MinGW.cpp
+++ lib/Driver/ToolChains/MinGW.cpp
@@ -285,28 +285,30 @@
   }
 }
 
+llvm::ErrorOr<std::string> toolchains::MinGW::findGcc() {
+  llvm::SmallVector<llvm::SmallString<32>, 2> Gccs;
+  Gccs.emplace_back(getTriple().getArchName());
+  Gccs[0] += "-w64-mingw32-gcc";
+  Gccs.emplace_back("mingw32-gcc");
+  // Please do not add "gcc" here
+  for (StringRef CandidateGcc : Gccs)
+    if (llvm::ErrorOr<std::string> GPPName = llvm::sys::findProgramByName(CandidateGcc))
+      return GPPName;
+  return make_error_code(std::errc::no_such_file_or_directory);
+}
+
 toolchains::MinGW::MinGW(const Driver &D, const llvm::Triple &Triple,
                          const ArgList &Args)
     : ToolChain(D, Triple, Args), CudaInstallation(D, Triple, Args) {
   getProgramPaths().push_back(getDriver().getInstalledDir());
 
-// In Windows there aren't any standard install locations, we search
-// for gcc on the PATH. In Linux the base is always /usr.
-#ifdef LLVM_ON_WIN32
   if (getDriver().SysRoot.size())
     Base = getDriver().SysRoot;
-  else if (llvm::ErrorOr<std::string> GPPName =
-               llvm::sys::findProgramByName("gcc"))
+  else if (llvm::ErrorOr<std::string> GPPName = findGcc())
     Base = llvm::sys::path::parent_path(
         llvm::sys::path::parent_path(GPPName.get()));
   else
     Base = llvm::sys::path::parent_path(getDriver().getInstalledDir());
-#else
-  if (getDriver().SysRoot.size())
-    Base = getDriver().SysRoot;
-  else
-    Base = "/usr";
-#endif
 
   Base += llvm::sys::path::get_separator();
   findGccLibDir();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15006.95292.patch
Type: text/x-patch
Size: 2111 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170414/4b1b9f3f/attachment.bin>


More information about the cfe-commits mailing list