blob: 0521ab48891a669191d6359df5799a1470e2fe5b [file] [log] [blame]
Douglas Gregor60b5d8e2009-10-05 18:52:24 +00001//===- 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//===----------------------------------------------------------------------===//
Ted Kremenek517e6762010-01-22 20:55:35 +000013
Ted Kremenek3687a5d2010-01-22 22:29:50 +000014#include "clang/Basic/Version.h"
Ted Kremenekf7a96a32010-01-22 22:12:47 +000015#include "llvm/Support/raw_ostream.h"
Douglas Gregor60b5d8e2009-10-05 18:52:24 +000016#include <cstring>
17#include <cstdlib>
Ted Kremenek517e6762010-01-22 20:55:35 +000018
Douglas Gregor60b5d8e2009-10-05 18:52:24 +000019using namespace std;
20
21namespace clang {
22
Ted Kremenek517e6762010-01-22 20:55:35 +000023llvm::StringRef getClangRepositoryPath() {
Douglas Gregor60b5d8e2009-10-05 18:52:24 +000024 static const char *Path = 0;
25 if (Path)
26 return Path;
27
28 static char URL[] = "$URL$";
29 char *End = strstr(URL, "/lib/Basic");
30 if (End)
31 *End = 0;
32
Douglas Gregor1fbf1f02009-11-05 23:46:05 +000033 End = strstr(URL, "/clang/tools/clang");
34 if (End)
35 *End = 0;
36
Douglas Gregor60b5d8e2009-10-05 18:52:24 +000037 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
Ted Kremenekf7a96a32010-01-22 22:12:47 +000048llvm::StringRef getClangRevision() {
Douglas Gregor60b5d8e2009-10-05 18:52:24 +000049#ifndef SVN_REVISION
Douglas Gregorb8d11912009-10-05 20:33:49 +000050 // Subversion was not available at build time?
Ted Kremenekf7a96a32010-01-22 22:12:47 +000051 return llvm::StringRef();
Douglas Gregor60b5d8e2009-10-05 18:52:24 +000052#else
Ted Kremenekf7a96a32010-01-22 22:12:47 +000053 static std::string revision;
54 if (revision.empty()) {
Ted Kremenek3687a5d2010-01-22 22:29:50 +000055 llvm::raw_string_ostream OS(revision);
56 OS << strtol(SVN_REVISION, 0, 10);
Ted Kremenekf7a96a32010-01-22 22:12:47 +000057 }
58 return revision;
Douglas Gregor60b5d8e2009-10-05 18:52:24 +000059#endif
60}
61
Ted Kremenekf7a96a32010-01-22 22:12:47 +000062llvm::StringRef getClangFullRepositoryVersion() {
63 static std::string buf;
64 if (buf.empty()) {
Ted Kremenek3687a5d2010-01-22 22:29:50 +000065 llvm::raw_string_ostream OS(buf);
66 OS << getClangRepositoryPath();
Ted Kremenekf7a96a32010-01-22 22:12:47 +000067 llvm::StringRef Revision = getClangRevision();
68 if (!Revision.empty())
Ted Kremenek3687a5d2010-01-22 22:29:50 +000069 OS << ' ' << Revision;
70 }
71 return buf;
72}
73
Ted Kremenek04bb7162010-01-22 22:44:15 +000074const char *getClangFullVendorVersion() {
Ted Kremenek3687a5d2010-01-22 22:29:50 +000075 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() << ')';
Ted Kremenekf7a96a32010-01-22 22:12:47 +000083 }
Ted Kremenek04bb7162010-01-22 22:44:15 +000084 return buf.c_str();
Ted Kremenekf7a96a32010-01-22 22:12:47 +000085}
86
Douglas Gregor60b5d8e2009-10-05 18:52:24 +000087} // end namespace clang