clang  5.0.0
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().
62  };
63 
64 private:
65  /// The distribution, possibly with specific version.
66  DistroType DistroVal;
67 
68 public:
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
bool operator!=(const Distro &Other) const
Definition: Distro.h:85
bool IsDebian() const
Definition: Distro.h:109
bool IsUbuntu() const
Definition: Distro.h:113
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:89
bool IsOpenSUSE() const
Definition: Distro.h:105
bool operator==(const Distro &Other) const
Definition: Distro.h:81
bool IsRedhat() const
Definition: Distro.h:101
Distro()
Default constructor leaves the distribution unknown.
Definition: Distro.h:73
bool operator<=(const Distro &Other) const
Definition: Distro.h:93
Distro(DistroType D)
Constructs a Distro type for specific distribution.
Definition: Distro.h:76
Defines the virtual file system interface vfs::FileSystem.