Coverage Report

Created: 2021-01-23 06:44

/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
246k
std::string getClangRepositoryPath() {
25
#if defined(CLANG_REPOSITORY_STRING)
26
  return CLANG_REPOSITORY_STRING;
27
#else
28
246k
#ifdef CLANG_REPOSITORY
29
246k
  return CLANG_REPOSITORY;
30
#else
31
  return "";
32
#endif
33
246k
#endif
34
246k
}
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
247k
std::string getClangRevision() {
45
247k
#ifdef CLANG_REVISION
46
247k
  return CLANG_REVISION;
47
#else
48
  return "";
49
#endif
50
247k
}
51
52
247k
std::string getLLVMRevision() {
53
247k
#ifdef LLVM_REVISION
54
247k
  return LLVM_REVISION;
55
#else
56
  return "";
57
#endif
58
247k
}
59
60
246k
std::string getClangFullRepositoryVersion() {
61
246k
  std::string buf;
62
246k
  llvm::raw_string_ostream OS(buf);
63
246k
  std::string Path = getClangRepositoryPath();
64
246k
  std::string Revision = getClangRevision();
65
246k
  if (!Path.empty() || 
!Revision.empty()0
) {
66
246k
    OS << '(';
67
246k
    if (!Path.empty())
68
246k
      OS << Path;
69
246k
    if (
!Revision.empty()246k
) {
70
246k
      if (!Path.empty())
71
246k
        OS << ' ';
72
246k
      OS << Revision;
73
246k
    }
74
246k
    OS << ')';
75
246k
  }
76
  // Support LLVM in a separate repository.
77
246k
  std::string LLVMRev = getLLVMRevision();
78
246k
  if (!LLVMRev.empty() && 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
246k
  return OS.str();
86
246k
}
87
88
47.1k
std::string getClangFullVersion() {
89
47.1k
  return getClangToolFullVersion("clang");
90
47.1k
}
91
92
47.1k
std::string getClangToolFullVersion(StringRef ToolName) {
93
47.1k
  std::string buf;
94
47.1k
  llvm::raw_string_ostream OS(buf);
95
#ifdef CLANG_VENDOR
96
  OS << CLANG_VENDOR;
97
#endif
98
47.1k
  OS << ToolName << " version " CLANG_VERSION_STRING;
99
100
47.1k
  std::string repo = getClangFullRepositoryVersion();
101
47.1k
  if (!repo.empty()) {
102
47.1k
    OS << " " << repo;
103
47.1k
  }
104
105
47.1k
  return OS.str();
106
47.1k
}
107
108
81.2k
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
81.2k
  std::string buf;
112
81.2k
  llvm::raw_string_ostream OS(buf);
113
#ifdef CLANG_VENDOR
114
  OS << CLANG_VENDOR;
115
#endif
116
81.2k
  OS << "Clang " CLANG_VERSION_STRING;
117
118
81.2k
  std::string repo = getClangFullRepositoryVersion();
119
81.2k
  if (!repo.empty()) {
120
81.2k
    OS << " " << repo;
121
81.2k
  }
122
123
81.2k
  return OS.str();
124
81.2k
}
125
126
} // end namespace clang