Coverage Report

Created: 2021-09-21 08:58

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