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.starts_with(
"DISTRIB_CODENAME="))
64 Version = llvm::StringSwitch<Distro::DistroType>(Line.substr(17))
117 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
File =
118 VFS.getBufferForFile(
"/etc/redhat-release");
121 StringRef
Data =
File.get()->getBuffer();
122 if (
Data.starts_with(
"Fedora release"))
124 if (
Data.starts_with(
"Red Hat Enterprise Linux") ||
125 Data.starts_with(
"CentOS") ||
Data.starts_with(
"Scientific Linux")) {
126 if (
Data.contains(
"release 7"))
128 else if (
Data.contains(
"release 6"))
130 else if (
Data.contains(
"release 5"))
137 File = VFS.getBufferForFile(
"/etc/debian_version");
139 StringRef
Data =
File.get()->getBuffer();
142 if (!
Data.split(
'.').first.getAsInteger(10, MajorVersion)) {
143 switch (MajorVersion) {
166 return llvm::StringSwitch<Distro::DistroType>(
Data.split(
"\n").first)
179 File = VFS.getBufferForFile(
"/etc/SuSE-release");
181 StringRef
Data =
File.get()->getBuffer();
183 Data.split(Lines,
"\n");
184 for (
const StringRef &Line : Lines) {
185 if (!Line.trim().starts_with(
"VERSION"))
187 std::pair<StringRef, StringRef> SplitLine = Line.split(
'=');
190 std::pair<StringRef, StringRef> SplitVer =
191 SplitLine.second.trim().split(
'.');
196 if (!SplitVer.first.getAsInteger(10, Version) && Version > 10)
204 if (VFS.exists(
"/etc/gentoo-release"))
211 const llvm::Triple &TargetOrHost) {
214 if (!TargetOrHost.isOSLinux())
218 const bool onRealFS = (llvm::vfs::getRealFileSystem() == &VFS);
224 llvm::Triple HostTriple(llvm::sys::getProcessTriple());
225 if (!HostTriple.isOSLinux() && onRealFS)
240 : 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.