clang: lib/Driver/Distro.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

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"

18

20using namespace clang;

21

23 llvm::ErrorOr<std::unique_ptrllvm::MemoryBuffer> File =

24 VFS.getBufferForFile("/etc/os-release");

26 File = VFS.getBufferForFile("/usr/lib/os-release");

29

31 File.get()->getBuffer().split(Lines, "\n");

33

34

35 for (StringRef Line : Lines)

37 Version = llvm::StringSwitchDistro::DistroType(Line.substr(3))

42

47 return Version;

48}

49

51 llvm::ErrorOr<std::unique_ptrllvm::MemoryBuffer> File =

52 VFS.getBufferForFile("/etc/lsb-release");

55

57 File.get()->getBuffer().split(Lines, "\n");

59

60 for (StringRef Line : Lines)

62 Line.starts_with("DISTRIB_CODENAME="))

63 Version = llvm::StringSwitchDistro::DistroType(Line.substr(17))

100 return Version;

101}

102

105

106

107

110 return Version;

111

112

115 return Version;

116

117

118 llvm::ErrorOr<std::unique_ptrllvm::MemoryBuffer> File =

119 VFS.getBufferForFile("/etc/redhat-release");

120

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"))

133 }

135 }

136

137

138 File = VFS.getBufferForFile("/etc/debian_version");

140 StringRef Data = File.get()->getBuffer();

141

142 int MajorVersion;

143 if (Data.split('.').first.getAsInteger(10, MajorVersion)) {

144 switch (MajorVersion) {

145 case 5:

147 case 6:

149 case 7:

151 case 8:

153 case 9:

155 case 10:

157 case 11:

159 case 12:

161 case 13:

163 default:

165 }

166 }

167 return llvm::StringSwitchDistro::DistroType(Data.split("\n").first)

177 }

178

179

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"))

187 continue;

188 std::pair<StringRef, StringRef> SplitLine = Line.split('=');

189

190

191 std::pair<StringRef, StringRef> SplitVer =

192 SplitLine.second.trim().split('.');

193 int Version;

194

195

196

197 if (!SplitVer.first.getAsInteger(10, Version) && Version > 10)

200 }

202 }

203

204

205 if (VFS.exists("/etc/gentoo-release"))

207

209}

210

212 const llvm::Triple &TargetOrHost) {

213

214

215 if (!TargetOrHost.isOSLinux())

217

218

219 const bool onRealFS = (llvm::vfs::getRealFileSystem() == &VFS);

220

221

222

223

224

225 llvm::Triple HostTriple(llvm::sys::getProcessTriple());

226 if (!HostTriple.isOSLinux() && onRealFS)

228

229 if (onRealFS) {

230

231

233 return LinuxDistro;

234 }

235

236

238}

239

240Distro::Distro(llvm::vfs::FileSystem &VFS, const llvm::Triple &TargetOrHost)

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.