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

llvm-svn: 354605
This commit is contained in:
Rui Ueyama 2019-02-21 18:37:26 +00:00
parent 599ce44d3f
commit 04661e1084
2 changed files with 36 additions and 25 deletions

View File

@ -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

View File

@ -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
}