[Heikki Kultala] This patch contains the ABI changes for the TCE target.
[clang.git] / lib / Basic / Version.cpp
blob9367319c5f453afa383f2930ca471d579ba66f68
1 //===- Version.cpp - Clang Version Number -----------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines several version-related utility functions for Clang.
12 //===----------------------------------------------------------------------===//
14 #include "clang/Basic/Version.h"
15 #include "llvm/Support/raw_ostream.h"
16 #include "llvm/Config/config.h"
17 #include <cstring>
18 #include <cstdlib>
20 using namespace std;
22 namespace clang {
24 std::string getClangRepositoryPath() {
25 #ifdef SVN_REPOSITORY
26 llvm::StringRef URL(SVN_REPOSITORY);
27 #else
28 llvm::StringRef URL("");
29 #endif
31 // If the SVN_REPOSITORY is empty, try to use the SVN keyword. This helps us
32 // pick up a tag in an SVN export, for example.
33 static llvm::StringRef SVNRepository("$URL$");
34 if (URL.empty()) {
35 URL = SVNRepository.slice(SVNRepository.find(':'),
36 SVNRepository.find("/lib/Basic"));
39 // Strip off version from a build from an integration branch.
40 URL = URL.slice(0, URL.find("/src/tools/clang"));
42 // Trim path prefix off, assuming path came from standard cfe path.
43 size_t Start = URL.find("cfe/");
44 if (Start != llvm::StringRef::npos)
45 URL = URL.substr(Start + 4);
47 return URL;
50 std::string getClangRevision() {
51 #ifdef SVN_REVISION
52 return SVN_REVISION;
53 #else
54 return "";
55 #endif
58 std::string getClangFullRepositoryVersion() {
59 std::string buf;
60 llvm::raw_string_ostream OS(buf);
61 std::string Path = getClangRepositoryPath();
62 std::string Revision = getClangRevision();
63 if (!Path.empty())
64 OS << Path;
65 if (!Revision.empty()) {
66 if (!Path.empty())
67 OS << ' ';
68 OS << Revision;
70 return OS.str();
73 std::string getClangFullVersion() {
74 std::string buf;
75 llvm::raw_string_ostream OS(buf);
76 #ifdef CLANG_VENDOR
77 OS << CLANG_VENDOR;
78 #endif
79 OS << "clang version " CLANG_VERSION_STRING " ("
80 << getClangFullRepositoryVersion() << ')';
82 // If vendor supplied, include the base LLVM version as well.
83 #ifdef CLANG_VENDOR
84 OS << " (based on LLVM " << PACKAGE_VERSION << ")";
85 #endif
87 return OS.str();
90 } // end namespace clang