clang  10.0.0svn
Distro.h
Go to the documentation of this file.
1 //===--- Distro.h - Linux distribution detection support --------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_CLANG_DRIVER_DISTRO_H
10 #define LLVM_CLANG_DRIVER_DISTRO_H
11 
12 #include "llvm/Support/VirtualFileSystem.h"
13 
14 namespace clang {
15 namespace driver {
16 
17 /// Distro - Helper class for detecting and classifying Linux distributions.
18 ///
19 /// This class encapsulates the clang Linux distribution detection mechanism
20 /// as well as helper functions that match the specific (versioned) results
21 /// into wider distribution classes.
22 class Distro {
23 public:
24  enum DistroType {
25  // NB: Releases of a particular Linux distro should be kept together
26  // in this enum, because some tests are done by integer comparison against
27  // the first and last known member in the family, e.g. IsRedHat().
69  };
70 
71 private:
72  /// The distribution, possibly with specific version.
73  DistroType DistroVal;
74 
75 public:
76  /// @name Constructors
77  /// @{
78 
79  /// Default constructor leaves the distribution unknown.
80  Distro() : DistroVal() {}
81 
82  /// Constructs a Distro type for specific distribution.
83  Distro(DistroType D) : DistroVal(D) {}
84 
85  /// Detects the distribution using specified VFS.
86  explicit Distro(llvm::vfs::FileSystem &VFS);
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  bool operator<=(const Distro &Other) const {
101  return DistroVal <= Other.DistroVal;
102  }
103 
104  /// @}
105  /// @name Convenience Predicates
106  /// @{
107 
108  bool IsRedhat() const {
109  return DistroVal == Fedora || (DistroVal >= RHEL5 && DistroVal <= RHEL7);
110  }
111 
112  bool IsOpenSUSE() const {
113  return DistroVal == OpenSUSE;
114  }
115 
116  bool IsDebian() const {
117  return DistroVal >= DebianLenny && DistroVal <= DebianBullseye;
118  }
119 
120  bool IsUbuntu() const {
121  return DistroVal >= UbuntuHardy && DistroVal <= UbuntuEoan;
122  }
123 
124  bool IsAlpineLinux() const {
125  return DistroVal == AlpineLinux;
126  }
127 
128  bool IsGentoo() const {
129  return DistroVal == Gentoo;
130  }
131 
132  /// @}
133 };
134 
135 } // end namespace driver
136 } // end namespace clang
137 
138 #endif
bool operator==(const Distro &Other) const
Definition: Distro.h:88
bool IsOpenSUSE() const
Definition: Distro.h:112
Distro - Helper class for detecting and classifying Linux distributions.
Definition: Distro.h:22
bool operator!=(const Distro &Other) const
Definition: Distro.h:92
Distro()
Default constructor leaves the distribution unknown.
Definition: Distro.h:80
bool IsDebian() const
Definition: Distro.h:116
Distro(DistroType D)
Constructs a Distro type for specific distribution.
Definition: Distro.h:83
bool IsAlpineLinux() const
Definition: Distro.h:124
Dataflow Directional Tag Classes.
bool operator<=(const Distro &Other) const
Definition: Distro.h:100
bool IsRedhat() const
Definition: Distro.h:108
bool IsUbuntu() const
Definition: Distro.h:120
bool operator>=(const Distro &Other) const
Definition: Distro.h:96
bool IsGentoo() const
Definition: Distro.h:128