clang  8.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 
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().
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
bool operator==(const Distro &Other) const
Definition: Distro.h:87
bool IsOpenSUSE() const
Definition: Distro.h:111
Distro - Helper class for detecting and classifying Linux distributions.
Definition: Distro.h:23
bool operator!=(const Distro &Other) const
Definition: Distro.h:91
Distro()
Default constructor leaves the distribution unknown.
Definition: Distro.h:79
bool IsDebian() const
Definition: Distro.h:115
Distro(DistroType D)
Constructs a Distro type for specific distribution.
Definition: Distro.h:82
bool IsAlpineLinux() const
Definition: Distro.h:123
Dataflow Directional Tag Classes.
bool operator<=(const Distro &Other) const
Definition: Distro.h:99
bool IsRedhat() const
Definition: Distro.h:107
bool IsUbuntu() const
Definition: Distro.h:119
bool operator>=(const Distro &Other) const
Definition: Distro.h:95
bool IsGentoo() const
Definition: Distro.h:127