[libc++abi][ci] Add a from-scratch config for libc++abi on Apple/system

I came across an issue where since we build the library for Apple with
the install name directory being /usr/lib, which means that if we don't
run the tests with DYLD_LIBRARY_PATH, we'll end up loading the
system-provided libc++abi when running the tests. That wreaks havoc.

Instead of fixing it in the legacy config file, this commit introduces
an Apple libc++abi config file that does the right thing.

Differential Revision: https://reviews.llvm.org/D111279

GitOrigin-RevId: d1e0f02e0ba98cd371749c8d70ee9d153c559e91
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 366dcc9..ea6ac11 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -178,9 +178,9 @@
 
 set(LIBCXXABI_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/lit.site.cfg.in" CACHE STRING
   "The path to the Lit testing configuration to use when running the tests.
-   If a relative path is provided, it is assumed to be relative to '<monorepo>/libcxx/test/configs'.")
+   If a relative path is provided, it is assumed to be relative to '<monorepo>/libcxxabi/test/configs'.")
 if (NOT IS_ABSOLUTE "${LIBCXXABI_TEST_CONFIG}")
-  set(LIBCXXABI_TEST_CONFIG "${LIBCXXABI_LIBCXX_PATH}/test/configs/${LIBCXXABI_TEST_CONFIG}")
+  set(LIBCXXABI_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/${LIBCXXABI_TEST_CONFIG}")
 endif()
 set(LIBCXXABI_TEST_PARAMS "" CACHE STRING
     "A list of parameters to run the Lit test suite with.")
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index a8a97ae..ea4d5c4 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -100,6 +100,10 @@
   serialize_lit_param("${name}" "\"${value}\"")
 endforeach()
 
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/configs/cmake-bridge.cfg.in"
+               "${CMAKE_CURRENT_BINARY_DIR}/cmake-bridge.cfg"
+               @ONLY)
+
 configure_lit_site_cfg(
   "${LIBCXXABI_TEST_CONFIG}"
   ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
diff --git a/test/configs/apple-libc++abi-shared.cfg.in b/test/configs/apple-libc++abi-shared.cfg.in
new file mode 100644
index 0000000..4165d7a
--- /dev/null
+++ b/test/configs/apple-libc++abi-shared.cfg.in
@@ -0,0 +1,29 @@
+# Testing configuration for Apple's system libc++abi.
+
+import sys
+
+lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
+
+config.substitutions.append(('%{flags}',
+    '-isysroot {}'.format('@CMAKE_OSX_SYSROOT@') if '@CMAKE_OSX_SYSROOT@' else ''
+))
+config.substitutions.append(('%{compile_flags}',
+    '-nostdinc++ -isystem %{install}/include/c++/v1 -DLIBCXXABI_NO_TIMER -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS ' +
+    '-I %{libcxx}/test/support -I %{libcxx}/src'
+))
+config.substitutions.append(('%{link_flags}',
+    '-nostdlib++ -L %{install}/lib -lc++ -lc++abi'
+))
+config.substitutions.append(('%{exec}',
+    '{} %{{libcxx}}/utils/run.py --execdir %T --env DYLD_LIBRARY_PATH=%{{install}}/lib -- '.format(sys.executable)
+))
+
+import os, site
+site.addsitedir(os.path.join('@LIBCXXABI_LIBCXX_PATH@', 'utils'))
+import libcxx.test.params, libcxx.test.newconfig, libcxx.test.newconfig
+libcxx.test.newconfig.configure(
+    libcxx.test.params.DEFAULT_PARAMETERS,
+    libcxx.test.features.DEFAULT_FEATURES,
+    config,
+    lit_config
+)
diff --git a/test/configs/cmake-bridge.cfg.in b/test/configs/cmake-bridge.cfg.in
new file mode 100644
index 0000000..469872c
--- /dev/null
+++ b/test/configs/cmake-bridge.cfg.in
@@ -0,0 +1,31 @@
+@AUTO_GEN_COMMENT@
+
+@SERIALIZED_LIT_PARAMS@
+
+#
+# This file performs the bridge between the CMake configuration and the Lit
+# configuration files by setting up the LitConfig object and various Lit
+# substitutions from CMake variables.
+#
+# Individual configuration files can take advantage of this bridge by
+# loading the file and then setting up the remaining Lit substitutions.
+#
+
+import os, site
+site.addsitedir(os.path.join('@LIBCXXABI_LIBCXX_PATH@', 'utils'))
+site.addsitedir(os.path.join('@LIBCXXABI_SOURCE_DIR@', 'test'))
+import libcxx.test.format
+
+# Basic configuration of the test suite
+config.name = os.path.basename('@LIBCXXABI_TEST_CONFIG@')
+config.test_source_root = os.path.join('@LIBCXXABI_SOURCE_DIR@', 'test')
+config.test_format = libcxx.test.format.CxxStandardLibraryTest()
+config.recursiveExpansionLimit = 10
+config.test_exec_root = '@CMAKE_BINARY_DIR@'
+
+# TODO: This is a non-standard Lit attribute and we should have another way of accessing this.
+config.host_triple = '@LLVM_HOST_TRIPLE@'
+
+config.substitutions.append(('%{cxx}', '@CMAKE_CXX_COMPILER@'))
+config.substitutions.append(('%{libcxx}', '@LIBCXXABI_LIBCXX_PATH@'))
+config.substitutions.append(('%{install}', '@CMAKE_BINARY_DIR@'))