clang  10.0.0git
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/ADT/Triple.h"
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().
71  };
72 
73 private:
74  /// The distribution, possibly with specific version.
75  DistroType DistroVal;
76 
77 public:
78  /// @name Constructors
79  /// @{
80 
81  /// Default constructor leaves the distribution unknown.
82  Distro() : DistroVal() {}
83 
84  /// Constructs a Distro type for specific distribution.
85  Distro(DistroType D) : DistroVal(D) {}
86 
87  /// Detects the distribution using specified VFS.
88  explicit Distro(llvm::vfs::FileSystem &VFS, const llvm::Triple &TargetOrHost);
89 
90  bool operator==(const Distro &Other) const {
91  return DistroVal == Other.DistroVal;
92  }
93 
94  bool operator!=(const Distro &Other) const {
95  return DistroVal != Other.DistroVal;
96  }
97 
98  bool operator>=(const Distro &Other) const {
99  return DistroVal >= Other.DistroVal;
100  }
101 
102  bool operator<=(const Distro &Other) const {
103  return DistroVal <= Other.DistroVal;
104  }
105 
106  /// @}
107  /// @name Convenience Predicates
108  /// @{
109 
110  bool IsRedhat() const {
111  return DistroVal == Fedora || (DistroVal >= RHEL5 && DistroVal <= RHEL7);
112  }
113 
114  bool IsOpenSUSE() const {
115  return DistroVal == OpenSUSE;
116  }
117 
118  bool IsDebian() const {
119  return DistroVal >= DebianLenny && DistroVal <= DebianBullseye;
120  }
121 
122  bool IsUbuntu() const {
123  return DistroVal >= UbuntuHardy && DistroVal <= UbuntuFocal;
124  }
125 
126  bool IsAlpineLinux() const {
127  return DistroVal == AlpineLinux;
128  }
129 
130  bool IsGentoo() const {
131  return DistroVal == Gentoo;
132  }
133 
134  /// @}
135 };
136 
137 } // end namespace driver
138 } // end namespace clang
139 
140 #endif
bool operator==(const Distro &Other) const
Definition: Distro.h:90
bool IsOpenSUSE() const
Definition: Distro.h:114
Distro - Helper class for detecting and classifying Linux distributions.
Definition: Distro.h:23
bool operator!=(const Distro &Other) const
Definition: Distro.h:94
Distro()
Default constructor leaves the distribution unknown.
Definition: Distro.h:82
bool IsDebian() const
Definition: Distro.h:118
Distro(DistroType D)
Constructs a Distro type for specific distribution.
Definition: Distro.h:85
bool IsAlpineLinux() const
Definition: Distro.h:126
Dataflow Directional Tag Classes.
bool operator<=(const Distro &Other) const
Definition: Distro.h:102
bool IsRedhat() const
Definition: Distro.h:110
bool IsUbuntu() const
Definition: Distro.h:122
bool operator>=(const Distro &Other) const
Definition: Distro.h:98
bool IsGentoo() const
Definition: Distro.h:130