mgorny updated this revision to Diff 75615. mgorny added a comment. Refactored the code as requested. Also I've noticed that if VERSION had invalid value, the code continued reading the file — now it immediately returns UnknownDistro in that case.
https://reviews.llvm.org/D24954 Files: lib/Driver/ToolChains.cpp Index: lib/Driver/ToolChains.cpp =================================================================== --- lib/Driver/ToolChains.cpp +++ lib/Driver/ToolChains.cpp @@ -3931,8 +3931,25 @@ .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) { + std::pair<StringRef, StringRef> SplitLine = Line.split('='); + int Version; + if (SplitLine.first.trim() != "VERSION") + continue; + // 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;
Index: lib/Driver/ToolChains.cpp =================================================================== --- lib/Driver/ToolChains.cpp +++ lib/Driver/ToolChains.cpp @@ -3931,8 +3931,25 @@ .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) { + std::pair<StringRef, StringRef> SplitLine = Line.split('='); + int Version; + if (SplitLine.first.trim() != "VERSION") + continue; + // 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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits