Select the highest version of the mingw toolchain found using Generic_GCC::GCCVersion
authorYaron Keren <yaron.keren@gmail.com>
Fri, 24 Jul 2015 20:18:27 +0000 (20:18 +0000)
committerYaron Keren <yaron.keren@gmail.com>
Fri, 24 Jul 2015 20:18:27 +0000 (20:18 +0000)
similar to the way Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple works.

llvm-svn: 243153

clang/lib/Driver/MinGWToolChain.cpp
clang/lib/Driver/ToolChains.h

index c4aac04..6de2c50 100644 (file)
@@ -21,18 +21,24 @@ using namespace clang;
 using namespace llvm::opt;
 
 namespace {
+// Simplified from Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple.
 bool findGccVersion(StringRef LibDir, std::string &GccLibDir,
                     std::string &Ver) {
+  Generic_GCC::GCCVersion Version = Generic_GCC::GCCVersion::Parse("0.0.0");
   std::error_code EC;
-  llvm::sys::fs::directory_iterator Entry(LibDir, EC);
-  while (!EC) {
-    GccLibDir = Entry->path();
-    Ver = llvm::sys::path::filename(GccLibDir);
-    if (Ver.size() && isdigit(Ver[0]))
-      return true;
-    Entry.increment(EC);
+  for (llvm::sys::fs::directory_iterator LI(LibDir, EC), LE; !EC && LI != LE;
+       LI = LI.increment(EC)) {
+    StringRef VersionText = llvm::sys::path::filename(LI->path());
+    Generic_GCC::GCCVersion CandidateVersion =
+        Generic_GCC::GCCVersion::Parse(VersionText);
+    if (CandidateVersion.Major == -1)
+      continue;
+    if (CandidateVersion <= Version)
+      continue;
+    Ver = VersionText;
+    GccLibDir = LI->path();
   }
-  return false;
+  return Ver.size();
 }
 }
 
@@ -44,12 +50,12 @@ void MinGW::findGccLibDir() {
   Arch = "unknown";
   // lib: Arch Linux, Ubuntu, Windows
   // lib64: openSUSE Linux
-  for (StringRef Lib : {"lib", "lib64"}) {
-    for (StringRef MaybeArch : Archs) {
+  for (StringRef CandidateLib : {"lib", "lib64"}) {
+    for (StringRef CandidateArch : Archs) {
       llvm::SmallString<1024> LibDir(Base);
-      llvm::sys::path::append(LibDir, Lib, "gcc", MaybeArch);
+      llvm::sys::path::append(LibDir, CandidateLib, "gcc", CandidateArch);
       if (findGccVersion(LibDir, GccLibDir, Ver)) {
-        Arch = MaybeArch;
+        Arch = CandidateArch;
         return;
       }
     }
index 2d1e789..8e62674 100644 (file)
@@ -29,7 +29,7 @@ namespace toolchains {
 /// all subcommands; this relies on gcc translating the majority of
 /// command line options.
 class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain {
-protected:
+public:
   /// \brief Struct to store and manipulate GCC versions.
   ///
   /// We rely on assumptions about the form and structure of GCC version
@@ -147,6 +147,7 @@ protected:
                                 bool NeedsBiarchSuffix = false);
   };
 
+protected:
   GCCInstallationDetector GCCInstallation;
 
 public: