Coverage Report

Created: 2021-08-24 07:12

/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
    UnknownDistro
77
  };
78
79
private:
80
  /// The distribution, possibly with specific version.
81
  DistroType DistroVal;
82
83
public:
84
  /// @name Constructors
85
  /// @{
86
87
  /// Default constructor leaves the distribution unknown.
88
0
  Distro() : DistroVal() {}
89
90
  /// Constructs a Distro type for specific distribution.
91
14.7k
  Distro(DistroType D) : DistroVal(D) {}
92
93
  /// Detects the distribution using specified VFS.
94
  explicit Distro(llvm::vfs::FileSystem &VFS, const llvm::Triple &TargetOrHost);
95
96
14.7k
  bool operator==(const Distro &Other) const {
97
14.7k
    return DistroVal == Other.DistroVal;
98
14.7k
  }
99
100
0
  bool operator!=(const Distro &Other) const {
101
0
    return DistroVal != Other.DistroVal;
102
0
  }
103
104
0
  bool operator>=(const Distro &Other) const {
105
0
    return DistroVal >= Other.DistroVal;
106
0
  }
107
108
0
  bool operator<=(const Distro &Other) const {
109
0
    return DistroVal <= Other.DistroVal;
110
0
  }
111
112
  /// @}
113
  /// @name Convenience Predicates
114
  /// @{
115
116
4.48k
  bool IsRedhat() const {
117
4.48k
    return DistroVal == Fedora || 
(4.48k
DistroVal >= RHEL54.48k
&&
DistroVal <= RHEL74.47k
);
118
4.48k
  }
119
120
19.0k
  bool IsOpenSUSE() const { return DistroVal == OpenSUSE; }
121
122
42.9k
  bool IsDebian() const {
123
42.9k
    return DistroVal >= DebianLenny && DistroVal <= DebianBookworm;
124
42.9k
  }
125
126
48.0k
  bool IsUbuntu() const {
127
48.0k
    return DistroVal >= UbuntuHardy && 
DistroVal <= UbuntuImpish48.0k
;
128
48.0k
  }
129
130
14.7k
  bool IsAlpineLinux() const { return DistroVal == AlpineLinux; }
131
132
26.3k
  bool IsGentoo() const { return DistroVal == Gentoo; }
133
134
  /// @}
135
};
136
137
} // end namespace driver
138
} // end namespace clang
139
140
#endif