Coverage Report

Created: 2024-01-17 10:31

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