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