Distro.h revision 355940
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 14namespace clang { 15namespace driver { 16 17/// Distro - Helper class for detecting and classifying Linux distributions. 18/// 19/// This class encapsulates the clang Linux distribution detection mechanism 20/// as well as helper functions that match the specific (versioned) results 21/// into wider distribution classes. 22class Distro { 23public: 24 enum DistroType { 25 // NB: Releases of a particular Linux distro should be kept together 26 // in this enum, because some tests are done by integer comparison against 27 // the first and last known member in the family, e.g. IsRedHat(). 28 AlpineLinux, 29 ArchLinux, 30 DebianLenny, 31 DebianSqueeze, 32 DebianWheezy, 33 DebianJessie, 34 DebianStretch, 35 DebianBuster, 36 DebianBullseye, 37 Exherbo, 38 RHEL5, 39 RHEL6, 40 RHEL7, 41 Fedora, 42 Gentoo, 43 OpenSUSE, 44 UbuntuHardy, 45 UbuntuIntrepid, 46 UbuntuJaunty, 47 UbuntuKarmic, 48 UbuntuLucid, 49 UbuntuMaverick, 50 UbuntuNatty, 51 UbuntuOneiric, 52 UbuntuPrecise, 53 UbuntuQuantal, 54 UbuntuRaring, 55 UbuntuSaucy, 56 UbuntuTrusty, 57 UbuntuUtopic, 58 UbuntuVivid, 59 UbuntuWily, 60 UbuntuXenial, 61 UbuntuYakkety, 62 UbuntuZesty, 63 UbuntuArtful, 64 UbuntuBionic, 65 UbuntuCosmic, 66 UbuntuDisco, 67 UbuntuEoan, 68 UnknownDistro 69 }; 70 71private: 72 /// The distribution, possibly with specific version. 73 DistroType DistroVal; 74 75public: 76 /// @name Constructors 77 /// @{ 78 79 /// Default constructor leaves the distribution unknown. 80 Distro() : DistroVal() {} 81 82 /// Constructs a Distro type for specific distribution. 83 Distro(DistroType D) : DistroVal(D) {} 84 85 /// Detects the distribution using specified VFS. 86 explicit Distro(llvm::vfs::FileSystem &VFS); 87 88 bool operator==(const Distro &Other) const { 89 return DistroVal == Other.DistroVal; 90 } 91 92 bool operator!=(const Distro &Other) const { 93 return DistroVal != Other.DistroVal; 94 } 95 96 bool operator>=(const Distro &Other) const { 97 return DistroVal >= Other.DistroVal; 98 } 99 100 bool operator<=(const Distro &Other) const { 101 return DistroVal <= Other.DistroVal; 102 } 103 104 /// @} 105 /// @name Convenience Predicates 106 /// @{ 107 108 bool IsRedhat() const { 109 return DistroVal == Fedora || (DistroVal >= RHEL5 && DistroVal <= RHEL7); 110 } 111 112 bool IsOpenSUSE() const { 113 return DistroVal == OpenSUSE; 114 } 115 116 bool IsDebian() const { 117 return DistroVal >= DebianLenny && DistroVal <= DebianBullseye; 118 } 119 120 bool IsUbuntu() const { 121 return DistroVal >= UbuntuHardy && DistroVal <= UbuntuEoan; 122 } 123 124 bool IsAlpineLinux() const { 125 return DistroVal == AlpineLinux; 126 } 127 128 bool IsGentoo() const { 129 return DistroVal == Gentoo; 130 } 131 132 /// @} 133}; 134 135} // end namespace driver 136} // end namespace clang 137 138#endif 139