forked from OSchip/llvm-project
[lldb] Make lldbVersion a full fledged library
Because of its dependency on clang (and potentially other compilers downstream, such as swift) lldb_private::GetVersion already lives in its own library called lldbBase. Despite that, its implementation was spread across unrelated files. This patch improves things by introducing a Version library with its own directory, header and implementation file. The benefits of this patch include: - We can get rid of the ugly quoting macros. - Other parts of LLDB can read the version number from lldb/Version/Version.inc. - The implementation can be swapped out for tools like lldb-server than don't need to depend on clang at all. Differential revision: https://reviews.llvm.org/D115211
This commit is contained in:
parent
cc8dc5e28b
commit
ccf1469a4c
|
@ -0,0 +1,23 @@
|
|||
//===-- Version.h -----------------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLDB_VERSION_VERSION_H
|
||||
#define LLDB_VERSION_VERSION_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace lldb_private {
|
||||
|
||||
/// Retrieves a string representing the complete LLDB version, which includes
|
||||
/// the lldb version number, as well as embedded compiler versions and the
|
||||
/// vendor tag.
|
||||
const char *GetVersion();
|
||||
|
||||
} // namespace lldb_private
|
||||
|
||||
#endif // LLDB_VERSION_VERSION_H
|
|
@ -0,0 +1,6 @@
|
|||
#define LLDB_VERSION @LLDB_VERSION@
|
||||
#define LLDB_VERSION_STRING "@LLDB_VERSION@"
|
||||
#define LLDB_VERSION_MAJOR @LLDB_VERSION_MAJOR@
|
||||
#define LLDB_VERSION_MINOR @LLDB_VERSION_MINOR@
|
||||
#define LLDB_VERSION_PATCHLEVEL @LLDB_VERSION_PATCHLEVEL@
|
||||
#cmakedefine LLDB_FULL_VERSION_STRING "@LLDB_FULL_VERSION_STRING@"
|
|
@ -17,12 +17,6 @@
|
|||
#include "lldb/lldb-private-types.h"
|
||||
#include "lldb/lldb-public.h"
|
||||
|
||||
namespace lldb_private {
|
||||
|
||||
const char *GetVersion();
|
||||
|
||||
} // namespace lldb_private
|
||||
|
||||
#endif // defined(__cplusplus)
|
||||
|
||||
#endif // LLDB_LLDB_PRIVATE_H
|
||||
|
|
|
@ -94,7 +94,6 @@ add_lldb_library(liblldb SHARED ${option_framework}
|
|||
${lldb_lua_wrapper}
|
||||
|
||||
LINK_LIBS
|
||||
lldbBase
|
||||
lldbBreakpoint
|
||||
lldbCore
|
||||
lldbDataFormatters
|
||||
|
@ -105,6 +104,7 @@ add_lldb_library(liblldb SHARED ${option_framework}
|
|||
lldbSymbol
|
||||
lldbTarget
|
||||
lldbUtility
|
||||
lldbVersion
|
||||
${LLDB_ALL_PLUGINS}
|
||||
LINK_COMPONENTS
|
||||
Support
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
|
||||
#include "lldb/API/SBDebugger.h"
|
||||
|
||||
#include "lldb/lldb-private.h"
|
||||
|
||||
#include "lldb/API/SBBroadcaster.h"
|
||||
#include "lldb/API/SBCommandInterpreter.h"
|
||||
#include "lldb/API/SBCommandInterpreterRunOptions.h"
|
||||
|
@ -52,6 +50,7 @@
|
|||
#include "lldb/Target/TargetList.h"
|
||||
#include "lldb/Utility/Args.h"
|
||||
#include "lldb/Utility/State.h"
|
||||
#include "lldb/Version/Version.h"
|
||||
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include "lldb/API/SBHostOS.h"
|
||||
#include "lldb/API/SBReproducer.h"
|
||||
#include "lldb/Host/FileSystem.h"
|
||||
#include "lldb/lldb-private.h"
|
||||
#include "lldb/Version/Version.h"
|
||||
|
||||
using namespace lldb;
|
||||
using namespace lldb_private;
|
||||
|
|
|
@ -1,41 +1,5 @@
|
|||
include_directories(.)
|
||||
|
||||
set(lldbBase_SOURCES
|
||||
lldb.cpp
|
||||
)
|
||||
|
||||
|
||||
find_first_existing_vc_file("${LLDB_SOURCE_DIR}" lldb_vc)
|
||||
|
||||
set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSVersion.inc")
|
||||
set(generate_vcs_version_script "${LLVM_CMAKE_DIR}/GenerateVersionFromVCS.cmake")
|
||||
|
||||
if(lldb_vc AND LLVM_APPEND_VC_REV)
|
||||
set(lldb_source_dir ${LLDB_SOURCE_DIR})
|
||||
endif()
|
||||
|
||||
add_custom_command(OUTPUT "${version_inc}"
|
||||
DEPENDS "${lldb_vc}" "${generate_vcs_version_script}"
|
||||
COMMAND ${CMAKE_COMMAND} "-DNAMES=LLDB"
|
||||
"-DLLDB_SOURCE_DIR=${lldb_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)
|
||||
|
||||
list(APPEND lldbBase_SOURCES ${version_inc})
|
||||
|
||||
if(LLDB_VERSION_STRING)
|
||||
set_property(SOURCE lldb.cpp APPEND PROPERTY
|
||||
COMPILE_DEFINITIONS "LLDB_VERSION_STRING=${LLDB_VERSION_STRING}")
|
||||
endif()
|
||||
|
||||
add_lldb_library(lldbBase
|
||||
${lldbBase_SOURCES}
|
||||
)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
add_subdirectory(Breakpoint)
|
||||
add_subdirectory(Commands)
|
||||
|
@ -49,6 +13,7 @@ add_subdirectory(Plugins)
|
|||
add_subdirectory(Symbol)
|
||||
add_subdirectory(Target)
|
||||
add_subdirectory(Utility)
|
||||
add_subdirectory(Version)
|
||||
|
||||
# Build API last. Since liblldb needs to link against every other target, it needs
|
||||
# those targets to have already been created.
|
||||
|
|
|
@ -41,7 +41,6 @@ add_lldb_library(lldbCommands
|
|||
CommandOptionsProcessLaunch.cpp
|
||||
|
||||
LINK_LIBS
|
||||
lldbBase
|
||||
lldbBreakpoint
|
||||
lldbCore
|
||||
lldbDataFormatters
|
||||
|
@ -51,6 +50,7 @@ add_lldb_library(lldbCommands
|
|||
lldbSymbol
|
||||
lldbTarget
|
||||
lldbUtility
|
||||
lldbVersion
|
||||
|
||||
LINK_COMPONENTS
|
||||
Support
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "CommandObjectVersion.h"
|
||||
|
||||
#include "lldb/Interpreter/CommandReturnObject.h"
|
||||
#include "lldb/lldb-private.h"
|
||||
#include "lldb/Version/Version.h"
|
||||
|
||||
using namespace lldb;
|
||||
using namespace lldb_private;
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include "lldb/Utility/Log.h"
|
||||
#include "lldb/Utility/ReproducerProvider.h"
|
||||
#include "lldb/Utility/Timer.h"
|
||||
#include "lldb/lldb-private.h"
|
||||
#include "lldb/Version/Version.h"
|
||||
|
||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
|
||||
#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
if(LLDB_VERSION_STRING)
|
||||
set(LLDB_FULL_VERSION_STRING LLDB_VERSION_STRING)
|
||||
endif()
|
||||
|
||||
# Configure the VCSVersion.inc file.
|
||||
set(vcs_version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSVersion.inc")
|
||||
set(generate_vcs_version_script "${LLVM_CMAKE_DIR}/GenerateVersionFromVCS.cmake")
|
||||
|
||||
find_first_existing_vc_file("${LLDB_SOURCE_DIR}" lldb_vc)
|
||||
|
||||
if(lldb_vc AND LLVM_APPEND_VC_REV)
|
||||
set(lldb_source_dir ${LLDB_SOURCE_DIR})
|
||||
endif()
|
||||
|
||||
add_custom_command(OUTPUT "${vcs_version_inc}"
|
||||
DEPENDS "${lldb_vc}" "${generate_vcs_version_script}"
|
||||
COMMAND ${CMAKE_COMMAND} "-DNAMES=LLDB"
|
||||
"-DLLDB_SOURCE_DIR=${lldb_source_dir}"
|
||||
"-DHEADER_FILE=${vcs_version_inc}"
|
||||
-P "${generate_vcs_version_script}")
|
||||
|
||||
set_source_files_properties("${vcs_version_inc}"
|
||||
PROPERTIES GENERATED TRUE
|
||||
HEADER_FILE_ONLY TRUE)
|
||||
|
||||
# Configure the Version.inc file.
|
||||
set(version_inc "${LLDB_BINARY_DIR}/include/lldb/Version/Version.inc")
|
||||
|
||||
configure_file(
|
||||
${LLDB_SOURCE_DIR}/include/lldb/Version/Version.inc.in
|
||||
${version_inc})
|
||||
|
||||
set_source_files_properties("${version_inc}"
|
||||
PROPERTIES GENERATED TRUE
|
||||
HEADER_FILE_ONLY TRUE)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
add_lldb_library(lldbVersion
|
||||
Version.cpp
|
||||
${vcs_version_inc}
|
||||
${version_inc})
|
|
@ -0,0 +1,73 @@
|
|||
//===-- Version.cpp -------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "lldb/Version/Version.h"
|
||||
#include "VCSVersion.inc"
|
||||
#include "lldb/Version/Version.inc"
|
||||
#include "clang/Basic/Version.h"
|
||||
|
||||
static const char *GetLLDBVersion() {
|
||||
#ifdef LLDB_FULL_VERSION_STRING
|
||||
return LLDB_FULL_VERSION_STRING;
|
||||
#else
|
||||
return "lldb version " CLANG_VERSION_STRING;
|
||||
#endif
|
||||
}
|
||||
|
||||
static const char *GetLLDBRevision() {
|
||||
#ifdef LLDB_REVISION
|
||||
return LLDB_REVISION;
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
static const char *GetLLDBRepository() {
|
||||
#ifdef LLDB_REPOSITORY
|
||||
return LLDB_REPOSITORY;
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
const char *lldb_private::GetVersion() {
|
||||
static std::string g_version_str;
|
||||
|
||||
if (g_version_str.empty()) {
|
||||
const char *lldb_version = GetLLDBVersion();
|
||||
const char *lldb_repo = GetLLDBRepository();
|
||||
const char *lldb_rev = GetLLDBRevision();
|
||||
g_version_str += lldb_version;
|
||||
if (lldb_repo || lldb_rev) {
|
||||
g_version_str += " (";
|
||||
if (lldb_repo)
|
||||
g_version_str += lldb_repo;
|
||||
if (lldb_repo && lldb_rev)
|
||||
g_version_str += " ";
|
||||
if (lldb_rev) {
|
||||
g_version_str += "revision ";
|
||||
g_version_str += lldb_rev;
|
||||
}
|
||||
g_version_str += ")";
|
||||
}
|
||||
|
||||
std::string clang_rev(clang::getClangRevision());
|
||||
if (clang_rev.length() > 0) {
|
||||
g_version_str += "\n clang revision ";
|
||||
g_version_str += clang_rev;
|
||||
}
|
||||
|
||||
std::string llvm_rev(clang::getLLVMRevision());
|
||||
if (llvm_rev.length() > 0) {
|
||||
g_version_str += "\n llvm revision ";
|
||||
g_version_str += llvm_rev;
|
||||
}
|
||||
}
|
||||
|
||||
return g_version_str.c_str();
|
||||
}
|
|
@ -46,9 +46,9 @@ add_lldb_tool(lldb-server
|
|||
SystemInitializerLLGS.cpp
|
||||
|
||||
LINK_LIBS
|
||||
lldbBase
|
||||
lldbHost
|
||||
lldbInitialization
|
||||
lldbVersion
|
||||
${LLDB_PLUGINS}
|
||||
lldbPluginInstructionARM
|
||||
lldbPluginInstructionMIPS
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#include "SystemInitializerLLGS.h"
|
||||
#include "lldb/Initialization/SystemLifetimeManager.h"
|
||||
#include "lldb/lldb-private.h"
|
||||
#include "lldb/Version/Version.h"
|
||||
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
|
|
|
@ -6,7 +6,6 @@ add_lldb_tool(lldb-test
|
|||
SystemInitializerTest.cpp
|
||||
|
||||
LINK_LIBS
|
||||
lldbBase
|
||||
lldbBreakpoint
|
||||
lldbCore
|
||||
lldbDataFormatters
|
||||
|
@ -17,6 +16,7 @@ add_lldb_tool(lldb-test
|
|||
lldbSymbol
|
||||
lldbTarget
|
||||
lldbUtility
|
||||
lldbVersion
|
||||
${LLDB_ALL_PLUGINS}
|
||||
|
||||
LINK_COMPONENTS
|
||||
|
|
Loading…
Reference in New Issue