[lld] r354605 - Update `ld.lld --version` string for monorepo.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 21 10:37:27 PST 2019


Author: ruiu
Date: Thu Feb 21 10:37:26 2019
New Revision: 354605

URL: http://llvm.org/viewvc/llvm-project?rev=354605&view=rev
Log:
Update `ld.lld --version` string for monorepo.

This patch basically does the same thing as
https://reviews.llvm.org/rL352729 did to clang.

With this patch, lld now prints out a correct version string including
a git commit id like this:

  $ bin/ld.lld --version
  LLD 9.0.0 (https://github.com/llvm/llvm-project.git c027658504fa9e68173f53dedaf223695a65e910) (compatible with GNU linkers)

Fixes https://bugs.llvm.org/show_bug.cgi?id=40780

Differential Revision: https://reviews.llvm.org/D58411

Modified:
    lld/trunk/Common/CMakeLists.txt
    lld/trunk/Common/Version.cpp

Modified: lld/trunk/Common/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/Common/CMakeLists.txt?rev=354605&r1=354604&r2=354605&view=diff
==============================================================================
--- lld/trunk/Common/CMakeLists.txt (original)
+++ lld/trunk/Common/CMakeLists.txt Thu Feb 21 10:37:26 2019
@@ -2,6 +2,31 @@ if(NOT LLD_BUILT_STANDALONE)
   set(tablegen_deps intrinsics_gen)
 endif()
 
+find_first_existing_vc_file("${LLVM_MAIN_SRC_DIR}" llvm_vc)
+find_first_existing_vc_file("${LLD_SOURCE_DIR}" lld_vc)
+
+set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSVersion.inc")
+set(generate_vcs_version_script "${LLVM_CMAKE_PATH}/GenerateVersionFromVCS.cmake")
+
+if(lld_vc)
+  set(lld_source_dir ${LLD_SOURCE_DIR})
+endif()
+
+add_custom_command(OUTPUT "${version_inc}"
+  DEPENDS "${lld_vc}" "${generate_vcs_version_script}"
+  COMMAND ${CMAKE_COMMAND} "-DNAMES=LLD"
+  "-DLLD_SOURCE_DIR=${LLD_SOURCE_DIR}"
+  "-DHEADER_FILE=${version_inc}"
+  -P "${generate_vcs_version_script}")
+
+# Mark the generated header as being generated.
+set_source_files_properties("${version_inc}"
+  PROPERTIES GENERATED TRUE
+  HEADER_FILE_ONLY TRUE)
+
+set_property(SOURCE Version.cpp APPEND PROPERTY
+  COMPILE_DEFINITIONS "HAVE_VCS_VERSION_INC")
+
 add_lld_library(lldCommon
   Args.cpp
   ErrorHandler.cpp
@@ -11,6 +36,7 @@ add_lld_library(lldCommon
   TargetOptionsCommandFlags.cpp
   Threads.cpp
   Timer.cpp
+  VCSVersion.inc
   Version.cpp
 
   ADDITIONAL_HEADER_DIRS

Modified: lld/trunk/Common/Version.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/Common/Version.cpp?rev=354605&r1=354604&r2=354605&view=diff
==============================================================================
--- lld/trunk/Common/Version.cpp (original)
+++ lld/trunk/Common/Version.cpp Thu Feb 21 10:37:26 2019
@@ -12,31 +12,16 @@
 
 #include "lld/Common/Version.h"
 
-using namespace llvm;
+#ifdef HAVE_VCS_VERSION_INC
+#include "VCSVersion.inc"
+#endif
 
-// Returns an SVN repository path, which is usually "trunk".
-static std::string getRepositoryPath() {
-  StringRef S = LLD_REPOSITORY_STRING;
-  size_t Pos = S.find("lld/");
-  if (Pos != StringRef::npos)
-    return S.substr(Pos + 4);
-  return S;
-}
-
-// Returns an SVN repository name, e.g., " (trunk 284614)"
-// or an empty string if no repository info is available.
-static std::string getRepository() {
-  std::string Repo = getRepositoryPath();
-  std::string Rev = LLD_REVISION_STRING;
-
-  if (Repo.empty() && Rev.empty())
-    return "";
-  if (!Repo.empty() && !Rev.empty())
-    return " (" + Repo + " " + Rev + ")";
-  return " (" + Repo + Rev + ")";
-}
-
-// Returns a version string, e.g., "LLD 4.0 (lld/trunk 284614)".
+// Returns a version string, e.g.:
+// lld 9.0.0 (https://github.com/llvm/llvm-project.git 9efdd7ac5e914d3c9fa1ef)
 std::string lld::getLLDVersion() {
-  return "LLD " + std::string(LLD_VERSION_STRING) + getRepository();
+#if defined(LLD_REPOSITORY) && defined(LLD_REVISION)
+  return "LLD " LLD_VERSION_STRING " (" LLD_REPOSITORY " " LLD_REVISION ")";
+#else
+  return "LLD " LLD_VERSION_STRING;
+#endif
 }




More information about the llvm-commits mailing list