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