11#include "llvm/ADT/StringRef.h"
12#include "llvm/ADT/StringSwitch.h"
13#include "llvm/Support/ErrorOr.h"
14#include "llvm/Support/MemoryBuffer.h"
15#include "llvm/Support/Threading.h"
16#include "llvm/TargetParser/Host.h"
17#include "llvm/TargetParser/Triple.h"
23 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
File =
24 VFS.getBufferForFile(
"/etc/os-release");
26 File = VFS.getBufferForFile(
"/usr/lib/os-release");
31 File.get()->getBuffer().split(Lines,
"\n");
35 for (StringRef Line : Lines)
37 Version = llvm::StringSwitch<Distro::DistroType>(Line.substr(3))
51 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
File =
52 VFS.getBufferForFile(
"/etc/lsb-release");
57 File.get()->getBuffer().split(Lines,
"\n");
60 for (StringRef Line : Lines)
62 Line.starts_with(
"DISTRIB_CODENAME="))
63 Version = llvm::StringSwitch<Distro::DistroType>(Line.substr(17))
118 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
File =
119 VFS.getBufferForFile(
"/etc/redhat-release");
122 StringRef
Data =
File.get()->getBuffer();
123 if (
Data.starts_with(
"Fedora release"))
125 if (
Data.starts_with(
"Red Hat Enterprise Linux") ||
126 Data.starts_with(
"CentOS") ||
Data.starts_with(
"Scientific Linux")) {
127 if (
Data.contains(
"release 7"))
129 else if (
Data.contains(
"release 6"))
131 else if (
Data.contains(
"release 5"))
138 File = VFS.getBufferForFile(
"/etc/debian_version");
140 StringRef
Data =
File.get()->getBuffer();
143 if (!
Data.split(
'.').first.getAsInteger(10, MajorVersion)) {
144 switch (MajorVersion) {
167 return llvm::StringSwitch<Distro::DistroType>(
Data.split(
"\n").first)
180 File = VFS.getBufferForFile(
"/etc/SuSE-release");
182 StringRef
Data =
File.get()->getBuffer();
184 Data.split(Lines,
"\n");
185 for (
const StringRef &Line : Lines) {
186 if (!Line.trim().starts_with(
"VERSION"))
188 std::pair<StringRef, StringRef> SplitLine = Line.split(
'=');
191 std::pair<StringRef, StringRef> SplitVer =
192 SplitLine.second.trim().split(
'.');
197 if (!SplitVer.first.getAsInteger(10, Version) && Version > 10)
205 if (VFS.exists(
"/etc/gentoo-release"))
212 const llvm::Triple &TargetOrHost) {
215 if (!TargetOrHost.isOSLinux())
219 const bool onRealFS = (llvm::vfs::getRealFileSystem() == &VFS);
225 llvm::Triple HostTriple(llvm::sys::getProcessTriple());
226 if (!HostTriple.isOSLinux() && onRealFS)
241 : 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.
The JSON file list parser is used to communicate input to InstallAPI.