11 #include "llvm/ADT/SmallVector.h" 12 #include "llvm/ADT/StringRef.h" 13 #include "llvm/ADT/StringSwitch.h" 14 #include "llvm/Support/ErrorOr.h" 15 #include "llvm/Support/MemoryBuffer.h" 18 using namespace clang;
21 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File =
24 StringRef Data = File.get()->getBuffer();
26 Data.split(Lines,
"\n");
28 for (StringRef
Line : Lines)
30 Version = llvm::StringSwitch<Distro::DistroType>(
Line.substr(17))
59 StringRef Data = File.get()->getBuffer();
60 if (Data.startswith(
"Fedora release"))
62 if (Data.startswith(
"Red Hat Enterprise Linux") ||
63 Data.startswith(
"CentOS") ||
64 Data.startswith(
"Scientific Linux")) {
65 if (Data.find(
"release 7") != StringRef::npos)
67 else if (Data.find(
"release 6") != StringRef::npos)
69 else if (Data.find(
"release 5") != StringRef::npos)
77 StringRef Data = File.get()->getBuffer();
80 if (!Data.split(
'.').first.getAsInteger(10, MajorVersion)) {
81 switch (MajorVersion) {
98 return llvm::StringSwitch<Distro::DistroType>(Data.split(
"\n").first)
108 StringRef Data = File.get()->getBuffer();
110 Data.split(Lines,
"\n");
111 for (
const StringRef&
Line : Lines) {
112 if (!
Line.trim().startswith(
"VERSION"))
114 std::pair<StringRef, StringRef> SplitLine =
Line.split(
'=');
117 std::pair<StringRef, StringRef> SplitVer = SplitLine.second.trim().split(
'.');
122 if (!SplitVer.first.getAsInteger(10, Version) && Version > 10)
129 if (VFS.
exists(
"/etc/exherbo-release"))
132 if (VFS.
exists(
"/etc/alpine-release"))
135 if (VFS.
exists(
"/etc/arch-release"))
static Distro::DistroType DetectDistro(vfs::FileSystem &VFS)
The virtual file system interface.
const AnnotatedLine * Line
Distro()
Default constructor leaves the distribution unknown.
Dataflow Directional Tag Classes.
bool exists(const Twine &Path)
Check whether a file exists. Provided for convenience.
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(const Twine &Name, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
This is a convenience method that opens a file, gets its content and then closes the file...