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