blob: 545ef53e6d858aebf7fa5e70f97311b635c4b21c [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"
Daniel Dunbar60362642010-10-07 15:00:30 +000016#include "llvm/Config/config.h"
Douglas Gregor7550a6c2009-10-05 18:52:24 +000017#include <cstring>
18#include <cstdlib>
Ted Kremenek2377a0e2010-01-22 20:55:35 +000019
Douglas Gregor7550a6c2009-10-05 18:52:24 +000020using namespace std;
21
22namespace clang {
23
Daniel Dunbar181ca582010-09-29 19:15:29 +000024std::string getClangRepositoryPath() {
Daniel Dunbarb800fdb2010-09-29 17:57:10 +000025#ifdef SVN_REPOSITORY
Daniel Dunbar181ca582010-09-29 19:15:29 +000026 llvm::StringRef URL(SVN_REPOSITORY);
27#else
28 llvm::StringRef URL("");
Daniel Dunbarb800fdb2010-09-29 17:57:10 +000029#endif
Daniel Dunbar181ca582010-09-29 19:15:29 +000030
Daniel Dunbard097d912010-10-11 23:44:19 +000031 // If the SVN_REPOSITORY is empty, try to use the SVN keyword. This helps us
32 // pick up a tag in an SVN export, for example.
33 static llvm::StringRef SVNRepository("$URL$");
34 if (URL.empty())
35 URL = SVNRepository.split(':').second;
36
Daniel Dunbar181ca582010-09-29 19:15:29 +000037 // Strip off version from a build from an integration branch.
38 URL = URL.slice(0, URL.find("/src/tools/clang"));
39
40 // Trim path prefix off, assuming path came from standard cfe path.
41 size_t Start = URL.find("cfe/");
42 if (Start != llvm::StringRef::npos)
43 URL = URL.substr(Start + 4);
44
45 return URL;
Douglas Gregor7550a6c2009-10-05 18:52:24 +000046}
47
Daniel Dunbar181ca582010-09-29 19:15:29 +000048std::string getClangRevision() {
Ted Kremenek47307292010-03-03 01:02:48 +000049#ifdef SVN_REVISION
Daniel Dunbar181ca582010-09-29 19:15:29 +000050 return SVN_REVISION;
51#else
Ted Kremenek47307292010-03-03 01:02:48 +000052 return "";
Daniel Dunbar181ca582010-09-29 19:15:29 +000053#endif
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 Dunbar181ca582010-09-29 19:15:29 +000059 std::string Path = getClangRepositoryPath();
60 std::string Revision = getClangRevision();
Daniel Dunbarb800fdb2010-09-29 17:57:10 +000061 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() << ')';
Daniel Dunbar60362642010-10-07 15:00:30 +000079
80 // If vendor supplied, include the base LLVM version as well.
81#ifdef CLANG_VENDOR
82 OS << " (based on LLVM " << PACKAGE_VERSION << ")";
83#endif
84
Benjamin Kramerd48707002010-03-05 15:39:20 +000085 return OS.str();
Ted Kremenek18e066f2010-01-22 22:12:47 +000086}
Ted Kremeneka3e65702010-02-12 22:54:40 +000087
Douglas Gregor7550a6c2009-10-05 18:52:24 +000088} // end namespace clang