Distro.h revision 321369
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 "clang/Basic/VirtualFileSystem.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:
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    ArchLinux,
30    DebianLenny,
31    DebianSqueeze,
32    DebianWheezy,
33    DebianJessie,
34    DebianStretch,
35    Exherbo,
36    RHEL5,
37    RHEL6,
38    RHEL7,
39    Fedora,
40    OpenSUSE,
41    UbuntuHardy,
42    UbuntuIntrepid,
43    UbuntuJaunty,
44    UbuntuKarmic,
45    UbuntuLucid,
46    UbuntuMaverick,
47    UbuntuNatty,
48    UbuntuOneiric,
49    UbuntuPrecise,
50    UbuntuQuantal,
51    UbuntuRaring,
52    UbuntuSaucy,
53    UbuntuTrusty,
54    UbuntuUtopic,
55    UbuntuVivid,
56    UbuntuWily,
57    UbuntuXenial,
58    UbuntuYakkety,
59    UbuntuZesty,
60    UbuntuArtful,
61    UnknownDistro
62  };
63
64private:
65  /// The distribution, possibly with specific version.
66  DistroType DistroVal;
67
68public:
69  /// @name Constructors
70  /// @{
71
72  /// Default constructor leaves the distribution unknown.
73  Distro() : DistroVal() {}
74
75  /// Constructs a Distro type for specific distribution.
76  Distro(DistroType D) : DistroVal(D) {}
77
78  /// Detects the distribution using specified VFS.
79  explicit Distro(clang::vfs::FileSystem& VFS);
80
81  bool operator==(const Distro &Other) const {
82    return DistroVal == Other.DistroVal;
83  }
84
85  bool operator!=(const Distro &Other) const {
86    return DistroVal != Other.DistroVal;
87  }
88
89  bool operator>=(const Distro &Other) const {
90    return DistroVal >= Other.DistroVal;
91  }
92
93  bool operator<=(const Distro &Other) const {
94    return DistroVal <= Other.DistroVal;
95  }
96
97  /// @}
98  /// @name Convenience Predicates
99  /// @{
100
101  bool IsRedhat() const {
102    return DistroVal == Fedora || (DistroVal >= RHEL5 && DistroVal <= RHEL7);
103  }
104
105  bool IsOpenSUSE() const {
106    return DistroVal == OpenSUSE;
107  }
108
109  bool IsDebian() const {
110    return DistroVal >= DebianLenny && DistroVal <= DebianStretch;
111  }
112
113  bool IsUbuntu() const {
114    return DistroVal >= UbuntuHardy && DistroVal <= UbuntuArtful;
115  }
116
117  /// @}
118};
119
120} // end namespace driver
121} // end namespace clang
122
123#endif
124