opnsense-src/lib/Basic/Version.cpp

76 lines
1.9 KiB
C++
Raw Normal View History

2009-10-14 14:03:49 -04:00
//===- 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.
//
//===----------------------------------------------------------------------===//
2010-01-23 06:10:26 -05:00
#include "clang/Basic/Version.h"
#include "llvm/Support/raw_ostream.h"
2009-10-14 14:03:49 -04:00
#include <cstring>
#include <cstdlib>
2010-01-23 06:10:26 -05:00
2009-10-14 14:03:49 -04:00
using namespace std;
namespace clang {
2010-01-23 06:10:26 -05:00
llvm::StringRef getClangRepositoryPath() {
2010-02-16 04:31:36 -05:00
static const char URL[] = "$URL: http://llvm.org/svn/llvm-project/cfe/trunk/lib/Basic/Version.cpp $";
const char *URLEnd = URL + strlen(URL);
const char *End = strstr(URL, "/lib/Basic");
2009-10-14 14:03:49 -04:00
if (End)
2010-02-16 04:31:36 -05:00
URLEnd = End;
2009-11-18 09:59:57 -05:00
End = strstr(URL, "/clang/tools/clang");
if (End)
2010-02-16 04:31:36 -05:00
URLEnd = End;
const char *Begin = strstr(URL, "cfe/");
if (Begin)
return llvm::StringRef(Begin + 4, URLEnd - Begin - 4);
2009-10-14 14:03:49 -04:00
2010-02-16 04:31:36 -05:00
return llvm::StringRef(URL, URLEnd - URL);
}
2009-10-14 14:03:49 -04:00
2010-02-16 04:31:36 -05:00
std::string getClangRevision() {
2009-10-14 14:03:49 -04:00
#ifndef SVN_REVISION
// Subversion was not available at build time?
2010-02-16 04:31:36 -05:00
return "";
2009-10-14 14:03:49 -04:00
#else
2010-02-16 04:31:36 -05:00
std::string revision;
llvm::raw_string_ostream OS(revision);
OS << strtol(SVN_REVISION, 0, 10);
2010-01-23 06:10:26 -05:00
return revision;
2009-10-14 14:03:49 -04:00
#endif
}
2010-02-16 04:31:36 -05:00
std::string getClangFullRepositoryVersion() {
std::string buf;
llvm::raw_string_ostream OS(buf);
OS << getClangRepositoryPath();
const std::string &Revision = getClangRevision();
if (!Revision.empty())
OS << ' ' << Revision;
2010-01-23 06:10:26 -05:00
return buf;
}
2010-02-16 04:31:36 -05:00
std::string getClangFullVersion() {
std::string buf;
llvm::raw_string_ostream OS(buf);
2010-01-23 06:10:26 -05:00
#ifdef CLANG_VENDOR
2010-02-16 04:31:36 -05:00
OS << CLANG_VENDOR;
2010-01-23 06:10:26 -05:00
#endif
2010-02-16 04:31:36 -05:00
OS << "clang version " CLANG_VERSION_STRING " ("
<< getClangFullRepositoryVersion() << ')';
return buf;
2010-01-23 06:10:26 -05:00
}
2010-02-16 04:31:36 -05:00
2009-10-14 14:03:49 -04:00
} // end namespace clang