llvm-project/clang/lib/Basic/Version.cpp
Ted Kremenek 18e066f6a9 (1) Rename getClangSubversionRevision() to getClangRevision(), and
have it return a StringRef instead of an integer (to be more VCS
    agnostic).

(2) Add getClangFullRepositoryVersion(), which contains an
    amalgamation of the repository name and the revision.

(3) Change PCH to only emit the string returned by
    getClangFullRepositoryVersion() instead of also emitting the value
    of getClangSubversionRevision() (which has been removed).  This is
    functionally equivalent.

More cleanup to version string generation pending...

llvm-svn: 94231
2010-01-22 22:12:47 +00:00

75 lines
1.7 KiB
C++

//===- Version.cpp - Clang Version Number -----------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines several version-related utility functions for Clang.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/raw_ostream.h"
#include <cstring>
#include <cstdlib>
using namespace std;
namespace clang {
llvm::StringRef getClangRepositoryPath() {
static const char *Path = 0;
if (Path)
return Path;
static char URL[] = "$URL$";
char *End = strstr(URL, "/lib/Basic");
if (End)
*End = 0;
End = strstr(URL, "/clang/tools/clang");
if (End)
*End = 0;
char *Begin = strstr(URL, "cfe/");
if (Begin) {
Path = Begin + 4;
return Path;
}
Path = URL;
return Path;
}
llvm::StringRef getClangRevision() {
#ifndef SVN_REVISION
// Subversion was not available at build time?
return llvm::StringRef();
#else
static std::string revision;
if (revision.empty()) {
llvm::raw_string_ostream Out(revision);
Out << strtol(SVN_REVISION, 0, 10);
}
return revision;
#endif
}
llvm::StringRef getClangFullRepositoryVersion() {
static std::string buf;
if (buf.empty()) {
llvm::raw_string_ostream Out(buf);
Out << getClangRepositoryPath();
llvm::StringRef Revision = getClangRevision();
if (!Revision.empty())
Out << ' ' << Revision;
}
return buf;
}
} // end namespace clang