Skip to content

Commit cd7f975

Browse files
committed
[libc++] NFC: Simplify substitutions by using lit recursive substitutions
Since lit supports expanding substitutions recursively, we can define substitutions in terms of other substitutions. This allows us to simplify how libc++ substitutions are defined. This doesn't change the substitutions at all, it only makes them simpler to define.
1 parent f4f4a8b commit cd7f975

File tree

3 files changed

+18
-26
lines changed

3 files changed

+18
-26
lines changed

libcxx/test/lit.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,5 @@ configuration = config_module.Configuration(lit_config, config)
5353
configuration.configure()
5454
configuration.print_config_info()
5555
config.test_format = configuration.get_test_format()
56+
57+
lit_config.recursiveExpansionLimit = 10

libcxx/utils/libcxx/test/config.py

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,35 +1039,26 @@ def configure_substitutions(self):
10391039
if self.target_info.is_darwin():
10401040
# Do not pass DYLD_LIBRARY_PATH to the compiler, linker, etc. as
10411041
# these tools are not meant to exercise the just-built libraries.
1042-
tool_env += 'env DYLD_LIBRARY_PATH="" '
1042+
tool_env += 'env DYLD_LIBRARY_PATH=""'
10431043

10441044
sub = self.config.substitutions
1045-
cxx_path = tool_env + pipes.quote(self.cxx.path)
10461045
# Configure compiler substitutions
1047-
sub.append(('%{cxx}', cxx_path))
1046+
sub.append(('%{cxx}', '{} {}'.format(tool_env, pipes.quote(self.cxx.path))))
10481047
sub.append(('%{libcxx_src_root}', self.libcxx_src_root))
10491048
# Configure flags substitutions
1050-
flags_str = ' '.join([pipes.quote(f) for f in self.cxx.flags])
1051-
compile_flags_str = ' '.join([pipes.quote(f) for f in self.cxx.compile_flags])
1052-
link_flags_str = ' '.join([pipes.quote(f) for f in self.cxx.link_flags])
1053-
all_flags = '%s %s %s' % (flags_str, compile_flags_str, link_flags_str)
1054-
sub.append(('%{flags}', flags_str))
1055-
sub.append(('%{compile_flags}', compile_flags_str))
1056-
sub.append(('%{link_flags}', link_flags_str))
1049+
sub.append(('%{flags}', ' '.join(map(pipes.quote, self.cxx.flags))))
1050+
sub.append(('%{compile_flags}', ' '.join(map(pipes.quote, self.cxx.compile_flags))))
1051+
sub.append(('%{link_flags}', ' '.join(map(pipes.quote, self.cxx.link_flags))))
10571052
if self.cxx.isVerifySupported():
1058-
verify_str = ' ' + ' '.join(self.cxx.verify_flags) + ' '
1059-
sub.append(('%{verify}', verify_str))
1060-
# Add compile and link shortcuts
1061-
compile_str = (cxx_path + ' -o %t.o %s -c ' + flags_str
1062-
+ ' ' + compile_flags_str)
1063-
build_str = cxx_path + ' -o %t.exe %s ' + all_flags
1053+
sub.append(('%{verify}', ' '.join(self.cxx.verify_flags)))
1054+
# Add compile and build shortcuts
1055+
sub.append(('%{compile}', '%{cxx} -o %t.o %s -c %{flags} %{compile_flags}'))
1056+
sub.append(('%{build}', '%{cxx} -o %t.exe %s %{flags} %{compile_flags} %{link_flags}'))
10641057
if self.cxx.use_modules:
1065-
sub.append(('%{build_module}', build_str))
1058+
sub.append(('%{build_module}', '%{build}'))
10661059
elif self.cxx.modules_flags is not None:
1067-
modules_str = ' '.join(self.cxx.modules_flags) + ' '
1068-
sub.append(('%{build_module}', build_str + ' ' + modules_str))
1069-
sub.append(('%{compile}', compile_str))
1070-
sub.append(('%{build}', build_str))
1060+
sub.append(('%{build_module}', '%{{build}} {}'.format(' '.join(self.cxx.modules_flags))))
1061+
10711062
# Configure exec prefix substitutions.
10721063
# Configure run env substitution.
10731064
codesign_ident = self.get_lit_conf('llvm_codesign_identity', '')
@@ -1077,13 +1068,11 @@ def configure_substitutions(self):
10771068
'--dependencies %%file_dependencies --env %s -- ' % \
10781069
(pipes.quote(sys.executable), pipes.quote(run_py),
10791070
codesign_ident, env_vars)
1080-
run_str = exec_str + '%t.exe'
10811071
sub.append(('%{exec}', exec_str))
1082-
sub.append(('%{run}', run_str))
1072+
sub.append(('%{run}', '%{exec} %t.exe'))
10831073
# Configure not program substitutions
10841074
not_py = os.path.join(self.libcxx_src_root, 'utils', 'not.py')
1085-
not_str = '%s %s ' % (pipes.quote(sys.executable), pipes.quote(not_py))
1086-
sub.append(('%{not} ', not_str))
1075+
sub.append(('%{not}', '{} {}'.format(pipes.quote(sys.executable), pipes.quote(not_py))))
10871076
if self.get_lit_conf('libcxx_gdb'):
10881077
sub.append(('%{libcxx_gdb}', self.get_lit_conf('libcxx_gdb')))
10891078

libcxx/utils/libcxx/test/format.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ def _execute(self, test, lit_config):
124124
substitutions = lit.TestRunner.getDefaultSubstitutions(test, tmpDir,
125125
tmpBase)
126126
substitutions.append(('%file_dependencies', ' '.join(data_files)))
127-
script = lit.TestRunner.applySubstitutions(script, substitutions)
127+
script = lit.TestRunner.applySubstitutions(script, substitutions,
128+
recursion_limit=lit_config.recursiveExpansionLimit)
128129

129130
test_cxx = copy.deepcopy(self.cxx)
130131
if is_fail_test:

0 commit comments

Comments
 (0)