[Driver] Disable OpenSUSE rules for OpenSUSE/SLES 10 and older
authorMichal Gorny <mgorny@gentoo.org>
Tue, 25 Oct 2016 15:33:32 +0000 (15:33 +0000)
committerMichal Gorny <mgorny@gentoo.org>
Tue, 25 Oct 2016 15:33:32 +0000 (15:33 +0000)
Disable the OpenSUSE rules for OpenSUSE versions older than 11 as they
are incompatible with the old binutils on that distribution.

Differential Revision: https://reviews.llvm.org/D24954

llvm-svn: 285076

clang/lib/Driver/ToolChains.cpp

index f04c443..509f6d9 100644 (file)
@@ -3968,8 +3968,25 @@ static Distro DetectDistro(vfs::FileSystem &VFS) {
         .Default(UnknownDistro);
   }
 
-  if (VFS.exists("/etc/SuSE-release"))
-    return OpenSUSE;
+  File = VFS.getBufferForFile("/etc/SuSE-release");
+  if (File) {
+    StringRef Data = File.get()->getBuffer();
+    SmallVector<StringRef, 8> Lines;
+    Data.split(Lines, "\n");
+    for (const StringRef& Line : Lines) {
+      if (!Line.trim().startswith("VERSION"))
+        continue;
+      std::pair<StringRef, StringRef> SplitLine = Line.split('=');
+      int Version;
+      // OpenSUSE/SLES 10 and older are not supported and not compatible
+      // with our rules, so just treat them as UnknownDistro.
+      if (!SplitLine.second.trim().getAsInteger(10, Version) &&
+          Version > 10)
+        return OpenSUSE;
+      return UnknownDistro;
+    }
+    return UnknownDistro;
+  }
 
   if (VFS.exists("/etc/exherbo-release"))
     return Exherbo;