From: Michal Gorny Date: Thu, 20 Oct 2016 20:13:35 +0000 (+0000) Subject: [Driver] Parse Debian version as integer when possible. NFC X-Git-Tag: llvmorg-4.0.0-rc1~6649 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0a2cd96e0527a1eb647016b32b13e9b98de6791a;p=platform%2Fupstream%2Fllvm.git [Driver] Parse Debian version as integer when possible. NFC Replace the string matching for /etc/debian_version with split integer/string matching algorithm. When the file contains 'major.minor' version number, parse the major version as integer and use a switch clause to match it. Otherwise, attempt 'codename/sid' matching using a StringSwitch. Differential Revision: https://reviews.llvm.org/D25696 llvm-svn: 284770 --- diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp index 558f473..cb1bddf 100644 --- a/clang/lib/Driver/ToolChains.cpp +++ b/clang/lib/Driver/ToolChains.cpp @@ -3905,17 +3905,30 @@ static Distro DetectDistro(const Driver &D, llvm::Triple::ArchType Arch) { 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(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"))