2009-10-06 02:52:24 +08:00
|
|
|
//===- Version.cpp - Clang Version Number -----------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// 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"
|
2011-12-27 06:43:17 +08:00
|
|
|
#include "llvm/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
|
|
|
|
2013-03-26 07:16:38 +08:00
|
|
|
#ifdef HAVE_SVN_VERSION_INC
|
|
|
|
# include "SVNVersion.inc"
|
|
|
|
#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
|
2010-09-30 01:57:10 +08:00
|
|
|
#ifdef SVN_REPOSITORY
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef URL(SVN_REPOSITORY);
|
2010-09-30 03:15:29 +08:00
|
|
|
#else
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef URL("");
|
2010-09-30 03:15:29 +08:00
|
|
|
#endif
|
2010-01-30 22:01:39 +08:00
|
|
|
|
2010-10-12 07:44:19 +08:00
|
|
|
// If the SVN_REPOSITORY is empty, try to use the SVN keyword. This helps us
|
|
|
|
// pick up a tag in an SVN export, for example.
|
2013-08-10 01:51:03 +08:00
|
|
|
StringRef SVNRepository("$URL$");
|
2010-10-12 07:50:34 +08:00
|
|
|
if (URL.empty()) {
|
|
|
|
URL = SVNRepository.slice(SVNRepository.find(':'),
|
|
|
|
SVNRepository.find("/lib/Basic"));
|
|
|
|
}
|
2010-10-12 07:44:19 +08:00
|
|
|
|
2010-09-30 03:15:29 +08:00
|
|
|
// Strip off version from a build from an integration branch.
|
|
|
|
URL = URL.slice(0, URL.find("/src/tools/clang"));
|
2010-01-30 22:01:39 +08:00
|
|
|
|
2010-09-30 03:15:29 +08:00
|
|
|
// Trim path prefix off, assuming path came from standard cfe path.
|
|
|
|
size_t Start = URL.find("cfe/");
|
2011-07-23 18:55:15 +08:00
|
|
|
if (Start != StringRef::npos)
|
2010-09-30 03:15:29 +08:00
|
|
|
URL = URL.substr(Start + 4);
|
2010-01-30 22:01:39 +08:00
|
|
|
|
2010-09-30 03:15:29 +08:00
|
|
|
return URL;
|
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
|
|
|
|
StringRef URL(LLVM_REPOSITORY);
|
|
|
|
#else
|
|
|
|
StringRef URL("");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Trim path prefix off, assuming path came from standard llvm path.
|
2012-03-07 08:44:24 +08:00
|
|
|
// Leave "llvm/" prefix to distinguish the following llvm revision from the
|
|
|
|
// clang revision.
|
2012-03-02 22:37:41 +08:00
|
|
|
size_t Start = URL.find("llvm/");
|
|
|
|
if (Start != StringRef::npos)
|
2012-03-07 08:44:24 +08:00
|
|
|
URL = URL.substr(Start);
|
2012-03-02 22:37:41 +08:00
|
|
|
|
|
|
|
return URL;
|
|
|
|
}
|
|
|
|
|
2010-09-30 03:15:29 +08:00
|
|
|
std::string getClangRevision() {
|
2010-03-03 09:02:48 +08:00
|
|
|
#ifdef SVN_REVISION
|
2010-09-30 03:15:29 +08:00
|
|
|
return SVN_REVISION;
|
|
|
|
#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 << ')';
|
|
|
|
}
|
2012-03-02 22:37:41 +08:00
|
|
|
// Support LLVM in a separate repository.
|
|
|
|
std::string LLVMRev = getLLVMRevision();
|
|
|
|
if (!LLVMRev.empty() && LLVMRev != Revision) {
|
2012-03-07 08:44:24 +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() {
|
|
|
|
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
|
2012-03-07 08:44:24 +08:00
|
|
|
OS << "clang version " CLANG_VERSION_STRING " "
|
|
|
|
<< getClangFullRepositoryVersion();
|
2010-10-07 23:00:30 +08:00
|
|
|
|
|
|
|
// If vendor supplied, include the base LLVM version as well.
|
|
|
|
#ifdef CLANG_VENDOR
|
|
|
|
OS << " (based on LLVM " << PACKAGE_VERSION << ")";
|
|
|
|
#endif
|
|
|
|
|
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() {
|
|
|
|
// 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-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
|