[clang] [libc++][lit] Allow overriding the executor for tests (PR #66545)

Alexander Richardson via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 25 08:24:52 PDT 2023


https://github.com/arichardson updated https://github.com/llvm/llvm-project/pull/66545

>From eb6f23cbc308bb30fd78094aba4259e3aae6657c Mon Sep 17 00:00:00 2001
From: Alex Richardson <alexrichardson at google.com>
Date: Mon, 25 Sep 2023 08:22:27 -0700
Subject: [PATCH 1/2] [libunwind][libc++][libc++abi] Allow overriding the
 executor for tests

This is useful when trying to run multiple tests with different
arguments to the executor script. This is needed in my case since I
do not know the correct ssh connection arguments when building libc++.
The testing script I have spawns multiple QEMU instances that listen on
a given port on localhost and runs lit with the --num-shards/--run-shard
argument. In order to connect each shard to the right QEMU instances I
need to customize the arguments passed to ssh.py (--extra-ssh-args and
--extra-scp-args) but can't do this at configure time since the target
port is only known when running the tests but not when calling CMake.
This change allows me to pass `executor=ssh.py <args>` to lit once I know
the right hostname/port for running the tests.

This also deprecates the `LIB{CXX,CXXABI,UNWIND}_EXECUTOR` CMake variable
as the same can be achieved by adding `executor=...` to the
`LIB{CXX,CXXABI,UNWIND}_TEST_PARAMS` variable.
---
 clang/cmake/caches/CrossWinToARMLinux.cmake |  6 +++---
 libcxx/docs/ReleaseNotes/18.rst             |  5 +++++
 libcxx/test/CMakeLists.txt                  |  8 +++++---
 libcxx/test/configs/cmake-bridge.cfg.in     |  1 -
 libcxx/utils/libcxx/test/params.py          | 14 +++++++++++++-
 libcxxabi/test/CMakeLists.txt               |  7 +++++--
 libcxxabi/test/configs/cmake-bridge.cfg.in  |  1 -
 libunwind/test/CMakeLists.txt               |  7 +++++--
 libunwind/test/configs/cmake-bridge.cfg.in  |  1 -
 9 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/clang/cmake/caches/CrossWinToARMLinux.cmake b/clang/cmake/caches/CrossWinToARMLinux.cmake
index bbb4b9e71be2d3d..fd341b182fd6563 100644
--- a/clang/cmake/caches/CrossWinToARMLinux.cmake
+++ b/clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -162,9 +162,9 @@ 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_EXECUTOR                      "${DEFAULT_TEST_EXECUTOR}" CACHE STRING "")
-  set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_EXECUTOR                      "${DEFAULT_TEST_EXECUTOR}" CACHE STRING "")
-  set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_EXECUTOR                         "${DEFAULT_TEST_EXECUTOR}" 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 "")
 endif()
 
 set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")
diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index 8869d0b07d39f74..f852e6ffc8b89fc 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -134,3 +134,8 @@ ABI Affecting Changes
 
 Build System Changes
 --------------------
+
+- The ``LIBCXX_EXECUTOR`` CMake variable has been deprecated. If you are relying on this, the new replacement
+  is either passing ``-Dexecutor=...`` to `llvm-lit`` or to make it persistent in the generated configuration
+  file, ``-DLIBCXX_TEST_PARAMS=executor=...`` can be used. The same also applies to the ``LIBUWIND_EXECTOR``
+  and ``LIBCXXABI_EXECUTOR`` CMake variables. LLVM 19 will completely remove support for these variables.
diff --git a/libcxx/test/CMakeLists.txt b/libcxx/test/CMakeLists.txt
index c7036b94dcc596e..fd194a36a28fc26 100644
--- a/libcxx/test/CMakeLists.txt
+++ b/libcxx/test/CMakeLists.txt
@@ -6,9 +6,6 @@ if (NOT LIBCXX_CXX_ABI_LIBRARY_PATH)
       "The path to libc++abi library.")
 endif()
 
-set(LIBCXX_EXECUTOR "\\\"${Python3_EXECUTABLE}\\\" ${CMAKE_CURRENT_LIST_DIR}/../utils/run.py" CACHE STRING
-    "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")
 
@@ -16,6 +13,11 @@ 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}\"")
+endif()
+
 if (NOT LIBCXX_ENABLE_EXCEPTIONS)
   serialize_lit_param(enable_exceptions False)
 endif()
diff --git a/libcxx/test/configs/cmake-bridge.cfg.in b/libcxx/test/configs/cmake-bridge.cfg.in
index 9067115598abd8a..0e3c3040c964462 100644
--- a/libcxx/test/configs/cmake-bridge.cfg.in
+++ b/libcxx/test/configs/cmake-bridge.cfg.in
@@ -30,7 +30,6 @@ config.substitutions.append(('%{include}', '@LIBCXX_GENERATED_INCLUDE_DIR@'))
 config.substitutions.append(('%{target-include}', '@LIBCXX_GENERATED_INCLUDE_TARGET_DIR@'))
 config.substitutions.append(('%{lib}', '@LIBCXX_LIBRARY_DIR@'))
 config.substitutions.append(('%{module}', '@LIBCXX_GENERATED_MODULE_DIR@'))
-config.substitutions.append(('%{executor}', '@LIBCXX_EXECUTOR@'))
 config.substitutions.append(('%{test-tools}', '@LIBCXX_TEST_TOOLS_PATH@'))
 
 # The test needs to manually rebuild the module. The compiler flags used in the
diff --git a/libcxx/utils/libcxx/test/params.py b/libcxx/utils/libcxx/test/params.py
index 6fe466ec0c6f595..7230e348e0af1ad 100644
--- a/libcxx/utils/libcxx/test/params.py
+++ b/libcxx/utils/libcxx/test/params.py
@@ -5,10 +5,13 @@
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 #
 # ===----------------------------------------------------------------------===##
+import sys
+import re
+from pathlib import Path
 
 from libcxx.test.dsl import *
 from libcxx.test.features import _isMSVC
-import re
+
 
 _warningFlags = [
     "-Werror",
@@ -314,5 +317,14 @@ def getStdFlag(cfg, std):
             AddCompileFlag("-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES"),
         ],
     ),
+    Parameter(
+        name="executor",
+        type=str,
+        default=f"{sys.executable} {Path(__file__).resolve().parent.parent.parent / 'run.py'}",
+        help="Custom executor to use instead of the configured default.",
+        actions=lambda executor: [] if not executor else [
+          AddSubstitution("%{executor}", executor)
+        ],
+    )
 ]
 # fmt: on
diff --git a/libcxxabi/test/CMakeLists.txt b/libcxxabi/test/CMakeLists.txt
index 0d861cff980cd5d..b65ac3a9d16422c 100644
--- a/libcxxabi/test/CMakeLists.txt
+++ b/libcxxabi/test/CMakeLists.txt
@@ -8,8 +8,6 @@ macro(pythonize_bool var)
 endmacro()
 
 pythonize_bool(LIBCXXABI_USE_LLVM_UNWINDER)
-set(LIBCXXABI_EXECUTOR "\\\"${Python3_EXECUTABLE}\\\" ${LIBCXXABI_LIBCXX_PATH}/utils/run.py" CACHE STRING
-    "Executor to use when running tests.")
 
 if (LIBCXXABI_ENABLE_SHARED)
   set(LIBCXXABI_TEST_DEPS cxxabi_shared)
@@ -29,6 +27,11 @@ 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}\"")
+endif()
+
 if (NOT LIBCXXABI_ENABLE_EXCEPTIONS)
   serialize_lit_param(enable_exceptions False)
 endif()
diff --git a/libcxxabi/test/configs/cmake-bridge.cfg.in b/libcxxabi/test/configs/cmake-bridge.cfg.in
index 89b2dca6e530592..1d0f51d37437bd1 100644
--- a/libcxxabi/test/configs/cmake-bridge.cfg.in
+++ b/libcxxabi/test/configs/cmake-bridge.cfg.in
@@ -32,7 +32,6 @@ config.substitutions.append(('%{include}', '@LIBCXXABI_SOURCE_DIR@/include'))
 config.substitutions.append(('%{cxx-include}', '@LIBCXXABI_HEADER_DIR@/include/c++/v1'))
 config.substitutions.append(('%{cxx-target-include}', '@LIBCXXABI_HEADER_DIR@/include/%{triple}/c++/v1'))
 config.substitutions.append(('%{lib}', '@LIBCXXABI_LIBRARY_DIR@'))
-config.substitutions.append(('%{executor}', '@LIBCXXABI_EXECUTOR@'))
 
 if @LIBCXXABI_USE_LLVM_UNWINDER@:
     config.substitutions.append(('%{maybe-include-libunwind}', '-I "@LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL@"'))
diff --git a/libunwind/test/CMakeLists.txt b/libunwind/test/CMakeLists.txt
index e6bd52690442578..084da0ab8f354d7 100644
--- a/libunwind/test/CMakeLists.txt
+++ b/libunwind/test/CMakeLists.txt
@@ -10,8 +10,6 @@ endmacro()
 pythonize_bool(LIBUNWIND_ENABLE_CET)
 pythonize_bool(LIBUNWIND_ENABLE_THREADS)
 pythonize_bool(LIBUNWIND_USES_ARM_EHABI)
-set(LIBUNWIND_EXECUTOR "\\\"${Python3_EXECUTABLE}\\\" ${LIBUNWIND_LIBCXX_PATH}/utils/run.py" CACHE STRING
-    "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")
@@ -20,6 +18,11 @@ 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}\"")
+endif()
+
 serialize_lit_param(enable_experimental False)
 
 if (LLVM_USE_SANITIZER)
diff --git a/libunwind/test/configs/cmake-bridge.cfg.in b/libunwind/test/configs/cmake-bridge.cfg.in
index 7860301c367fbc5..c5f34c87abb92a1 100644
--- a/libunwind/test/configs/cmake-bridge.cfg.in
+++ b/libunwind/test/configs/cmake-bridge.cfg.in
@@ -31,6 +31,5 @@ if not @LIBUNWIND_ENABLE_THREADS@:
 # Add substitutions for bootstrapping the test suite configuration
 import shlex
 config.substitutions.append(('%{cxx}', shlex.quote('@CMAKE_CXX_COMPILER@')))
-config.substitutions.append(('%{executor}', '@LIBUNWIND_EXECUTOR@'))
 config.substitutions.append(('%{include}', '@LIBUNWIND_SOURCE_DIR@/include'))
 config.substitutions.append(('%{lib}', '@LIBUNWIND_LIBRARY_DIR@'))

>From 772200b892e5e6ed2189e508f764951930749e15 Mon Sep 17 00:00:00 2001
From: Alexander Richardson <mail at alexrichardson.me>
Date: Mon, 25 Sep 2023 16:24:46 +0100
Subject: [PATCH 2/2] Fix rst syntax

---
 libcxx/docs/ReleaseNotes/18.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index f852e6ffc8b89fc..ffc44035c3c94f5 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -136,6 +136,6 @@ Build System Changes
 --------------------
 
 - The ``LIBCXX_EXECUTOR`` CMake variable has been deprecated. If you are relying on this, the new replacement
-  is either passing ``-Dexecutor=...`` to `llvm-lit`` or to make it persistent in the generated configuration
+  is either passing ``-Dexecutor=...`` to ``llvm-lit`` or to make it persistent in the generated configuration
   file, ``-DLIBCXX_TEST_PARAMS=executor=...`` can be used. The same also applies to the ``LIBUWIND_EXECTOR``
   and ``LIBCXXABI_EXECUTOR`` CMake variables. LLVM 19 will completely remove support for these variables.



More information about the cfe-commits mailing list