Version.cpp revision 202879
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
19using namespace std;
20
21namespace clang {
22
23llvm::StringRef getClangRepositoryPath() {
24  static const char *Path = 0;
25  if (Path)
26    return Path;
27
28  static char URL[] = "$URL: http://llvm.org/svn/llvm-project/cfe/trunk/lib/Basic/Version.cpp $";
29  char *End = strstr(URL, "/lib/Basic");
30  if (End)
31    *End = 0;
32
33  End = strstr(URL, "/clang/tools/clang");
34  if (End)
35    *End = 0;
36
37  char *Begin = strstr(URL, "cfe/");
38  if (Begin) {
39    Path = Begin + 4;
40    return Path;
41  }
42
43  Path = URL;
44  return Path;
45}
46
47
48llvm::StringRef getClangRevision() {
49#ifndef SVN_REVISION
50  // Subversion was not available at build time?
51  return llvm::StringRef();
52#else
53  static std::string revision;
54  if (revision.empty()) {
55    llvm::raw_string_ostream OS(revision);
56    OS << strtol(SVN_REVISION, 0, 10);
57  }
58  return revision;
59#endif
60}
61
62llvm::StringRef getClangFullRepositoryVersion() {
63  static std::string buf;
64  if (buf.empty()) {
65    llvm::raw_string_ostream OS(buf);
66    OS << getClangRepositoryPath();
67    llvm::StringRef Revision = getClangRevision();
68    if (!Revision.empty())
69      OS << ' ' << Revision;
70  }
71  return buf;
72}
73
74const char *getClangFullVersion() {
75  static std::string buf;
76  if (buf.empty()) {
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  return buf.c_str();
85}
86
87} // end namespace clang
88