Coverage Report

Created: 2020-02-15 09:57

/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
    // 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().
29
    AlpineLinux,
30
    ArchLinux,
31
    DebianLenny,
32
    DebianSqueeze,
33
    DebianWheezy,
34
    DebianJessie,
35
    DebianStretch,
36
    DebianBuster,
37
    DebianBullseye,
38
    Exherbo,
39
    RHEL5,
40
    RHEL6,
41
    RHEL7,
42
    Fedora,
43
    Gentoo,
44
    OpenSUSE,
45
    UbuntuHardy,
46
    UbuntuIntrepid,
47
    UbuntuJaunty,
48
    UbuntuKarmic,
49
    UbuntuLucid,
50
    UbuntuMaverick,
51
    UbuntuNatty,
52
    UbuntuOneiric,
53
    UbuntuPrecise,
54
    UbuntuQuantal,
55
    UbuntuRaring,
56
    UbuntuSaucy,
57
    UbuntuTrusty,
58
    UbuntuUtopic,
59
    UbuntuVivid,
60
    UbuntuWily,
61
    UbuntuXenial,
62
    UbuntuYakkety,
63
    UbuntuZesty,
64
    UbuntuArtful,
65
    UbuntuBionic,
66
    UbuntuCosmic,
67
    UbuntuDisco,
68
    UbuntuEoan,
69
    UbuntuFocal,
70
    UnknownDistro
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
0
  Distro() : DistroVal() {}
83
84
  /// Constructs a Distro type for specific distribution.
85
9.00k
  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
9.00k
  bool operator==(const Distro &Other) const {
91
9.00k
    return DistroVal == Other.DistroVal;
92
9.00k
  }
93
94
0
  bool operator!=(const Distro &Other) const {
95
0
    return DistroVal != Other.DistroVal;
96
0
  }
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
  /// @}
107
  /// @name Convenience Predicates
108
  /// @{
109
110
2.63k
  bool IsRedhat() const {
111
2.63k
    return DistroVal == Fedora || 
(2.63k
DistroVal >= RHEL52.63k
&&
DistroVal <= RHEL72.62k
);
112
2.63k
  }
113
114
11.6k
  bool IsOpenSUSE() const {
115
11.6k
    return DistroVal == OpenSUSE;
116
11.6k
  }
117
118
31.3k
  bool IsDebian() const {
119
31.3k
    return DistroVal >= DebianLenny && DistroVal <= DebianBullseye;
120
31.3k
  }
121
122
34.6k
  bool IsUbuntu() const {
123
34.6k
    return DistroVal >= UbuntuHardy && 
DistroVal <= UbuntuFocal34.6k
;
124
34.6k
  }
125
126
9.23k
  bool IsAlpineLinux() const {
127
9.23k
    return DistroVal == AlpineLinux;
128
9.23k
  }
129
130
8.96k
  bool IsGentoo() const {
131
8.96k
    return DistroVal == Gentoo;
132
8.96k
  }
133
134
  /// @}
135
};
136
137
} // end namespace driver
138
} // end namespace clang
139
140
#endif