]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/clang/Driver/Distro.h
Vendor import of clang trunk r351319 (just before the release_80 branch
[FreeBSD/FreeBSD.git] / include / clang / Driver / Distro.h
1 //===--- Distro.h - Linux distribution detection support --------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CLANG_DRIVER_DISTRO_H
11 #define LLVM_CLANG_DRIVER_DISTRO_H
12
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     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     UnknownDistro
68   };
69
70 private:
71   /// The distribution, possibly with specific version.
72   DistroType DistroVal;
73
74 public:
75   /// @name Constructors
76   /// @{
77
78   /// Default constructor leaves the distribution unknown.
79   Distro() : DistroVal() {}
80
81   /// Constructs a Distro type for specific distribution.
82   Distro(DistroType D) : DistroVal(D) {}
83
84   /// Detects the distribution using specified VFS.
85   explicit Distro(llvm::vfs::FileSystem &VFS);
86
87   bool operator==(const Distro &Other) const {
88     return DistroVal == Other.DistroVal;
89   }
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   /// @}
104   /// @name Convenience Predicates
105   /// @{
106
107   bool IsRedhat() const {
108     return DistroVal == Fedora || (DistroVal >= RHEL5 && DistroVal <= RHEL7);
109   }
110
111   bool IsOpenSUSE() const {
112     return DistroVal == OpenSUSE;
113   }
114
115   bool IsDebian() const {
116     return DistroVal >= DebianLenny && DistroVal <= DebianBuster;
117   }
118
119   bool IsUbuntu() const {
120     return DistroVal >= UbuntuHardy && DistroVal <= UbuntuDisco;
121   }
122
123   bool IsAlpineLinux() const {
124     return DistroVal == AlpineLinux;
125   }
126
127   bool IsGentoo() const {
128     return DistroVal == Gentoo;
129   }
130
131   /// @}
132 };
133
134 } // end namespace driver
135 } // end namespace clang
136
137 #endif