[lld] r219277 - Add support to print version.
Shankar Easwaran
shankarke at gmail.com
Tue Oct 7 20:47:51 PDT 2014
Author: shankare
Date: Tue Oct 7 22:47:51 2014
New Revision: 219277
URL: http://llvm.org/viewvc/llvm-project?rev=219277&view=rev
Log:
Add support to print version.
Summary: Add support in the universal driver to print the lld version and the
repository version.
Test Plan: A driver test is added
Reviewers: kledzik, ruiu
Reviewed By: ruiu
Subscribers: llvm-commits
Projects: #lld
Differential Revision: http://reviews.llvm.org/D5641
Added:
lld/trunk/include/lld/Config/
lld/trunk/include/lld/Config/Makefile
lld/trunk/include/lld/Config/Version.h
lld/trunk/include/lld/Config/Version.inc.in
lld/trunk/lib/Config/
lld/trunk/lib/Config/CMakeLists.txt
lld/trunk/lib/Config/Makefile
- copied, changed from r219268, lld/trunk/lib/Makefile
lld/trunk/lib/Config/Version.cpp
Modified:
lld/trunk/CMakeLists.txt
lld/trunk/include/lld/Makefile
lld/trunk/lib/CMakeLists.txt
lld/trunk/lib/Driver/CMakeLists.txt
lld/trunk/lib/Driver/UniversalDriver.cpp
lld/trunk/lib/Driver/UniversalDriverOptions.td
lld/trunk/lib/Makefile
lld/trunk/tools/lld/Makefile
lld/trunk/unittests/DriverTests/Makefile
Modified: lld/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/CMakeLists.txt?rev=219277&r1=219276&r2=219277&view=diff
==============================================================================
--- lld/trunk/CMakeLists.txt (original)
+++ lld/trunk/CMakeLists.txt Tue Oct 7 22:47:51 2014
@@ -81,6 +81,49 @@ endif()
set(LLD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(LLD_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
+# Compute the LLD version from the LLVM version.
+string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" LLD_VERSION
+ ${PACKAGE_VERSION})
+message(STATUS "LLD version: ${LLD_VERSION}")
+
+string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" LLD_VERSION_MAJOR
+ ${LLD_VERSION})
+string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" LLD_VERSION_MINOR
+ ${LLD_VERSION})
+
+# Determine LLD revision and repository.
+# TODO: Figure out a way to get the revision and the repository on windows.
+if ( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" )
+ execute_process(COMMAND ${CMAKE_SOURCE_DIR}/utils/GetSourceVersion ${LLD_SOURCE_DIR}
+ OUTPUT_VARIABLE LLD_REVISION)
+
+ execute_process(COMMAND ${CMAKE_SOURCE_DIR}/utils/GetRepositoryPath ${LLD_SOURCE_DIR}
+ OUTPUT_VARIABLE LLD_REPOSITORY)
+ if ( LLD_REPOSITORY )
+ # Replace newline characters with spaces
+ string(REGEX REPLACE "(\r?\n)+" " " LLD_REPOSITORY ${LLD_REPOSITORY})
+ # Remove leading spaces
+ STRING(REGEX REPLACE "^[ \t\r\n]+" "" LLD_REPOSITORY "${LLD_REPOSITORY}" )
+ # Remove trailing spaces
+ string(REGEX REPLACE "(\ )+$" "" LLD_REPOSITORY ${LLD_REPOSITORY})
+ endif()
+
+ if ( LLD_REVISION )
+ # Replace newline characters with spaces
+ string(REGEX REPLACE "(\r?\n)+" " " LLD_REVISION ${LLD_REVISION})
+ # Remove leading spaces
+ STRING(REGEX REPLACE "^[ \t\r\n]+" "" LLD_REVISION "${LLD_REVISION}" )
+ # Remove trailing spaces
+ string(REGEX REPLACE "(\ )+$" "" LLD_REVISION ${LLD_REVISION})
+ endif()
+endif ()
+
+# Configure the Version.inc file.
+configure_file(
+ ${CMAKE_CURRENT_SOURCE_DIR}/include/lld/Config/Version.inc.in
+ ${CMAKE_CURRENT_BINARY_DIR}/include/lld/Config/Version.inc)
+
+
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite "
"the makefiles distributed with LLVM. Please create a directory and run cmake "
Added: lld/trunk/include/lld/Config/Makefile
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Config/Makefile?rev=219277&view=auto
==============================================================================
--- lld/trunk/include/lld/Config/Makefile (added)
+++ lld/trunk/include/lld/Config/Makefile Tue Oct 7 22:47:51 2014
@@ -0,0 +1,32 @@
+LLD_LEVEL := ../../..
+
+BUILT_SOURCES = Version.inc
+
+TABLEGEN_INC_FILES_COMMON = 1
+
+include $(LLD_LEVEL)/Makefile
+
+# Compute the lld version from the LLVM version, unless specified explicitly.
+ifndef LLD_VERSION
+LLD_VERSION := $(subst svn,,$(LLVMVersion))
+LLD_VERSION := $(subst rc,,$(LLD_VERSION))
+endif
+
+LLD_VERSION_COMPONENTS := $(subst ., ,$(LLD_VERSION))
+LLD_VERSION_MAJOR := $(word 1,$(LLD_VERSION_COMPONENTS))
+LLD_VERSION_MINOR := $(word 2,$(LLD_VERSION_COMPONENTS))
+
+LLD_REVISION := $(strip \
+ $(shell $(LLVM_SRC_ROOT)/utils/GetSourceVersion $(LLVM_SRC_ROOT)/tools/lld))
+
+LLD_REPOSITORY := $(strip \
+ $(shell $(LLVM_SRC_ROOT)/utils/GetRepositoryPath $(LLVM_SRC_ROOT)/tools/lld))
+
+$(ObjDir)/Version.inc.tmp : Version.inc.in Makefile $(LLVM_OBJ_ROOT)/Makefile.config $(ObjDir)/.dir
+ $(Echo) "Updating LLD version info."
+ $(Verb)sed -e "s#@LLD_VERSION@#$(LLD_VERSION)#g" \
+ -e "s#@LLD_VERSION_MAJOR@#$(LLD_VERSION_MAJOR)#g" \
+ -e "s#@LLD_VERSION_MINOR@#$(LLD_VERSION_MINOR)#g" \
+ -e "s#@LLD_REVISION@#$(LLD_REVISION)#g" \
+ -e "s#@LLD_REPOSITORY@#$(LLD_REPOSITORY)#g" \
+ $< > $@
Added: lld/trunk/include/lld/Config/Version.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Config/Version.h?rev=219277&view=auto
==============================================================================
--- lld/trunk/include/lld/Config/Version.h (added)
+++ lld/trunk/include/lld/Config/Version.h Tue Oct 7 22:47:51 2014
@@ -0,0 +1,51 @@
+//===- lld/Config/Version.h - LLD Version Number ----------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Defines version macros and version-related utility functions
+/// for lld.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLD_VERSION_H
+#define LLD_VERSION_H
+
+#include "lld/Config/Version.inc"
+#include "llvm/ADT/StringRef.h"
+#include <string>
+
+/// \brief Helper macro for LLD_VERSION_STRING.
+#define LLD_MAKE_VERSION_STRING2(X) #X
+
+/// \brief Helper macro for LLD_VERSION_STRING.
+#define LLD_MAKE_VERSION_STRING(X, Y) LLD_MAKE_VERSION_STRING2(X.Y)
+
+/// \brief A string that describes the lld version number, e.g., "1.0".
+#define LLD_VERSION_STRING \
+ LLD_MAKE_VERSION_STRING(LLD_VERSION_MAJOR, LLD_VERSION_MINOR)
+
+namespace lld {
+/// \brief Retrieves the repository path (e.g., Subversion path) that
+/// identifies the particular lld branch, tag, or trunk from which this
+/// lld was built.
+llvm::StringRef getLLDRepositoryPath();
+
+/// \brief Retrieves the repository revision number (or identifer) from which
+/// this lld was built.
+llvm::StringRef getLLDRevision();
+
+/// \brief Retrieves the full repository version that is an amalgamation of
+/// the information in getLLDRepositoryPath() and getLLDRevision().
+std::string getLLDRepositoryVersion();
+
+/// \brief Retrieves a string representing the complete lld version.
+llvm::StringRef getLLDVersion();
+}
+
+#endif // LLD_VERSION_H
Added: lld/trunk/include/lld/Config/Version.inc.in
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Config/Version.inc.in?rev=219277&view=auto
==============================================================================
--- lld/trunk/include/lld/Config/Version.inc.in (added)
+++ lld/trunk/include/lld/Config/Version.inc.in Tue Oct 7 22:47:51 2014
@@ -0,0 +1,5 @@
+#define LLD_VERSION @LLD_VERSION@
+#define LLD_VERSION_MAJOR @LLD_VERSION_MAJOR@
+#define LLD_VERSION_MINOR @LLD_VERSION_MINOR@
+#define LLD_REVISION_STRING "@LLD_REVISION@"
+#define LLD_REPOSITORY_STRING "@LLD_REPOSITORY@"
Modified: lld/trunk/include/lld/Makefile
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Makefile?rev=219277&r1=219276&r2=219277&view=diff
==============================================================================
--- lld/trunk/include/lld/Makefile (original)
+++ lld/trunk/include/lld/Makefile Tue Oct 7 22:47:51 2014
@@ -1,5 +1,5 @@
LLD_LEVEL := ../..
-DIRS :=
+DIRS := Config
include $(LLD_LEVEL)/Makefile
Modified: lld/trunk/lib/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/CMakeLists.txt?rev=219277&r1=219276&r2=219277&view=diff
==============================================================================
--- lld/trunk/lib/CMakeLists.txt (original)
+++ lld/trunk/lib/CMakeLists.txt Tue Oct 7 22:47:51 2014
@@ -1,3 +1,4 @@
+add_subdirectory(Config)
add_subdirectory(Core)
add_subdirectory(Driver)
add_subdirectory(Passes)
Added: lld/trunk/lib/Config/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Config/CMakeLists.txt?rev=219277&view=auto
==============================================================================
--- lld/trunk/lib/Config/CMakeLists.txt (added)
+++ lld/trunk/lib/Config/CMakeLists.txt Tue Oct 7 22:47:51 2014
@@ -0,0 +1,3 @@
+add_lld_library(lldConfig
+ Version.cpp
+ )
Copied: lld/trunk/lib/Config/Makefile (from r219268, lld/trunk/lib/Makefile)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Config/Makefile?p2=lld/trunk/lib/Config/Makefile&p1=lld/trunk/lib/Makefile&r1=219268&r2=219277&rev=219277&view=diff
==============================================================================
--- lld/trunk/lib/Makefile (original)
+++ lld/trunk/lib/Config/Makefile Tue Oct 7 22:47:51 2014
@@ -1,4 +1,4 @@
-##===- lib/Makefile ----------------------------------------*- Makefile -*-===##
+##===- lib/Config/Makefile ---------------------------------*- Makefile -*-===##
#
# The LLVM Compiler Infrastructure
#
@@ -6,11 +6,8 @@
# License. See LICENSE.TXT for details.
#
##===----------------------------------------------------------------------===##
-LLD_LEVEL := ..
-# ARCMigrate and Rewrite are always needed because of libclang.
-PARALLEL_DIRS = Core Driver Passes ReaderWriter
-
-include $(LLD_LEVEL)/../../Makefile.config
+LLD_LEVEL := ../..
+LIBRARYNAME := lldConfig
include $(LLD_LEVEL)/Makefile
Added: lld/trunk/lib/Config/Version.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Config/Version.cpp?rev=219277&view=auto
==============================================================================
--- lld/trunk/lib/Config/Version.cpp (added)
+++ lld/trunk/lib/Config/Version.cpp Tue Oct 7 22:47:51 2014
@@ -0,0 +1,66 @@
+//===- lib/Config/Version.cpp - LLD Version Number ---------------*- C++-=====//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines several version-related utility functions for LLD.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lld/Config/Version.h"
+#include "llvm/Support/raw_ostream.h"
+#include <cstdlib>
+#include <cstring>
+
+using namespace llvm;
+
+namespace lld {
+
+StringRef getLLDRepositoryPath() {
+#ifdef LLD_REPOSITORY_STRING
+ return LLD_REPOSITORY_STRING;
+#else
+ return "";
+#endif
+}
+
+StringRef getLLDRevision() {
+#ifdef LLD_REVISION_STRING
+ return LLD_REVISION_STRING;
+#else
+ return "";
+#endif
+}
+
+std::string getLLDRepositoryVersion() {
+ std::string buf;
+ llvm::raw_string_ostream OS(buf);
+ std::string Path = getLLDRepositoryPath();
+ std::string Revision = getLLDRevision();
+ if (!Path.empty() || !Revision.empty()) {
+ OS << '(';
+ if (!Path.empty())
+ OS << Path;
+ if (!Revision.empty()) {
+ if (!Path.empty())
+ OS << ' ';
+ OS << Revision;
+ }
+ OS << ')';
+ }
+ return OS.str();
+}
+
+StringRef getLLDVersion() {
+#ifdef LLD_VERSION_STRING
+ return LLD_VERSION_STRING;
+#else
+ return "";
+#endif
+}
+
+} // end namespace lld
Modified: lld/trunk/lib/Driver/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/CMakeLists.txt?rev=219277&r1=219276&r2=219277&view=diff
==============================================================================
--- lld/trunk/lib/Driver/CMakeLists.txt (original)
+++ lld/trunk/lib/Driver/CMakeLists.txt Tue Oct 7 22:47:51 2014
@@ -26,6 +26,7 @@ add_lld_library(lldDriver
add_dependencies(lldDriver DriverOptionsTableGen)
target_link_libraries(lldDriver
+ lldConfig
lldPasses
lldMachO
lldPECOFF
Modified: lld/trunk/lib/Driver/UniversalDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/UniversalDriver.cpp?rev=219277&r1=219276&r2=219277&view=diff
==============================================================================
--- lld/trunk/lib/Driver/UniversalDriver.cpp (original)
+++ lld/trunk/lib/Driver/UniversalDriver.cpp Tue Oct 7 22:47:51 2014
@@ -15,6 +15,7 @@
//===----------------------------------------------------------------------===//
#include "lld/Driver/Driver.h"
+#include "lld/Config/Version.h"
#include "lld/Core/LLVM.h"
@@ -188,6 +189,13 @@ bool UniversalDriver::link(int argc, con
return true;
}
+ // Handle -version
+ if (parsedArgs->getLastArg(OPT_version)) {
+ diagnostics << "LLVM Linker Version: " << getLLDVersion()
+ << getLLDRepositoryVersion() << "\n";
+ return true;
+ }
+
Flavor flavor = getFlavor(argc, argv, parsedArgs);
std::vector<const char *> args(argv, argv + argc);
Modified: lld/trunk/lib/Driver/UniversalDriverOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/UniversalDriverOptions.td?rev=219277&r1=219276&r2=219277&view=diff
==============================================================================
--- lld/trunk/lib/Driver/UniversalDriverOptions.td (original)
+++ lld/trunk/lib/Driver/UniversalDriverOptions.td Tue Oct 7 22:47:51 2014
@@ -11,6 +11,9 @@ def core : Flag<["-"], "core">,
def target: Separate<["-"], "target">,
HelpText<"Select the target">;
+def version: Flag<["-"], "version">,
+ HelpText<"Display the version">;
+
// Help message
def help : Flag<["-"], "help">,
HelpText<"Display this help message">;
Modified: lld/trunk/lib/Makefile
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Makefile?rev=219277&r1=219276&r2=219277&view=diff
==============================================================================
--- lld/trunk/lib/Makefile (original)
+++ lld/trunk/lib/Makefile Tue Oct 7 22:47:51 2014
@@ -9,7 +9,7 @@
LLD_LEVEL := ..
# ARCMigrate and Rewrite are always needed because of libclang.
-PARALLEL_DIRS = Core Driver Passes ReaderWriter
+PARALLEL_DIRS = Config Core Driver Passes ReaderWriter
include $(LLD_LEVEL)/../../Makefile.config
Modified: lld/trunk/tools/lld/Makefile
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/tools/lld/Makefile?rev=219277&r1=219276&r2=219277&view=diff
==============================================================================
--- lld/trunk/tools/lld/Makefile (original)
+++ lld/trunk/tools/lld/Makefile Tue Oct 7 22:47:51 2014
@@ -19,7 +19,7 @@ LEVEL := $(LLD_LEVEL)/../..
include $(LEVEL)/Makefile.config
LINK_COMPONENTS := $(TARGETS_TO_BUILD)
-USEDLIBS = lldDriver.a \
+USEDLIBS = lldDriver.a lldConfig.a \
lldELF.a lldMachO.a lldPasses.a lldPECOFF.a lldYAML.a \
lldReaderWriter.a lldCore.a lldNative.a \
lldHexagonELFTarget.a lldPPCELFTarget.a lldMipsELFTarget.a \
Modified: lld/trunk/unittests/DriverTests/Makefile
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/Makefile?rev=219277&r1=219276&r2=219277&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/Makefile (original)
+++ lld/trunk/unittests/DriverTests/Makefile Tue Oct 7 22:47:51 2014
@@ -9,7 +9,7 @@
LLD_LEVEL = ../..
TESTNAME = DriverTests
-USEDLIBS = lldDriver.a \
+USEDLIBS = lldDriver.a lldConfig.a \
lldELF.a lldMachO.a lldPasses.a lldPECOFF.a \
lldCore.a lldNative.a lldReaderWriter.a \
lldHexagonELFTarget.a lldPPCELFTarget.a lldMipsELFTarget.a \
More information about the llvm-commits
mailing list