On Mon, Oct 5, 2009 at 1:33 PM, Douglas Gregor <[email protected]> wrote: > Author: dgregor > Date: Mon Oct 5 15:33:49 2009 > New Revision: 83321 > > URL: http://llvm.org/viewvc/llvm-project?rev=83321&view=rev > Log: > Provide a common set of routines in Version.h that return Subversion > branch/revision information. Use that information in the driver, > rather than one-off branch/revision computation.
Nice! Want to update clang-cc to print this with its version as well? It might also be nice to make the function names more generic, like GetClangSourcePath/Revision and return a string from the latter. This would allow us to sensibly add support for printing the git revision for such users as have been corrupted. - Daniel > Modified: > cfe/trunk/include/clang/Basic/Version.h > cfe/trunk/lib/Basic/CMakeLists.txt > cfe/trunk/lib/Basic/Makefile > cfe/trunk/lib/Basic/Version.cpp > cfe/trunk/lib/Driver/Driver.cpp > cfe/trunk/lib/Driver/Makefile > > Modified: cfe/trunk/include/clang/Basic/Version.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Version.h?rev=83321&r1=83320&r2=83321&view=diff > > ============================================================================== > --- cfe/trunk/include/clang/Basic/Version.h (original) > +++ cfe/trunk/include/clang/Basic/Version.h Mon Oct 5 15:33:49 2009 > @@ -7,7 +7,8 @@ > // > //===----------------------------------------------------------------------===// > // > -// This header defines version macros for Clang. > +// This header defines version macros and version-related utility functions > +// for Clang. > // > //===----------------------------------------------------------------------===// > > @@ -45,4 +46,14 @@ > CLANG_MAKE_VERSION_STRING(CLANG_VERSION_MAJOR,CLANG_VERSION_MINOR) > #endif > > +namespace clang { > + /// \brief Retrieves the Subversion path that identifies the particular > + /// Clang branch, tag, or trunk from which this Clang was built. > + const char *getClangSubversionPath(); > + > + /// \brief Retrieves the Subversion revision number from which this Clang > + /// was built. > + unsigned getClangSubversionRevision(); > +} > + > #endif // LLVM_CLANG_BASIC_VERSION_H > > Modified: cfe/trunk/lib/Basic/CMakeLists.txt > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/CMakeLists.txt?rev=83321&r1=83320&r2=83321&view=diff > > ============================================================================== > --- cfe/trunk/lib/Basic/CMakeLists.txt (original) > +++ cfe/trunk/lib/Basic/CMakeLists.txt Mon Oct 5 15:33:49 2009 > @@ -11,8 +11,19 @@ > TargetInfo.cpp > Targets.cpp > TokenKinds.cpp > + Version.cpp > ) > > +# Determine Subversion revision. > +# FIXME: This only gets updated when CMake is run, so this revision number > +# may be out-of-date! > +find_package(Subversion) > +if (Subversion_FOUND) > + Subversion_WC_INFO(${CLANG_SOURCE_DIR} CLANG) > + set_source_files_properties(Version.cpp > + PROPERTIES COMPILE_DEFINITIONS "SVN_REVISION=\"${CLANG_WC_REVISION}\"") > +endif() > + > add_dependencies(clangBasic > ClangDiagnosticAnalysis > ClangDiagnosticAST > > Modified: cfe/trunk/lib/Basic/Makefile > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Makefile?rev=83321&r1=83320&r2=83321&view=diff > > ============================================================================== > --- cfe/trunk/lib/Basic/Makefile (original) > +++ cfe/trunk/lib/Basic/Makefile Mon Oct 5 15:33:49 2009 > @@ -23,3 +23,14 @@ > > include $(LEVEL)/Makefile.common > > +SVN_REVISION := $(shell cd $(PROJ_SRC_DIR)/../.. && svnversion) > + > +CPP.Defines += -I$(PROJ_SRC_DIR)/../../include > -I$(PROJ_OBJ_DIR)/../../include \ > + -DSVN_REVISION='"$(SVN_REVISION)"' > + > +$(ObjDir)/.ver-svn .ver: $(ObjDir)/.dir > + @if [ '$(SVN_REVISION)' != '$(shell cat $(ObjDir)/.ver-svn > 2>/dev/null)' ]; then\ > + echo '$(SVN_REVISION)' > $(ObjDir)/.ver-svn; > \ > + fi > +$(ObjDir)/.ver-svn: .ver > +$(ObjDir)/Version.o: $(ObjDir)/.ver-svn > > Modified: cfe/trunk/lib/Basic/Version.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Version.cpp?rev=83321&r1=83320&r2=83321&view=diff > > ============================================================================== > --- cfe/trunk/lib/Basic/Version.cpp (original) > +++ cfe/trunk/lib/Basic/Version.cpp Mon Oct 5 15:33:49 2009 > @@ -39,24 +39,10 @@ > > unsigned getClangSubversionRevision() { > #ifndef SVN_REVISION > + // Subversion was not available at build time? > return 0; > #else > - // What follows is an evil trick. We can end up getting three different > - // kinds of results when asking for the Subversion information: > - // - if SVN_REVISION is a number, we return that number (adding 0 to it > is > - // harmless). > - // - if SVN_REVISION is "exported" (for an tree without any Subversion > - // info), we end up referencing the local variable "exported" and > adding > - // zero to it, and we return 0. > - // - if SVN_REVISION is empty (because "svn info" returned no results), > - // the "+" turns into a unary "+" operator and we return 0. > - // > - // Making this less ugly requires doing more computation in the CMake- and > - // Makefile-based build systems, with all sorts of checking to make sure we > - // don't end up breaking this build. It's better this way. Really. > - const unsigned exported = 0; > - (void)exported; > - return SVN_REVISION + 0; > + return strtol(SVN_REVISION, 0, 10); > #endif > } > > > Modified: cfe/trunk/lib/Driver/Driver.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=83321&r1=83320&r2=83321&view=diff > > ============================================================================== > --- cfe/trunk/lib/Driver/Driver.cpp (original) > +++ cfe/trunk/lib/Driver/Driver.cpp Mon Oct 5 15:33:49 2009 > @@ -410,24 +410,13 @@ > } > > void Driver::PrintVersion(const Compilation &C, llvm::raw_ostream &OS) const > { > - static char buf[] = "$URL$"; > - char *zap = strstr(buf, "/lib/Driver"); > - if (zap) > - *zap = 0; > - zap = strstr(buf, "/clang/tools/clang"); > - if (zap) > - *zap = 0; > - const char *vers = buf+6; > - // FIXME: Add cmake support and remove #ifdef > -#ifdef SVN_REVISION > - const char *revision = SVN_REVISION; > -#else > - const char *revision = ""; > -#endif > // FIXME: The following handlers should use a callback mechanism, we don't > // know what the client would like to do. > OS << "clang version " CLANG_VERSION_STRING " (" > - << vers << " " << revision << ")" << '\n'; > + << getClangSubversionPath(); > + if (unsigned Revision = getClangSubversionRevision()) > + OS << " " << Revision; > + OS << ")" << '\n'; > > const ToolChain &TC = C.getDefaultToolChain(); > OS << "Target: " << TC.getTripleString() << '\n'; > > Modified: cfe/trunk/lib/Driver/Makefile > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Makefile?rev=83321&r1=83320&r2=83321&view=diff > > ============================================================================== > --- cfe/trunk/lib/Driver/Makefile (original) > +++ cfe/trunk/lib/Driver/Makefile Mon Oct 5 15:33:49 2009 > @@ -15,16 +15,6 @@ > # Don't install Clang libraries > NO_INSTALL = 1 > > -include $(LEVEL)/Makefile.common > - > -SVN_REVISION := $(shell cd $(PROJ_SRC_DIR)/../.. && svnversion) > +CPPFLAGS += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include > > -CPP.Defines += -I$(PROJ_SRC_DIR)/../../include > -I$(PROJ_OBJ_DIR)/../../include \ > - -DSVN_REVISION='"$(SVN_REVISION)"' > - > -$(ObjDir)/.ver-svn .ver: $(ObjDir)/.dir > - @if [ '$(SVN_REVISION)' != '$(shell cat $(ObjDir)/.ver-svn > 2>/dev/null)' ]; then\ > - echo '$(SVN_REVISION)' > $(ObjDir)/.ver-svn; > \ > - fi > -$(ObjDir)/.ver-svn: .ver > -$(ObjDir)/Driver.o: $(ObjDir)/.ver-svn > +include $(LEVEL)/Makefile.common > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits > _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
