Coverage Report

Created: 2022-05-21 09:15

/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
    Exherbo,
42
    RHEL5,
43
    RHEL6,
44
    RHEL7,
45
    Fedora,
46
    Gentoo,
47
    OpenSUSE,
48
    UbuntuHardy,
49
    UbuntuIntrepid,
50
    UbuntuJaunty,
51
    UbuntuKarmic,
52
    UbuntuLucid,
53
    UbuntuMaverick,
54
    UbuntuNatty,
55
    UbuntuOneiric,
56
    UbuntuPrecise,
57
    UbuntuQuantal,
58
    UbuntuRaring,
59
    UbuntuSaucy,
60
    UbuntuTrusty,
61
    UbuntuUtopic,
62
    UbuntuVivid,
63
    UbuntuWily,
64
    UbuntuXenial,
65
    UbuntuYakkety,
66
    UbuntuZesty,
67
    UbuntuArtful,
68
    UbuntuBionic,
69
    UbuntuCosmic,
70
    UbuntuDisco,
71
    UbuntuEoan,
72
    UbuntuFocal,
73
    UbuntuGroovy,
74
    UbuntuHirsute,
75
    UbuntuImpish,
76
    UbuntuJammy,
77
    UnknownDistro
78
  };
79
80
private:
81
  /// The distribution, possibly with specific version.
82
  DistroType DistroVal;
83
84
public:
85
  /// @name Constructors
86
  /// @{
87
88
  /// Default constructor leaves the distribution unknown.
89
0
  Distro() : DistroVal() {}
90
91
  /// Constructs a Distro type for specific distribution.
92
12.9k
  Distro(DistroType D) : DistroVal(D) {}
93
94
  /// Detects the distribution using specified VFS.
95
  explicit Distro(llvm::vfs::FileSystem &VFS, const llvm::Triple &TargetOrHost);
96
97
12.9k
  bool operator==(const Distro &Other) const {
98
12.9k
    return DistroVal == Other.DistroVal;
99
12.9k
  }
100
101
0
  bool operator!=(const Distro &Other) const {
102
0
    return DistroVal != Other.DistroVal;
103
0
  }
104
105
0
  bool operator>=(const Distro &Other) const {
106
0
    return DistroVal >= Other.DistroVal;
107
0
  }
108
109
0
  bool operator<=(const Distro &Other) const {
110
0
    return DistroVal <= Other.DistroVal;
111
0
  }
112
113
  /// @}
114
  /// @name Convenience Predicates
115
  /// @{
116
117
3.93k
  bool IsRedhat() const {
118
3.93k
    return DistroVal == Fedora || 
(3.93k
DistroVal >= RHEL53.93k
&&
DistroVal <= RHEL73.93k
);
119
3.93k
  }
120
121
16.5k
  bool IsOpenSUSE() const { return DistroVal == OpenSUSE; }
122
123
43.5k
  bool IsDebian() const {
124
43.5k
    return DistroVal >= DebianLenny && DistroVal <= DebianBookworm;
125
43.5k
  }
126
127
47.9k
  bool IsUbuntu() const {
128
47.9k
    return DistroVal >= UbuntuHardy && 
DistroVal <= UbuntuJammy47.9k
;
129
47.9k
  }
130
131
12.7k
  bool IsAlpineLinux() const { return DistroVal == AlpineLinux; }
132
133
26.5k
  bool IsGentoo() const { return DistroVal == Gentoo; }
134
135
  /// @}
136
};
137
138
} // end namespace driver
139
} // end namespace clang
140
141
#endif