From 18e066f6a9b1109cb0d3738cd0e570f79ce896ac Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Fri, 22 Jan 2010 22:12:47 +0000 Subject: [PATCH] (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 --- clang/include/clang/Basic/Version.h | 10 +++++++--- clang/lib/Basic/Version.cpp | 24 +++++++++++++++++++++--- clang/lib/Driver/Driver.cpp | 4 +--- clang/lib/Frontend/PCHReader.cpp | 9 +-------- clang/lib/Frontend/PCHWriter.cpp | 15 +++++++-------- 5 files changed, 37 insertions(+), 25 deletions(-) diff --git a/clang/include/clang/Basic/Version.h b/clang/include/clang/Basic/Version.h index c44c0f040708..fe35e24d3169 100644 --- a/clang/include/clang/Basic/Version.h +++ b/clang/include/clang/Basic/Version.h @@ -54,9 +54,13 @@ namespace clang { /// Clang was built. llvm::StringRef getClangRepositoryPath(); - /// \brief Retrieves the Subversion revision number from which this Clang - /// was built. - unsigned getClangSubversionRevision(); + /// \brief Retrieves the repository revision number (or identifer) from which + /// this Clang was built. + llvm::StringRef getClangRevision(); + + /// \brief Retrieves the full repository version that is an amalgamation of + /// the information in getClangRepositoryPath() and getClangRevision(). + llvm::StringRef getClangFullRepositoryVersion(); } #endif // LLVM_CLANG_BASIC_VERSION_H diff --git a/clang/lib/Basic/Version.cpp b/clang/lib/Basic/Version.cpp index 0751cfcf5d4e..ca65130ffc8d 100644 --- a/clang/lib/Basic/Version.cpp +++ b/clang/lib/Basic/Version.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/StringRef.h" +#include "llvm/Support/raw_ostream.h" #include #include @@ -44,13 +45,30 @@ llvm::StringRef getClangRepositoryPath() { } -unsigned getClangSubversionRevision() { +llvm::StringRef getClangRevision() { #ifndef SVN_REVISION // Subversion was not available at build time? - return 0; + return llvm::StringRef(); #else - return strtol(SVN_REVISION, 0, 10); + 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 diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 5490ef3d67af..298e173e387f 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -286,9 +286,7 @@ void Driver::PrintVersion(const Compilation &C, llvm::raw_ostream &OS) const { OS << CLANG_VENDOR; #endif OS << "clang version " CLANG_VERSION_STRING " (" - << getClangRepositoryPath(); - if (unsigned Revision = getClangSubversionRevision()) - OS << " " << Revision; + << getClangFullRepositoryVersion(); OS << ")" << '\n'; const ToolChain &TC = C.getDefaultToolChain(); diff --git a/clang/lib/Frontend/PCHReader.cpp b/clang/lib/Frontend/PCHReader.cpp index cc738e6fb96e..259355145aa3 100644 --- a/clang/lib/Frontend/PCHReader.cpp +++ b/clang/lib/Frontend/PCHReader.cpp @@ -1400,14 +1400,7 @@ PCHReader::ReadPCHBlock() { break; case pch::VERSION_CONTROL_BRANCH_REVISION: { - unsigned CurRevision = getClangSubversionRevision(); - if (Record[0] && CurRevision && Record[0] != CurRevision) { - Diag(Record[0] < CurRevision? diag::warn_pch_version_too_old - : diag::warn_pch_version_too_new); - return IgnorePCH; - } - - llvm::StringRef CurBranch = getClangRepositoryPath(); + llvm::StringRef CurBranch = getClangFullRepositoryVersion(); llvm::StringRef PCHBranch(BlobStart, BlobLen); if (CurBranch != PCHBranch) { Diag(diag::warn_pch_different_branch) << PCHBranch << CurBranch; diff --git a/clang/lib/Frontend/PCHWriter.cpp b/clang/lib/Frontend/PCHWriter.cpp index d1aa1d8b500b..9909c95847ee 100644 --- a/clang/lib/Frontend/PCHWriter.cpp +++ b/clang/lib/Frontend/PCHWriter.cpp @@ -707,16 +707,15 @@ void PCHWriter::WriteMetadata(ASTContext &Context, const char *isysroot) { Stream.EmitRecordWithBlob(FileAbbrevCode, Record, MainFileNameStr); } - // Subversion branch/version information. - BitCodeAbbrev *SvnAbbrev = new BitCodeAbbrev(); - SvnAbbrev->Add(BitCodeAbbrevOp(pch::VERSION_CONTROL_BRANCH_REVISION)); - SvnAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // SVN revision - SvnAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag - unsigned SvnAbbrevCode = Stream.EmitAbbrev(SvnAbbrev); + // Repository branch/version information. + BitCodeAbbrev *RepoAbbrev = new BitCodeAbbrev(); + RepoAbbrev->Add(BitCodeAbbrevOp(pch::VERSION_CONTROL_BRANCH_REVISION)); + RepoAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag + unsigned RepoAbbrevCode = Stream.EmitAbbrev(RepoAbbrev); Record.clear(); Record.push_back(pch::VERSION_CONTROL_BRANCH_REVISION); - Record.push_back(getClangSubversionRevision()); - Stream.EmitRecordWithBlob(SvnAbbrevCode, Record, getClangRepositoryPath()); + Stream.EmitRecordWithBlob(RepoAbbrevCode, Record, + getClangFullRepositoryVersion()); } /// \brief Write the LangOptions structure.