Skip to content

[lldb] Make lldbVersion a full fledged library #3662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lldb/include/lldb/Version/Version.h
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions lldb/include/lldb/Version/Version.inc.in
Original file line number Diff line number Diff line change
@@ -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@"
6 changes: 0 additions & 6 deletions lldb/include/lldb/lldb-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lldb/source/API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ add_lldb_library(liblldb SHARED ${option_framework}
${lldb_lua_wrapper}

LINK_LIBS
lldbBase
lldbBreakpoint
lldbCore
lldbDataFormatters
Expand All @@ -115,6 +114,7 @@ add_lldb_library(liblldb SHARED ${option_framework}
lldbSymbol
lldbTarget
lldbUtility
lldbVersion
${LLDB_ALL_PLUGINS}
## BEGIN SWIFT
${SWIFT_ALL_LIBS}
Expand Down
3 changes: 1 addition & 2 deletions lldb/source/API/SBDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/API/SBReproducer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
41 changes: 3 additions & 38 deletions lldb/source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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_PATH}/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)
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Commands/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ add_lldb_library(lldbCommands
CommandOptionsProcessLaunch.cpp

LINK_LIBS
lldbBase
lldbBreakpoint
lldbCore
lldbDataFormatters
Expand All @@ -52,6 +51,7 @@ add_lldb_library(lldbCommands
lldbSymbol
lldbTarget
lldbUtility
lldbVersion

LINK_COMPONENTS
Support
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Commands/CommandObjectVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Initialization/SystemInitializerCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
42 changes: 42 additions & 0 deletions lldb/source/Version/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
26 changes: 11 additions & 15 deletions lldb/source/lldb.cpp → lldb/source/Version/Version.cpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
//===-- lldb.cpp ----------------------------------------------------------===//
//===-- 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/lldb-private.h"
#include "lldb/Version/Version.inc"
#include "clang/Basic/Version.h"

#ifdef LLDB_ENABLE_SWIFT
#include "swift/Basic/Version.h"
#endif // LLDB_ENABLE_SWIFT

using namespace lldb;
using namespace lldb_private;

// LLDB_VERSION_STRING is set through a define so unlike the other defines
// expanded with CMake, it lacks the double quotes.
#define QUOTE(str) #str
#define EXPAND_AND_QUOTE(str) QUOTE(str)

static const char *GetLLDBVersion() {
#ifdef LLDB_VERSION_STRING
return EXPAND_AND_QUOTE(LLDB_VERSION_STRING);
#ifdef LLDB_FULL_VERSION_STRING
return LLDB_FULL_VERSION_STRING;
#else
return "lldb version " CLANG_VERSION_STRING;
#endif
Expand All @@ -34,20 +27,21 @@ static const char *GetLLDBRevision() {
#ifdef LLDB_REVISION
return LLDB_REVISION;
#else
return NULL;
return nullptr;
#endif
}

static const char *GetLLDBRepository() {
#ifdef LLDB_REPOSITORY
return LLDB_REPOSITORY;
#else
return NULL;
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();
Expand Down Expand Up @@ -78,12 +72,14 @@ const char *lldb_private::GetVersion() {
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;
}
#endif // LLDB_ENABLE_SWIFT
#endif
}

return g_version_str.c_str();
}
2 changes: 1 addition & 1 deletion lldb/tools/lldb-server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ add_lldb_tool(lldb-server
SystemInitializerLLGS.cpp

LINK_LIBS
lldbBase
lldbHost
lldbInitialization
lldbVersion
${LLDB_PLUGINS}
lldbPluginInstructionARM
lldbPluginInstructionMIPS
Expand Down
2 changes: 1 addition & 1 deletion lldb/tools/lldb-server/lldb-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lldb/tools/lldb-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ add_lldb_tool(lldb-test
SystemInitializerTest.cpp

LINK_LIBS
lldbBase
lldbBreakpoint
lldbCore
lldbDataFormatters
Expand All @@ -17,6 +16,7 @@ add_lldb_tool(lldb-test
lldbSymbol
lldbTarget
lldbUtility
lldbVersion
${LLDB_ALL_PLUGINS}
${host_lib}

Expand Down