Coverage Report

Created: 2020-09-22 08:39

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