Skip to content

Commit 19a3e24

Browse files
committed
[libc++] Simplify writing testing config files
Reduce code duplication by sharing most of the test suite setup across the different from-scratch configs. Differential Revision: https://reviews.llvm.org/D111196
1 parent 07e5394 commit 19a3e24

File tree

6 files changed

+60
-129
lines changed

6 files changed

+60
-129
lines changed

libcxx/test/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ endif()
130130
if (LIBCXX_INCLUDE_TESTS)
131131
include(AddLLVM) # for configure_lit_site_cfg and add_lit_testsuite
132132

133+
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/configs/cmake-bridge.cfg.in"
134+
"${CMAKE_CURRENT_BINARY_DIR}/cmake-bridge.cfg"
135+
@ONLY)
136+
133137
configure_lit_site_cfg(
134138
"${LIBCXX_TEST_CONFIG}"
135139
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg

libcxx/test/configs/apple-libc++-shared.cfg.in

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
@AUTO_GEN_COMMENT@
2-
3-
@SERIALIZED_LIT_PARAMS@
4-
5-
#
61
# Testing configuration for Apple's system libc++.
72
#
83
# This configuration differs from a normal LLVM shared library configuration in
@@ -11,57 +6,27 @@
116
#
127
# We also don't use a per-target include directory layout, so we have only one
138
# include directory for the libc++ headers.
14-
#
15-
16-
LIBCXX_ROOT = "@LIBCXX_SOURCE_DIR@"
17-
INSTALL_ROOT = "@CMAKE_BINARY_DIR@"
18-
COMPILER = "@CMAKE_CXX_COMPILER@"
19-
EXEC_ROOT = "@LIBCXX_BINARY_DIR@"
20-
CMAKE_OSX_SYSROOT = "@CMAKE_OSX_SYSROOT@"
21-
INCLUDE_DIR = "@LIBCXX_INSTALL_INCLUDE_DIR@"
22-
LIBRARY_DIR = "@LIBCXX_INSTALL_LIBRARY_DIR@"
239

24-
import os
25-
import pipes
26-
import site
2710
import sys
28-
site.addsitedir(os.path.join(LIBCXX_ROOT, 'utils'))
29-
import libcxx.test.features
30-
import libcxx.test.format
31-
import libcxx.test.newconfig
32-
import libcxx.test.params
3311

34-
# Configure basic properties of the test suite
35-
config.name = 'libcxx-trunk-shared'
36-
config.test_source_root = os.path.join(LIBCXX_ROOT, 'test')
37-
config.test_format = libcxx.test.format.CxxStandardLibraryTest()
38-
config.recursiveExpansionLimit = 10
39-
config.test_exec_root = EXEC_ROOT
12+
lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
4013

41-
# Configure basic substitutions
42-
runPy = os.path.join(LIBCXX_ROOT, 'utils', 'run.py')
43-
config.substitutions.append(('%{cxx}', COMPILER))
4414
config.substitutions.append(('%{flags}',
45-
'-isysroot {}'.format(CMAKE_OSX_SYSROOT) if CMAKE_OSX_SYSROOT else ''
15+
'-isysroot {}'.format('@CMAKE_OSX_SYSROOT@') if '@CMAKE_OSX_SYSROOT@' else ''
4616
))
4717
config.substitutions.append(('%{compile_flags}',
48-
'-nostdinc++ -isystem {} -I {}'.format(
49-
os.path.join(INSTALL_ROOT, INCLUDE_DIR),
50-
os.path.join(LIBCXX_ROOT, 'test', 'support'))
18+
'-nostdinc++ -isystem %{install}/include/c++/v1 -I %{libcxx}/test/support'
5119
))
5220
config.substitutions.append(('%{link_flags}',
53-
'-nostdlib++ -L {} -lc++'.format(
54-
os.path.join(INSTALL_ROOT, LIBRARY_DIR))
21+
'-nostdlib++ -L %{install}/lib -lc++'
5522
))
5623
config.substitutions.append(('%{exec}',
57-
'{} {} --execdir %T --env DYLD_LIBRARY_PATH={} -- '.format(
58-
pipes.quote(sys.executable),
59-
pipes.quote(runPy),
60-
pipes.quote(os.path.join(INSTALL_ROOT, LIBRARY_DIR)))
24+
'{} %{{libcxx}}/utils/run.py --execdir %T --env DYLD_LIBRARY_PATH=%{{install}}/lib -- '.format(sys.executable)
6125
))
62-
config.substitutions.append(('%{install}', INSTALL_ROOT))
6326

64-
# Add parameters and features to the config
27+
import os, site
28+
site.addsitedir(os.path.join('@LIBCXX_SOURCE_DIR@', 'utils'))
29+
import libcxx.test.params, libcxx.test.newconfig, libcxx.test.newconfig
6530
libcxx.test.newconfig.configure(
6631
libcxx.test.params.DEFAULT_PARAMETERS,
6732
libcxx.test.features.DEFAULT_FEATURES,
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
@AUTO_GEN_COMMENT@
2+
3+
@SERIALIZED_LIT_PARAMS@
4+
5+
#
6+
# This file performs the bridge between the CMake configuration and the Lit
7+
# configuration files by setting up the LitConfig object and various Lit
8+
# substitutions from CMake variables.
9+
#
10+
# Individual configuration files can take advantage of this bridge by
11+
# loading the file and then setting up the remaining Lit substitutions.
12+
#
13+
14+
import os, site
15+
site.addsitedir(os.path.join('@LIBCXX_SOURCE_DIR@', 'utils'))
16+
import libcxx.test.format
17+
18+
# Basic configuration of the test suite
19+
config.name = os.path.basename('@LIBCXX_TEST_CONFIG@')
20+
config.test_source_root = os.path.join('@LIBCXX_SOURCE_DIR@', 'test')
21+
config.test_format = libcxx.test.format.CxxStandardLibraryTest()
22+
config.recursiveExpansionLimit = 10
23+
config.test_exec_root = '@CMAKE_BINARY_DIR@'
24+
25+
# Add substitutions for bootstrapping the test suite configuration
26+
config.substitutions.append(('%{cxx}', '@CMAKE_CXX_COMPILER@'))
27+
config.substitutions.append(('%{libcxx}', '@LIBCXX_SOURCE_DIR@'))
28+
config.substitutions.append(('%{install}', '@CMAKE_BINARY_DIR@'))
29+
config.substitutions.append(('%{include}', '%{install}/@LIBCXX_INSTALL_INCLUDE_DIR@'))
30+
config.substitutions.append(('%{target-include}', '%{install}/@LIBCXX_INSTALL_INCLUDE_TARGET_DIR@'))
31+
config.substitutions.append(('%{lib}', '%{install}/@LIBCXX_INSTALL_LIBRARY_DIR@'))

libcxx/test/configs/llvm-libc++-shared.cfg.in

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,26 @@
1-
@AUTO_GEN_COMMENT@
2-
3-
@SERIALIZED_LIT_PARAMS@
4-
5-
#
61
# This testing configuration handles running the test suite against LLVM's libc++
72
# using a shared library.
8-
#
9-
10-
LIBCXX_ROOT = "@LIBCXX_SOURCE_DIR@"
11-
INSTALL_ROOT = "@CMAKE_BINARY_DIR@"
12-
COMPILER = "@CMAKE_CXX_COMPILER@"
13-
EXEC_ROOT = "@LIBCXX_BINARY_DIR@"
14-
CMAKE_OSX_SYSROOT = "@CMAKE_OSX_SYSROOT@"
15-
INCLUDE_DIR = "@LIBCXX_INSTALL_INCLUDE_DIR@"
16-
INCLUDE_TARGET_DIR = "@LIBCXX_INSTALL_INCLUDE_TARGET_DIR@"
17-
LIBRARY_DIR = "@LIBCXX_INSTALL_LIBRARY_DIR@"
183

19-
import os
20-
import pipes
21-
import site
224
import sys
23-
site.addsitedir(os.path.join(LIBCXX_ROOT, 'utils'))
24-
import libcxx.test.features
25-
import libcxx.test.format
26-
import libcxx.test.newconfig
27-
import libcxx.test.params
285

29-
# Configure basic properties of the test suite
30-
config.name = 'llvm-libc++-shared'
31-
config.test_source_root = os.path.join(LIBCXX_ROOT, 'test')
32-
config.test_format = libcxx.test.format.CxxStandardLibraryTest()
33-
config.recursiveExpansionLimit = 10
34-
config.test_exec_root = EXEC_ROOT
6+
lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
357

36-
# Configure basic substitutions
37-
runPy = os.path.join(LIBCXX_ROOT, 'utils', 'run.py')
38-
config.substitutions.append(('%{cxx}', COMPILER))
398
config.substitutions.append(('%{flags}',
40-
'-isysroot {}'.format(CMAKE_OSX_SYSROOT) if CMAKE_OSX_SYSROOT else ''
9+
'-isysroot {}'.format('@CMAKE_OSX_SYSROOT@') if '@CMAKE_OSX_SYSROOT@' else ''
4110
))
4211
config.substitutions.append(('%{compile_flags}',
43-
'-nostdinc++ -isystem {} -isystem {} -I {}'.format(
44-
os.path.join(INSTALL_ROOT, INCLUDE_DIR),
45-
os.path.join(INSTALL_ROOT, INCLUDE_TARGET_DIR),
46-
os.path.join(LIBCXX_ROOT, 'test', 'support'))
12+
'-nostdinc++ -isystem %{include} -isystem %{target-include} -I %{libcxx}/test/support'
4713
))
4814
config.substitutions.append(('%{link_flags}',
49-
'-nostdlib++ -L {0} -lc++ -Wl,-rpath,{0} -pthread'.format(
50-
os.path.join(INSTALL_ROOT, LIBRARY_DIR))
15+
'-nostdlib++ -L %{lib} -Wl,-rpath,%{lib} -lc++ -pthread'
5116
))
5217
config.substitutions.append(('%{exec}',
53-
'{} {} --execdir %T -- '.format(
54-
pipes.quote(sys.executable),
55-
pipes.quote(runPy))
18+
'{} %{{libcxx}}/utils/run.py --execdir %T -- '.format(sys.executable)
5619
))
5720

58-
# Add parameters and features to the config
21+
import os, site
22+
site.addsitedir(os.path.join('@LIBCXX_SOURCE_DIR@', 'utils'))
23+
import libcxx.test.params, libcxx.test.newconfig, libcxx.test.newconfig
5924
libcxx.test.newconfig.configure(
6025
libcxx.test.params.DEFAULT_PARAMETERS,
6126
libcxx.test.features.DEFAULT_FEATURES,

libcxx/test/configs/llvm-libc++-static.cfg.in

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,26 @@
1-
@AUTO_GEN_COMMENT@
2-
3-
@SERIALIZED_LIT_PARAMS@
4-
5-
#
61
# This testing configuration handles running the test suite against LLVM's libc++
72
# using a static library.
8-
#
9-
10-
LIBCXX_ROOT = "@LIBCXX_SOURCE_DIR@"
11-
INSTALL_ROOT = "@CMAKE_BINARY_DIR@"
12-
COMPILER = "@CMAKE_CXX_COMPILER@"
13-
EXEC_ROOT = "@LIBCXX_BINARY_DIR@"
14-
CMAKE_OSX_SYSROOT = "@CMAKE_OSX_SYSROOT@"
15-
INCLUDE_DIR = "@LIBCXX_INSTALL_INCLUDE_DIR@"
16-
INCLUDE_TARGET_DIR = "@LIBCXX_INSTALL_INCLUDE_TARGET_DIR@"
17-
LIBRARY_DIR = "@LIBCXX_INSTALL_LIBRARY_DIR@"
183

19-
import os
20-
import pipes
21-
import site
224
import sys
23-
site.addsitedir(os.path.join(LIBCXX_ROOT, 'utils'))
24-
import libcxx.test.features
25-
import libcxx.test.format
26-
import libcxx.test.newconfig
27-
import libcxx.test.params
285

29-
# Configure basic properties of the test suite
30-
config.name = 'llvm-libc++-static'
31-
config.test_source_root = os.path.join(LIBCXX_ROOT, 'test')
32-
config.test_format = libcxx.test.format.CxxStandardLibraryTest()
33-
config.recursiveExpansionLimit = 10
34-
config.test_exec_root = EXEC_ROOT
6+
lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
357

36-
# Configure basic substitutions
37-
runPy = os.path.join(LIBCXX_ROOT, 'utils', 'run.py')
38-
config.substitutions.append(('%{cxx}', COMPILER))
398
config.substitutions.append(('%{flags}',
40-
'-isysroot {}'.format(CMAKE_OSX_SYSROOT) if CMAKE_OSX_SYSROOT else ''
9+
'-isysroot {}'.format('@CMAKE_OSX_SYSROOT@') if '@CMAKE_OSX_SYSROOT@' else ''
4110
))
4211
config.substitutions.append(('%{compile_flags}',
43-
'-nostdinc++ -isystem {} -isystem {} -I {}'.format(
44-
os.path.join(INSTALL_ROOT, INCLUDE_DIR),
45-
os.path.join(INSTALL_ROOT, INCLUDE_TARGET_DIR),
46-
os.path.join(LIBCXX_ROOT, 'test', 'support'))
12+
'-nostdinc++ -isystem %{include} -isystem %{target-include} -I %{libcxx}/test/support'
4713
))
4814
config.substitutions.append(('%{link_flags}',
49-
'-nostdlib++ -L {} -lc++ -lc++abi -pthread'.format(
50-
os.path.join(INSTALL_ROOT, LIBRARY_DIR))
15+
'-nostdlib++ -L %{lib} -lc++ -lc++abi -pthread'
5116
))
5217
config.substitutions.append(('%{exec}',
53-
'{} {} --execdir %T -- '.format(
54-
pipes.quote(sys.executable),
55-
pipes.quote(runPy))
18+
'{} %{{libcxx}}/utils/run.py --execdir %T -- '.format(sys.executable)
5619
))
5720

58-
# Add parameters and features to the config
21+
import os, site
22+
site.addsitedir(os.path.join('@LIBCXX_SOURCE_DIR@', 'utils'))
23+
import libcxx.test.params, libcxx.test.newconfig, libcxx.test.newconfig
5924
libcxx.test.newconfig.configure(
6025
libcxx.test.params.DEFAULT_PARAMETERS,
6126
libcxx.test.features.DEFAULT_FEATURES,

libcxx/utils/libcxx/test/params.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def getStdFlag(cfg, std):
6060
actions=lambda triple: filter(None, [
6161
AddFeature('target={}'.format(triple)),
6262
AddFlagIfSupported('--target={}'.format(triple)),
63+
AddSubstitution('%{triple}', triple)
6364
])),
6465

6566
Parameter(name='std', choices=_allStandards, type=str,

0 commit comments

Comments
 (0)