1 //===- Version.cpp - Clang Version Number -----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines several version-related utility functions for Clang.
12 //===----------------------------------------------------------------------===//
14 #include "clang/Basic/Version.h"
15 #include "llvm/Support/raw_ostream.h"
16 #include "llvm/Config/config.h"
24 std::string
getClangRepositoryPath() {
26 llvm::StringRef
URL(SVN_REPOSITORY
);
28 llvm::StringRef
URL("");
31 // 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$");
35 URL
= SVNRepository
.slice(SVNRepository
.find(':'),
36 SVNRepository
.find("/lib/Basic"));
39 // Strip off version from a build from an integration branch.
40 URL
= URL
.slice(0, URL
.find("/src/tools/clang"));
42 // Trim path prefix off, assuming path came from standard cfe path.
43 size_t Start
= URL
.find("cfe/");
44 if (Start
!= llvm::StringRef::npos
)
45 URL
= URL
.substr(Start
+ 4);
50 std::string
getClangRevision() {
58 std::string
getClangFullRepositoryVersion() {
60 llvm::raw_string_ostream
OS(buf
);
61 std::string Path
= getClangRepositoryPath();
62 std::string Revision
= getClangRevision();
65 if (!Revision
.empty()) {
73 std::string
getClangFullVersion() {
75 llvm::raw_string_ostream
OS(buf
);
79 OS
<< "clang version " CLANG_VERSION_STRING
" ("
80 << getClangFullRepositoryVersion() << ')';
82 // If vendor supplied, include the base LLVM version as well.
84 OS
<< " (based on LLVM " << PACKAGE_VERSION
<< ")";
90 } // end namespace clang