Skip to content

Commit

Permalink
[libc++] Serialize Lit parameters to make them available to from-scra…
Browse files Browse the repository at this point in the history
…tch configs

Before this patch, Lit parameters that were set as a result of CMake
options were not made available to from-scratch configs. This patch
serializes those parameters into the generated lit config file so that
they are available to all configs.

Differential Revision: https://reviews.llvm.org/D105047
  • Loading branch information
ldionne committed Jun 29, 2021
1 parent 7756216 commit 58a2304
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 28 deletions.
33 changes: 29 additions & 4 deletions libcxx/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ if(LIBCXX_INCLUDE_TESTS AND NOT LIBCXX_LINK_TESTS_WITH_SHARED_LIBCXX AND NOT LIB
message(FATAL_ERROR "LIBCXX_LINK_TESTS_WITH_SHARED_LIBCXX being OFF requires LIBCXX_ENABLE_STATIC to be ON")
endif()

pythonize_bool(LIBCXX_ENABLE_EXCEPTIONS)
pythonize_bool(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY)
pythonize_bool(LIBCXX_ENABLE_RTTI)
pythonize_bool(LIBCXX_ENABLE_SHARED)
pythonize_bool(LIBCXX_LINK_TESTS_WITH_SHARED_LIBCXX)
pythonize_bool(LIBCXX_LINK_TESTS_WITH_SHARED_LIBCXXABI)
Expand All @@ -71,7 +68,6 @@ pythonize_bool(LIBCXX_HAS_ATOMIC_LIB)
pythonize_bool(LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB)
pythonize_bool(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY)
pythonize_bool(LIBCXX_DEBUG_BUILD)
pythonize_bool(LIBCXX_ENABLE_DEBUG_MODE_SUPPORT)
pythonize_bool(LIBCXX_ENABLE_PARALLEL_ALGORITHMS)

# By default, for non-standalone builds, libcxx and libcxxabi share a library
Expand All @@ -87,6 +83,35 @@ set(LIBCXX_EXECUTOR "\\\"${Python3_EXECUTABLE}\\\" ${CMAKE_CURRENT_LIST_DIR}/../
"Executor to use when running tests.")

set(AUTO_GEN_COMMENT "## Autogenerated by libcxx configuration.\n# Do not edit!")
set(SERIALIZED_LIT_PARAMS "# Lit parameters serialized here for llvm-lit to pick them up\n")

macro(serialize_lit_param param value)
string(APPEND SERIALIZED_LIT_PARAMS "config.${param} = ${value}\n")
endmacro()

if (NOT LIBCXX_ENABLE_EXCEPTIONS)
serialize_lit_param(enable_exceptions False)
endif()

if (NOT LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY)
serialize_lit_param(enable_experimental False)
endif()

if (NOT LIBCXX_ENABLE_RTTI)
serialize_lit_param(enable_rtti False)
endif()

if (NOT LIBCXX_ENABLE_DEBUG_MODE_SUPPORT)
serialize_lit_param(enable_debug_tests False)
endif()

if (TARGET_TRIPLE)
serialize_lit_param(target_triple "\"${TARGET_TRIPLE}\"")
endif()

if (LLVM_USE_SANITIZER)
serialize_lit_param(use_sanitizer "\"${LLVM_USE_SANITIZER}\"")
endif()

if (NOT DEFINED LIBCXX_TEST_DEPS)
message(FATAL_ERROR "Expected LIBCXX_TEST_DEPS to be defined")
Expand Down
9 changes: 2 additions & 7 deletions libcxx/test/configs/legacy.cfg.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@AUTO_GEN_COMMENT@

@SERIALIZED_LIT_PARAMS@

import os
import site

Expand All @@ -10,18 +12,11 @@ config.libcxx_src_root = "@LIBCXX_SOURCE_DIR@"
config.libcxx_obj_root = "@LIBCXX_BINARY_DIR@"
config.cxx_library_root = "@LIBCXX_LIBRARY_DIR@"
config.abi_library_root = "@LIBCXX_CXX_ABI_LIBRARY_PATH@"
config.enable_exceptions = @LIBCXX_ENABLE_EXCEPTIONS@
config.enable_debug_tests = @LIBCXX_ENABLE_DEBUG_MODE_SUPPORT@
config.enable_experimental = @LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY@
config.enable_rtti = @LIBCXX_ENABLE_RTTI@
config.enable_shared = @LIBCXX_LINK_TESTS_WITH_SHARED_LIBCXX@
config.enable_32bit = @LIBCXX_BUILD_32_BITS@
config.cxx_abi = "@LIBCXX_CXX_ABI_LIBNAME@"
config.use_sanitizer = "@LLVM_USE_SANITIZER@"
config.configuration_variant = "@LIBCXX_LIT_VARIANT@"
config.host_triple = "@LLVM_HOST_TRIPLE@"
if "@TARGET_TRIPLE@":
config.target_triple = "@TARGET_TRIPLE@"
config.sysroot = "@LIBCXX_SYSROOT@"
config.gcc_toolchain = "@LIBCXX_GCC_TOOLCHAIN@"
config.generate_coverage = @LIBCXX_GENERATE_COVERAGE@
Expand Down
5 changes: 2 additions & 3 deletions libcxx/test/configs/libcxx-trunk-shared.cfg.in
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
@AUTO_GEN_COMMENT@

@SERIALIZED_LIT_PARAMS@

LIBCXX_ROOT = "@LIBCXX_SOURCE_DIR@"
INSTALL_ROOT = "@CMAKE_BINARY_DIR@"
COMPILER = "@CMAKE_CXX_COMPILER@"
EXEC_ROOT = "@LIBCXX_BINARY_DIR@"
CMAKE_OSX_SYSROOT = "@CMAKE_OSX_SYSROOT@"
TARGET_TRIPLE = "@TARGET_TRIPLE@"

import os
import pipes
Expand All @@ -23,8 +24,6 @@ config.test_source_root = os.path.join(LIBCXX_ROOT, 'test')
config.test_format = libcxx.test.format.CxxStandardLibraryTest()
config.recursiveExpansionLimit = 10
config.test_exec_root = EXEC_ROOT
if TARGET_TRIPLE:
config.target_triple = TARGET_TRIPLE

# Configure basic substitutions
runPy = os.path.join(LIBCXX_ROOT, 'utils', 'run.py')
Expand Down
5 changes: 2 additions & 3 deletions libcxx/test/configs/libcxx-trunk-static.cfg.in
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
@AUTO_GEN_COMMENT@

@SERIALIZED_LIT_PARAMS@

LIBCXX_ROOT = "@LIBCXX_SOURCE_DIR@"
INSTALL_ROOT = "@CMAKE_BINARY_DIR@"
COMPILER = "@CMAKE_CXX_COMPILER@"
EXEC_ROOT = "@LIBCXX_BINARY_DIR@"
CMAKE_OSX_SYSROOT = "@CMAKE_OSX_SYSROOT@"
TARGET_TRIPLE = "@TARGET_TRIPLE@"

import os
import pipes
Expand All @@ -23,8 +24,6 @@ config.test_source_root = os.path.join(LIBCXX_ROOT, 'test')
config.test_format = libcxx.test.format.CxxStandardLibraryTest()
config.recursiveExpansionLimit = 10
config.test_exec_root = EXEC_ROOT
if TARGET_TRIPLE:
config.target_triple = TARGET_TRIPLE

# Configure basic substitutions
runPy = os.path.join(LIBCXX_ROOT, 'utils', 'run.py')
Expand Down
21 changes: 20 additions & 1 deletion libcxxabi/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pythonize_bool(LIBCXXABI_BUILD_32_BITS)
pythonize_bool(LIBCXX_ENABLE_SHARED)
pythonize_bool(LIBCXXABI_ENABLE_SHARED)
pythonize_bool(LIBCXXABI_ENABLE_THREADS)
pythonize_bool(LIBCXXABI_ENABLE_EXCEPTIONS)
pythonize_bool(LIBCXXABI_USE_LLVM_UNWINDER)
pythonize_bool(LIBCXXABI_USE_COMPILER_RT)
pythonize_bool(LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
Expand Down Expand Up @@ -71,6 +70,26 @@ if (NOT LIBCXXABI_STANDALONE_BUILD)
endif()

set(AUTO_GEN_COMMENT "## Autogenerated by libcxxabi configuration.\n# Do not edit!")
set(SERIALIZED_LIT_PARAMS "# Lit parameters serialized here for llvm-lit to pick them up\n")

macro(serialize_lit_param param value)
string(APPEND SERIALIZED_LIT_PARAMS "config.${param} = ${value}\n")
endmacro()

if (NOT LIBCXXABI_ENABLE_EXCEPTIONS)
serialize_lit_param(enable_exceptions False)
endif()

serialize_lit_param(enable_experimental False)

if (LLVM_USE_SANITIZER)
serialize_lit_param(use_sanitizer "\"${LLVM_USE_SANITIZER}\"")
endif()

if (TARGET_TRIPLE)
serialize_lit_param(target_triple "\"${TARGET_TRIPLE}\"")
endif()

configure_lit_site_cfg(
"${LIBCXXABI_TEST_CONFIG}"
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
Expand Down
7 changes: 2 additions & 5 deletions libcxxabi/test/lit.site.cfg.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@AUTO_GEN_COMMENT@

@SERIALIZED_LIT_PARAMS@

import os
import site

Expand All @@ -16,20 +18,15 @@ config.cxx_library_root = "@LIBCXXABI_LIBCXX_LIBRARY_PATH@"
config.llvm_unwinder = @LIBCXXABI_USE_LLVM_UNWINDER@
config.builtins_library = "@LIBCXXABI_BUILTINS_LIBRARY@"
config.enable_threads = @LIBCXXABI_ENABLE_THREADS@
config.use_sanitizer = "@LLVM_USE_SANITIZER@"
config.enable_32bit = @LIBCXXABI_BUILD_32_BITS@
config.target_info = "@LIBCXXABI_TARGET_INFO@"
config.executor = "@LIBCXXABI_EXECUTOR@"
config.libcxxabi_shared = @LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXXABI@
config.enable_shared = @LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXX@
config.enable_exceptions = @LIBCXXABI_ENABLE_EXCEPTIONS@
config.host_triple = "@LLVM_HOST_TRIPLE@"
if "@TARGET_TRIPLE@":
config.target_triple = "@TARGET_TRIPLE@"
config.sysroot = "@LIBCXXABI_SYSROOT@"
config.gcc_toolchain = "@LIBCXXABI_GCC_TOOLCHAIN@"
config.cxx_ext_threads = @LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY@
config.enable_experimental = False

config.pstl_src_root = "@ParallelSTL_SOURCE_DIR@" if @LIBCXX_ENABLE_PARALLEL_ALGORITHMS@ else None
config.pstl_obj_root = "@ParallelSTL_BINARY_DIR@" if @LIBCXX_ENABLE_PARALLEL_ALGORITHMS@ else None
Expand Down
16 changes: 16 additions & 0 deletions libunwind/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ set(LIBUNWIND_EXECUTOR "${Python3_EXECUTABLE} ${LIBUNWIND_LIBCXX_PATH}/utils/run
"Executor to use when running tests.")

set(AUTO_GEN_COMMENT "## Autogenerated by libunwind configuration.\n# Do not edit!")
set(SERIALIZED_LIT_PARAMS "# Lit parameters serialized here for llvm-lit to pick them up\n")

macro(serialize_lit_param param value)
string(APPEND SERIALIZED_LIT_PARAMS "config.${param} = ${value}\n")
endmacro()

serialize_lit_param(enable_experimental False)

if (LLVM_USE_SANITIZER)
serialize_lit_param(use_sanitizer "\"${LLVM_USE_SANITIZER}\"")
endif()

if (TARGET_TRIPLE)
serialize_lit_param(target_triple "\"${TARGET_TRIPLE}\"")
endif()

configure_lit_site_cfg(
"${LIBUNWIND_TEST_CONFIG}"
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
Expand Down
2 changes: 1 addition & 1 deletion libunwind/test/libunwind/test/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def configure_compile_flags(self):
self.cxx.compile_flags += ['-funwind-tables']
# Make symbols available in the tests.
triple = self.get_lit_conf('target_triple', None)
if 'linux' in triple:
if triple is not None and 'linux' in triple:
self.cxx.link_flags += ['-Wl,--export-dynamic']
if not self.get_lit_bool('enable_threads', True):
self.cxx.compile_flags += ['-D_LIBUNWIND_HAS_NO_THREADS']
Expand Down
6 changes: 2 additions & 4 deletions libunwind/test/lit.site.cfg.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@AUTO_GEN_COMMENT@

@SERIALIZED_LIT_PARAMS@

import os
import site

Expand All @@ -14,7 +16,6 @@ config.cxx_library_root = "@LIBUNWIND_LIBCXX_LIBRARY_PATH@"
config.llvm_unwinder = True
config.builtins_library = "@LIBUNWIND_BUILTINS_LIBRARY@"
config.enable_threads = @LIBUNWIND_ENABLE_THREADS@
config.use_sanitizer = "@LLVM_USE_SANITIZER@"
config.enable_32bit = @LIBUNWIND_BUILD_32_BITS@
config.target_info = "@LIBUNWIND_TARGET_INFO@"
config.test_linker_flags = "@LIBUNWIND_TEST_LINKER_FLAGS@"
Expand All @@ -24,12 +25,9 @@ config.libunwind_shared = @LIBUNWIND_ENABLE_SHARED@
config.enable_shared = @LIBCXX_ENABLE_SHARED@
config.arm_ehabi = @LIBUNWIND_USES_ARM_EHABI@
config.host_triple = "@LLVM_HOST_TRIPLE@"
if "@TARGET_TRIPLE@":
config.target_triple = "@TARGET_TRIPLE@"
config.sysroot = "@LIBUNWIND_SYSROOT@"
config.gcc_toolchain = "@LIBUNWIND_GCC_TOOLCHAIN@"
config.cxx_ext_threads = @LIBUNWIND_BUILD_EXTERNAL_THREAD_LIBRARY@
config.enable_experimental = False

site.addsitedir(os.path.join(config.libunwind_src_root, 'test'))
site.addsitedir(os.path.join(config.libcxx_src_root, 'utils'))
Expand Down

0 comments on commit 58a2304

Please sign in to comment.