]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/lib/Basic/Version.cpp
Upgrade to OpenSSH 5.6p1.
[FreeBSD/FreeBSD.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 <cstring>
17 #include <cstdlib>
18
19 using namespace std;
20
21 namespace clang {
22   
23 llvm::StringRef getClangRepositoryPath() {
24   static const char URL[] = "$URL: http://llvm.org/svn/llvm-project/cfe/tags/RELEASE_28/lib/Basic/Version.cpp $";
25   const char *URLEnd = URL + strlen(URL);
26
27   const char *End = strstr(URL, "/lib/Basic");
28   if (End)
29     URLEnd = End;
30
31   // Strip off version from a build from an integration branch.
32   End = strstr(URL, "/src/tools/clang");
33   if (End)
34     URLEnd = End;
35
36   const char *Begin = strstr(URL, "cfe/");
37   if (Begin)
38     return llvm::StringRef(Begin + 4, URLEnd - Begin - 4);
39
40   return llvm::StringRef(URL, URLEnd - URL);
41 }
42
43 std::string getClangRevision() {
44 #ifdef SVN_REVISION
45   if (SVN_REVISION[0] != '\0') {
46     std::string revision;
47     llvm::raw_string_ostream OS(revision);
48     OS << strtol(SVN_REVISION, 0, 10);
49     return OS.str();
50   }
51 #endif
52   return "";
53 }
54
55 std::string getClangFullRepositoryVersion() {
56   std::string buf;
57   llvm::raw_string_ostream OS(buf);
58   OS << getClangRepositoryPath();
59   const std::string &Revision = getClangRevision();
60   if (!Revision.empty())
61     OS << ' ' << Revision;
62   return OS.str();
63 }
64   
65 std::string getClangFullVersion() {
66   std::string buf;
67   llvm::raw_string_ostream OS(buf);
68 #ifdef CLANG_VENDOR
69   OS << CLANG_VENDOR;
70 #endif
71   OS << "clang version " CLANG_VERSION_STRING " ("
72      << getClangFullRepositoryVersion() << ')';
73 #ifdef CLANG_VENDOR_SUFFIX
74   OS << CLANG_VENDOR_SUFFIX;
75 #endif
76   return OS.str();
77 }
78
79 } // end namespace clang