r243153 - Select the highest version of the mingw toolchain found using Generic_GCC::GCCVersion

Yaron Keren yaron.keren at gmail.com
Fri Jul 24 13:18:27 PDT 2015


Author: yrnkrn
Date: Fri Jul 24 15:18:27 2015
New Revision: 243153

URL: http://llvm.org/viewvc/llvm-project?rev=243153&view=rev
Log:
Select the highest version of the mingw toolchain found using Generic_GCC::GCCVersion
similar to the way Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple works.


Modified:
    cfe/trunk/lib/Driver/MinGWToolChain.cpp
    cfe/trunk/lib/Driver/ToolChains.h

Modified: cfe/trunk/lib/Driver/MinGWToolChain.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/MinGWToolChain.cpp?rev=243153&r1=243152&r2=243153&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/MinGWToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/MinGWToolChain.cpp Fri Jul 24 15:18:27 2015
@@ -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;
       }
     }

Modified: cfe/trunk/lib/Driver/ToolChains.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=243153&r1=243152&r2=243153&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.h (original)
+++ cfe/trunk/lib/Driver/ToolChains.h Fri Jul 24 15:18:27 2015
@@ -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:





More information about the cfe-commits mailing list