[PATCH] D25696: [Driver] Parse Debian version as integer when possible. NFC

Michał Górny via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 20 13:23:00 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL284770: [Driver] Parse Debian version as integer when possible. NFC (authored by mgorny).

Changed prior to commit:
  https://reviews.llvm.org/D25696?vs=75269&id=75345#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25696

Files:
  cfe/trunk/lib/Driver/ToolChains.cpp


Index: cfe/trunk/lib/Driver/ToolChains.cpp
===================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp
+++ cfe/trunk/lib/Driver/ToolChains.cpp
@@ -3905,17 +3905,30 @@
   File = D.getVFS().getBufferForFile("/etc/debian_version");
   if (File) {
     StringRef Data = File.get()->getBuffer();
-    if (Data[0] == '5')
-      return DebianLenny;
-    else if (Data.startswith("squeeze/sid") || Data[0] == '6')
-      return DebianSqueeze;
-    else if (Data.startswith("wheezy/sid") || Data[0] == '7')
-      return DebianWheezy;
-    else if (Data.startswith("jessie/sid") || Data[0] == '8')
-      return DebianJessie;
-    else if (Data.startswith("stretch/sid") || Data[0] == '9')
-      return DebianStretch;
-    return UnknownDistro;
+    // Contents: < major.minor > or < codename/sid >
+    int MajorVersion;
+    if (!Data.split('.').first.getAsInteger(10, MajorVersion)) {
+      switch (MajorVersion) {
+      case 5:
+        return DebianLenny;
+      case 6:
+        return DebianSqueeze;
+      case 7:
+        return DebianWheezy;
+      case 8:
+        return DebianJessie;
+      case 9:
+        return DebianStretch;
+      default:
+        return UnknownDistro;
+      }
+    }
+    return llvm::StringSwitch<Distro>(Data.split("\n").first)
+        .Case("squeeze/sid", DebianSqueeze)
+        .Case("wheezy/sid", DebianWheezy)
+        .Case("jessie/sid", DebianJessie)
+        .Case("stretch/sid", DebianStretch)
+        .Default(UnknownDistro);
   }
 
   if (D.getVFS().exists("/etc/SuSE-release"))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25696.75345.patch
Type: text/x-patch
Size: 1576 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161020/b3681f97/attachment.bin>


More information about the cfe-commits mailing list