2009-10-06 02:52:24 +08:00
|
|
|
//===- Version.cpp - Clang Version Number -----------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2009-10-06 02:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines several version-related utility functions for Clang.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2010-01-23 04:55:35 +08:00
|
|
|
|
2010-01-23 06:29:50 +08:00
|
|
|
#include "clang/Basic/Version.h"
|
2011-07-23 18:55:15 +08:00
|
|
|
#include "clang/Basic/LLVM.h"
|
2014-06-06 18:36:22 +08:00
|
|
|
#include "clang/Config/config.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-10-06 02:52:24 +08:00
|
|
|
#include <cstdlib>
|
2012-12-04 17:13:33 +08:00
|
|
|
#include <cstring>
|
2010-01-23 04:55:35 +08:00
|
|
|
|
2019-02-06 11:51:00 +08:00
|
|
|
#ifdef HAVE_VCS_VERSION_INC
|
|
|
|
#include "VCSVersion.inc"
|
2019-01-31 15:12:43 +08:00
|
|
|
#endif
|
|
|
|
|
2009-10-06 02:52:24 +08:00
|
|
|
namespace clang {
|
2012-03-02 22:37:41 +08:00
|
|
|
|
2010-09-30 03:15:29 +08:00
|
|
|
std::string getClangRepositoryPath() {
|
2011-03-31 08:32:50 +08:00
|
|
|
#if defined(CLANG_REPOSITORY_STRING)
|
|
|
|
return CLANG_REPOSITORY_STRING;
|
|
|
|
#else
|
2019-02-06 11:51:00 +08:00
|
|
|
#ifdef CLANG_REPOSITORY
|
2020-01-16 23:27:25 +08:00
|
|
|
return CLANG_REPOSITORY;
|
2010-09-30 03:15:29 +08:00
|
|
|
#else
|
2020-01-16 23:27:25 +08:00
|
|
|
return "";
|
2010-09-30 03:15:29 +08:00
|
|
|
#endif
|
2011-03-31 08:32:50 +08:00
|
|
|
#endif
|
2009-10-06 02:52:24 +08:00
|
|
|
}
|
|
|
|
|
2012-03-02 22:37:41 +08:00
|
|
|
std::string getLLVMRepositoryPath() {
|
|
|
|
#ifdef LLVM_REPOSITORY
|
2020-01-16 23:27:25 +08:00
|
|
|
return LLVM_REPOSITORY;
|
2012-03-02 22:37:41 +08:00
|
|
|
#else
|
2020-01-16 23:27:25 +08:00
|
|
|
return "";
|
2012-03-02 22:37:41 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-09-30 03:15:29 +08:00
|
|
|
std::string getClangRevision() {
|
2019-02-06 11:51:00 +08:00
|
|
|
#ifdef CLANG_REVISION
|
|
|
|
return CLANG_REVISION;
|
2010-09-30 03:15:29 +08:00
|
|
|
#else
|
2010-03-03 09:02:48 +08:00
|
|
|
return "";
|
2010-09-30 03:15:29 +08:00
|
|
|
#endif
|
2009-10-06 02:52:24 +08:00
|
|
|
}
|
|
|
|
|
2012-03-02 22:37:41 +08:00
|
|
|
std::string getLLVMRevision() {
|
|
|
|
#ifdef LLVM_REVISION
|
|
|
|
return LLVM_REVISION;
|
|
|
|
#else
|
|
|
|
return "";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-02-13 06:54:40 +08:00
|
|
|
std::string getClangFullRepositoryVersion() {
|
|
|
|
std::string buf;
|
|
|
|
llvm::raw_string_ostream OS(buf);
|
2010-09-30 03:15:29 +08:00
|
|
|
std::string Path = getClangRepositoryPath();
|
|
|
|
std::string Revision = getClangRevision();
|
2012-03-07 08:44:24 +08:00
|
|
|
if (!Path.empty() || !Revision.empty()) {
|
|
|
|
OS << '(';
|
2010-09-30 01:57:10 +08:00
|
|
|
if (!Path.empty())
|
2012-03-07 08:44:24 +08:00
|
|
|
OS << Path;
|
|
|
|
if (!Revision.empty()) {
|
|
|
|
if (!Path.empty())
|
|
|
|
OS << ' ';
|
|
|
|
OS << Revision;
|
|
|
|
}
|
|
|
|
OS << ')';
|
2014-01-14 18:25:26 +08:00
|
|
|
}
|
2012-03-02 22:37:41 +08:00
|
|
|
// Support LLVM in a separate repository.
|
|
|
|
std::string LLVMRev = getLLVMRevision();
|
|
|
|
if (!LLVMRev.empty() && LLVMRev != Revision) {
|
2014-01-14 18:25:26 +08:00
|
|
|
OS << " (";
|
2012-03-02 22:37:41 +08:00
|
|
|
std::string LLVMRepo = getLLVMRepositoryPath();
|
|
|
|
if (!LLVMRepo.empty())
|
2012-03-07 08:44:24 +08:00
|
|
|
OS << LLVMRepo << ' ';
|
|
|
|
OS << LLVMRev << ')';
|
2012-03-02 22:37:41 +08:00
|
|
|
}
|
2010-03-05 23:39:20 +08:00
|
|
|
return OS.str();
|
2010-01-23 06:29:50 +08:00
|
|
|
}
|
2012-03-02 22:37:41 +08:00
|
|
|
|
2010-02-13 06:54:40 +08:00
|
|
|
std::string getClangFullVersion() {
|
2014-01-08 00:27:35 +08:00
|
|
|
return getClangToolFullVersion("clang");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string getClangToolFullVersion(StringRef ToolName) {
|
2010-02-13 06:54:40 +08:00
|
|
|
std::string buf;
|
|
|
|
llvm::raw_string_ostream OS(buf);
|
2010-01-23 06:29:50 +08:00
|
|
|
#ifdef CLANG_VENDOR
|
2010-02-13 06:54:40 +08:00
|
|
|
OS << CLANG_VENDOR;
|
2010-01-23 06:29:50 +08:00
|
|
|
#endif
|
2014-01-08 00:27:35 +08:00
|
|
|
OS << ToolName << " version " CLANG_VERSION_STRING " "
|
2012-03-07 08:44:24 +08:00
|
|
|
<< getClangFullRepositoryVersion();
|
2010-10-07 23:00:30 +08:00
|
|
|
|
2010-03-05 23:39:20 +08:00
|
|
|
return OS.str();
|
2010-01-23 06:12:47 +08:00
|
|
|
}
|
2010-02-13 06:54:40 +08:00
|
|
|
|
2011-03-31 08:53:51 +08:00
|
|
|
std::string getClangFullCPPVersion() {
|
2019-07-13 14:27:35 +08:00
|
|
|
// The version string we report in __VERSION__ is just a compacted version of
|
|
|
|
// the one we report on the command line.
|
2011-03-31 08:53:51 +08:00
|
|
|
std::string buf;
|
|
|
|
llvm::raw_string_ostream OS(buf);
|
|
|
|
#ifdef CLANG_VENDOR
|
|
|
|
OS << CLANG_VENDOR;
|
|
|
|
#endif
|
2012-05-27 03:39:52 +08:00
|
|
|
OS << "Clang " CLANG_VERSION_STRING " " << getClangFullRepositoryVersion();
|
2011-03-31 08:53:51 +08:00
|
|
|
return OS.str();
|
|
|
|
}
|
|
|
|
|
2009-10-06 02:52:24 +08:00
|
|
|
} // end namespace clang
|