clang 23.0.0git
Distro.h
Go to the documentation of this file.
1//===--- Distro.h - Linux distribution detection support --------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_DRIVER_DISTRO_H
10#define LLVM_CLANG_DRIVER_DISTRO_H
11
12#include "llvm/Support/VirtualFileSystem.h"
13#include "llvm/TargetParser/Triple.h"
14
15namespace clang {
16namespace driver {
17
18/// Distro - Helper class for detecting and classifying Linux distributions.
19///
20/// This class encapsulates the clang Linux distribution detection mechanism
21/// as well as helper functions that match the specific (versioned) results
22/// into wider distribution classes.
23class Distro {
24public:
80
81private:
82 /// The distribution, possibly with specific version.
83 DistroType DistroVal;
84
85public:
86 /// @name Constructors
87 /// @{
88
89 /// Default constructor leaves the distribution unknown.
90 Distro() : DistroVal() {}
91
92 /// Constructs a Distro type for specific distribution.
93 Distro(DistroType D) : DistroVal(D) {}
94
95 /// Detects the distribution using specified VFS.
96 explicit Distro(llvm::vfs::FileSystem &VFS, const llvm::Triple &TargetOrHost);
97
98 bool operator==(const Distro &Other) const {
99 return DistroVal == Other.DistroVal;
100 }
101
102 bool operator!=(const Distro &Other) const {
103 return DistroVal != Other.DistroVal;
104 }
105
106 bool operator>=(const Distro &Other) const {
107 return DistroVal >= Other.DistroVal;
108 }
109
110 bool operator<=(const Distro &Other) const {
111 return DistroVal <= Other.DistroVal;
112 }
113
114 /// @}
115 /// @name Convenience Predicates
116 /// @{
117
118 bool IsRedhat() const {
119 return DistroVal == Fedora || (DistroVal >= RHEL7 && DistroVal <= RHEL10);
120 }
121
122 bool IsOpenSUSE() const { return DistroVal == OpenSUSE; }
123
124 bool IsDebian() const {
125 return DistroVal >= DebianJessie && DistroVal <= DebianDuke;
126 }
127
128 bool IsUbuntu() const {
129 return DistroVal >= UbuntuQuantal && DistroVal <= UbuntuStonking;
130 }
131
132 bool IsAlpineLinux() const { return DistroVal == AlpineLinux; }
133
134 bool IsGentoo() const { return DistroVal == Gentoo; }
135
136 /// @}
137};
138
139} // end namespace driver
140} // end namespace clang
141
142#endif
bool IsDebian() const
Definition Distro.h:124
Distro()
Default constructor leaves the distribution unknown.
Definition Distro.h:90
bool IsOpenSUSE() const
Definition Distro.h:122
bool IsGentoo() const
Definition Distro.h:134
Distro(DistroType D)
Constructs a Distro type for specific distribution.
Definition Distro.h:93
bool operator!=(const Distro &Other) const
Definition Distro.h:102
bool operator==(const Distro &Other) const
Definition Distro.h:98
bool IsAlpineLinux() const
Definition Distro.h:132
bool IsRedhat() const
Definition Distro.h:118
bool operator<=(const Distro &Other) const
Definition Distro.h:110
bool operator>=(const Distro &Other) const
Definition Distro.h:106
bool IsUbuntu() const
Definition Distro.h:128
The JSON file list parser is used to communicate input to InstallAPI.
@ Other
Other implicit parameter.
Definition Decl.h:1763