Skip to content

Commit 7116a31

Browse files
Merge pull request #6906 from Michael137/bugfix/lldb-buildbots-fixes
[cherry-pick][stable/20221013] [lldb][cmake] Allow specifying custom libcxx for tests in standalone builds
2 parents c287648 + dcaff83 commit 7116a31

File tree

13 files changed

+84
-19
lines changed

13 files changed

+84
-19
lines changed

lldb/cmake/modules/LLDBStandalone.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ set(LLVM_MAIN_SRC_DIR ${LLVM_BUILD_MAIN_SRC_DIR} CACHE PATH "Path to LLVM source
2525
set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_INCLUDE_DIR} CACHE PATH "Path to llvm/include")
2626
set(LLVM_BINARY_DIR ${LLVM_BINARY_DIR} CACHE PATH "Path to LLVM build tree")
2727

28+
set(LLDB_TEST_LIBCXX_ROOT_DIR "${LLVM_BINARY_DIR}" CACHE PATH
29+
"The build root for libcxx. Used in standalone builds to point the API tests to a custom build of libcxx.")
30+
2831
set(LLVM_LIT_ARGS "-sv" CACHE STRING "Default options for lit")
2932

3033
set(lit_file_name "llvm-lit")

lldb/packages/Python/lldbsuite/test/builders/builder.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,12 @@ def getModuleCacheSpec(self):
135135

136136
def getLibCxxArgs(self):
137137
if configuration.libcxx_include_dir and configuration.libcxx_library_dir:
138-
return ["LIBCPP_INCLUDE_DIR={}".format(configuration.libcxx_include_dir),
139-
"LIBCPP_LIBRARY_DIR={}".format(configuration.libcxx_library_dir)]
138+
libcpp_args = ["LIBCPP_INCLUDE_DIR={}".format(configuration.libcxx_include_dir),
139+
"LIBCPP_LIBRARY_DIR={}".format(configuration.libcxx_library_dir)]
140+
if configuration.libcxx_include_target_dir:
141+
libcpp_args.append("LIBCPP_INCLUDE_TARGET_DIR={}".format(
142+
configuration.libcxx_include_target_dir))
143+
return libcpp_args
140144
return []
141145

142146
def getLLDBSwiftLibs(self):

lldb/packages/Python/lldbsuite/test/configuration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
lldb_libs_dir = None
132132

133133
libcxx_include_dir = None
134+
libcxx_include_target_dir = None
134135
libcxx_library_dir = None
135136

136137
# A plugin whose tests will be enabled, like intel-pt.

lldb/packages/Python/lldbsuite/test/dotest.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,17 +280,15 @@ def parseOptionsAndInitTestdirs():
280280
logging.warning('No valid FileCheck executable; some tests may fail...')
281281
logging.warning('(Double-check the --llvm-tools-dir argument to dotest.py)')
282282

283-
configuration.libcxx_include_dir = args.libcxx_include_dir
284-
configuration.libcxx_library_dir = args.libcxx_library_dir
285283
if args.libcxx_include_dir or args.libcxx_library_dir:
286284
if args.lldb_platform_name:
287285
logging.warning('Custom libc++ is not supported for remote runs: ignoring --libcxx arguments')
288-
elif args.libcxx_include_dir and args.libcxx_library_dir:
289-
configuration.libcxx_include_dir = args.libcxx_include_dir
290-
configuration.libcxx_library_dir = args.libcxx_library_dir
291-
else:
286+
elif not (args.libcxx_include_dir and args.libcxx_library_dir):
292287
logging.error('Custom libc++ requires both --libcxx-include-dir and --libcxx-library-dir')
293288
sys.exit(-1)
289+
configuration.libcxx_include_dir = args.libcxx_include_dir
290+
configuration.libcxx_include_target_dir = args.libcxx_include_target_dir
291+
configuration.libcxx_library_dir = args.libcxx_library_dir
294292

295293
if args.channels:
296294
lldbtest_config.channels = args.channels

lldb/packages/Python/lldbsuite/test/dotest_args.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ def create_parser():
4747
if sys.platform == 'darwin':
4848
group.add_argument('--apple-sdk', metavar='apple_sdk', dest='apple_sdk', default="", help=textwrap.dedent(
4949
'''Specify the name of the Apple SDK (macosx, macosx.internal, iphoneos, iphoneos.internal, or path to SDK) and use the appropriate tools from that SDK's toolchain.'''))
50-
group.add_argument('--libcxx-include-dir', help=textwrap.dedent('Specify the path to a custom libc++ include directory. Must be used in conjunction with --libcxx-library-dir.'))
51-
group.add_argument('--libcxx-library-dir', help=textwrap.dedent('Specify the path to a custom libc++ library directory. Must be used in conjunction with --libcxx-include-dir.'))
50+
group.add_argument('--libcxx-include-dir', help=textwrap.dedent(
51+
'Specify the path to a custom libc++ include directory. Must be used in conjunction with --libcxx-library-dir.'))
52+
group.add_argument('--libcxx-include-target-dir', help=textwrap.dedent(
53+
'Specify the path to a custom libc++ include target directory to use in addition to --libcxx-include-dir. Optional.'))
54+
group.add_argument('--libcxx-library-dir', help=textwrap.dedent(
55+
'Specify the path to a custom libc++ library directory. Must be used in conjunction with --libcxx-include-dir.'))
5256
# FIXME? This won't work for different extra flags according to each arch.
5357
group.add_argument(
5458
'-E',

lldb/packages/Python/lldbsuite/test/make/Makefile.rules

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,10 @@ endif
482482
ifeq (1,$(USE_LIBCPP))
483483
ifneq ($(and $(LIBCPP_INCLUDE_DIR), $(LIBCPP_LIBRARY_DIR)),)
484484
CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(LIBCPP_INCLUDE_DIR)
485-
LDFLAGS += -L$(LLVM_LIBS_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++
485+
ifneq "$(LIBCPP_INCLUDE_TARGET_DIR)" ""
486+
CXXFLAGS += -cxx-isystem $(LIBCPP_INCLUDE_TARGET_DIR)
487+
endif
488+
LDFLAGS += -L$(LIBCPP_LIBRARY_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++
486489
else
487490
ifeq "$(OS)" "Android"
488491
# Nothing to do, this is already handled in
@@ -504,7 +507,10 @@ endif
504507
ifeq ($(or $(USE_LIBSTDCPP), $(USE_LIBCPP), $(USE_SYSTEM_STDLIB)),)
505508
ifneq ($(and $(LIBCPP_INCLUDE_DIR), $(LIBCPP_LIBRARY_DIR)),)
506509
CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(LIBCPP_INCLUDE_DIR)
507-
LDFLAGS += -L$(LLVM_LIBS_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++
510+
ifneq "$(LIBCPP_INCLUDE_TARGET_DIR)" ""
511+
CXXFLAGS += -cxx-isystem $(LIBCPP_INCLUDE_TARGET_DIR)
512+
endif
513+
LDFLAGS += -L$(LIBCPP_LIBRARY_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++
508514
endif
509515
endif
510516

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/ranges/ref_view/TestDataFormatterLibcxxRangesRefView.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def check_foo(self):
2828
children=self.check_string_vec_children())
2929

3030
@add_test_categories(["libc++"])
31-
@skipIf(bugnumber="rdar://109455906") # The standalone build of LLDB doesn't test against custom libcxx builds
3231
def test_with_run_command(self):
3332
"""Test that std::ranges::ref_view is formatted correctly when printed.
3433
"""

lldb/test/API/lang/cpp/std-function-step-into-callable/TestStdFunctionStepIntoCallable.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class LibCxxFunctionSteppingIntoCallableTestCase(TestBase):
1414

1515
NO_DEBUG_INFO_TESTCASE = True
1616

17+
@skipIfDarwin
1718
@add_test_categories(["libc++"])
1819
def test(self):
1920
"""Test that std::function as defined by libc++ is correctly printed by LLDB"""

lldb/test/API/lit.cfg.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,11 @@ def delete_module_cache(path):
181181
# If we have a just-built libcxx, prefer it over the system one.
182182
if is_configured('has_libcxx') and config.has_libcxx:
183183
if platform.system() != 'Windows':
184-
if is_configured('llvm_include_dir') and is_configured('llvm_libs_dir'):
185-
dotest_cmd += ['--libcxx-include-dir', os.path.join(config.llvm_include_dir, 'c++', 'v1')]
186-
dotest_cmd += ['--libcxx-library-dir', config.llvm_libs_dir]
184+
if is_configured('libcxx_include_dir') and is_configured('libcxx_libs_dir'):
185+
dotest_cmd += ['--libcxx-include-dir', config.libcxx_include_dir]
186+
if is_configured('libcxx_include_target_dir'):
187+
dotest_cmd += ['--libcxx-include-target-dir', config.libcxx_include_target_dir]
188+
dotest_cmd += ['--libcxx-library-dir', config.libcxx_libs_dir]
187189

188190
# Forward ASan-specific environment variables to tests, as a test may load an
189191
# ASan-ified dylib.

lldb/test/API/lit.site.cfg.py.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ config.test_compiler = lit_config.substitute('@LLDB_TEST_COMPILER@')
3333
config.test_swift_compiler = lit_config.substitute('@LLDB_SWIFTC@')
3434
config.dsymutil = lit_config.substitute('@LLDB_TEST_DSYMUTIL@')
3535
config.has_libcxx = @LLDB_HAS_LIBCXX@
36+
config.libcxx_libs_dir = "@LIBCXX_LIBRARY_DIR@"
37+
config.libcxx_include_dir = "@LIBCXX_GENERATED_INCLUDE_DIR@"
38+
config.libcxx_include_target_dir = "@LIBCXX_GENERATED_INCLUDE_TARGET_DIR@"
3639
# The API tests use their own module caches.
3740
config.lldb_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_LLDB@", "lldb-api")
3841
config.clang_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_CLANG@", "lldb-api")

lldb/test/CMakeLists.txt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ if(TARGET clang)
122122

123123
if (TARGET libcxx OR ("libcxx" IN_LIST LLVM_ENABLE_RUNTIMES))
124124
set(LLDB_HAS_LIBCXX ON)
125+
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
126+
set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
127+
set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
128+
set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1")
129+
else()
130+
set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
131+
set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1")
132+
endif()
125133
add_lldb_test_dependency(cxx)
126134
endif()
127135

@@ -134,9 +142,18 @@ if(TARGET clang)
134142
# FIXME: Standalone builds should import the cxx target as well.
135143
if(LLDB_BUILT_STANDALONE)
136144
# For now check that the include directory exists.
137-
set(cxx_dir "${LLVM_BINARY_DIR}/include/c++")
138-
if(NOT EXISTS ${cxx_dir})
139-
message(WARNING "LLDB test suite requires libc++ in llvm/projects/libcxx or an existing build symlinked to ${cxx_dir}")
145+
set(cxx_dir "${LLDB_TEST_LIBCXX_ROOT_DIR}/include/c++")
146+
if(EXISTS ${cxx_dir})
147+
# These variables make sure the API tests can run against a custom
148+
# build of libcxx even for standalone builds.
149+
set(LLDB_HAS_LIBCXX ON)
150+
set(LIBCXX_LIBRARY_DIR "${LLDB_TEST_LIBCXX_ROOT_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}")
151+
set(LIBCXX_GENERATED_INCLUDE_DIR "${LLDB_TEST_LIBCXX_ROOT_DIR}/include/c++/v1")
152+
else()
153+
message(FATAL_ERROR
154+
"Couldn't find libcxx build in '${LLDB_TEST_LIBCXX_ROOT_DIR}'. To run the "
155+
"test-suite for a standalone LLDB build please build libcxx and point "
156+
"LLDB_TEST_LIBCXX_ROOT_DIR to it.")
140157
endif()
141158
else()
142159
# We require libcxx for the test suite, so if we aren't building it,

lldb/utils/lldb-dotest/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,21 @@ set(LLDB_LIBS_DIR "${LLVM_LIBRARY_OUTPUT_INTDIR}")
99

1010
llvm_canonicalize_cmake_booleans(
1111
LLDB_BUILD_INTEL_PT
12+
LLDB_HAS_LIBCXX
1213
)
1314

15+
if ("libcxx" IN_LIST LLVM_ENABLE_RUNTIMES)
16+
set(LLDB_HAS_LIBCXX ON)
17+
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
18+
set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
19+
set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
20+
set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1")
21+
else()
22+
set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
23+
set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1")
24+
endif()
25+
endif()
26+
1427
set(LLVM_TOOLS_DIR "${LLVM_TOOLS_BINARY_DIR}")
1528
set(vars
1629
LLDB_TEST_COMMON_ARGS
@@ -24,8 +37,13 @@ set(vars
2437
LLDB_LIBS_DIR
2538
LLVM_TOOLS_DIR
2639
LLDB_SWIFTC
40+
LIBCXX_LIBRARY_DIR
41+
LIBCXX_GENERATED_INCLUDE_DIR
42+
LIBCXX_GENERATED_INCLUDE_TARGET_DIR
2743
)
2844

45+
llvm_canonicalize_cmake_booleans(LLDB_HAS_LIBCXX)
46+
2947
# Generate lldb-dotest Python driver script for each build mode.
3048
if(LLDB_BUILT_STANDALONE)
3149
set(config_types ".")

lldb/utils/lldb-dotest/lldb-dotest.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ lldb_framework_dir = "@LLDB_FRAMEWORK_DIR_CONFIGURED@"
1515
lldb_libs_dir = "@LLDB_LIBS_DIR_CONFIGURED@"
1616
llvm_tools_dir = "@LLVM_TOOLS_DIR_CONFIGURED@"
1717
swift_libs_dir = '@LLDB_SWIFT_LIBS@'
18+
has_libcxx = @LLDB_HAS_LIBCXX@
19+
libcxx_libs_dir = "@LIBCXX_LIBRARY_DIR@"
20+
libcxx_include_dir = "@LIBCXX_GENERATED_INCLUDE_DIR@"
21+
libcxx_include_target_dir = "@LIBCXX_GENERATED_INCLUDE_TARGET_DIR@"
1822

1923
if __name__ == '__main__':
2024
wrapper_args = sys.argv[1:]
@@ -35,6 +39,11 @@ if __name__ == '__main__':
3539
cmd.extend(['--llvm-tools-dir', llvm_tools_dir])
3640
if swift_compiler:
3741
cmd.extend(['--swift-compiler', swift_compiler])
42+
if has_libcxx:
43+
cmd.extend(['--libcxx-include-dir', libcxx_include_dir])
44+
if libcxx_include_target_dir:
45+
cmd.extend(['--libcxx-include-target-dir', libcxx_include_target_dir])
46+
cmd.extend(['--libcxx-library-dir', libcxx_libs_dir])
3847
if lldb_framework_dir:
3948
cmd.extend(['--framework', lldb_framework_dir])
4049
if lldb_build_intel_pt == "1":

0 commit comments

Comments
 (0)