blob: 67c6c36c92146c5b8304897dc079d896f56c4324 [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
31 // Strip off version from a build from an integration branch.
32 URL = URL.slice(0, URL.find("/src/tools/clang"));
33
34 // Trim path prefix off, assuming path came from standard cfe path.
35 size_t Start = URL.find("cfe/");
36 if (Start != llvm::StringRef::npos)
37 URL = URL.substr(Start + 4);
38
39 return URL;
Douglas Gregor7550a6c2009-10-05 18:52:24 +000040}
41
Daniel Dunbar181ca582010-09-29 19:15:29 +000042std::string getClangRevision() {
Ted Kremenek47307292010-03-03 01:02:48 +000043#ifdef SVN_REVISION
Daniel Dunbar181ca582010-09-29 19:15:29 +000044 return SVN_REVISION;
45#else
Ted Kremenek47307292010-03-03 01:02:48 +000046 return "";
Daniel Dunbar181ca582010-09-29 19:15:29 +000047#endif
Douglas Gregor7550a6c2009-10-05 18:52:24 +000048}
49
Ted Kremeneka3e65702010-02-12 22:54:40 +000050std::string getClangFullRepositoryVersion() {
51 std::string buf;
52 llvm::raw_string_ostream OS(buf);
Daniel Dunbar181ca582010-09-29 19:15:29 +000053 std::string Path = getClangRepositoryPath();
54 std::string Revision = getClangRevision();
Daniel Dunbarb800fdb2010-09-29 17:57:10 +000055 if (!Path.empty())
56 OS << Path;
57 if (!Revision.empty()) {
58 if (!Path.empty())
59 OS << ' ';
60 OS << Revision;
61 }
Benjamin Kramerd48707002010-03-05 15:39:20 +000062 return OS.str();
Ted Kremenek51b8bc92010-01-22 22:29:50 +000063}
64
Ted Kremeneka3e65702010-02-12 22:54:40 +000065std::string getClangFullVersion() {
66 std::string buf;
67 llvm::raw_string_ostream OS(buf);
Ted Kremenek51b8bc92010-01-22 22:29:50 +000068#ifdef CLANG_VENDOR
Ted Kremeneka3e65702010-02-12 22:54:40 +000069 OS << CLANG_VENDOR;
Ted Kremenek51b8bc92010-01-22 22:29:50 +000070#endif
Ted Kremeneka3e65702010-02-12 22:54:40 +000071 OS << "clang version " CLANG_VERSION_STRING " ("
72 << getClangFullRepositoryVersion() << ')';
Daniel Dunbar60362642010-10-07 15:00:30 +000073
74 // If vendor supplied, include the base LLVM version as well.
75#ifdef CLANG_VENDOR
76 OS << " (based on LLVM " << PACKAGE_VERSION << ")";
77#endif
78
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