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());



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());

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to