Skip to content

Commit

Permalink
[runtimes] Fix parsing of LIB{CXX,CXXABI,UNWIND}_TEST_PARAMS (llvm#67691
Browse files Browse the repository at this point in the history
)

Since 78d649a the recommended way to
pass an executor is to use the _TEST_PARAMS variable, which means we now
pass more complicated value (including ones that may contain multiple
`=`) as part of this variable. However, the `REGEX REPLACE` being used
has greedy matches so everything up to the last = becomes part of the
variable name which results in invalid syntax in the generated lit
config file.

This was noticed due to builder failures for those using the
CrossWinToARMLinux.cmake cache file.

---------

Co-authored-by: Vladimir Vereschaka <vvereschaka@accesssoftek.com>
  • Loading branch information
arichardson and vvereschaka authored Oct 4, 2023
1 parent 5099dc3 commit e599422
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 52 deletions.
14 changes: 11 additions & 3 deletions clang/cmake/caches/CrossWinToARMLinux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS

find_package(Python3 COMPONENTS Interpreter)

set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_TEST_PARAMS_default "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_TEST_PARAMS}")
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_TEST_PARAMS_default "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_TEST_PARAMS}")
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_TEST_PARAMS_default "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_TEST_PARAMS}")

# Remote test configuration.
if(DEFINED REMOTE_TEST_HOST)
# Allow override with the custom values.
Expand All @@ -162,11 +166,15 @@ if(DEFINED REMOTE_TEST_HOST)
"\\\"${Python3_EXECUTABLE}\\\" \\\"${LLVM_PROJECT_DIR}/llvm/utils/remote-exec.py\\\" --host=${REMOTE_TEST_USER}@${REMOTE_TEST_HOST}"
CACHE STRING "")

set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_TEST_PARAMS "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_TEST_PARAMS} 'executor=${DEFAULT_TEST_EXECUTOR}'" CACHE STRING "")
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_TEST_PARAMS "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_TEST_PARAMS} 'executor=${DEFAULT_TEST_EXECUTOR}'" CACHE STRING "")
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_TEST_PARAMS "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_TEST_PARAMS} 'executor=${DEFAULT_TEST_EXECUTOR}'" CACHE STRING "")
list(APPEND RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_TEST_PARAMS_default "executor=${DEFAULT_TEST_EXECUTOR}")
list(APPEND RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_TEST_PARAMS_default "executor=${DEFAULT_TEST_EXECUTOR}")
list(APPEND RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_TEST_PARAMS_default "executor=${DEFAULT_TEST_EXECUTOR}")
endif()

set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_TEST_PARAMS "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_TEST_PARAMS_default}" CACHE INTERNAL "")
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_TEST_PARAMS "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_TEST_PARAMS_default}" CACHE INTERNAL "")
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_TEST_PARAMS "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_TEST_PARAMS_default}" CACHE INTERNAL "")

set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")
set(LLVM_TOOLCHAIN_TOOLS
llvm-ar
Expand Down
31 changes: 12 additions & 19 deletions libcxx/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include(HandleLitArguments)
add_subdirectory(tools)

# By default, libcxx and libcxxabi share a library directory.
Expand All @@ -9,40 +10,32 @@ endif()
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 (LIBCXX_EXECUTOR)
message(DEPRECATION "LIBCXX_EXECUTOR is deprecated, please add executor=... to LIBCXX_TEST_PARAMS")
serialize_lit_param(executor "\"${LIBCXX_EXECUTOR}\"")
serialize_lit_string_param(SERIALIZED_LIT_PARAMS executor "${LIBCXX_EXECUTOR}")
endif()

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

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

serialize_lit_param(hardening_mode "\"${LIBCXX_HARDENING_MODE}\"")
serialize_lit_string_param(SERIALIZED_LIT_PARAMS hardening_mode "${LIBCXX_HARDENING_MODE}")

if (CMAKE_CXX_COMPILER_TARGET)
serialize_lit_param(target_triple "\"${CMAKE_CXX_COMPILER_TARGET}\"")
serialize_lit_string_param(SERIALIZED_LIT_PARAMS target_triple "${CMAKE_CXX_COMPILER_TARGET}")
else()
serialize_lit_param(target_triple "\"${LLVM_DEFAULT_TARGET_TRIPLE}\"")
serialize_lit_string_param(SERIALIZED_LIT_PARAMS target_triple "${LLVM_DEFAULT_TARGET_TRIPLE}")
endif()

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

foreach(param IN LISTS LIBCXX_TEST_PARAMS)
string(REGEX REPLACE "(.+)=(.+)" "\\1" name "${param}")
string(REGEX REPLACE "(.+)=(.+)" "\\2" value "${param}")
serialize_lit_param("${name}" "\"${value}\"")
endforeach()
serialize_lit_params_list(SERIALIZED_LIT_PARAMS LIBCXX_TEST_PARAMS)

if (NOT DEFINED LIBCXX_TEST_DEPS)
message(FATAL_ERROR "Expected LIBCXX_TEST_DEPS to be defined")
Expand All @@ -68,9 +61,9 @@ if (MSVC)
set(cxx_lib "${cxx_lib}d")
endif()

serialize_lit_param(dbg_include "\"${dbg_include}\"")
serialize_lit_param(fms_runtime_lib "\"${fms_runtime_lib}\"")
serialize_lit_param(cxx_lib "\"${cxx_lib}\"")
serialize_lit_string_param(SERIALIZED_LIT_PARAMS dbg_include "${dbg_include}")
serialize_lit_string_param(SERIALIZED_LIT_PARAMS fms_runtime_lib "${fms_runtime_lib}")
serialize_lit_string_param(SERIALIZED_LIT_PARAMS cxx_lib "${cxx_lib}")
endif()

if (LIBCXX_INCLUDE_TESTS)
Expand Down
25 changes: 9 additions & 16 deletions libcxxabi/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include(AddLLVM) # for configure_lit_site_cfg and add_lit_testsuite
include(HandleLitArguments)
macro(pythonize_bool var)
if (${var})
set(${var} True)
Expand All @@ -23,40 +24,32 @@ 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 (LIBCXXABI_EXECUTOR)
message(DEPRECATION "LIBCXXABI_EXECUTOR is deprecated, please add executor=... to LIBCXXABI_TEST_PARAMS")
serialize_lit_param(executor "\"${LIBCXXABI_EXECUTOR}\"")
serialize_lit_string_param(SERIALIZED_LIT_PARAMS executor "${LIBCXXABI_EXECUTOR}")
endif()

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

if (LIBCXXABI_ENABLE_ASSERTIONS)
serialize_lit_param(enable_assertions True)
serialize_lit_param(SERIALIZED_LIT_PARAMS enable_assertions True)
endif()

serialize_lit_param(enable_experimental False)
serialize_lit_param(SERIALIZED_LIT_PARAMS enable_experimental False)

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

if (CMAKE_CXX_COMPILER_TARGET)
serialize_lit_param(target_triple "\"${CMAKE_CXX_COMPILER_TARGET}\"")
serialize_lit_string_param(SERIALIZED_LIT_PARAMS target_triple "${CMAKE_CXX_COMPILER_TARGET}")
else()
serialize_lit_param(target_triple "\"${LLVM_DEFAULT_TARGET_TRIPLE}\"")
serialize_lit_string_param(SERIALIZED_LIT_PARAMS target_triple "${LLVM_DEFAULT_TARGET_TRIPLE}")
endif()

foreach(param IN LISTS LIBCXXABI_TEST_PARAMS)
string(REGEX REPLACE "(.+)=(.+)" "\\1" name "${param}")
string(REGEX REPLACE "(.+)=(.+)" "\\2" value "${param}")
serialize_lit_param("${name}" "\"${value}\"")
endforeach()
serialize_lit_params_list(SERIALIZED_LIT_PARAMS LIBCXXABI_TEST_PARAMS)

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/configs/cmake-bridge.cfg.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake-bridge.cfg"
Expand Down
21 changes: 7 additions & 14 deletions libunwind/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include(AddLLVM) # for add_lit_testsuite
include(HandleLitArguments)
macro(pythonize_bool var)
if (${var})
set(${var} True)
Expand All @@ -14,32 +15,24 @@ pythonize_bool(LIBUNWIND_USES_ARM_EHABI)
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()

if (LIBUNWIND_EXECUTOR)
message(DEPRECATION "LIBUNWIND_EXECUTOR is deprecated, please add executor=... to LIBUNWIND_TEST_PARAMS")
serialize_lit_param(executor "\"${LIBUNWIND_EXECUTOR}\"")
serialize_lit_string_param(SERIALIZED_LIT_PARAMS executor "${LIBUNWIND_EXECUTOR}")
endif()

serialize_lit_param(enable_experimental False)
serialize_lit_param(SERIALIZED_LIT_PARAMS enable_experimental False)

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

if (CMAKE_CXX_COMPILER_TARGET)
serialize_lit_param(target_triple "\"${CMAKE_CXX_COMPILER_TARGET}\"")
serialize_lit_string_param(SERIALIZED_LIT_PARAMS target_triple "${CMAKE_CXX_COMPILER_TARGET}")
else()
serialize_lit_param(target_triple "\"${LLVM_DEFAULT_TARGET_TRIPLE}\"")
serialize_lit_string_param(SERIALIZED_LIT_PARAMS target_triple "${LLVM_DEFAULT_TARGET_TRIPLE}")
endif()

foreach(param IN LISTS LIBUNWIND_TEST_PARAMS)
string(REGEX REPLACE "(.+)=(.+)" "\\1" name "${param}")
string(REGEX REPLACE "(.+)=(.+)" "\\2" value "${param}")
serialize_lit_param("${name}" "\"${value}\"")
endforeach()
serialize_lit_params_list(SERIALIZED_LIT_PARAMS LIBUNWIND_TEST_PARAMS)

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/configs/cmake-bridge.cfg.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake-bridge.cfg"
Expand Down
20 changes: 20 additions & 0 deletions runtimes/cmake/Modules/HandleLitArguments.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

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

macro(serialize_lit_string_param output_var param value)
# Ensure that all quotes in the value are escaped for a valid python string.
string(REPLACE "\"" "\\\"" _escaped_value "${value}")
string(APPEND ${output_var} "config.${param} = \"${_escaped_value}\"\n")
endmacro()

macro(serialize_lit_params_list output_var list)
foreach(param IN LISTS ${list})
string(FIND "${param}" "=" _eq_index)
string(SUBSTRING "${param}" 0 ${_eq_index} name)
string(SUBSTRING "${param}" ${_eq_index} -1 value)
string(SUBSTRING "${value}" 1 -1 value) # strip the leading =
serialize_lit_string_param("${output_var}" "${name}" "${value}")
endforeach()
endmacro()

0 comments on commit e599422

Please sign in to comment.