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

Martell Malone via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 25 22:44:21 PST 2015


martell updated this revision to Diff 41209.
martell added a comment.

Updated to reflect feedback

I'm not too sure what todo for testcases on this one because they already exist for the most part.
I ran the test suite and they all pass.

I would have to create a mingw32-gcc and {armv7|i686|x86_64}-w64-mingw32-gcc and chmod+x for the testcase.
Is that safe ?


http://reviews.llvm.org/D15006

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

Index: lib/Driver/ToolChains.h
===================================================================
--- lib/Driver/ToolChains.h
+++ lib/Driver/ToolChains.h
@@ -661,6 +661,7 @@
   std::string Arch;
   mutable std::unique_ptr<tools::gcc::Preprocessor> Preprocessor;
   mutable std::unique_ptr<tools::gcc::Compiler> Compiler;
+  void findGccDir();
   void findGccLibDir();
 };
 
Index: lib/Driver/MinGWToolChain.cpp
===================================================================
--- lib/Driver/MinGWToolChain.cpp
+++ lib/Driver/MinGWToolChain.cpp
@@ -62,19 +62,29 @@
   }
 }

+void MinGW::findGccDir() {
+  llvm::SmallVector<llvm::SmallString<32>, 2> Gccs;
+  Gccs.emplace_back(getTriple().getArchName());
+  Gccs[0] += "-w64-mingw32-gcc";
+  Gccs.emplace_back("mingw32-gcc");
+  for (StringRef CandidateGcc : Gccs)
+    if (llvm::ErrorOr<std::string> GPPName =
+          llvm::sys::findProgramByName(CandidateGcc)) {
+      Base = llvm::sys::path::parent_path(
+          llvm::sys::path::parent_path(GPPName.get()));
+      return;
+    }
+}
+
 MinGW::MinGW(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
     : ToolChain(D, Triple, Args) {
   getProgramPaths().push_back(getDriver().getInstalledDir());

-  // On Windows if there is no sysroot we search for gcc on the PATH.
   if (getDriver().SysRoot.size())
-  Base = getDriver().SysRoot;
-#ifdef LLVM_ON_WIN32
-  else if (llvm::ErrorOr<std::string> GPPName =
-               llvm::sys::findProgramByName("gcc"))
-    Base = llvm::sys::path::parent_path(
-        llvm::sys::path::parent_path(GPPName.get()));
-#endif
+    Base = getDriver().SysRoot;
+  else
+    findGccDir();
+
   if (!Base.size())
     Base = llvm::sys::path::parent_path(getDriver().getInstalledDir());



-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15006.41209.patch
Type: text/x-patch
Size: 1751 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151126/fc241647/attachment-0001.bin>


More information about the cfe-commits mailing list