Skip to content

Commit a95db48

Browse files
committed
Address review comments
1 parent 196cedd commit a95db48

12 files changed

+101
-100
lines changed

libcxx/test/libcxx/module_std.gen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"%{clang-tidy}",
3030
"%{test-tools}/clang_tidy_checks/libcxx-tidy.plugin",
3131
"%{cxx}",
32-
"%{flags} %{compile_flags} %{module_flags}",
32+
"%{flags} %{compile_flags}",
3333
"std",
3434
)
3535

libcxx/test/libcxx/module_std_compat.gen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"%{clang-tidy}",
3030
"%{test-tools}/clang_tidy_checks/libcxx-tidy.plugin",
3131
"%{cxx}",
32-
"%{flags} %{compile_flags} %{module_flags}",
32+
"%{flags} %{compile_flags}",
3333
"std.compat",
3434
)
3535

libcxx/test/libcxx/selftest/modules/no-modules.sh.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// Make sure that the module flags are empty when no module is supplied.
9+
// Make sure that the compile flags contain no module information.
1010

11-
// MODULES:
12-
// RUN: echo "%{module_flags}" | grep "^$"
11+
// MODULE_DEPENDENCIES:
12+
13+
// RUN: echo "%{compile_flags}" | grep -v -- "-fprebuilt-module-path="
14+
// RUN: echo "%{compile_flags}" | grep -v "std.pcm"
15+
// RUN: echo "%{compile_flags}" | grep -v "std.compat.pcm"

libcxx/test/libcxx/selftest/modules/std-and-std.compat-module.sh.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
// UNSUPPORTED: clang-modules-build
1111
// UNSUPPORTED: gcc
1212

13-
// XFAIL: has-no-module-support
13+
// XFAIL: has-no-cxx-module-support
1414

15-
// Make sure that the module flags contain the expected elements.
15+
// Make sure that the compile flags contain the expected elements.
1616
// The tests only look for the expected components and not the exact flags.
1717
// Otherwise changing the location of the module breaks this test.
1818

19-
// MODULES: std std.compat
20-
//
21-
// RUN: echo "%{module_flags}" | grep -- "-fprebuilt-module-path="
22-
// RUN: echo "%{module_flags}" | grep "std.pcm"
23-
// RUN: echo "%{module_flags}" | grep "std.compat.pcm"
19+
// MODULE_DEPENDENCIES: std std.compat
20+
21+
// RUN: echo "%{compile_flags}" | grep -- "-fprebuilt-module-path="
22+
// RUN: echo "%{compile_flags}" | grep "std.pcm"
23+
// RUN: echo "%{compile_flags}" | grep "std.compat.pcm"

libcxx/test/libcxx/selftest/modules/std-module.sh.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
// UNSUPPORTED: clang-modules-build
1111
// UNSUPPORTED: gcc
1212

13-
// XFAIL: has-no-module-support
13+
// XFAIL: has-no-cxx-module-support
1414

15-
// Make sure that the module flags contain the expected elements.
15+
// Make sure that the compile flags contain the expected elements.
1616
// The tests only look for the expected components and not the exact flags.
1717
// Otherwise changing the location of the module breaks this test.
1818

19-
// MODULES: std
20-
//
21-
// RUN: echo "%{module_flags}" | grep -- "-fprebuilt-module-path="
22-
// RUN: echo "%{module_flags}" | grep "std.pcm"
19+
// MODULE_DEPENDENCIES: std
20+
21+
// RUN: echo "%{compile_flags}" | grep -- "-fprebuilt-module-path="
22+
// RUN: echo "%{compile_flags}" | grep "std.pcm"
2323

2424
// The std module should not provide the std.compat module
25-
// RUN: echo "%{module_flags}" | grep -v "std.compat.pcm"
25+
// RUN: echo "%{compile_flags}" | grep -v "std.compat.pcm"

libcxx/test/libcxx/selftest/modules/std.compat-module.sh.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
// UNSUPPORTED: clang-modules-build
1111
// UNSUPPORTED: gcc
1212

13-
// XFAIL: has-no-module-support
13+
// XFAIL: has-no-cxx-module-support
1414

15-
// Make sure that the module flags contain the expected elements.
15+
// Make sure that the compile flags contain the expected elements.
1616
// The tests only look for the expected components and not the exact flags.
1717
// Otherwise changing the location of the module breaks this test.
1818

19-
// MODULES: std.compat
20-
//
21-
// RUN: echo "%{module_flags}" | grep -- "-fprebuilt-module-path="
22-
// RUN: echo "%{module_flags}" | grep "std.compat.pcm"
19+
// MODULE_DEPENDENCIES: std.compat
20+
21+
// RUN: echo "%{compile_flags}" | grep -- "-fprebuilt-module-path="
22+
// RUN: echo "%{compile_flags}" | grep "std.compat.pcm"
2323

2424
// It's unspecified whether std.compat is built on the std module.
2525
// Therefore don't test its presence

libcxx/test/libcxx/selftest/modules/unknown-module.compile.pass.cpp

Lines changed: 0 additions & 13 deletions
This file was deleted.

libcxx/test/std/modules/std.compat.pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
// UNSUPPORTED: clang-modules-build
1111
// UNSUPPORTED: gcc
1212

13-
// XFAIL: has-no-module-support
13+
// XFAIL: has-no-cxx-module-support
1414

1515
// A minimal test to validate import works.
1616

17-
// MODULES: std.compat
17+
// MODULE_DEPENDENCIES: std.compat
1818

1919
import std.compat;
2020

libcxx/test/std/modules/std.pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
// UNSUPPORTED: clang-modules-build
1111
// UNSUPPORTED: gcc
1212

13-
// XFAIL: has-no-module-support
13+
// XFAIL: has-no-cxx-module-support
1414

1515
// A minimal test to validate import works.
1616

17-
// MODULES: std
17+
// MODULE_DEPENDENCIES: std
1818

1919
import std;
2020

libcxx/utils/libcxx/test/features.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ def _getAndroidDeviceApi(cfg):
319319
),
320320
# Whether module support for the platform is available.
321321
Feature(
322-
name="has-no-module-support",
323-
# The libc of these platforms have functions with internal linkages.
322+
name="has-no-cxx-module-support",
323+
# The libc of these platforms have functions with internal linkage.
324324
# This is not allowed per C11 7.1.2 Standard headers/6
325325
# Any declaration of a library function shall have external linkage.
326326
when=lambda cfg: "__ANDROID__" in compilerMacros(cfg)

libcxx/utils/libcxx/test/format.py

Lines changed: 66 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ def _executeScriptInternal(test, litConfig, commands):
5252
return (out, err, exitCode, timeoutInfo, parsedCommands)
5353

5454

55+
def _validateModuleDependencies(modules):
56+
for m in modules:
57+
if m not in ("std", "std.compat"):
58+
raise RuntimeError(
59+
f"Invalid module dependency '{m}', only 'std' and 'std.compat' are valid"
60+
)
61+
62+
63+
def _getSubstitution(substitution, config):
64+
for (orig, replacement) in config.substitutions:
65+
if orig == substitution:
66+
return replacement
67+
raise ValueError("Substitution {} is not in the config.".format(substitution))
68+
69+
5570
def parseScript(test, preamble):
5671
"""
5772
Extract the script from a test, with substitutions applied.
@@ -105,7 +120,7 @@ def parseScript(test, preamble):
105120
initial_value=additionalCompileFlags,
106121
),
107122
lit.TestRunner.IntegratedTestKeywordParser(
108-
"MODULES:",
123+
"MODULE_DEPENDENCIES:",
109124
lit.TestRunner.ParserKind.SPACE_LIST,
110125
initial_value=modules,
111126
),
@@ -138,65 +153,62 @@ def parseScript(test, preamble):
138153
script += preamble
139154
script += scriptInTest
140155

141-
has_std_module = False
142-
has_std_compat_module = False
143-
for module in modules:
144-
if module == "std":
145-
has_std_module = True
146-
elif module == "std.compat":
147-
has_std_compat_module = True
148-
else:
149-
script.insert(
150-
0,
151-
f"echo \"The module '{module}' is not valid, use 'std' or 'std.compat'\"",
152-
)
153-
script.insert(1, "false")
154-
return script
156+
# Add compile flags specified with ADDITIONAL_COMPILE_FLAGS.
157+
# Modules need to be build with the same compilation flags as the
158+
# test. So add these flags before adding the modules.
159+
substitutions = [
160+
(s, x + " " + " ".join(additionalCompileFlags))
161+
if s == "%{compile_flags}"
162+
else (s, x)
163+
for (s, x) in substitutions
164+
]
155165

156166
if modules:
167+
_validateModuleDependencies(modules)
168+
157169
# This flag is needed for both modules.
158170
moduleCompileFlags.append("-fprebuilt-module-path=%T")
159171

160-
# Building the modules needs to happen before the other script commands
161-
# are executed. Therefore the commands are added to the front of the
162-
# list.
163-
if has_std_compat_module:
172+
# The moduleCompileFlags are added to the %{compile_flags}, but
173+
# the modules need should be built without these flags. So
174+
# expand the compile_flags and add the expanded value to the
175+
# build script.
176+
compileFlags = _getSubstitution("%{compile_flags}", test.config)
177+
178+
# Building the modules needs to happen before the other script
179+
# commands are executed. Therefore the commands are added to the
180+
# front of the list.
181+
if "std.compat" in modules:
164182
script.insert(
165183
0,
166-
"%dbg(MODULE std.compat) %{cxx} %{flags} %{compile_flags} "
184+
"%dbg(MODULE std.compat) %{cxx} %{flags} "
185+
f"{compileFlags} "
167186
"-Wno-reserved-module-identifier -Wno-reserved-user-defined-literal "
168187
"--precompile -o %T/std.compat.pcm -c %{module}/std.compat.cppm",
169188
)
170189
moduleCompileFlags.append("%T/std.compat.pcm")
171190

172-
# Make sure the std module is added before std.compat.
173-
# Libc++'s std.compat module will depend on its std module.
174-
# It is not known whether the compiler expects the modules in the order
175-
# of their dependencies. However it's trivial to provide them in that
176-
# order.
177-
if has_std_module:
178-
script.insert(
179-
0,
180-
"%dbg(MODULE std) %{cxx} %{flags} %{compile_flags} "
181-
"-Wno-reserved-module-identifier -Wno-reserved-user-defined-literal "
182-
"--precompile -o %T/std.pcm -c %{module}/std.cppm",
183-
)
184-
moduleCompileFlags.append("%T/std.pcm")
185-
186-
# Add compile flags specified with ADDITIONAL_COMPILE_FLAGS.
187-
substitutions = [
188-
(s, x + " " + " ".join(additionalCompileFlags))
189-
if s == "%{compile_flags}"
190-
else (s, x)
191-
for (s, x) in substitutions
192-
]
193-
# In order to use modules, additional compilation flags are required.
194-
# Adding these to the %{compile_flags} gives a chicken and egg issue:
195-
# - the modules need to be built with the same compilation flags as the
196-
# tests,
197-
# - except for the module dependency, which does not exist.
198-
# The issue is resolved by adding a private substitution.
199-
substitutions.append(("%{module_flags}", " ".join(moduleCompileFlags)))
191+
# Make sure the std module is added before std.compat. Libc++'s
192+
# std.compat module will depend on its std module. It is not
193+
# known whether the compiler expects the modules in the order of
194+
# their dependencies. However it's trivial to provide them in
195+
# that order.
196+
script.insert(
197+
0,
198+
"%dbg(MODULE std) %{cxx} %{flags} "
199+
f"{compileFlags} "
200+
"-Wno-reserved-module-identifier -Wno-reserved-user-defined-literal "
201+
"--precompile -o %T/std.pcm -c %{module}/std.cppm",
202+
)
203+
moduleCompileFlags.append("%T/std.pcm")
204+
205+
# Add compile flags required for the modules.
206+
substitutions = [
207+
(s, x + " " + " ".join(moduleCompileFlags))
208+
if s == "%{compile_flags}"
209+
else (s, x)
210+
for (s, x) in substitutions
211+
]
200212

201213
# Perform substitutions in the script itself.
202214
script = lit.TestRunner.applySubstitutions(
@@ -250,7 +262,6 @@ class CxxStandardLibraryTest(lit.formats.FileBasedTest):
250262
constructs:
251263
%{cxx} - A command that can be used to invoke the compiler
252264
%{compile_flags} - Flags to use when compiling a test case
253-
%{module_flags} - Flags to use when compiling a test case that imports modules
254265
%{link_flags} - Flags to use when linking a test case
255266
%{flags} - Flags to use either when compiling or linking a test case
256267
%{exec} - A command to prefix the execution of executables
@@ -287,7 +298,7 @@ class CxxStandardLibraryTest(lit.formats.FileBasedTest):
287298
288299
This directive will build the required C++23 standard library
289300
modules and add the additional compiler flags in
290-
%{module_flags}. (Libc++ offers these modules in C++20 as an
301+
%{compile_flags}. (Libc++ offers these modules in C++20 as an
291302
extension.)
292303
293304
Additional provided substitutions and features
@@ -354,22 +365,22 @@ def execute(self, test, litConfig):
354365
".compile.pass.mm"
355366
):
356367
steps = [
357-
"%dbg(COMPILED WITH) %{cxx} %s %{flags} %{compile_flags} %{module_flags} -fsyntax-only"
368+
"%dbg(COMPILED WITH) %{cxx} %s %{flags} %{compile_flags} -fsyntax-only"
358369
]
359370
return self._executeShTest(test, litConfig, steps)
360371
elif filename.endswith(".compile.fail.cpp"):
361372
steps = [
362-
"%dbg(COMPILED WITH) ! %{cxx} %s %{flags} %{compile_flags} %{module_flags} -fsyntax-only"
373+
"%dbg(COMPILED WITH) ! %{cxx} %s %{flags} %{compile_flags} -fsyntax-only"
363374
]
364375
return self._executeShTest(test, litConfig, steps)
365376
elif filename.endswith(".link.pass.cpp") or filename.endswith(".link.pass.mm"):
366377
steps = [
367-
"%dbg(COMPILED WITH) %{cxx} %s %{flags} %{compile_flags} %{module_flags} %{link_flags} -o %t.exe"
378+
"%dbg(COMPILED WITH) %{cxx} %s %{flags} %{compile_flags} %{link_flags} -o %t.exe"
368379
]
369380
return self._executeShTest(test, litConfig, steps)
370381
elif filename.endswith(".link.fail.cpp"):
371382
steps = [
372-
"%dbg(COMPILED WITH) %{cxx} %s %{flags} %{compile_flags} %{module_flags} -c -o %t.o",
383+
"%dbg(COMPILED WITH) %{cxx} %s %{flags} %{compile_flags} -c -o %t.o",
373384
"%dbg(LINKED WITH) ! %{cxx} %t.o %{flags} %{link_flags} -o %t.exe",
374385
]
375386
return self._executeShTest(test, litConfig, steps)
@@ -387,7 +398,7 @@ def execute(self, test, litConfig):
387398
# suffixes above too.
388399
elif filename.endswith(".pass.cpp") or filename.endswith(".pass.mm"):
389400
steps = [
390-
"%dbg(COMPILED WITH) %{cxx} %s %{flags} %{compile_flags} %{module_flags} %{link_flags} -o %t.exe",
401+
"%dbg(COMPILED WITH) %{cxx} %s %{flags} %{compile_flags} %{link_flags} -o %t.exe",
391402
"%dbg(EXECUTED AS) %{exec} %t.exe",
392403
]
393404
return self._executeShTest(test, litConfig, steps)

libcxx/utils/libcxx/test/modules.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def write_lit_configuration(self):
126126
// The GCC compiler flags are not always compatible with clang-tidy.
127127
// UNSUPPORTED: gcc
128128
129-
// MODULES: {self.module}
129+
// MODULE_DEPENDENCIES: {self.module}
130130
131131
// RUN: echo -n > {self.tmp_prefix}.all_partitions
132132
"""

0 commit comments

Comments
 (0)