clang 20.0.0git
Version.cpp
Go to the documentation of this file.
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
22namespace clang {
23
25#if defined(CLANG_REPOSITORY_STRING)
26 return CLANG_REPOSITORY_STRING;
27#else
28#ifdef CLANG_REPOSITORY
29 return CLANG_REPOSITORY;
30#else
31 return "";
32#endif
33#endif
34}
35
36std::string getLLVMRepositoryPath() {
37#ifdef LLVM_REPOSITORY
38 return LLVM_REPOSITORY;
39#else
40 return "";
41#endif
42}
43
44std::string getClangRevision() {
45#ifdef CLANG_REVISION
46 return CLANG_REVISION;
47#else
48 return "";
49#endif
50}
51
52std::string getLLVMRevision() {
53#ifdef LLVM_REVISION
54 return LLVM_REVISION;
55#else
56 return "";
57#endif
58}
59
60std::string getClangVendor() {
61#ifdef CLANG_VENDOR
62 return CLANG_VENDOR;
63#else
64 return "";
65#endif
66}
67
69 std::string buf;
70 llvm::raw_string_ostream OS(buf);
71 std::string Path = getClangRepositoryPath();
72 std::string Revision = getClangRevision();
73 if (!Path.empty() || !Revision.empty()) {
74 OS << '(';
75 if (!Path.empty())
76 OS << Path;
77 if (!Revision.empty()) {
78 if (!Path.empty())
79 OS << ' ';
80 OS << Revision;
81 }
82 OS << ')';
83 }
84 // Support LLVM in a separate repository.
85 std::string LLVMRev = getLLVMRevision();
86 if (!LLVMRev.empty() && LLVMRev != Revision) {
87 OS << " (";
88 std::string LLVMRepo = getLLVMRepositoryPath();
89 if (!LLVMRepo.empty())
90 OS << LLVMRepo << ' ';
91 OS << LLVMRev << ')';
92 }
93 return buf;
94}
95
96std::string getClangFullVersion() {
97 return getClangToolFullVersion("clang");
98}
99
100std::string getClangToolFullVersion(StringRef ToolName) {
101 std::string buf;
102 llvm::raw_string_ostream OS(buf);
103 OS << getClangVendor() << ToolName << " version " CLANG_VERSION_STRING;
104
105 std::string repo = getClangFullRepositoryVersion();
106 if (!repo.empty()) {
107 OS << " " << repo;
108 }
109
110 return buf;
111}
112
114 // The version string we report in __VERSION__ is just a compacted version of
115 // the one we report on the command line.
116 std::string buf;
117 llvm::raw_string_ostream OS(buf);
118 OS << getClangVendor() << "Clang " CLANG_VERSION_STRING;
119
120 std::string repo = getClangFullRepositoryVersion();
121 if (!repo.empty()) {
122 OS << " " << repo;
123 }
124
125 return buf;
126}
127
128} // end namespace clang
IndirectLocalPath & Path
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines version macros and version-related utility functions for Clang.
The JSON file list parser is used to communicate input to InstallAPI.
std::string getLLVMRevision()
Retrieves the repository revision number (or identifier) from which LLVM was built.
Definition: Version.cpp:52
std::string getClangVendor()
Retrieves the Clang vendor tag.
Definition: Version.cpp:60
std::string getClangToolFullVersion(llvm::StringRef ToolName)
Like getClangFullVersion(), but with a custom tool name.
std::string getClangRevision()
Retrieves the repository revision number (or identifier) from which this Clang was built.
Definition: Version.cpp:44
std::string getClangRepositoryPath()
Retrieves the repository path (e.g., Subversion path) that identifies the particular Clang branch,...
Definition: Version.cpp:24
std::string getLLVMRepositoryPath()
Retrieves the repository path from which LLVM was built.
Definition: Version.cpp:36
std::string getClangFullRepositoryVersion()
Retrieves the full repository version that is an amalgamation of the information in getClangRepositor...
Definition: Version.cpp:68
std::string getClangFullCPPVersion()
Retrieves a string representing the complete clang version suitable for use in the CPP VERSION macro,...
Definition: Version.cpp:113
std::string getClangFullVersion()
Retrieves a string representing the complete clang version, which includes the clang version number,...
Definition: Version.cpp:96