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

llvm-svn: 219277
This commit is contained in:
Shankar Easwaran 2014-10-08 03:47:51 +00:00
parent d9d0f86a79
commit c3550f9231
15 changed files with 230 additions and 4 deletions

View File

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

View File

@ -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" \
$< > $@

View File

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

View File

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

View File

@ -1,5 +1,5 @@
LLD_LEVEL := ../..
DIRS :=
DIRS := Config
include $(LLD_LEVEL)/Makefile

View File

@ -1,3 +1,4 @@
add_subdirectory(Config)
add_subdirectory(Core)
add_subdirectory(Driver)
add_subdirectory(Passes)

View File

@ -0,0 +1,3 @@
add_lld_library(lldConfig
Version.cpp
)

13
lld/lib/Config/Makefile Normal file
View File

@ -0,0 +1,13 @@
##===- lib/Config/Makefile ---------------------------------*- Makefile -*-===##
#
# The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
#
##===----------------------------------------------------------------------===##
LLD_LEVEL := ../..
LIBRARYNAME := lldConfig
include $(LLD_LEVEL)/Makefile

View File

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

View File

@ -26,6 +26,7 @@ add_lld_library(lldDriver
add_dependencies(lldDriver DriverOptionsTableGen)
target_link_libraries(lldDriver
lldConfig
lldPasses
lldMachO
lldPECOFF

View File

@ -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, const char *argv[],
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);

View File

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

View File

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

View File

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

View File

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