Coverage Report

Created: 2020-02-15 09:57

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