clang  6.0.0svn
Distro.h
Go to the documentation of this file.
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 
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().
65  };
66 
67 private:
68  /// The distribution, possibly with specific version.
69  DistroType DistroVal;
70 
71 public:
72  /// @name Constructors
73  /// @{
74 
75  /// Default constructor leaves the distribution unknown.
76  Distro() : DistroVal() {}
77 
78  /// Constructs a Distro type for specific distribution.
79  Distro(DistroType D) : DistroVal(D) {}
80 
81  /// Detects the distribution using specified VFS.
82  explicit Distro(clang::vfs::FileSystem& VFS);
83 
84  bool operator==(const Distro &Other) const {
85  return DistroVal == Other.DistroVal;
86  }
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  /// @}
101  /// @name Convenience Predicates
102  /// @{
103 
104  bool IsRedhat() const {
105  return DistroVal == Fedora || (DistroVal >= RHEL5 && DistroVal <= RHEL7);
106  }
107 
108  bool IsOpenSUSE() const {
109  return DistroVal == OpenSUSE;
110  }
111 
112  bool IsDebian() const {
113  return DistroVal >= DebianLenny && DistroVal <= DebianBuster;
114  }
115 
116  bool IsUbuntu() const {
117  return DistroVal >= UbuntuHardy && DistroVal <= UbuntuBionic;
118  }
119 
120  bool IsAlpineLinux() const {
121  return DistroVal == AlpineLinux;
122  }
123 
124  /// @}
125 };
126 
127 } // end namespace driver
128 } // end namespace clang
129 
130 #endif
bool operator==(const Distro &Other) const
Definition: Distro.h:84
bool IsOpenSUSE() const
Definition: Distro.h:108
The virtual file system interface.
Distro - Helper class for detecting and classifying Linux distributions.
Definition: Distro.h:23
bool operator!=(const Distro &Other) const
Definition: Distro.h:88
Distro()
Default constructor leaves the distribution unknown.
Definition: Distro.h:76
bool IsDebian() const
Definition: Distro.h:112
Distro(DistroType D)
Constructs a Distro type for specific distribution.
Definition: Distro.h:79
bool IsAlpineLinux() const
Definition: Distro.h:120
Dataflow Directional Tag Classes.
Defines the virtual file system interface vfs::FileSystem.
bool operator<=(const Distro &Other) const
Definition: Distro.h:96
bool IsRedhat() const
Definition: Distro.h:104
bool IsUbuntu() const
Definition: Distro.h:116
bool operator>=(const Distro &Other) const
Definition: Distro.h:92