clang 18.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().
82 };
83
84private:
85 /// The distribution, possibly with specific version.
86 DistroType DistroVal;
87
88public:
89 /// @name Constructors
90 /// @{
91
92 /// Default constructor leaves the distribution unknown.
93 Distro() : DistroVal() {}
94
95 /// Constructs a Distro type for specific distribution.
96 Distro(DistroType D) : DistroVal(D) {}
97
98 /// Detects the distribution using specified VFS.
99 explicit Distro(llvm::vfs::FileSystem &VFS, const llvm::Triple &TargetOrHost);
100
101 bool operator==(const Distro &Other) const {
102 return DistroVal == Other.DistroVal;
103 }
104
105 bool operator!=(const Distro &Other) const {
106 return DistroVal != Other.DistroVal;
107 }
108
109 bool operator>=(const Distro &Other) const {
110 return DistroVal >= Other.DistroVal;
111 }
112
113 bool operator<=(const Distro &Other) const {
114 return DistroVal <= Other.DistroVal;
115 }
116
117 /// @}
118 /// @name Convenience Predicates
119 /// @{
120
121 bool IsRedhat() const {
122 return DistroVal == Fedora || (DistroVal >= RHEL5 && DistroVal <= RHEL7);
123 }
124
125 bool IsOpenSUSE() const { return DistroVal == OpenSUSE; }
126
127 bool IsDebian() const {
128 return DistroVal >= DebianLenny && DistroVal <= DebianTrixie;
129 }
130
131 bool IsUbuntu() const {
132 return DistroVal >= UbuntuHardy && DistroVal <= UbuntuMantic;
133 }
134
135 bool IsAlpineLinux() const { return DistroVal == AlpineLinux; }
136
137 bool IsGentoo() const { return DistroVal == Gentoo; }
138
139 /// @}
140};
141
142} // end namespace driver
143} // end namespace clang
144
145#endif
Distro - Helper class for detecting and classifying Linux distributions.
Definition: Distro.h:23
bool IsDebian() const
Definition: Distro.h:127
Distro()
Default constructor leaves the distribution unknown.
Definition: Distro.h:93
bool IsOpenSUSE() const
Definition: Distro.h:125
bool IsGentoo() const
Definition: Distro.h:137
Distro(DistroType D)
Constructs a Distro type for specific distribution.
Definition: Distro.h:96
bool operator!=(const Distro &Other) const
Definition: Distro.h:105
bool operator==(const Distro &Other) const
Definition: Distro.h:101
bool IsAlpineLinux() const
Definition: Distro.h:135
bool IsRedhat() const
Definition: Distro.h:121
bool operator<=(const Distro &Other) const
Definition: Distro.h:113
bool operator>=(const Distro &Other) const
Definition: Distro.h:109
bool IsUbuntu() const
Definition: Distro.h:131