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))
60 StringRef Data = File.get()->getBuffer();
61 if (Data.startswith(
"Fedora release"))
63 if (Data.startswith(
"Red Hat Enterprise Linux") ||
64 Data.startswith(
"CentOS") ||
65 Data.startswith(
"Scientific Linux")) {
66 if (Data.find(
"release 7") != StringRef::npos)
68 else if (Data.find(
"release 6") != StringRef::npos)
70 else if (Data.find(
"release 5") != StringRef::npos)
78 StringRef Data = File.get()->getBuffer();
81 if (!Data.split(
'.').first.getAsInteger(10, MajorVersion)) {
82 switch (MajorVersion) {
99 return llvm::StringSwitch<Distro::DistroType>(Data.split(
"\n").first)
109 StringRef Data = File.get()->getBuffer();
111 Data.split(Lines,
"\n");
112 for (
const StringRef&
Line : Lines) {
113 if (!
Line.trim().startswith(
"VERSION"))
115 std::pair<StringRef, StringRef> SplitLine =
Line.split(
'=');
118 std::pair<StringRef, StringRef> SplitVer = SplitLine.second.trim().split(
'.');
123 if (!SplitVer.first.getAsInteger(10, Version) && Version > 10)
130 if (VFS.
exists(
"/etc/exherbo-release"))
133 if (VFS.
exists(
"/etc/alpine-release"))
136 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...