Skip to content

Commit 66e9cce

Browse files
authored
Merge pull request #6532 from bulbazord/20221013/guard-swift-changes
[LLDB] Support building LLDB standalone without Swift
2 parents f388e67 + bf94658 commit 66e9cce

File tree

5 files changed

+62
-33
lines changed

5 files changed

+62
-33
lines changed

lldb/CMakeLists.txt

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ endif()
1717
# Must go below project(..)
1818
include(GNUInstallDirs)
1919

20+
# BEGIN SWIFT MOD
21+
option(LLDB_ENABLE_SWIFT_SUPPORT "Enable swift support" ON)
22+
# END SWIFT MOD
23+
2024
if(LLDB_BUILT_STANDALONE)
2125
include(LLDBStandalone)
2226

@@ -33,25 +37,29 @@ include(LLDBConfig)
3337
include(AddLLDB)
3438

3539
# BEGIN - Swift Mods
36-
if(EXISTS "${LLVM_EXTERNAL_SWIFT_SOURCE_DIR}")
37-
list(APPEND CMAKE_MODULE_PATH
38-
"${LLVM_EXTERNAL_SWIFT_SOURCE_DIR}/cmake"
39-
"${LLVM_EXTERNAL_SWIFT_SOURCE_DIR}/cmake/modules")
40-
elseif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../swift)
41-
list(APPEND CMAKE_MODULE_PATH
42-
"${CMAKE_CURRENT_SOURCE_DIR}/../swift/cmake"
43-
"${CMAKE_CURRENT_SOURCE_DIR}/../swift/cmake/modules")
40+
if (LLDB_ENABLE_SWIFT_SUPPORT)
41+
if(EXISTS "${LLVM_EXTERNAL_SWIFT_SOURCE_DIR}")
42+
list(APPEND CMAKE_MODULE_PATH
43+
"${LLVM_EXTERNAL_SWIFT_SOURCE_DIR}/cmake"
44+
"${LLVM_EXTERNAL_SWIFT_SOURCE_DIR}/cmake/modules")
45+
elseif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../swift)
46+
list(APPEND CMAKE_MODULE_PATH
47+
"${CMAKE_CURRENT_SOURCE_DIR}/../swift/cmake"
48+
"${CMAKE_CURRENT_SOURCE_DIR}/../swift/cmake/modules")
49+
endif()
4450
endif()
4551

4652
# When we have the early SwiftSyntax build, we can include its parser.
47-
if(SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR)
48-
set(SWIFT_PATH_TO_EARLYSWIFTSYNTAX_TARGETS
49-
${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/cmake/SwiftSyntaxTargets.cmake)
50-
if(NOT EXISTS "${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_TARGETS}")
51-
message(STATUS "Skipping Swift Swift parser integration due to missing early SwiftSyntax")
52-
else()
53-
set(SWIFT_SWIFT_PARSER TRUE)
54-
include(${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_TARGETS})
53+
if (LLDB_ENABLE_SWIFT_SUPPORT)
54+
if(SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR)
55+
set(SWIFT_PATH_TO_EARLYSWIFTSYNTAX_TARGETS
56+
${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/cmake/SwiftSyntaxTargets.cmake)
57+
if(NOT EXISTS "${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_TARGETS}")
58+
message(STATUS "Skipping Swift Swift parser integration due to missing early SwiftSyntax")
59+
else()
60+
set(SWIFT_SWIFT_PARSER TRUE)
61+
include(${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_TARGETS})
62+
endif()
5563
endif()
5664
endif()
5765
# END - Swift Mods

lldb/cmake/modules/LLDBConfig.cmake

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,18 @@ option(LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS
8686
"Fail to configure if certain requirements are not met for testing." OFF)
8787

8888
# BEGIN SWIFT MOD
89-
option(LLDB_ENABLE_SWIFT_SUPPORT "Enable swift support" ON)
9089
option(LLDB_ENABLE_WERROR "Fail and stop if a warning is triggered." ${LLVM_ENABLE_WERROR})
9190
if(LLDB_ENABLE_SWIFT_SUPPORT)
9291
add_definitions( -DLLDB_ENABLE_SWIFT )
92+
else()
93+
# LLVM_DISTRIBUTION_COMPONENTS may have swift-specific things in them (e.g.
94+
# repl_swift). This may be set in a cache where LLDB_ENABLE_SWIFT_SUPPORT does
95+
# not yet have a value. We have to touch up LLVM_DISTRIBUTION_COMPONENTS after
96+
# the fact.
97+
if(LLVM_DISTRIBUTION_COMPONENTS)
98+
list(REMOVE_ITEM LLVM_DISTRIBUTION_COMPONENTS repl_swift)
99+
set(LLVM_DISTRIBUTION_COMPONENTS ${LLVM_DISTRIBUTION_COMPONENTS} CACHE STRING "" FORCE)
100+
endif()
93101
endif()
94102
# END SWIFT CODE
95103

@@ -210,17 +218,19 @@ else ()
210218
endif ()
211219
include_directories("${CMAKE_CURRENT_BINARY_DIR}/../clang/include")
212220

213-
if(NOT LLDB_BUILT_STANDALONE)
214-
if (LLVM_EXTERNAL_SWIFT_SOURCE_DIR)
215-
include_directories(${LLVM_EXTERNAL_SWIFT_SOURCE_DIR}/include)
216-
include_directories(${LLVM_EXTERNAL_SWIFT_SOURCE_DIR}/stdlib/public/SwiftShims)
221+
if(LLDB_ENABLE_SWIFT_SUPPORT)
222+
if(NOT LLDB_BUILT_STANDALONE)
223+
if (LLVM_EXTERNAL_SWIFT_SOURCE_DIR)
224+
include_directories(${LLVM_EXTERNAL_SWIFT_SOURCE_DIR}/include)
225+
include_directories(${LLVM_EXTERNAL_SWIFT_SOURCE_DIR}/stdlib/public/SwiftShims)
226+
else ()
227+
include_directories(${CMAKE_SOURCE_DIR}/tools/swift/include)
228+
include_directories(${CMAKE_SOURCE_DIR}/tools/swift/stdlib/public/SwiftShims)
229+
endif ()
230+
include_directories("${CMAKE_CURRENT_BINARY_DIR}/../swift/include")
217231
else ()
218-
include_directories(${CMAKE_SOURCE_DIR}/tools/swift/include)
219-
include_directories(${CMAKE_SOURCE_DIR}/tools/swift/stdlib/public/SwiftShims)
220-
endif ()
221-
include_directories("${CMAKE_CURRENT_BINARY_DIR}/../swift/include")
222-
else ()
223-
include_directories("${SWIFT_INCLUDE_DIRS}")
232+
include_directories("${SWIFT_INCLUDE_DIRS}")
233+
endif()
224234
endif()
225235

226236
# GCC silently accepts any -Wno-<foo> option, but warns about those options

lldb/cmake/modules/LLDBStandalone.cmake

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install
1414

1515
find_package(LLVM REQUIRED CONFIG HINTS ${LLVM_DIR} NO_CMAKE_FIND_ROOT_PATH)
1616
find_package(Clang REQUIRED CONFIG HINTS ${Clang_DIR} ${LLVM_DIR}/../clang NO_CMAKE_FIND_ROOT_PATH)
17-
find_package(Swift REQUIRED CONFIG HINTS "${Swift_DIR}" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
17+
if(LLDB_ENABLE_SWIFT_SUPPORT)
18+
find_package(Swift REQUIRED CONFIG HINTS "${Swift_DIR}" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
19+
endif()
1820

1921
# We set LLVM_CMAKE_DIR so that GetSVN.cmake is found correctly when building SVNVersion.inc
2022
set(LLVM_CMAKE_DIR ${LLVM_CMAKE_DIR} CACHE PATH "Path to LLVM CMake modules")
@@ -88,7 +90,9 @@ endif()
8890
# CMake modules to be in that directory as well.
8991
file(TO_CMAKE_PATH ${LLVM_DIR} LLVM_DIR)
9092
list(APPEND CMAKE_MODULE_PATH "${LLVM_DIR}")
91-
list(APPEND CMAKE_MODULE_PATH "${SWIFT_CMAKE_DIR}")
93+
if(LLDB_ENABLE_SWIFT_SUPPORT)
94+
list(APPEND CMAKE_MODULE_PATH "${SWIFT_CMAKE_DIR}")
95+
endif()
9296

9397
include(AddLLVM)
9498
include(TableGen)
@@ -124,9 +128,12 @@ include_directories(
124128
"${CMAKE_BINARY_DIR}/include"
125129
"${LLVM_INCLUDE_DIRS}"
126130
"${CLANG_INCLUDE_DIRS}"
127-
"${SWIFT_INCLUDE_DIRS}"
128-
"${SWIFT_MAIN_SRC_DIR}/include"
129131
"${CMAKE_CURRENT_SOURCE_DIR}/source")
132+
if(LLDB_ENABLE_SWIFT_SUPPORT)
133+
include_directories(
134+
"${SWIFT_INCLUDE_DIRS}"
135+
"${SWIFT_MAIN_SRC_DIR}/include")
136+
endif()
130137

131138
if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS)
132139
set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)

lldb/test/API/commands/dwim-print/swift/TestDWIMPrintSwift.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from lldbsuite.test.decorators import *
88
import lldbsuite.test.lldbutil as lldbutil
99

10-
1110
class TestCase(TestBase):
11+
@swiftTest
1212
def test_swift_po_address(self):
1313
self.build()
1414
_, _, thread, _ = lldbutil.run_to_source_breakpoint(
@@ -20,6 +20,7 @@ def test_swift_po_address(self):
2020
self.expect(f"dwim-print -O -- 0x{hex_addr}", patterns=[f"Object@0x0*{hex_addr}"])
2121
self.expect(f"dwim-print -O -- {addr}", patterns=[f"Object@0x0*{hex_addr}"])
2222

23+
@swiftTest
2324
def test_swift_po_non_address_hex(self):
2425
"""No special handling of non-memory integer values."""
2526
self.build()

lldb/test/API/functionalities/breakpoint/swift_exception/TestExpressionErrorBreakpoint.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,29 @@ class TestSwiftErrorBreakpoint(TestBase):
2828
@swiftTest
2929
def test_swift_error_no_typename(self):
3030
"""Tests that swift error throws are correctly caught by the Swift Error breakpoint"""
31+
self.build()
3132
self.do_tests(None, True)
3233

3334
@swiftTest
3435
def test_swift_error_matching_base_typename(self):
3536
"""Tests that swift error throws are correctly caught by the Swift Error breakpoint"""
37+
self.build()
3638
self.do_tests("EnumError", True)
3739

3840
@swiftTest
3941
def test_swift_error_matching_full_typename(self):
4042
"""Tests that swift error throws are correctly caught by the Swift Error breakpoint"""
43+
self.build()
4144
self.do_tests("a.EnumError", True)
4245

4346
@swiftTest
4447
def test_swift_error_bogus_typename(self):
4548
"""Tests that swift error throws are correctly caught by the Swift Error breakpoint"""
49+
self.build()
4650
self.do_tests("NoSuchErrorHere", False)
4751

4852
def setUp(self):
4953
TestBase.setUp(self)
50-
self.build()
5154

5255
def do_tests(self, typename, should_stop):
5356
self.do_test(typename, should_stop, self.create_breakpoint_with_api)

0 commit comments

Comments
 (0)