[cfe-commits] r115071 - in /cfe/trunk: include/clang/Basic/Version.h lib/Basic/Makefile lib/Basic/Version.cpp
Daniel Dunbar
daniel at zuster.org
Wed Sep 29 12:15:29 PDT 2010
Author: ddunbar
Date: Wed Sep 29 14:15:29 2010
New Revision: 115071
URL: http://llvm.org/viewvc/llvm-project?rev=115071&view=rev
Log:
Basic: Simplify getClangRepositoryPath and getClangRevision.
- I don't like returning StringRef's ever, unless it is actually important for
performance, which it isn't here.
- Also, stop validating getClangRevision to be an integer, I don't see a good
reason to do this.
Modified:
cfe/trunk/include/clang/Basic/Version.h
cfe/trunk/lib/Basic/Makefile
cfe/trunk/lib/Basic/Version.cpp
Modified: cfe/trunk/include/clang/Basic/Version.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Version.h?rev=115071&r1=115070&r2=115071&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Version.h (original)
+++ cfe/trunk/include/clang/Basic/Version.h Wed Sep 29 14:15:29 2010
@@ -44,11 +44,11 @@
/// \brief Retrieves the repository path (e.g., Subversion path) that
/// identifies the particular Clang branch, tag, or trunk from which this
/// Clang was built.
- llvm::StringRef getClangRepositoryPath();
+ std::string getClangRepositoryPath();
/// \brief Retrieves the repository revision number (or identifer) from which
/// this Clang was built.
- llvm::StringRef getClangRevision();
+ std::string getClangRevision();
/// \brief Retrieves the full repository version that is an amalgamation of
/// the information in getClangRepositoryPath() and getClangRevision().
Modified: cfe/trunk/lib/Basic/Makefile
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Makefile?rev=115071&r1=115070&r2=115071&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Makefile (original)
+++ cfe/trunk/lib/Basic/Makefile Wed Sep 29 14:15:29 2010
@@ -16,9 +16,11 @@
include $(CLANG_LEVEL)/Makefile
-SVN_REVISION := $(shell $(LLVM_SRC_ROOT)/utils/GetSourceVersion $(PROJ_SRC_DIR)/../..)
+SVN_REVISION := $(strip \
+ $(shell $(LLVM_SRC_ROOT)/utils/GetSourceVersion $(PROJ_SRC_DIR)/../..))
-SVN_REPOSITORY := $(shell $(LLVM_SRC_ROOT)/utils/GetRepositoryPath $(PROJ_SRC_DIR)/../..)
+SVN_REPOSITORY := $(strip \
+ $(shell $(LLVM_SRC_ROOT)/utils/GetRepositoryPath $(PROJ_SRC_DIR)/../..))
CPP.Defines += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include \
-DSVN_REVISION='"$(SVN_REVISION)"' -DSVN_REPOSITORY='"$(SVN_REPOSITORY)"'
Modified: cfe/trunk/lib/Basic/Version.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Version.cpp?rev=115071&r1=115070&r2=115071&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Version.cpp (original)
+++ cfe/trunk/lib/Basic/Version.cpp Wed Sep 29 14:15:29 2010
@@ -20,44 +20,37 @@
namespace clang {
-llvm::StringRef getClangRepositoryPath() {
+std::string getClangRepositoryPath() {
#ifdef SVN_REPOSITORY
- if (SVN_REPOSITORY[0] != '\0') {
- static const char URL[] = SVN_REPOSITORY;
- const char *URLEnd = URL + strlen(URL) - 1;
-
- // Strip off version from a build from an integration branch.
- const char *End = strstr(URL, "/src/tools/clang");
- if (End)
- URLEnd = End;
-
- const char *Begin = strstr(URL, "cfe/");
- if (Begin)
- return llvm::StringRef(Begin + 4, URLEnd - Begin - 4);
-
- return llvm::StringRef(URL, URLEnd - URL);
- }
+ llvm::StringRef URL(SVN_REPOSITORY);
+#else
+ llvm::StringRef URL("");
#endif
- return "";
+
+ // Strip off version from a build from an integration branch.
+ URL = URL.slice(0, URL.find("/src/tools/clang"));
+
+ // Trim path prefix off, assuming path came from standard cfe path.
+ size_t Start = URL.find("cfe/");
+ if (Start != llvm::StringRef::npos)
+ URL = URL.substr(Start + 4);
+
+ return URL;
}
-llvm::StringRef getClangRevision() {
+std::string getClangRevision() {
#ifdef SVN_REVISION
- if (SVN_REVISION[0] != '\0') {
- std::string revision;
- llvm::raw_string_ostream OS(revision);
- OS << strtol(SVN_REVISION, 0, 10);
- return OS.str();
- }
-#endif
+ return SVN_REVISION;
+#else
return "";
+#endif
}
std::string getClangFullRepositoryVersion() {
std::string buf;
llvm::raw_string_ostream OS(buf);
- const llvm::StringRef &Path = getClangRepositoryPath();
- const llvm::StringRef &Revision = getClangRevision();
+ std::string Path = getClangRepositoryPath();
+ std::string Revision = getClangRevision();
if (!Path.empty())
OS << Path;
if (!Revision.empty()) {
More information about the cfe-commits
mailing list