Coverage Report

Created: 2022-05-17 06:19

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Basic/Version.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- Version.cpp - Clang Version Number -----------------------*- 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
// This file defines several version-related utility functions for Clang.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "clang/Basic/Version.h"
14
#include "clang/Basic/LLVM.h"
15
#include "clang/Config/config.h"
16
#include "llvm/Support/raw_ostream.h"
17
#include <cstdlib>
18
#include <cstring>
19
20
#include "VCSVersion.inc"
21
22
namespace clang {
23
24
271k
std::string getClangRepositoryPath() {
25
#if defined(CLANG_REPOSITORY_STRING)
26
  return CLANG_REPOSITORY_STRING;
27
#else
28
271k
#ifdef CLANG_REPOSITORY
29
271k
  return CLANG_REPOSITORY;
30
#else
31
  return "";
32
#endif
33
271k
#endif
34
271k
}
35
36
0
std::string getLLVMRepositoryPath() {
37
0
#ifdef LLVM_REPOSITORY
38
0
  return LLVM_REPOSITORY;
39
#else
40
  return "";
41
#endif
42
0
}
43
44
272k
std::string getClangRevision() {
45
272k
#ifdef CLANG_REVISION
46
272k
  return CLANG_REVISION;
47
#else
48
  return "";
49
#endif
50
272k
}
51
52
272k
std::string getLLVMRevision() {
53
272k
#ifdef LLVM_REVISION
54
272k
  return LLVM_REVISION;
55
#else
56
  return "";
57
#endif
58
272k
}
59
60
271k
std::string getClangFullRepositoryVersion() {
61
271k
  std::string buf;
62
271k
  llvm::raw_string_ostream OS(buf);
63
271k
  std::string Path = getClangRepositoryPath();
64
271k
  std::string Revision = getClangRevision();
65
271k
  if (
!Path.empty()271k
||
!Revision.empty()0
) {
66
271k
    OS << '(';
67
271k
    if (!Path.empty())
68
271k
      OS << Path;
69
271k
    if (!Revision.empty()) {
70
271k
      if (!Path.empty())
71
271k
        OS << ' ';
72
271k
      OS << Revision;
73
271k
    }
74
271k
    OS << ')';
75
271k
  }
76
  // Support LLVM in a separate repository.
77
271k
  std::string LLVMRev = getLLVMRevision();
78
271k
  if (
!LLVMRev.empty()271k
&& LLVMRev != Revision) {
79
0
    OS << " (";
80
0
    std::string LLVMRepo = getLLVMRepositoryPath();
81
0
    if (!LLVMRepo.empty())
82
0
      OS << LLVMRepo << ' ';
83
0
    OS << LLVMRev << ')';
84
0
  }
85
271k
  return buf;
86
271k
}
87
88
55.1k
std::string getClangFullVersion() {
89
55.1k
  return getClangToolFullVersion("clang");
90
55.1k
}
91
92
55.1k
std::string getClangToolFullVersion(StringRef ToolName) {
93
55.1k
  std::string buf;
94
55.1k
  llvm::raw_string_ostream OS(buf);
95
#ifdef CLANG_VENDOR
96
  OS << CLANG_VENDOR;
97
#endif
98
55.1k
  OS << ToolName << " version " CLANG_VERSION_STRING;
99
100
55.1k
  std::string repo = getClangFullRepositoryVersion();
101
55.1k
  if (!repo.empty()) {
102
55.1k
    OS << " " << repo;
103
55.1k
  }
104
105
55.1k
  return buf;
106
55.1k
}
107
108
88.7k
std::string getClangFullCPPVersion() {
109
  // The version string we report in __VERSION__ is just a compacted version of
110
  // the one we report on the command line.
111
88.7k
  std::string buf;
112
88.7k
  llvm::raw_string_ostream OS(buf);
113
#ifdef CLANG_VENDOR
114
  OS << CLANG_VENDOR;
115
#endif
116
88.7k
  OS << "Clang " CLANG_VERSION_STRING;
117
118
88.7k
  std::string repo = getClangFullRepositoryVersion();
119
88.7k
  if (
!repo.empty()88.7k
) {
120
88.7k
    OS << " " << repo;
121
88.7k
  }
122
123
88.7k
  return buf;
124
88.7k
}
125
126
} // end namespace clang