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