Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/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
128k
std::string getClangRepositoryPath() {
27
#if defined(CLANG_REPOSITORY_STRING)
28
  return CLANG_REPOSITORY_STRING;
29
#else
30
#ifdef CLANG_REPOSITORY
31
  StringRef URL(CLANG_REPOSITORY);
32
#else
33
  StringRef URL("");
34
128k
#endif
35
128k
36
128k
  // If the CLANG_REPOSITORY is empty, try to use the SVN keyword. This helps us
37
128k
  // pick up a tag in an SVN export, for example.
38
128k
  StringRef SVNRepository("$URL: http://llvm.org/svn/llvm-project/cfe/trunk/lib/Basic/Version.cpp $");
39
128k
  if (URL.empty()) {
40
128k
    URL = SVNRepository.slice(SVNRepository.find(':'),
41
128k
                              SVNRepository.find("/lib/Basic"));
42
128k
  }
43
128k
44
128k
  // Strip off version from a build from an integration branch.
45
128k
  URL = URL.slice(0, URL.find("/src/tools/clang"));
46
128k
47
128k
  // Trim path prefix off, assuming path came from standard cfe path.
48
128k
  size_t Start = URL.find("cfe/");
49
128k
  if (Start != StringRef::npos)
50
128k
    URL = URL.substr(Start + 4);
51
128k
52
128k
  return URL;
53
128k
#endif
54
128k
}
55
56
0
std::string getLLVMRepositoryPath() {
57
#ifdef LLVM_REPOSITORY
58
  StringRef URL(LLVM_REPOSITORY);
59
#else
60
  StringRef URL("");
61
0
#endif
62
0
63
0
  // Trim path prefix off, assuming path came from standard llvm path.
64
0
  // Leave "llvm/" prefix to distinguish the following llvm revision from the
65
0
  // clang revision.
66
0
  size_t Start = URL.find("llvm/");
67
0
  if (Start != StringRef::npos)
68
0
    URL = URL.substr(Start);
69
0
70
0
  return URL;
71
0
}
72
73
128k
std::string getClangRevision() {
74
#ifdef CLANG_REVISION
75
  return CLANG_REVISION;
76
#else
77
  return "";
78
128k
#endif
79
128k
}
80
81
128k
std::string getLLVMRevision() {
82
#ifdef LLVM_REVISION
83
  return LLVM_REVISION;
84
#else
85
  return "";
86
128k
#endif
87
128k
}
88
89
128k
std::string getClangFullRepositoryVersion() {
90
128k
  std::string buf;
91
128k
  llvm::raw_string_ostream OS(buf);
92
128k
  std::string Path = getClangRepositoryPath();
93
128k
  std::string Revision = getClangRevision();
94
128k
  if (
!Path.empty()128k
||
!Revision.empty()0
) {
95
128k
    OS << '(';
96
128k
    if (!Path.empty())
97
128k
      OS << Path;
98
128k
    if (!Revision.empty()) {
99
0
      if (!Path.empty())
100
0
        OS << ' ';
101
0
      OS << Revision;
102
0
    }
103
128k
    OS << ')';
104
128k
  }
105
128k
  // Support LLVM in a separate repository.
106
128k
  std::string LLVMRev = getLLVMRevision();
107
128k
  if (!LLVMRev.empty() && 
LLVMRev != Revision0
) {
108
0
    OS << " (";
109
0
    std::string LLVMRepo = getLLVMRepositoryPath();
110
0
    if (!LLVMRepo.empty())
111
0
      OS << LLVMRepo << ' ';
112
0
    OS << LLVMRev << ')';
113
0
  }
114
128k
  return OS.str();
115
128k
}
116
117
28.2k
std::string getClangFullVersion() {
118
28.2k
  return getClangToolFullVersion("clang");
119
28.2k
}
120
121
28.2k
std::string getClangToolFullVersion(StringRef ToolName) {
122
28.2k
  std::string buf;
123
28.2k
  llvm::raw_string_ostream OS(buf);
124
#ifdef CLANG_VENDOR
125
  OS << CLANG_VENDOR;
126
#endif
127
  OS << ToolName << " version " CLANG_VERSION_STRING " "
128
28.2k
     << getClangFullRepositoryVersion();
129
28.2k
130
28.2k
  // If vendor supplied, include the base LLVM version as well.
131
#ifdef CLANG_VENDOR
132
  OS << " (based on " << BACKEND_PACKAGE_STRING << ")";
133
#endif
134
135
28.2k
  return OS.str();
136
28.2k
}
137
138
44.1k
std::string getClangFullCPPVersion() {
139
44.1k
  // The version string we report in __VERSION__ is just a compacted version of
140
44.1k
  // the one we report on the command line.
141
44.1k
  std::string buf;
142
44.1k
  llvm::raw_string_ostream OS(buf);
143
#ifdef CLANG_VENDOR
144
  OS << CLANG_VENDOR;
145
#endif
146
  OS << "Clang " CLANG_VERSION_STRING " " << getClangFullRepositoryVersion();
147
44.1k
  return OS.str();
148
44.1k
}
149
150
} // end namespace clang