Coverage Report

Created: 2022-01-25 06:29

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