1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
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 | 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 | #endif |
35 | |
36 | |
37 | |
38 | StringRef SVNRepository("$URL$"); |
39 | if (URL.empty()) { |
40 | URL = SVNRepository.slice(SVNRepository.find(':'), |
41 | SVNRepository.find("/lib/Basic")); |
42 | } |
43 | |
44 | |
45 | URL = URL.slice(0, URL.find("/src/tools/clang")); |
46 | |
47 | |
48 | size_t Start = URL.find("cfe/"); |
49 | if (Start != StringRef::npos) |
50 | URL = URL.substr(Start + 4); |
51 | |
52 | return URL; |
53 | #endif |
54 | } |
55 | |
56 | std::string getLLVMRepositoryPath() { |
57 | #ifdef LLVM_REPOSITORY |
58 | StringRef URL(LLVM_REPOSITORY); |
59 | #else |
60 | StringRef URL(""); |
61 | #endif |
62 | |
63 | |
64 | |
65 | |
66 | size_t Start = URL.find("llvm/"); |
67 | if (Start != StringRef::npos) |
68 | URL = URL.substr(Start); |
69 | |
70 | return URL; |
71 | } |
72 | |
73 | std::string getClangRevision() { |
74 | #ifdef CLANG_REVISION |
75 | return CLANG_REVISION; |
76 | #else |
77 | return ""; |
78 | #endif |
79 | } |
80 | |
81 | std::string getLLVMRevision() { |
82 | #ifdef LLVM_REVISION |
83 | return LLVM_REVISION; |
84 | #else |
85 | return ""; |
86 | #endif |
87 | } |
88 | |
89 | std::string getClangFullRepositoryVersion() { |
90 | std::string buf; |
91 | llvm::raw_string_ostream OS(buf); |
92 | std::string Path = getClangRepositoryPath(); |
93 | std::string Revision = getClangRevision(); |
94 | if (!Path.empty() || !Revision.empty()) { |
95 | OS << '('; |
96 | if (!Path.empty()) |
97 | OS << Path; |
98 | if (!Revision.empty()) { |
99 | if (!Path.empty()) |
100 | OS << ' '; |
101 | OS << Revision; |
102 | } |
103 | OS << ')'; |
104 | } |
105 | |
106 | std::string LLVMRev = getLLVMRevision(); |
107 | if (!LLVMRev.empty() && LLVMRev != Revision) { |
108 | OS << " ("; |
109 | std::string LLVMRepo = getLLVMRepositoryPath(); |
110 | if (!LLVMRepo.empty()) |
111 | OS << LLVMRepo << ' '; |
112 | OS << LLVMRev << ')'; |
113 | } |
114 | return OS.str(); |
115 | } |
116 | |
117 | std::string getClangFullVersion() { |
118 | return getClangToolFullVersion("clang"); |
119 | } |
120 | |
121 | std::string getClangToolFullVersion(StringRef ToolName) { |
122 | std::string buf; |
123 | llvm::raw_string_ostream OS(buf); |
124 | #ifdef CLANG_VENDOR |
125 | OS << CLANG_VENDOR; |
126 | #endif |
127 | OS << ToolName << " version " CLANG_VERSION_STRING " " |
128 | << getClangFullRepositoryVersion(); |
129 | |
130 | |
131 | #ifdef CLANG_VENDOR |
132 | OS << " (based on " << BACKEND_PACKAGE_STRING << ")"; |
133 | #endif |
134 | |
135 | return OS.str(); |
136 | } |
137 | |
138 | std::string getClangFullCPPVersion() { |
139 | |
140 | |
141 | std::string buf; |
142 | llvm::raw_string_ostream OS(buf); |
143 | #ifdef CLANG_VENDOR |
144 | OS << CLANG_VENDOR; |
145 | #endif |
146 | OS << "Clang " CLANG_VERSION_STRING " " << getClangFullRepositoryVersion(); |
147 | return OS.str(); |
148 | } |
149 | |
150 | } |
151 | |