Path: blob/main/contrib/llvm-project/clang/lib/Basic/Version.cpp
35232 views
//===- Version.cpp - Clang Version Number -----------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file defines several version-related utility functions for Clang.9//10//===----------------------------------------------------------------------===//1112#include "clang/Basic/Version.h"13#include "clang/Basic/LLVM.h"14#include "clang/Config/config.h"15#include "llvm/Support/raw_ostream.h"16#include <cstdlib>17#include <cstring>1819#include "VCSVersion.inc"2021namespace clang {2223std::string getClangRepositoryPath() {24#if defined(CLANG_REPOSITORY_STRING)25return CLANG_REPOSITORY_STRING;26#else27#ifdef CLANG_REPOSITORY28return CLANG_REPOSITORY;29#else30return "";31#endif32#endif33}3435std::string getLLVMRepositoryPath() {36#ifdef LLVM_REPOSITORY37return LLVM_REPOSITORY;38#else39return "";40#endif41}4243std::string getClangRevision() {44#ifdef CLANG_REVISION45return CLANG_REVISION;46#else47return "";48#endif49}5051std::string getLLVMRevision() {52#ifdef LLVM_REVISION53return LLVM_REVISION;54#else55return "";56#endif57}5859std::string getClangVendor() {60#ifdef CLANG_VENDOR61return CLANG_VENDOR;62#else63return "";64#endif65}6667std::string getClangFullRepositoryVersion() {68std::string buf;69llvm::raw_string_ostream OS(buf);70std::string Path = getClangRepositoryPath();71std::string Revision = getClangRevision();72if (!Path.empty() || !Revision.empty()) {73OS << '(';74if (!Path.empty())75OS << Path;76if (!Revision.empty()) {77if (!Path.empty())78OS << ' ';79OS << Revision;80}81OS << ')';82}83// Support LLVM in a separate repository.84std::string LLVMRev = getLLVMRevision();85if (!LLVMRev.empty() && LLVMRev != Revision) {86OS << " (";87std::string LLVMRepo = getLLVMRepositoryPath();88if (!LLVMRepo.empty())89OS << LLVMRepo << ' ';90OS << LLVMRev << ')';91}92return buf;93}9495std::string getClangFullVersion() {96return getClangToolFullVersion("clang");97}9899std::string getClangToolFullVersion(StringRef ToolName) {100std::string buf;101llvm::raw_string_ostream OS(buf);102OS << getClangVendor() << ToolName << " version " CLANG_VERSION_STRING;103104std::string repo = getClangFullRepositoryVersion();105if (!repo.empty()) {106OS << " " << repo;107}108109return buf;110}111112std::string getClangFullCPPVersion() {113// The version string we report in __VERSION__ is just a compacted version of114// the one we report on the command line.115std::string buf;116llvm::raw_string_ostream OS(buf);117OS << getClangVendor() << "Clang " CLANG_VERSION_STRING;118119std::string repo = getClangFullRepositoryVersion();120if (!repo.empty()) {121OS << " " << repo;122}123124return buf;125}126127} // end namespace clang128129130