1 //===- Version.cpp - Clang Version Number -----------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines several version-related utility functions for Clang.
11 //===----------------------------------------------------------------------===//
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"
20 #include "VCSVersion.inc"
24 std::string getClangRepositoryPath() {
25 #if defined(CLANG_REPOSITORY_STRING)
26 return CLANG_REPOSITORY_STRING;
28 #ifdef CLANG_REPOSITORY
29 return CLANG_REPOSITORY;
36 std::string getLLVMRepositoryPath() {
37 #ifdef LLVM_REPOSITORY
38 return LLVM_REPOSITORY;
44 std::string getClangRevision() {
46 return CLANG_REVISION;
52 std::string getLLVMRevision() {
60 std::string getClangFullRepositoryVersion() {
62 llvm::raw_string_ostream OS(buf);
63 std::string Path = getClangRepositoryPath();
64 std::string Revision = getClangRevision();
65 if (!Path.empty() || !Revision.empty()) {
69 if (!Revision.empty()) {
76 // Support LLVM in a separate repository.
77 std::string LLVMRev = getLLVMRevision();
78 if (!LLVMRev.empty() && LLVMRev != Revision) {
80 std::string LLVMRepo = getLLVMRepositoryPath();
81 if (!LLVMRepo.empty())
82 OS << LLVMRepo << ' ';
88 std::string getClangFullVersion() {
89 return getClangToolFullVersion("clang");
92 std::string getClangToolFullVersion(StringRef ToolName) {
94 llvm::raw_string_ostream OS(buf);
98 OS << ToolName << " version " CLANG_VERSION_STRING;
100 std::string repo = getClangFullRepositoryVersion();
108 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.
112 llvm::raw_string_ostream OS(buf);
116 OS << "Clang " CLANG_VERSION_STRING;
118 std::string repo = getClangFullRepositoryVersion();
126 } // end namespace clang