clang 22.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:
79
80private:
81 /// The distribution, possibly with specific version.
82 DistroType DistroVal;
83
84public:
85 /// @name Constructors
86 /// @{
87
88 /// Default constructor leaves the distribution unknown.
89 Distro() : DistroVal() {}
90
91 /// Constructs a Distro type for specific distribution.
92 Distro(DistroType D) : DistroVal(D) {}
93
94 /// Detects the distribution using specified VFS.
95 explicit Distro(llvm::vfs::FileSystem &VFS, const llvm::Triple &TargetOrHost);
96
97 bool operator==(const Distro &Other) const {
98 return DistroVal == Other.DistroVal;
99 }
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 /// @}
114 /// @name Convenience Predicates
115 /// @{
116
117 bool IsRedhat() const {
118 return DistroVal == Fedora || (DistroVal >= RHEL7 && DistroVal <= RHEL10);
119 }
120
121 bool IsOpenSUSE() const { return DistroVal == OpenSUSE; }
122
123 bool IsDebian() const {
124 return DistroVal >= DebianJessie && DistroVal <= DebianDuke;
125 }
126
127 bool IsUbuntu() const {
128 return DistroVal >= UbuntuQuantal && DistroVal <= UbuntuResolute;
129 }
130
131 bool IsAlpineLinux() const { return DistroVal == AlpineLinux; }
132
133 bool IsGentoo() const { return DistroVal == Gentoo; }
134
135 /// @}
136};
137
138} // end namespace driver
139} // end namespace clang
140
141#endif
bool IsDebian() const
Definition Distro.h:123
Distro()
Default constructor leaves the distribution unknown.
Definition Distro.h:89
bool IsOpenSUSE() const
Definition Distro.h:121
bool IsGentoo() const
Definition Distro.h:133
Distro(DistroType D)
Constructs a Distro type for specific distribution.
Definition Distro.h:92
bool operator!=(const Distro &Other) const
Definition Distro.h:101
bool operator==(const Distro &Other) const
Definition Distro.h:97
bool IsAlpineLinux() const
Definition Distro.h:131
bool IsRedhat() const
Definition Distro.h:117
bool operator<=(const Distro &Other) const
Definition Distro.h:109
bool operator>=(const Distro &Other) const
Definition Distro.h:105
bool IsUbuntu() const
Definition Distro.h:127
The JSON file list parser is used to communicate input to InstallAPI.
@ Other
Other implicit parameter.
Definition Decl.h:1746