blob: e9649e284d0739c624835ab25535668890d8d1aa [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() {
Daniel Dunbarb800fdb2010-09-29 17:57:10 +000024#ifdef SVN_REPOSITORY
25 if (SVN_REPOSITORY[0] != '\0') {
26 static const char URL[] = SVN_REPOSITORY;
27 const char *URLEnd = URL + strlen(URL) - 1;
Benjamin Kramera87bdb72010-01-30 14:01:39 +000028
Daniel Dunbarb800fdb2010-09-29 17:57:10 +000029 // Strip off version from a build from an integration branch.
30 const char *End = strstr(URL, "/src/tools/clang");
31 if (End)
32 URLEnd = End;
Benjamin Kramera87bdb72010-01-30 14:01:39 +000033
Daniel Dunbarb800fdb2010-09-29 17:57:10 +000034 const char *Begin = strstr(URL, "cfe/");
35 if (Begin)
36 return llvm::StringRef(Begin + 4, URLEnd - Begin - 4);
Benjamin Kramera87bdb72010-01-30 14:01:39 +000037
Daniel Dunbarb800fdb2010-09-29 17:57:10 +000038 return llvm::StringRef(URL, URLEnd - URL);
39 }
40#endif
41 return "";
Douglas Gregor7550a6c2009-10-05 18:52:24 +000042}
43
Daniel Dunbarb800fdb2010-09-29 17:57:10 +000044llvm::StringRef getClangRevision() {
Ted Kremenek47307292010-03-03 01:02:48 +000045#ifdef SVN_REVISION
Ted Kremenekc9ef64f2010-03-03 01:30:39 +000046 if (SVN_REVISION[0] != '\0') {
Ted Kremenek47307292010-03-03 01:02:48 +000047 std::string revision;
48 llvm::raw_string_ostream OS(revision);
49 OS << strtol(SVN_REVISION, 0, 10);
Benjamin Kramerd48707002010-03-05 15:39:20 +000050 return OS.str();
Ted Kremenek47307292010-03-03 01:02:48 +000051 }
Douglas Gregor7550a6c2009-10-05 18:52:24 +000052#endif
Ted Kremenek47307292010-03-03 01:02:48 +000053 return "";
Douglas Gregor7550a6c2009-10-05 18:52:24 +000054}
55
Ted Kremeneka3e65702010-02-12 22:54:40 +000056std::string getClangFullRepositoryVersion() {
57 std::string buf;
58 llvm::raw_string_ostream OS(buf);
Daniel Dunbarb800fdb2010-09-29 17:57:10 +000059 const llvm::StringRef &Path = getClangRepositoryPath();
60 const llvm::StringRef &Revision = getClangRevision();
61 if (!Path.empty())
62 OS << Path;
63 if (!Revision.empty()) {
64 if (!Path.empty())
65 OS << ' ';
66 OS << Revision;
67 }
Benjamin Kramerd48707002010-03-05 15:39:20 +000068 return OS.str();
Ted Kremenek51b8bc92010-01-22 22:29:50 +000069}
70
Ted Kremeneka3e65702010-02-12 22:54:40 +000071std::string getClangFullVersion() {
72 std::string buf;
73 llvm::raw_string_ostream OS(buf);
Ted Kremenek51b8bc92010-01-22 22:29:50 +000074#ifdef CLANG_VENDOR
Ted Kremeneka3e65702010-02-12 22:54:40 +000075 OS << CLANG_VENDOR;
Ted Kremenek51b8bc92010-01-22 22:29:50 +000076#endif
Ted Kremeneka3e65702010-02-12 22:54:40 +000077 OS << "clang version " CLANG_VERSION_STRING " ("
78 << getClangFullRepositoryVersion() << ')';
Benjamin Kramerd48707002010-03-05 15:39:20 +000079 return OS.str();
Ted Kremenek18e066f2010-01-22 22:12:47 +000080}
Ted Kremeneka3e65702010-02-12 22:54:40 +000081
Douglas Gregor7550a6c2009-10-05 18:52:24 +000082} // end namespace clang