diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Basic/Version.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/Basic/Version.cpp | 61 |
1 files changed, 37 insertions, 24 deletions
diff --git a/contrib/llvm/tools/clang/lib/Basic/Version.cpp b/contrib/llvm/tools/clang/lib/Basic/Version.cpp index 986f4d5..3a82e5d 100644 --- a/contrib/llvm/tools/clang/lib/Basic/Version.cpp +++ b/contrib/llvm/tools/clang/lib/Basic/Version.cpp @@ -13,6 +13,7 @@ #include "clang/Basic/Version.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Config/config.h" #include <cstring> #include <cstdlib> @@ -20,45 +21,52 @@ using namespace std; namespace clang { -llvm::StringRef getClangRepositoryPath() { - static const char URL[] = "$URL: http://llvm.org/svn/llvm-project/cfe/tags/RELEASE_28/lib/Basic/Version.cpp $"; - const char *URLEnd = URL + strlen(URL); +std::string getClangRepositoryPath() { +#ifdef SVN_REPOSITORY + llvm::StringRef URL(SVN_REPOSITORY); +#else + llvm::StringRef URL(""); +#endif - const char *End = strstr(URL, "/lib/Basic"); - if (End) - URLEnd = End; + // If the SVN_REPOSITORY is empty, try to use the SVN keyword. This helps us + // pick up a tag in an SVN export, for example. + static llvm::StringRef SVNRepository("$URL: http://llvm.org/svn/llvm-project/cfe/trunk/lib/Basic/Version.cpp $"); + if (URL.empty()) { + URL = SVNRepository.slice(SVNRepository.find(':'), + SVNRepository.find("/lib/Basic")); + } // Strip off version from a build from an integration branch. - End = strstr(URL, "/src/tools/clang"); - if (End) - URLEnd = End; + URL = URL.slice(0, URL.find("/src/tools/clang")); - const char *Begin = strstr(URL, "cfe/"); - if (Begin) - return llvm::StringRef(Begin + 4, URLEnd - Begin - 4); + // Trim path prefix off, assuming path came from standard cfe path. + size_t Start = URL.find("cfe/"); + if (Start != llvm::StringRef::npos) + URL = URL.substr(Start + 4); - return llvm::StringRef(URL, URLEnd - URL); + return URL; } std::string getClangRevision() { #ifdef SVN_REVISION - if (SVN_REVISION[0] != '\0') { - std::string revision; - llvm::raw_string_ostream OS(revision); - OS << strtol(SVN_REVISION, 0, 10); - return OS.str(); - } -#endif + return SVN_REVISION; +#else return ""; +#endif } std::string getClangFullRepositoryVersion() { std::string buf; llvm::raw_string_ostream OS(buf); - OS << getClangRepositoryPath(); - const std::string &Revision = getClangRevision(); - if (!Revision.empty()) - OS << ' ' << Revision; + std::string Path = getClangRepositoryPath(); + std::string Revision = getClangRevision(); + if (!Path.empty()) + OS << Path; + if (!Revision.empty()) { + if (!Path.empty()) + OS << ' '; + OS << Revision; + } return OS.str(); } @@ -70,9 +78,14 @@ std::string getClangFullVersion() { #endif OS << "clang version " CLANG_VERSION_STRING " (" << getClangFullRepositoryVersion() << ')'; + #ifdef CLANG_VENDOR_SUFFIX OS << CLANG_VENDOR_SUFFIX; +#elif defined(CLANG_VENDOR) + // If vendor supplied, include the base LLVM version as well. + OS << " (based on LLVM " << PACKAGE_VERSION << ")"; #endif + return OS.str(); } |