Coverage Report

Created: 2021-01-19 06:58

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