blob: 900b3e3859bc7fbca85541166d77f9bd612527ba [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
Daniel Dunbar16a8fb72010-09-29 19:15:29 +000023std::string getClangRepositoryPath() {
Daniel Dunbar640cf372010-09-29 17:57:10 +000024#ifdef SVN_REPOSITORY
Daniel Dunbar16a8fb72010-09-29 19:15:29 +000025 llvm::StringRef URL(SVN_REPOSITORY);
26#else
27 llvm::StringRef URL("");
Daniel Dunbar640cf372010-09-29 17:57:10 +000028#endif
Daniel Dunbar16a8fb72010-09-29 19:15:29 +000029
30 // Strip off version from a build from an integration branch.
31 URL = URL.slice(0, URL.find("/src/tools/clang"));
32
33 // Trim path prefix off, assuming path came from standard cfe path.
34 size_t Start = URL.find("cfe/");
35 if (Start != llvm::StringRef::npos)
36 URL = URL.substr(Start + 4);
37
38 return URL;
Douglas Gregor60b5d8e2009-10-05 18:52:24 +000039}
40
Daniel Dunbar16a8fb72010-09-29 19:15:29 +000041std::string getClangRevision() {
Ted Kremenek971cc482010-03-03 01:02:48 +000042#ifdef SVN_REVISION
Daniel Dunbar16a8fb72010-09-29 19:15:29 +000043 return SVN_REVISION;
44#else
Ted Kremenek971cc482010-03-03 01:02:48 +000045 return "";
Daniel Dunbar16a8fb72010-09-29 19:15:29 +000046#endif
Douglas Gregor60b5d8e2009-10-05 18:52:24 +000047}
48
Ted Kremeneka2a9d6e2010-02-12 22:54:40 +000049std::string getClangFullRepositoryVersion() {
50 std::string buf;
51 llvm::raw_string_ostream OS(buf);
Daniel Dunbar16a8fb72010-09-29 19:15:29 +000052 std::string Path = getClangRepositoryPath();
53 std::string Revision = getClangRevision();
Daniel Dunbar640cf372010-09-29 17:57:10 +000054 if (!Path.empty())
55 OS << Path;
56 if (!Revision.empty()) {
57 if (!Path.empty())
58 OS << ' ';
59 OS << Revision;
60 }
Benjamin Kramer940f6462010-03-05 15:39:20 +000061 return OS.str();
Ted Kremenek3687a5d2010-01-22 22:29:50 +000062}
63
Ted Kremeneka2a9d6e2010-02-12 22:54:40 +000064std::string getClangFullVersion() {
65 std::string buf;
66 llvm::raw_string_ostream OS(buf);
Ted Kremenek3687a5d2010-01-22 22:29:50 +000067#ifdef CLANG_VENDOR
Ted Kremeneka2a9d6e2010-02-12 22:54:40 +000068 OS << CLANG_VENDOR;
Ted Kremenek3687a5d2010-01-22 22:29:50 +000069#endif
Ted Kremeneka2a9d6e2010-02-12 22:54:40 +000070 OS << "clang version " CLANG_VERSION_STRING " ("
71 << getClangFullRepositoryVersion() << ')';
Benjamin Kramer940f6462010-03-05 15:39:20 +000072 return OS.str();
Ted Kremenekf7a96a32010-01-22 22:12:47 +000073}
Ted Kremeneka2a9d6e2010-02-12 22:54:40 +000074
Douglas Gregor60b5d8e2009-10-05 18:52:24 +000075} // end namespace clang