Coverage Report

Created: 2022-07-16 07:03

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/Driver/Distro.h
Line
Count
Source (jump to first uncovered line)
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
    // Special value means that no detection was performed yet.
27
    UninitializedDistro,
28
    // NB: Releases of a particular Linux distro should be kept together
29
    // in this enum, because some tests are done by integer comparison against
30
    // the first and last known member in the family, e.g. IsRedHat().
31
    AlpineLinux,
32
    ArchLinux,
33
    DebianLenny,
34
    DebianSqueeze,
35
    DebianWheezy,
36
    DebianJessie,
37
    DebianStretch,
38
    DebianBuster,
39
    DebianBullseye,
40
    DebianBookworm,
41
    DebianTrixie,
42
    Exherbo,
43
    RHEL5,
44
    RHEL6,
45
    RHEL7,
46
    Fedora,
47
    Gentoo,
48
    OpenSUSE,
49
    UbuntuHardy,
50
    UbuntuIntrepid,
51
    UbuntuJaunty,
52
    UbuntuKarmic,
53
    UbuntuLucid,
54
    UbuntuMaverick,
55
    UbuntuNatty,
56
    UbuntuOneiric,
57
    UbuntuPrecise,
58
    UbuntuQuantal,
59
    UbuntuRaring,
60
    UbuntuSaucy,
61
    UbuntuTrusty,
62
    UbuntuUtopic,
63
    UbuntuVivid,
64
    UbuntuWily,
65
    UbuntuXenial,
66
    UbuntuYakkety,
67
    UbuntuZesty,
68
    UbuntuArtful,
69
    UbuntuBionic,
70
    UbuntuCosmic,
71
    UbuntuDisco,
72
    UbuntuEoan,
73
    UbuntuFocal,
74
    UbuntuGroovy,
75
    UbuntuHirsute,
76
    UbuntuImpish,
77
    UbuntuJammy,
78
    UbuntuKinetic,
79
    UnknownDistro
80
  };
81
82
private:
83
  /// The distribution, possibly with specific version.
84
  DistroType DistroVal;
85
86
public:
87
  /// @name Constructors
88
  /// @{
89
90
  /// Default constructor leaves the distribution unknown.
91
0
  Distro() : DistroVal() {}
92
93
  /// Constructs a Distro type for specific distribution.
94
14.0k
  Distro(DistroType D) : DistroVal(D) {}
95
96
  /// Detects the distribution using specified VFS.
97
  explicit Distro(llvm::vfs::FileSystem &VFS, const llvm::Triple &TargetOrHost);
98
99
14.0k
  bool operator==(const Distro &Other) const {
100
14.0k
    return DistroVal == Other.DistroVal;
101
14.0k
  }
102
103
0
  bool operator!=(const Distro &Other) const {
104
0
    return DistroVal != Other.DistroVal;
105
0
  }
106
107
0
  bool operator>=(const Distro &Other) const {
108
0
    return DistroVal >= Other.DistroVal;
109
0
  }
110
111
0
  bool operator<=(const Distro &Other) const {
112
0
    return DistroVal <= Other.DistroVal;
113
0
  }
114
115
  /// @}
116
  /// @name Convenience Predicates
117
  /// @{
118
119
4.29k
  bool IsRedhat() const {
120
4.29k
    return DistroVal == Fedora || 
(4.29k
DistroVal >= RHEL54.29k
&&
DistroVal <= RHEL74.28k
);
121
4.29k
  }
122
123
17.9k
  bool IsOpenSUSE() const { return DistroVal == OpenSUSE; }
124
125
45.1k
  bool IsDebian() const {
126
45.1k
    return DistroVal >= DebianLenny && 
DistroVal <= DebianTrixie45.1k
;
127
45.1k
  }
128
129
49.9k
  bool IsUbuntu() const {
130
49.9k
    return DistroVal >= UbuntuHardy && 
DistroVal <= UbuntuKinetic49.9k
;
131
49.9k
  }
132
133
13.8k
  bool IsAlpineLinux() const { return DistroVal == AlpineLinux; }
134
135
27.4k
  bool IsGentoo() const { return DistroVal == Gentoo; }
136
137
  /// @}
138
};
139
140
} // end namespace driver
141
} // end namespace clang
142
143
#endif