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" 16 #include "llvm/ADT/Triple.h" 19 using namespace clang;
22 const llvm::Triple &TargetOrHost) {
25 if (!TargetOrHost.isOSLinux())
33 llvm::vfs::getRealFileSystem();
34 llvm::Triple HostTriple(llvm::sys::getProcessTriple());
35 if (!HostTriple.isOSLinux() && &VFS == RealFS.get())
38 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File =
39 VFS.getBufferForFile(
"/etc/lsb-release");
41 StringRef Data = File.get()->getBuffer();
43 Data.split(Lines,
"\n");
45 for (StringRef
Line : Lines)
47 Version = llvm::StringSwitch<Distro::DistroType>(
Line.substr(17))
78 File = VFS.getBufferForFile(
"/etc/redhat-release");
80 StringRef Data = File.get()->getBuffer();
81 if (Data.startswith(
"Fedora release"))
83 if (Data.startswith(
"Red Hat Enterprise Linux") ||
84 Data.startswith(
"CentOS") ||
85 Data.startswith(
"Scientific Linux")) {
86 if (Data.find(
"release 7") != StringRef::npos)
88 else if (Data.find(
"release 6") != StringRef::npos)
90 else if (Data.find(
"release 5") != StringRef::npos)
96 File = VFS.getBufferForFile(
"/etc/debian_version");
98 StringRef Data = File.get()->getBuffer();
101 if (!Data.split(
'.').first.getAsInteger(10, MajorVersion)) {
102 switch (MajorVersion) {
121 return llvm::StringSwitch<Distro::DistroType>(Data.split(
"\n").first)
131 File = VFS.getBufferForFile(
"/etc/SuSE-release");
133 StringRef Data = File.get()->getBuffer();
135 Data.split(Lines,
"\n");
136 for (
const StringRef&
Line : Lines) {
137 if (!
Line.trim().startswith(
"VERSION"))
139 std::pair<StringRef, StringRef> SplitLine =
Line.split(
'=');
142 std::pair<StringRef, StringRef> SplitVer = SplitLine.second.trim().split(
'.');
147 if (!SplitVer.first.getAsInteger(10, Version) && Version > 10)
154 if (VFS.exists(
"/etc/exherbo-release"))
157 if (VFS.exists(
"/etc/alpine-release"))
160 if (VFS.exists(
"/etc/arch-release"))
163 if (VFS.exists(
"/etc/gentoo-release"))
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
const AnnotatedLine * Line
Distro()
Default constructor leaves the distribution unknown.
static Distro::DistroType DetectDistro(llvm::vfs::FileSystem &VFS, const llvm::Triple &TargetOrHost)
Dataflow Directional Tag Classes.