[cfe-commits] r94231 - in /cfe/trunk: include/clang/Basic/Version.h lib/Basic/Version.cpp lib/Driver/Driver.cpp lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp

Ted Kremenek kremenek at apple.com
Fri Jan 22 14:12:48 PST 2010


Author: kremenek
Date: Fri Jan 22 16:12:47 2010
New Revision: 94231

URL: http://llvm.org/viewvc/llvm-project?rev=94231&view=rev
Log:
(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...


Modified:
    cfe/trunk/include/clang/Basic/Version.h
    cfe/trunk/lib/Basic/Version.cpp
    cfe/trunk/lib/Driver/Driver.cpp
    cfe/trunk/lib/Frontend/PCHReader.cpp
    cfe/trunk/lib/Frontend/PCHWriter.cpp

Modified: cfe/trunk/include/clang/Basic/Version.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Version.h?rev=94231&r1=94230&r2=94231&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/Version.h (original)
+++ cfe/trunk/include/clang/Basic/Version.h Fri Jan 22 16:12:47 2010
@@ -54,9 +54,13 @@
   /// 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

Modified: cfe/trunk/lib/Basic/Version.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Version.cpp?rev=94231&r1=94230&r2=94231&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/Version.cpp (original)
+++ cfe/trunk/lib/Basic/Version.cpp Fri Jan 22 16:12:47 2010
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/raw_ostream.h"
 #include <cstring>
 #include <cstdlib>
 
@@ -44,13 +45,30 @@
 }
 
 
-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

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=94231&r1=94230&r2=94231&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Fri Jan 22 16:12:47 2010
@@ -286,9 +286,7 @@
   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();

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=94231&r1=94230&r2=94231&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Fri Jan 22 16:12:47 2010
@@ -1400,14 +1400,7 @@
       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;

Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=94231&r1=94230&r2=94231&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Fri Jan 22 16:12:47 2010
@@ -707,16 +707,15 @@
     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.





More information about the cfe-commits mailing list