Skip to content

Commit ccf1469

Browse files
committed
[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
1 parent cc8dc5e commit ccf1469

File tree

15 files changed

+156
-54
lines changed

15 files changed

+156
-54
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
@@ -94,7 +94,6 @@ add_lldb_library(liblldb SHARED ${option_framework}
9494
${lldb_lua_wrapper}
9595

9696
LINK_LIBS
97-
lldbBase
9897
lldbBreakpoint
9998
lldbCore
10099
lldbDataFormatters
@@ -105,6 +104,7 @@ add_lldb_library(liblldb SHARED ${option_framework}
105104
lldbSymbol
106105
lldbTarget
107106
lldbUtility
107+
lldbVersion
108108
${LLDB_ALL_PLUGINS}
109109
LINK_COMPONENTS
110110
Support

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_DIR}/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
@@ -41,7 +41,6 @@ add_lldb_library(lldbCommands
4141
CommandOptionsProcessLaunch.cpp
4242

4343
LINK_LIBS
44-
lldbBase
4544
lldbBreakpoint
4645
lldbCore
4746
lldbDataFormatters
@@ -51,6 +50,7 @@ add_lldb_library(lldbCommands
5150
lldbSymbol
5251
lldbTarget
5352
lldbUtility
53+
lldbVersion
5454

5555
LINK_COMPONENTS
5656
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/Version/Version.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//===-- Version.cpp -------------------------------------------------------===//
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+
#include "lldb/Version/Version.h"
10+
#include "VCSVersion.inc"
11+
#include "lldb/Version/Version.inc"
12+
#include "clang/Basic/Version.h"
13+
14+
static const char *GetLLDBVersion() {
15+
#ifdef LLDB_FULL_VERSION_STRING
16+
return LLDB_FULL_VERSION_STRING;
17+
#else
18+
return "lldb version " CLANG_VERSION_STRING;
19+
#endif
20+
}
21+
22+
static const char *GetLLDBRevision() {
23+
#ifdef LLDB_REVISION
24+
return LLDB_REVISION;
25+
#else
26+
return nullptr;
27+
#endif
28+
}
29+
30+
static const char *GetLLDBRepository() {
31+
#ifdef LLDB_REPOSITORY
32+
return LLDB_REPOSITORY;
33+
#else
34+
return nullptr;
35+
#endif
36+
}
37+
38+
const char *lldb_private::GetVersion() {
39+
static std::string g_version_str;
40+
41+
if (g_version_str.empty()) {
42+
const char *lldb_version = GetLLDBVersion();
43+
const char *lldb_repo = GetLLDBRepository();
44+
const char *lldb_rev = GetLLDBRevision();
45+
g_version_str += lldb_version;
46+
if (lldb_repo || lldb_rev) {
47+
g_version_str += " (";
48+
if (lldb_repo)
49+
g_version_str += lldb_repo;
50+
if (lldb_repo && lldb_rev)
51+
g_version_str += " ";
52+
if (lldb_rev) {
53+
g_version_str += "revision ";
54+
g_version_str += lldb_rev;
55+
}
56+
g_version_str += ")";
57+
}
58+
59+
std::string clang_rev(clang::getClangRevision());
60+
if (clang_rev.length() > 0) {
61+
g_version_str += "\n clang revision ";
62+
g_version_str += clang_rev;
63+
}
64+
65+
std::string llvm_rev(clang::getLLVMRevision());
66+
if (llvm_rev.length() > 0) {
67+
g_version_str += "\n llvm revision ";
68+
g_version_str += llvm_rev;
69+
}
70+
}
71+
72+
return g_version_str.c_str();
73+
}

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

2222
LINK_COMPONENTS

0 commit comments

Comments
 (0)