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/Support/Threading.h"
17#include "llvm/TargetParser/Host.h"
18#include "llvm/TargetParser/Triple.h"
24 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
File =
25 VFS.getBufferForFile(
"/etc/os-release");
27 File = VFS.getBufferForFile(
"/usr/lib/os-release");
32 File.get()->getBuffer().split(Lines,
"\n");
36 for (StringRef Line : Lines)
38 Version = llvm::StringSwitch<Distro::DistroType>(Line.substr(3))
52 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
File =
53 VFS.getBufferForFile(
"/etc/lsb-release");
58 File.get()->getBuffer().split(Lines,
"\n");
61 for (StringRef Line : Lines)
63 Line.startswith(
"DISTRIB_CODENAME="))
64 Version = llvm::StringSwitch<Distro::DistroType>(Line.substr(17))
116 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
File =
117 VFS.getBufferForFile(
"/etc/redhat-release");
120 StringRef
Data =
File.get()->getBuffer();
121 if (
Data.startswith(
"Fedora release"))
123 if (
Data.startswith(
"Red Hat Enterprise Linux") ||
124 Data.startswith(
"CentOS") ||
Data.startswith(
"Scientific Linux")) {
125 if (
Data.contains(
"release 7"))
127 else if (
Data.contains(
"release 6"))
129 else if (
Data.contains(
"release 5"))
136 File = VFS.getBufferForFile(
"/etc/debian_version");
138 StringRef
Data =
File.get()->getBuffer();
141 if (!
Data.split(
'.').first.getAsInteger(10, MajorVersion)) {
142 switch (MajorVersion) {
165 return llvm::StringSwitch<Distro::DistroType>(
Data.split(
"\n").first)
178 File = VFS.getBufferForFile(
"/etc/SuSE-release");
180 StringRef
Data =
File.get()->getBuffer();
182 Data.split(Lines,
"\n");
183 for (
const StringRef &Line : Lines) {
184 if (!Line.trim().startswith(
"VERSION"))
186 std::pair<StringRef, StringRef> SplitLine = Line.split(
'=');
189 std::pair<StringRef, StringRef> SplitVer =
190 SplitLine.second.trim().split(
'.');
195 if (!SplitVer.first.getAsInteger(10, Version) && Version > 10)
203 if (VFS.exists(
"/etc/gentoo-release"))
210 const llvm::Triple &TargetOrHost) {
213 if (!TargetOrHost.isOSLinux())
217 const bool onRealFS = (llvm::vfs::getRealFileSystem() == &VFS);
223 llvm::Triple HostTriple(llvm::sys::getProcessTriple());
224 if (!HostTriple.isOSLinux() && onRealFS)
239 : DistroVal(
GetDistro(VFS, TargetOrHost)) {}
static Distro::DistroType DetectOsRelease(llvm::vfs::FileSystem &VFS)
static Distro::DistroType DetectLsbRelease(llvm::vfs::FileSystem &VFS)
static Distro::DistroType DetectDistro(llvm::vfs::FileSystem &VFS)
static Distro::DistroType GetDistro(llvm::vfs::FileSystem &VFS, const llvm::Triple &TargetOrHost)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Distro()
Default constructor leaves the distribution unknown.