]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/tools/clang/lib/Basic/Version.cpp
Copy head to stable/9 as part of 9.0-RELEASE release cycle.
[FreeBSD/stable/9.git] / contrib / llvm / tools / clang / lib / Basic / Version.cpp
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.
11 //
12 //===----------------------------------------------------------------------===//
13
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>
19
20 namespace clang {
21   
22 std::string getClangRepositoryPath() {
23 #if defined(CLANG_REPOSITORY_STRING)
24   return CLANG_REPOSITORY_STRING;
25 #else
26 #ifdef SVN_REPOSITORY
27   llvm::StringRef URL(SVN_REPOSITORY);
28 #else
29   llvm::StringRef URL("");
30 #endif
31
32   // If the SVN_REPOSITORY is empty, try to use the SVN keyword. This helps us
33   // pick up a tag in an SVN export, for example.
34   static llvm::StringRef SVNRepository("$URL: http://llvm.org/svn/llvm-project/cfe/trunk/lib/Basic/Version.cpp $");
35   if (URL.empty()) {
36     URL = SVNRepository.slice(SVNRepository.find(':'),
37                               SVNRepository.find("/lib/Basic"));
38   }
39
40   // Strip off version from a build from an integration branch.
41   URL = URL.slice(0, URL.find("/src/tools/clang"));
42
43   // Trim path prefix off, assuming path came from standard cfe path.
44   size_t Start = URL.find("cfe/");
45   if (Start != llvm::StringRef::npos)
46     URL = URL.substr(Start + 4);
47
48   return URL;
49 #endif
50 }
51
52 std::string getClangRevision() {
53 #ifdef SVN_REVISION
54   return SVN_REVISION;
55 #else
56   return "";
57 #endif
58 }
59
60 std::string getClangFullRepositoryVersion() {
61   std::string buf;
62   llvm::raw_string_ostream OS(buf);
63   std::string Path = getClangRepositoryPath();
64   std::string Revision = getClangRevision();
65   if (!Path.empty())
66     OS << Path;
67   if (!Revision.empty()) {
68     if (!Path.empty())
69       OS << ' ';
70     OS << Revision;
71   }
72   return OS.str();
73 }
74   
75 std::string getClangFullVersion() {
76   std::string buf;
77   llvm::raw_string_ostream OS(buf);
78 #ifdef CLANG_VENDOR
79   OS << CLANG_VENDOR;
80 #endif
81   OS << "clang version " CLANG_VERSION_STRING " ("
82      << getClangFullRepositoryVersion() << ')';
83
84 #ifdef CLANG_VENDOR_SUFFIX
85   OS << CLANG_VENDOR_SUFFIX;
86 #elif defined(CLANG_VENDOR)
87   // If vendor supplied, include the base LLVM version as well.
88   OS << " (based on LLVM " << PACKAGE_VERSION << ")";
89 #endif
90
91   return OS.str();
92 }
93
94 std::string getClangFullCPPVersion() {
95   // The version string we report in __VERSION__ is just a compacted version of
96   // the one we report on the command line.
97   std::string buf;
98   llvm::raw_string_ostream OS(buf);
99 #ifdef CLANG_VENDOR
100   OS << CLANG_VENDOR;
101 #endif
102   OS << "Clang " CLANG_VERSION_STRING " ("
103      << getClangFullRepositoryVersion() << ')';
104   return OS.str();
105 }
106
107 } // end namespace clang