[libcxx-commits] [libcxx] 422ec52 - [libunwind] Introduce a cmake-bridge.cfg.in file to reduce test config duplication

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri May 20 06:36:42 PDT 2022


Author: Louis Dionne
Date: 2022-05-20T09:36:29-04:00
New Revision: 422ec524388b524f48d49fccd436105bb848f833

URL: https://github.com/llvm/llvm-project/commit/422ec524388b524f48d49fccd436105bb848f833
DIFF: https://github.com/llvm/llvm-project/commit/422ec524388b524f48d49fccd436105bb848f833.diff

LOG: [libunwind] Introduce a cmake-bridge.cfg.in file to reduce test config duplication

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

Added: 
    libunwind/test/configs/cmake-bridge.cfg.in

Modified: 
    libcxx/test/configs/cmake-bridge.cfg.in
    libunwind/test/CMakeLists.txt
    libunwind/test/configs/llvm-libunwind-merged.cfg.in
    libunwind/test/configs/llvm-libunwind-shared.cfg.in
    libunwind/test/configs/llvm-libunwind-static.cfg.in

Removed: 
    


################################################################################
diff  --git a/libcxx/test/configs/cmake-bridge.cfg.in b/libcxx/test/configs/cmake-bridge.cfg.in
index 05ac7e594aea..df58522d6cbb 100644
--- a/libcxx/test/configs/cmake-bridge.cfg.in
+++ b/libcxx/test/configs/cmake-bridge.cfg.in
@@ -2,8 +2,6 @@
 
 @SERIALIZED_LIT_PARAMS@
 
-import shlex
-
 #
 # This file performs the bridge between the CMake configuration and the Lit
 # configuration files by setting up the LitConfig object and various Lit
@@ -25,6 +23,7 @@ config.recursiveExpansionLimit = 10
 config.test_exec_root = os.path.join('@CMAKE_BINARY_DIR@', 'test')
 
 # Add substitutions for bootstrapping the test suite configuration
+import shlex
 config.substitutions.append(('%{cxx}', shlex.quote('@CMAKE_CXX_COMPILER@')))
 config.substitutions.append(('%{libcxx}', '@LIBCXX_SOURCE_DIR@'))
 config.substitutions.append(('%{include}', '@LIBCXX_GENERATED_INCLUDE_DIR@'))

diff  --git a/libunwind/test/CMakeLists.txt b/libunwind/test/CMakeLists.txt
index 736b692969e7..94fc9c359586 100644
--- a/libunwind/test/CMakeLists.txt
+++ b/libunwind/test/CMakeLists.txt
@@ -48,6 +48,10 @@ foreach(param IN LISTS LIBUNWIND_TEST_PARAMS)
   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(
   "${LIBUNWIND_TEST_CONFIG}"
   ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg

diff  --git a/libunwind/test/configs/cmake-bridge.cfg.in b/libunwind/test/configs/cmake-bridge.cfg.in
new file mode 100644
index 000000000000..21768702f6d8
--- /dev/null
+++ b/libunwind/test/configs/cmake-bridge.cfg.in
@@ -0,0 +1,37 @@
+ at AUTO_GEN_COMMENT@
+
+ at 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('@LIBUNWIND_LIBCXX_PATH@', 'utils'))
+import libcxx.test.format
+
+# Basic configuration of the test suite
+config.name = os.path.basename('@LIBUNWIND_TEST_CONFIG@')
+config.test_source_root = os.path.join('@LIBUNWIND_SOURCE_DIR@', 'test')
+config.test_format = libcxx.test.format.CxxStandardLibraryTest()
+config.recursiveExpansionLimit = 10
+config.test_exec_root = '@CMAKE_BINARY_DIR@'
+config.target_info = "@LIBUNWIND_TARGET_INFO@"
+
+# Add a few features that are common to all the configurations
+if @LIBUNWIND_USES_ARM_EHABI@:
+    config.available_features.add('libunwind-arm-ehabi')
+if not @LIBUNWIND_ENABLE_THREADS@:
+    config.available_features.add('libunwind-no-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@'))

diff  --git a/libunwind/test/configs/llvm-libunwind-merged.cfg.in b/libunwind/test/configs/llvm-libunwind-merged.cfg.in
index 76b572c4cdbf..d01ee7470de7 100644
--- a/libunwind/test/configs/llvm-libunwind-merged.cfg.in
+++ b/libunwind/test/configs/llvm-libunwind-merged.cfg.in
@@ -1,31 +1,12 @@
- at AUTO_GEN_COMMENT@
-
- at SERIALIZED_LIT_PARAMS@
-
 #
 # Configuration file for running the libunwind tests against a libc++ shared library
 # into which the unwinder was merged.
 #
 
-import os, site
-site.addsitedir(os.path.join('@LIBUNWIND_LIBCXX_PATH@', 'utils'))
-import libcxx.test.format
-
-# Basic configuration of the test suite
-config.name = os.path.basename('@LIBUNWIND_TEST_CONFIG@')
-config.test_source_root = os.path.join('@LIBUNWIND_SOURCE_DIR@', 'test')
-config.test_format = libcxx.test.format.CxxStandardLibraryTest()
-config.recursiveExpansionLimit = 10
-config.test_exec_root = '@CMAKE_BINARY_DIR@'
-config.target_info = "@LIBUNWIND_TARGET_INFO@"
+lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
 
 compile_flags = []
 link_flags = []
-if @LIBUNWIND_USES_ARM_EHABI@:
-    config.available_features.add('libunwind-arm-ehabi')
-
-if not @LIBUNWIND_ENABLE_THREADS@:
-    config.available_features.add('libunwind-no-threads')
 
 if @LIBUNWIND_ENABLE_CET@:
     compile_flags.append('-fcf-protection=full')
@@ -36,21 +17,18 @@ if '@CMAKE_SYSTEM_NAME@' == 'Linux':
 # Stack unwinding tests need unwinding tables and these are not generated by default on all targets.
 compile_flags.append('-funwind-tables')
 
-config.substitutions.append(('%{executor}', '@LIBUNWIND_EXECUTOR@'))
-
-config.substitutions.append(('%{cxx}', '@CMAKE_CXX_COMPILER@'))
 local_sysroot = '@CMAKE_OSX_SYSROOT@' or '@CMAKE_SYSROOT@'
 config.substitutions.append(('%{flags}',
     '-isysroot {}'.format(local_sysroot) if local_sysroot else ''
 ))
 config.substitutions.append(('%{compile_flags}',
-    '-nostdinc++ -I {}/include {}'.format('@LIBUNWIND_SOURCE_DIR@', ' '.join(compile_flags))
+    '-nostdinc++ -I %{{include}} {}'.format(' '.join(compile_flags))
 ))
 config.substitutions.append(('%{link_flags}',
-    '-L {0} -Wl,-rpath,{0} -lc++ -ldl {1}'.format('@LIBUNWIND_LIBRARY_DIR@', ' '.join(link_flags))
+    '-L %{{lib}} -Wl,-rpath,%{{lib}} -lc++ -ldl {}'.format(' '.join(link_flags))
 ))
 config.substitutions.append(('%{exec}',
-    '%{executor} --execdir %T -- ' if '@LIBUNWIND_EXECUTOR@' else ''
+    '%{executor} --execdir %T -- '
 ))
 
 import os, site

diff  --git a/libunwind/test/configs/llvm-libunwind-shared.cfg.in b/libunwind/test/configs/llvm-libunwind-shared.cfg.in
index 11c9faedf0b8..b82eec71b02f 100644
--- a/libunwind/test/configs/llvm-libunwind-shared.cfg.in
+++ b/libunwind/test/configs/llvm-libunwind-shared.cfg.in
@@ -1,34 +1,11 @@
- at AUTO_GEN_COMMENT@
-
- at SERIALIZED_LIT_PARAMS@
-
 #
 # Configuration file for running the libunwind tests against the shared library.
 #
-# This file is a lot simpler than the ones for libc++ and libc++abi because
-# while libunwind is written in C++, it doesn't use the C++ Standard Library
-# so we don't need to set that up to run the tests correctly.
-#
-
-import os, site
-site.addsitedir(os.path.join('@LIBUNWIND_LIBCXX_PATH@', 'utils'))
-import libcxx.test.format
 
-# Basic configuration of the test suite
-config.name = os.path.basename('@LIBUNWIND_TEST_CONFIG@')
-config.test_source_root = os.path.join('@LIBUNWIND_SOURCE_DIR@', 'test')
-config.test_format = libcxx.test.format.CxxStandardLibraryTest()
-config.recursiveExpansionLimit = 10
-config.test_exec_root = '@CMAKE_BINARY_DIR@'
-config.target_info = "@LIBUNWIND_TARGET_INFO@"
+lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
 
 compile_flags = []
 link_flags = []
-if @LIBUNWIND_USES_ARM_EHABI@:
-    config.available_features.add('libunwind-arm-ehabi')
-
-if not @LIBUNWIND_ENABLE_THREADS@:
-    config.available_features.add('libunwind-no-threads')
 
 if @LIBUNWIND_ENABLE_CET@:
     compile_flags.append('-fcf-protection=full')
@@ -39,21 +16,18 @@ if '@CMAKE_SYSTEM_NAME@' == 'Linux':
 # Stack unwinding tests need unwinding tables and these are not generated by default on all targets.
 compile_flags.append('-funwind-tables')
 
-config.substitutions.append(('%{executor}', '@LIBUNWIND_EXECUTOR@'))
-
-config.substitutions.append(('%{cxx}', '@CMAKE_CXX_COMPILER@'))
 local_sysroot = '@CMAKE_OSX_SYSROOT@' or '@CMAKE_SYSROOT@'
 config.substitutions.append(('%{flags}',
     '-isysroot {}'.format(local_sysroot) if local_sysroot else ''
 ))
 config.substitutions.append(('%{compile_flags}',
-    '-nostdinc++ -I {}/include {}'.format('@LIBUNWIND_SOURCE_DIR@', ' '.join(compile_flags))
+    '-nostdinc++ -I %{{include}} {}'.format(' '.join(compile_flags))
 ))
 config.substitutions.append(('%{link_flags}',
-    '-L {0} -Wl,-rpath,{0} -lunwind -ldl {1}'.format('@LIBUNWIND_LIBRARY_DIR@', ' '.join(link_flags))
+    '-L %{{lib}} -Wl,-rpath,%{{lib}} -lunwind -ldl {}'.format(' '.join(link_flags))
 ))
 config.substitutions.append(('%{exec}',
-    '%{executor} --execdir %T -- ' if '@LIBUNWIND_EXECUTOR@' else ''
+    '%{executor} --execdir %T -- '
 ))
 
 import os, site

diff  --git a/libunwind/test/configs/llvm-libunwind-static.cfg.in b/libunwind/test/configs/llvm-libunwind-static.cfg.in
index ce5a6c82caa0..a947a5d08f58 100644
--- a/libunwind/test/configs/llvm-libunwind-static.cfg.in
+++ b/libunwind/test/configs/llvm-libunwind-static.cfg.in
@@ -1,36 +1,13 @@
- at AUTO_GEN_COMMENT@
-
- at SERIALIZED_LIT_PARAMS@
-
 #
 # Configuration file for running the libunwind tests against the static library.
 #
-# This file is a lot simpler than the ones for libc++ and libc++abi because
-# while libunwind is written in C++, it doesn't use the C++ Standard Library
-# so we don't need to set that up to run the tests correctly.
-#
-
-import os, site
-site.addsitedir(os.path.join('@LIBUNWIND_LIBCXX_PATH@', 'utils'))
-import libcxx.test.format
 
-# Basic configuration of the test suite
-config.name = os.path.basename('@LIBUNWIND_TEST_CONFIG@')
-config.test_source_root = os.path.join('@LIBUNWIND_SOURCE_DIR@', 'test')
-config.test_format = libcxx.test.format.CxxStandardLibraryTest()
-config.recursiveExpansionLimit = 10
-config.test_exec_root = '@CMAKE_BINARY_DIR@'
-config.target_info = "@LIBUNWIND_TARGET_INFO@"
+lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
 
 compile_flags = []
 link_flags = []
 
-if @LIBUNWIND_USES_ARM_EHABI@:
-    config.available_features.add('libunwind-arm-ehabi')
-
-if not @LIBUNWIND_ENABLE_THREADS@:
-    config.available_features.add('libunwind-no-threads')
-else:
+if @LIBUNWIND_ENABLE_THREADS@:
     link_flags.append('-lpthread')
 
 if @LIBUNWIND_ENABLE_CET@:
@@ -39,26 +16,21 @@ if @LIBUNWIND_ENABLE_CET@:
 if '@CMAKE_SYSTEM_NAME@' == 'Linux':
     link_flags.append('-Wl,--export-dynamic')
 
-
 # Stack unwinding tests need unwinding tables and these are not generated by default on all targets.
 compile_flags.append('-funwind-tables')
 
-config.substitutions.append(('%{executor}', '@LIBUNWIND_EXECUTOR@'))
-
-config.substitutions.append(('%{cxx}', '@CMAKE_CXX_COMPILER@'))
-
 local_sysroot = '@CMAKE_OSX_SYSROOT@' or '@CMAKE_SYSROOT@'
 config.substitutions.append(('%{flags}',
     '-isysroot {}'.format(local_sysroot) if local_sysroot else ''
 ))
 config.substitutions.append(('%{compile_flags}',
-    '-nostdinc++ -I {}/include {}'.format('@LIBUNWIND_SOURCE_DIR@', ' '.join(compile_flags))
+    '-nostdinc++ -I %{{include}} {}'.format(' '.join(compile_flags))
 ))
 config.substitutions.append(('%{link_flags}',
-    '{}/libunwind.a -ldl {}'.format('@LIBUNWIND_LIBRARY_DIR@', ' '.join(link_flags))
+    '%{{lib}}/libunwind.a -ldl {}'.format(' '.join(link_flags))
 ))
 config.substitutions.append(('%{exec}',
-    '%{executor} --execdir %T -- ' if '@LIBUNWIND_EXECUTOR@' else ''
+    '%{executor} --execdir %T -- '
 ))
 
 import os, site


        


More information about the libcxx-commits mailing list