blob: f9d62f9dc7c1ee2070fe1bd7f7c3404d42f34c4e [file] [log] [blame]
Douglas Gregor7550a6c2009-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 Kremenek2377a0e2010-01-22 20:55:35 +000013
Ted Kremenek51b8bc92010-01-22 22:29:50 +000014#include "clang/Basic/Version.h"
Ted Kremenek18e066f2010-01-22 22:12:47 +000015#include "llvm/Support/raw_ostream.h"
Douglas Gregor7550a6c2009-10-05 18:52:24 +000016#include <cstring>
17#include <cstdlib>
Ted Kremenek2377a0e2010-01-22 20:55:35 +000018
Douglas Gregor7550a6c2009-10-05 18:52:24 +000019using namespace std;
20
21namespace clang {
22
Ted Kremenek2377a0e2010-01-22 20:55:35 +000023llvm::StringRef getClangRepositoryPath() {
Benjamin Kramera87bdb72010-01-30 14:01:39 +000024 static const char URL[] = "$URL$";
25 const char *URLEnd = URL + strlen(URL);
26
27 const char *End = strstr(URL, "/lib/Basic");
Douglas Gregor7550a6c2009-10-05 18:52:24 +000028 if (End)
Benjamin Kramera87bdb72010-01-30 14:01:39 +000029 URLEnd = End;
30
Douglas Gregor4c25ce72009-11-05 23:46:05 +000031 End = strstr(URL, "/clang/tools/clang");
32 if (End)
Benjamin Kramera87bdb72010-01-30 14:01:39 +000033 URLEnd = End;
34
35 const char *Begin = strstr(URL, "cfe/");
36 if (Begin)
37 return llvm::StringRef(Begin + 4, URLEnd - Begin - 4);
38
39 return llvm::StringRef(URL, URLEnd - URL);
Douglas Gregor7550a6c2009-10-05 18:52:24 +000040}
41
42
Ted Kremenek18e066f2010-01-22 22:12:47 +000043llvm::StringRef getClangRevision() {
Douglas Gregor7550a6c2009-10-05 18:52:24 +000044#ifndef SVN_REVISION
Douglas Gregor1b7035d2009-10-05 20:33:49 +000045 // Subversion was not available at build time?
Ted Kremenek18e066f2010-01-22 22:12:47 +000046 return llvm::StringRef();
Douglas Gregor7550a6c2009-10-05 18:52:24 +000047#else
Ted Kremenek18e066f2010-01-22 22:12:47 +000048 static std::string revision;
49 if (revision.empty()) {
Ted Kremenek51b8bc92010-01-22 22:29:50 +000050 llvm::raw_string_ostream OS(revision);
51 OS << strtol(SVN_REVISION, 0, 10);
Ted Kremenek18e066f2010-01-22 22:12:47 +000052 }
53 return revision;
Douglas Gregor7550a6c2009-10-05 18:52:24 +000054#endif
55}
56
Ted Kremenek18e066f2010-01-22 22:12:47 +000057llvm::StringRef getClangFullRepositoryVersion() {
58 static std::string buf;
59 if (buf.empty()) {
Ted Kremenek51b8bc92010-01-22 22:29:50 +000060 llvm::raw_string_ostream OS(buf);
61 OS << getClangRepositoryPath();
Ted Kremenek18e066f2010-01-22 22:12:47 +000062 llvm::StringRef Revision = getClangRevision();
63 if (!Revision.empty())
Ted Kremenek51b8bc92010-01-22 22:29:50 +000064 OS << ' ' << Revision;
65 }
66 return buf;
67}
68
Ted Kremenek4c0df3d2010-01-23 02:11:34 +000069const char *getClangFullVersion() {
Ted Kremenek51b8bc92010-01-22 22:29:50 +000070 static std::string buf;
71 if (buf.empty()) {
72 llvm::raw_string_ostream OS(buf);
73#ifdef CLANG_VENDOR
74 OS << CLANG_VENDOR;
75#endif
76 OS << "clang version " CLANG_VERSION_STRING " ("
77 << getClangFullRepositoryVersion() << ')';
Ted Kremenek18e066f2010-01-22 22:12:47 +000078 }
Ted Kremenekc0f3f722010-01-22 22:44:15 +000079 return buf.c_str();
Ted Kremenek18e066f2010-01-22 22:12:47 +000080}
81
Douglas Gregor7550a6c2009-10-05 18:52:24 +000082} // end namespace clang