clang 20.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:
26 // Special value means that no detection was performed yet.
28 // NB: Releases of a particular Linux distro should be kept together
29 // in this enum, because some tests are done by integer comparison against
30 // the first and last known member in the family, e.g. IsRedHat().
85 };
86
87private:
88 /// The distribution, possibly with specific version.
89 DistroType DistroVal;
90
91public:
92 /// @name Constructors
93 /// @{
94
95 /// Default constructor leaves the distribution unknown.
96 Distro() : DistroVal() {}
97
98 /// Constructs a Distro type for specific distribution.
99 Distro(DistroType D) : DistroVal(D) {}
100
101 /// Detects the distribution using specified VFS.
102 explicit Distro(llvm::vfs::FileSystem &VFS, const llvm::Triple &TargetOrHost);
103
104 bool operator==(const Distro &Other) const {
105 return DistroVal == Other.DistroVal;
106 }
107
108 bool operator!=(const Distro &Other) const {
109 return DistroVal != Other.DistroVal;
110 }
111
112 bool operator>=(const Distro &Other) const {
113 return DistroVal >= Other.DistroVal;
114 }
115
116 bool operator<=(const Distro &Other) const {
117 return DistroVal <= Other.DistroVal;
118 }
119
120 /// @}
121 /// @name Convenience Predicates
122 /// @{
123
124 bool IsRedhat() const {
125 return DistroVal == Fedora || (DistroVal >= RHEL5 && DistroVal <= RHEL7);
126 }
127
128 bool IsOpenSUSE() const { return DistroVal == OpenSUSE; }
129
130 bool IsDebian() const {
131 return DistroVal >= DebianLenny && DistroVal <= DebianTrixie;
132 }
133
134 bool IsUbuntu() const {
135 return DistroVal >= UbuntuHardy && DistroVal <= UbuntuPlucky;
136 }
137
138 bool IsAlpineLinux() const { return DistroVal == AlpineLinux; }
139
140 bool IsGentoo() const { return DistroVal == Gentoo; }
141
142 /// @}
143};
144
145} // end namespace driver
146} // end namespace clang
147
148#endif
const Decl * D
Distro - Helper class for detecting and classifying Linux distributions.
Definition: Distro.h:23
bool IsDebian() const
Definition: Distro.h:130
Distro()
Default constructor leaves the distribution unknown.
Definition: Distro.h:96
bool IsOpenSUSE() const
Definition: Distro.h:128
bool IsGentoo() const
Definition: Distro.h:140
Distro(DistroType D)
Constructs a Distro type for specific distribution.
Definition: Distro.h:99
bool operator!=(const Distro &Other) const
Definition: Distro.h:108
bool operator==(const Distro &Other) const
Definition: Distro.h:104
bool IsAlpineLinux() const
Definition: Distro.h:138
bool IsRedhat() const
Definition: Distro.h:124
bool operator<=(const Distro &Other) const
Definition: Distro.h:116
bool operator>=(const Distro &Other) const
Definition: Distro.h:112
bool IsUbuntu() const
Definition: Distro.h:134
The JSON file list parser is used to communicate input to InstallAPI.
@ Other
Other implicit parameter.