2009-10-05 18:52:24 +00:00
|
|
|
//===- Version.cpp - Clang Version Number -----------------------*- C++ -*-===//
|
|
|
|
|
//
|
2019-01-19 08:50:56 +00: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-05 18:52:24 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
//
|
|
|
|
|
// This file defines several version-related utility functions for Clang.
|
|
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2010-01-22 20:55:35 +00:00
|
|
|
|
2019-01-31 06:21:01 +00:00
|
|
|
#include "VCSRevision.h"
|
2010-01-22 22:29:50 +00:00
|
|
|
#include "clang/Basic/Version.h"
|
2011-07-23 10:55:15 +00:00
|
|
|
#include "clang/Basic/LLVM.h"
|
2014-06-06 10:36:22 +00:00
|
|
|
#include "clang/Config/config.h"
|
2012-12-04 09:13:33 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-10-05 18:52:24 +00:00
|
|
|
#include <cstdlib>
|
2012-12-04 09:13:33 +00:00
|
|
|
#include <cstring>
|
2010-01-22 20:55:35 +00:00
|
|
|
|
2009-10-05 18:52:24 +00:00
|
|
|
namespace clang {
|
2012-03-02 14:37:41 +00:00
|
|
|
|
2010-09-29 19:15:29 +00:00
|
|
|
std::string getClangRepositoryPath() {
|
2011-03-31 00:32:50 +00:00
|
|
|
#if defined(CLANG_REPOSITORY_STRING)
|
|
|
|
|
return CLANG_REPOSITORY_STRING;
|
|
|
|
|
#else
|
2019-01-31 06:21:01 +00:00
|
|
|
#ifdef CLANG_REPOSITORY
|
|
|
|
|
StringRef URL(CLANG_REPOSITORY);
|
2010-09-29 19:15:29 +00:00
|
|
|
#else
|
2011-07-23 10:55:15 +00:00
|
|
|
StringRef URL("");
|
2010-09-29 19:15:29 +00:00
|
|
|
#endif
|
2010-01-30 14:01:39 +00:00
|
|
|
|
2019-01-31 06:21:01 +00:00
|
|
|
// If the CLANG_REPOSITORY is empty, try to use the SVN keyword. This helps us
|
2010-10-11 23:44:19 +00:00
|
|
|
// pick up a tag in an SVN export, for example.
|
2013-08-09 17:51:03 +00:00
|
|
|
StringRef SVNRepository("$URL$");
|
2010-10-11 23:50:34 +00:00
|
|
|
if (URL.empty()) {
|
|
|
|
|
URL = SVNRepository.slice(SVNRepository.find(':'),
|
|
|
|
|
SVNRepository.find("/lib/Basic"));
|
|
|
|
|
}
|
2010-10-11 23:44:19 +00:00
|
|
|
|
2010-09-29 19:15:29 +00:00
|
|
|
// Strip off version from a build from an integration branch.
|
|
|
|
|
URL = URL.slice(0, URL.find("/src/tools/clang"));
|
2010-01-30 14:01:39 +00:00
|
|
|
|
2010-09-29 19:15:29 +00:00
|
|
|
// Trim path prefix off, assuming path came from standard cfe path.
|
|
|
|
|
size_t Start = URL.find("cfe/");
|
2011-07-23 10:55:15 +00:00
|
|
|
if (Start != StringRef::npos)
|
2010-09-29 19:15:29 +00:00
|
|
|
URL = URL.substr(Start + 4);
|
2010-01-30 14:01:39 +00:00
|
|
|
|
2010-09-29 19:15:29 +00:00
|
|
|
return URL;
|
2011-03-31 00:32:50 +00:00
|
|
|
#endif
|
2009-10-05 18:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-02 14:37:41 +00:00
|
|
|
std::string getLLVMRepositoryPath() {
|
|
|
|
|
#ifdef LLVM_REPOSITORY
|
|
|
|
|
StringRef URL(LLVM_REPOSITORY);
|
|
|
|
|
#else
|
|
|
|
|
StringRef URL("");
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Trim path prefix off, assuming path came from standard llvm path.
|
2012-03-07 00:44:24 +00:00
|
|
|
// Leave "llvm/" prefix to distinguish the following llvm revision from the
|
|
|
|
|
// clang revision.
|
2012-03-02 14:37:41 +00:00
|
|
|
size_t Start = URL.find("llvm/");
|
|
|
|
|
if (Start != StringRef::npos)
|
2012-03-07 00:44:24 +00:00
|
|
|
URL = URL.substr(Start);
|
2012-03-02 14:37:41 +00:00
|
|
|
|
|
|
|
|
return URL;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-29 19:15:29 +00:00
|
|
|
std::string getClangRevision() {
|
2019-01-31 06:21:01 +00:00
|
|
|
#ifdef CLANG_REVISION
|
|
|
|
|
return CLANG_REVISION;
|
2010-09-29 19:15:29 +00:00
|
|
|
#else
|
2010-03-03 01:02:48 +00:00
|
|
|
return "";
|
2010-09-29 19:15:29 +00:00
|
|
|
#endif
|
2009-10-05 18:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-02 14:37:41 +00:00
|
|
|
std::string getLLVMRevision() {
|
|
|
|
|
#ifdef LLVM_REVISION
|
|
|
|
|
return LLVM_REVISION;
|
|
|
|
|
#else
|
|
|
|
|
return "";
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-12 22:54:40 +00:00
|
|
|
std::string getClangFullRepositoryVersion() {
|
|
|
|
|
std::string buf;
|
|
|
|
|
llvm::raw_string_ostream OS(buf);
|
2010-09-29 19:15:29 +00:00
|
|
|
std::string Path = getClangRepositoryPath();
|
|
|
|
|
std::string Revision = getClangRevision();
|
2012-03-07 00:44:24 +00:00
|
|
|
if (!Path.empty() || !Revision.empty()) {
|
|
|
|
|
OS << '(';
|
2010-09-29 17:57:10 +00:00
|
|
|
if (!Path.empty())
|
2012-03-07 00:44:24 +00:00
|
|
|
OS << Path;
|
|
|
|
|
if (!Revision.empty()) {
|
|
|
|
|
if (!Path.empty())
|
|
|
|
|
OS << ' ';
|
|
|
|
|
OS << Revision;
|
|
|
|
|
}
|
|
|
|
|
OS << ')';
|
2014-01-14 10:25:26 +00:00
|
|
|
}
|
2012-03-02 14:37:41 +00:00
|
|
|
// Support LLVM in a separate repository.
|
|
|
|
|
std::string LLVMRev = getLLVMRevision();
|
|
|
|
|
if (!LLVMRev.empty() && LLVMRev != Revision) {
|
2014-01-14 10:25:26 +00:00
|
|
|
OS << " (";
|
2012-03-02 14:37:41 +00:00
|
|
|
std::string LLVMRepo = getLLVMRepositoryPath();
|
|
|
|
|
if (!LLVMRepo.empty())
|
2012-03-07 00:44:24 +00:00
|
|
|
OS << LLVMRepo << ' ';
|
|
|
|
|
OS << LLVMRev << ')';
|
2012-03-02 14:37:41 +00:00
|
|
|
}
|
2010-03-05 15:39:20 +00:00
|
|
|
return OS.str();
|
2010-01-22 22:29:50 +00:00
|
|
|
}
|
2012-03-02 14:37:41 +00:00
|
|
|
|
2010-02-12 22:54:40 +00:00
|
|
|
std::string getClangFullVersion() {
|
2014-01-07 16:27:35 +00:00
|
|
|
return getClangToolFullVersion("clang");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string getClangToolFullVersion(StringRef ToolName) {
|
2010-02-12 22:54:40 +00:00
|
|
|
std::string buf;
|
|
|
|
|
llvm::raw_string_ostream OS(buf);
|
2010-01-22 22:29:50 +00:00
|
|
|
#ifdef CLANG_VENDOR
|
2010-02-12 22:54:40 +00:00
|
|
|
OS << CLANG_VENDOR;
|
2010-01-22 22:29:50 +00:00
|
|
|
#endif
|
2014-01-07 16:27:35 +00:00
|
|
|
OS << ToolName << " version " CLANG_VERSION_STRING " "
|
2012-03-07 00:44:24 +00:00
|
|
|
<< getClangFullRepositoryVersion();
|
2010-10-07 15:00:30 +00:00
|
|
|
|
|
|
|
|
// If vendor supplied, include the base LLVM version as well.
|
|
|
|
|
#ifdef CLANG_VENDOR
|
2014-06-06 10:36:22 +00:00
|
|
|
OS << " (based on " << BACKEND_PACKAGE_STRING << ")";
|
2010-10-07 15:00:30 +00:00
|
|
|
#endif
|
|
|
|
|
|
2010-03-05 15:39:20 +00:00
|
|
|
return OS.str();
|
2010-01-22 22:12:47 +00:00
|
|
|
}
|
2010-02-12 22:54:40 +00:00
|
|
|
|
2011-03-31 00:53:51 +00:00
|
|
|
std::string getClangFullCPPVersion() {
|
|
|
|
|
// The version string we report in __VERSION__ is just a compacted version of
|
|
|
|
|
// the one we report on the command line.
|
|
|
|
|
std::string buf;
|
|
|
|
|
llvm::raw_string_ostream OS(buf);
|
|
|
|
|
#ifdef CLANG_VENDOR
|
|
|
|
|
OS << CLANG_VENDOR;
|
|
|
|
|
#endif
|
2012-05-26 19:39:52 +00:00
|
|
|
OS << "Clang " CLANG_VERSION_STRING " " << getClangFullRepositoryVersion();
|
2011-03-31 00:53:51 +00:00
|
|
|
return OS.str();
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-05 18:52:24 +00:00
|
|
|
} // end namespace clang
|