Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/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/Support/VirtualFileSystem.h"
13
14
namespace clang {
15
namespace driver {
16
17
/// Distro - Helper class for detecting and classifying Linux distributions.
18
///
19
/// This class encapsulates the clang Linux distribution detection mechanism
20
/// as well as helper functions that match the specific (versioned) results
21
/// into wider distribution classes.
22
class Distro {
23
public:
24
  enum DistroType {
25
    // NB: Releases of a particular Linux distro should be kept together
26
    // in this enum, because some tests are done by integer comparison against
27
    // the first and last known member in the family, e.g. IsRedHat().
28
    AlpineLinux,
29
    ArchLinux,
30
    DebianLenny,
31
    DebianSqueeze,
32
    DebianWheezy,
33
    DebianJessie,
34
    DebianStretch,
35
    DebianBuster,
36
    DebianBullseye,
37
    Exherbo,
38
    RHEL5,
39
    RHEL6,
40
    RHEL7,
41
    Fedora,
42
    Gentoo,
43
    OpenSUSE,
44
    UbuntuHardy,
45
    UbuntuIntrepid,
46
    UbuntuJaunty,
47
    UbuntuKarmic,
48
    UbuntuLucid,
49
    UbuntuMaverick,
50
    UbuntuNatty,
51
    UbuntuOneiric,
52
    UbuntuPrecise,
53
    UbuntuQuantal,
54
    UbuntuRaring,
55
    UbuntuSaucy,
56
    UbuntuTrusty,
57
    UbuntuUtopic,
58
    UbuntuVivid,
59
    UbuntuWily,
60
    UbuntuXenial,
61
    UbuntuYakkety,
62
    UbuntuZesty,
63
    UbuntuArtful,
64
    UbuntuBionic,
65
    UbuntuCosmic,
66
    UbuntuDisco,
67
    UbuntuEoan,
68
    UnknownDistro
69
  };
70
71
private:
72
  /// The distribution, possibly with specific version.
73
  DistroType DistroVal;
74
75
public:
76
  /// @name Constructors
77
  /// @{
78
79
  /// Default constructor leaves the distribution unknown.
80
0
  Distro() : DistroVal() {}
81
82
  /// Constructs a Distro type for specific distribution.
83
8.65k
  Distro(DistroType D) : DistroVal(D) {}
84
85
  /// Detects the distribution using specified VFS.
86
  explicit Distro(llvm::vfs::FileSystem &VFS);
87
88
8.65k
  bool operator==(const Distro &Other) const {
89
8.65k
    return DistroVal == Other.DistroVal;
90
8.65k
  }
91
92
0
  bool operator!=(const Distro &Other) const {
93
0
    return DistroVal != Other.DistroVal;
94
0
  }
95
96
0
  bool operator>=(const Distro &Other) const {
97
0
    return DistroVal >= Other.DistroVal;
98
0
  }
99
100
0
  bool operator<=(const Distro &Other) const {
101
0
    return DistroVal <= Other.DistroVal;
102
0
  }
103
104
  /// @}
105
  /// @name Convenience Predicates
106
  /// @{
107
108
2.53k
  bool IsRedhat() const {
109
2.53k
    return DistroVal == Fedora || 
(2.53k
DistroVal >= RHEL52.53k
&&
DistroVal <= RHEL72.52k
);
110
2.53k
  }
111
112
11.2k
  bool IsOpenSUSE() const {
113
11.2k
    return DistroVal == OpenSUSE;
114
11.2k
  }
115
116
32.1k
  bool IsDebian() const {
117
32.1k
    return DistroVal >= DebianLenny && 
DistroVal <= DebianBullseye32.1k
;
118
32.1k
  }
119
120
35.3k
  bool IsUbuntu() const {
121
35.3k
    return DistroVal >= UbuntuHardy && 
DistroVal <= UbuntuEoan35.3k
;
122
35.3k
  }
123
124
8.90k
  bool IsAlpineLinux() const {
125
8.90k
    return DistroVal == AlpineLinux;
126
8.90k
  }
127
128
8.37k
  bool IsGentoo() const {
129
8.37k
    return DistroVal == Gentoo;
130
8.37k
  }
131
132
  /// @}
133
};
134
135
} // end namespace driver
136
} // end namespace clang
137
138
#endif