martell created this revision.
martell added a reviewer: yaron.keren.
martell added a subscriber: cfe-commits.

As discussed after r253898 here is the better gcc detection.

Note: I could add a break in the new for loop but I don't feel it is needed

Thoughts?


http://reviews.llvm.org/D15006

Files:
  lib/Driver/MinGWToolChain.cpp

Index: lib/Driver/MinGWToolChain.cpp
===================================================================
--- lib/Driver/MinGWToolChain.cpp
+++ lib/Driver/MinGWToolChain.cpp
@@ -66,15 +66,22 @@
     : ToolChain(D, Triple, Args) {
   getProgramPaths().push_back(getDriver().getInstalledDir());

-  // On Windows if there is no sysroot we search for gcc on the PATH.
+  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()));
+      break;
+    }
+
   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;
+
   if (!Base.size())
     Base = llvm::sys::path::parent_path(getDriver().getInstalledDir());
 


Index: lib/Driver/MinGWToolChain.cpp
===================================================================
--- lib/Driver/MinGWToolChain.cpp
+++ lib/Driver/MinGWToolChain.cpp
@@ -66,15 +66,22 @@
     : ToolChain(D, Triple, Args) {
   getProgramPaths().push_back(getDriver().getInstalledDir());

-  // On Windows if there is no sysroot we search for gcc on the PATH.
+  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()));
+      break;
+    }
+
   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;
+
   if (!Base.size())
     Base = llvm::sys::path::parent_path(getDriver().getInstalledDir());
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to