Skip to content

Commit 6a15209

Browse files
authored
Merge pull request #3662 from apple/🍒/FBI/ccf1469a4cdb+eaf4f60507fd
[lldb] Make lldbVersion a full fledged library
2 parents f37aacd + 2b93a39 commit 6a15209

File tree

15 files changed

+94
-69
lines changed

15 files changed

+94
-69
lines changed

lldb/include/lldb/Version/Version.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===-- Version.h -----------------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLDB_VERSION_VERSION_H
10+
#define LLDB_VERSION_VERSION_H
11+
12+
#include <string>
13+
14+
namespace lldb_private {
15+
16+
/// Retrieves a string representing the complete LLDB version, which includes
17+
/// the lldb version number, as well as embedded compiler versions and the
18+
/// vendor tag.
19+
const char *GetVersion();
20+
21+
} // namespace lldb_private
22+
23+
#endif // LLDB_VERSION_VERSION_H
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#define LLDB_VERSION @LLDB_VERSION@
2+
#define LLDB_VERSION_STRING "@LLDB_VERSION@"
3+
#define LLDB_VERSION_MAJOR @LLDB_VERSION_MAJOR@
4+
#define LLDB_VERSION_MINOR @LLDB_VERSION_MINOR@
5+
#define LLDB_VERSION_PATCHLEVEL @LLDB_VERSION_PATCHLEVEL@
6+
#cmakedefine LLDB_FULL_VERSION_STRING "@LLDB_FULL_VERSION_STRING@"

lldb/include/lldb/lldb-private.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@
1717
#include "lldb/lldb-private-types.h"
1818
#include "lldb/lldb-public.h"
1919

20-
namespace lldb_private {
21-
22-
const char *GetVersion();
23-
24-
} // namespace lldb_private
25-
2620
#endif // defined(__cplusplus)
2721

2822
#endif // LLDB_LLDB_PRIVATE_H

lldb/source/API/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ add_lldb_library(liblldb SHARED ${option_framework}
104104
${lldb_lua_wrapper}
105105

106106
LINK_LIBS
107-
lldbBase
108107
lldbBreakpoint
109108
lldbCore
110109
lldbDataFormatters
@@ -115,6 +114,7 @@ add_lldb_library(liblldb SHARED ${option_framework}
115114
lldbSymbol
116115
lldbTarget
117116
lldbUtility
117+
lldbVersion
118118
${LLDB_ALL_PLUGINS}
119119
## BEGIN SWIFT
120120
${SWIFT_ALL_LIBS}

lldb/source/API/SBDebugger.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
#include "lldb/API/SBDebugger.h"
1313

14-
#include "lldb/lldb-private.h"
15-
1614
#include "lldb/API/SBBroadcaster.h"
1715
#include "lldb/API/SBCommandInterpreter.h"
1816
#include "lldb/API/SBCommandInterpreterRunOptions.h"
@@ -52,6 +50,7 @@
5250
#include "lldb/Target/TargetList.h"
5351
#include "lldb/Utility/Args.h"
5452
#include "lldb/Utility/State.h"
53+
#include "lldb/Version/Version.h"
5554

5655
#include "llvm/ADT/STLExtras.h"
5756
#include "llvm/ADT/StringRef.h"

lldb/source/API/SBReproducer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "lldb/API/SBHostOS.h"
2424
#include "lldb/API/SBReproducer.h"
2525
#include "lldb/Host/FileSystem.h"
26-
#include "lldb/lldb-private.h"
26+
#include "lldb/Version/Version.h"
2727

2828
using namespace lldb;
2929
using namespace lldb_private;

lldb/source/CMakeLists.txt

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,5 @@
1-
include_directories(.)
2-
3-
set(lldbBase_SOURCES
4-
lldb.cpp
5-
)
6-
7-
8-
find_first_existing_vc_file("${LLDB_SOURCE_DIR}" lldb_vc)
9-
10-
set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSVersion.inc")
11-
set(generate_vcs_version_script "${LLVM_CMAKE_PATH}/GenerateVersionFromVCS.cmake")
12-
13-
if(lldb_vc AND LLVM_APPEND_VC_REV)
14-
set(lldb_source_dir ${LLDB_SOURCE_DIR})
15-
endif()
16-
17-
add_custom_command(OUTPUT "${version_inc}"
18-
DEPENDS "${lldb_vc}" "${generate_vcs_version_script}"
19-
COMMAND ${CMAKE_COMMAND} "-DNAMES=LLDB"
20-
"-DLLDB_SOURCE_DIR=${lldb_source_dir}"
21-
"-DHEADER_FILE=${version_inc}"
22-
-P "${generate_vcs_version_script}")
23-
24-
# Mark the generated header as being generated.
25-
set_source_files_properties("${version_inc}"
26-
PROPERTIES GENERATED TRUE
27-
HEADER_FILE_ONLY TRUE)
28-
29-
list(APPEND lldbBase_SOURCES ${version_inc})
30-
31-
if(LLDB_VERSION_STRING)
32-
set_property(SOURCE lldb.cpp APPEND PROPERTY
33-
COMPILE_DEFINITIONS "LLDB_VERSION_STRING=${LLDB_VERSION_STRING}")
34-
endif()
35-
36-
add_lldb_library(lldbBase
37-
${lldbBase_SOURCES}
38-
)
1+
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
2+
include_directories(${CMAKE_CURRENT_BINARY_DIR})
393

404
add_subdirectory(Breakpoint)
415
add_subdirectory(Commands)
@@ -49,6 +13,7 @@ add_subdirectory(Plugins)
4913
add_subdirectory(Symbol)
5014
add_subdirectory(Target)
5115
add_subdirectory(Utility)
16+
add_subdirectory(Version)
5217

5318
# Build API last. Since liblldb needs to link against every other target, it needs
5419
# those targets to have already been created.

lldb/source/Commands/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ add_lldb_library(lldbCommands
4242
CommandOptionsProcessLaunch.cpp
4343

4444
LINK_LIBS
45-
lldbBase
4645
lldbBreakpoint
4746
lldbCore
4847
lldbDataFormatters
@@ -52,6 +51,7 @@ add_lldb_library(lldbCommands
5251
lldbSymbol
5352
lldbTarget
5453
lldbUtility
54+
lldbVersion
5555

5656
LINK_COMPONENTS
5757
Support

lldb/source/Commands/CommandObjectVersion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "CommandObjectVersion.h"
1010

1111
#include "lldb/Interpreter/CommandReturnObject.h"
12-
#include "lldb/lldb-private.h"
12+
#include "lldb/Version/Version.h"
1313

1414
using namespace lldb;
1515
using namespace lldb_private;

lldb/source/Initialization/SystemInitializerCommon.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "lldb/Utility/Log.h"
1616
#include "lldb/Utility/ReproducerProvider.h"
1717
#include "lldb/Utility/Timer.h"
18-
#include "lldb/lldb-private.h"
18+
#include "lldb/Version/Version.h"
1919

2020
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
2121
#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"

lldb/source/Version/CMakeLists.txt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
if(LLDB_VERSION_STRING)
2+
set(LLDB_FULL_VERSION_STRING LLDB_VERSION_STRING)
3+
endif()
4+
5+
# Configure the VCSVersion.inc file.
6+
set(vcs_version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSVersion.inc")
7+
set(generate_vcs_version_script "${LLVM_CMAKE_DIR}/GenerateVersionFromVCS.cmake")
8+
9+
find_first_existing_vc_file("${LLDB_SOURCE_DIR}" lldb_vc)
10+
11+
if(lldb_vc AND LLVM_APPEND_VC_REV)
12+
set(lldb_source_dir ${LLDB_SOURCE_DIR})
13+
endif()
14+
15+
add_custom_command(OUTPUT "${vcs_version_inc}"
16+
DEPENDS "${lldb_vc}" "${generate_vcs_version_script}"
17+
COMMAND ${CMAKE_COMMAND} "-DNAMES=LLDB"
18+
"-DLLDB_SOURCE_DIR=${lldb_source_dir}"
19+
"-DHEADER_FILE=${vcs_version_inc}"
20+
-P "${generate_vcs_version_script}")
21+
22+
set_source_files_properties("${vcs_version_inc}"
23+
PROPERTIES GENERATED TRUE
24+
HEADER_FILE_ONLY TRUE)
25+
26+
# Configure the Version.inc file.
27+
set(version_inc "${LLDB_BINARY_DIR}/include/lldb/Version/Version.inc")
28+
29+
configure_file(
30+
${LLDB_SOURCE_DIR}/include/lldb/Version/Version.inc.in
31+
${version_inc})
32+
33+
set_source_files_properties("${version_inc}"
34+
PROPERTIES GENERATED TRUE
35+
HEADER_FILE_ONLY TRUE)
36+
37+
include_directories(${CMAKE_CURRENT_BINARY_DIR})
38+
39+
add_lldb_library(lldbVersion
40+
Version.cpp
41+
${vcs_version_inc}
42+
${version_inc})

lldb/source/lldb.cpp renamed to lldb/source/Version/Version.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
1-
//===-- lldb.cpp ----------------------------------------------------------===//
1+
//===-- Version.cpp -------------------------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "lldb/Version/Version.h"
910
#include "VCSVersion.inc"
10-
#include "lldb/lldb-private.h"
11+
#include "lldb/Version/Version.inc"
1112
#include "clang/Basic/Version.h"
1213

1314
#ifdef LLDB_ENABLE_SWIFT
1415
#include "swift/Basic/Version.h"
1516
#endif // LLDB_ENABLE_SWIFT
1617

17-
using namespace lldb;
18-
using namespace lldb_private;
19-
20-
// LLDB_VERSION_STRING is set through a define so unlike the other defines
21-
// expanded with CMake, it lacks the double quotes.
22-
#define QUOTE(str) #str
23-
#define EXPAND_AND_QUOTE(str) QUOTE(str)
24-
2518
static const char *GetLLDBVersion() {
26-
#ifdef LLDB_VERSION_STRING
27-
return EXPAND_AND_QUOTE(LLDB_VERSION_STRING);
19+
#ifdef LLDB_FULL_VERSION_STRING
20+
return LLDB_FULL_VERSION_STRING;
2821
#else
2922
return "lldb version " CLANG_VERSION_STRING;
3023
#endif
@@ -34,20 +27,21 @@ static const char *GetLLDBRevision() {
3427
#ifdef LLDB_REVISION
3528
return LLDB_REVISION;
3629
#else
37-
return NULL;
30+
return nullptr;
3831
#endif
3932
}
4033

4134
static const char *GetLLDBRepository() {
4235
#ifdef LLDB_REPOSITORY
4336
return LLDB_REPOSITORY;
4437
#else
45-
return NULL;
38+
return nullptr;
4639
#endif
4740
}
4841

4942
const char *lldb_private::GetVersion() {
5043
static std::string g_version_str;
44+
5145
if (g_version_str.empty()) {
5246
const char *lldb_version = GetLLDBVersion();
5347
const char *lldb_repo = GetLLDBRepository();
@@ -78,12 +72,14 @@ const char *lldb_private::GetVersion() {
7872
g_version_str += "\n clang revision ";
7973
g_version_str += clang_rev;
8074
}
75+
8176
std::string llvm_rev(clang::getLLVMRevision());
8277
if (llvm_rev.length() > 0) {
8378
g_version_str += "\n llvm revision ";
8479
g_version_str += llvm_rev;
8580
}
86-
#endif // LLDB_ENABLE_SWIFT
81+
#endif
8782
}
83+
8884
return g_version_str.c_str();
8985
}

lldb/tools/lldb-server/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ add_lldb_tool(lldb-server
4646
SystemInitializerLLGS.cpp
4747

4848
LINK_LIBS
49-
lldbBase
5049
lldbHost
5150
lldbInitialization
51+
lldbVersion
5252
${LLDB_PLUGINS}
5353
lldbPluginInstructionARM
5454
lldbPluginInstructionMIPS

lldb/tools/lldb-server/lldb-server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "SystemInitializerLLGS.h"
1010
#include "lldb/Initialization/SystemLifetimeManager.h"
11-
#include "lldb/lldb-private.h"
11+
#include "lldb/Version/Version.h"
1212

1313
#include "llvm/ADT/STLExtras.h"
1414
#include "llvm/ADT/StringRef.h"

lldb/tools/lldb-test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ add_lldb_tool(lldb-test
66
SystemInitializerTest.cpp
77

88
LINK_LIBS
9-
lldbBase
109
lldbBreakpoint
1110
lldbCore
1211
lldbDataFormatters
@@ -17,6 +16,7 @@ add_lldb_tool(lldb-test
1716
lldbSymbol
1817
lldbTarget
1918
lldbUtility
19+
lldbVersion
2020
${LLDB_ALL_PLUGINS}
2121
${host_lib}
2222

0 commit comments

Comments
 (0)