aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouis Dionne <ldionne.2@gmail.com>2023-09-15 10:15:50 -0400
committerGitHub <noreply@github.com>2023-09-15 10:15:50 -0400
commitb64bf895e5a81153e2385023e0d699ffc24a0b7c (patch)
tree9bec08170caf494163e611e8662b025cbc2a0812
parent320d4c90fa52d59cc0ed7bac570cd62323dae56f (diff)
downloadllvm-b64bf895e5a81153e2385023e0d699ffc24a0b7c.zip
llvm-b64bf895e5a81153e2385023e0d699ffc24a0b7c.tar.gz
llvm-b64bf895e5a81153e2385023e0d699ffc24a0b7c.tar.bz2
[libc++] Improve the verbosity of configuration errors when a compiler flag is not supported (#66379)
If an assertion fails during the configuration of the test suite because the compiler doesn't support a flag (or the compiler configuration is borked entirely), we will now print additional context to help debug the issue instead of just saying "The compiler doesn't support the flag" and bailing.
-rw-r--r--libcxx/utils/libcxx/test/dsl.py48
1 files changed, 25 insertions, 23 deletions
diff --git a/libcxx/utils/libcxx/test/dsl.py b/libcxx/utils/libcxx/test/dsl.py
index 847cebf..64e44ee 100644
--- a/libcxx/utils/libcxx/test/dsl.py
+++ b/libcxx/utils/libcxx/test/dsl.py
@@ -203,6 +203,19 @@ def programSucceeds(config, program, args=None):
@_memoizeExpensiveOperation(lambda c, f: (c.substitutions, c.environment, f))
+def tryCompileFlag(config, flag):
+ """
+ Try using the given compiler flag and return the exit code along with stdout and stderr.
+ """
+ # fmt: off
+ with _makeConfigTest(config) as test:
+ out, err, exitCode, timeoutInfo, _ = _executeWithFakeConfig(test, [
+ "%{{cxx}} -xc++ {} -Werror -fsyntax-only %{{flags}} %{{compile_flags}} {}".format(os.devnull, flag)
+ ])
+ return exitCode, out, err
+ # fmt: on
+
+
def hasCompileFlag(config, flag):
"""
Return whether the compiler in the configuration supports a given compiler flag.
@@ -210,16 +223,8 @@ def hasCompileFlag(config, flag):
This is done by executing the %{cxx} substitution with the given flag and
checking whether that succeeds.
"""
- with _makeConfigTest(config) as test:
- out, err, exitCode, timeoutInfo, _ = _executeWithFakeConfig(
- test,
- [
- "%{{cxx}} -xc++ {} -Werror -fsyntax-only %{{flags}} %{{compile_flags}} {}".format(
- os.devnull, flag
- )
- ],
- )
- return exitCode == 0
+ (exitCode, _, _) = tryCompileFlag(config, flag)
+ return exitCode == 0
@_memoizeExpensiveOperation(lambda c, s: (c.substitutions, c.environment, s))
@@ -348,10 +353,15 @@ def _getSubstitution(substitution, config):
def _appendToSubstitution(substitutions, key, value):
return [(k, v + " " + value) if k == key else (k, v) for (k, v) in substitutions]
-
def _prependToSubstitution(substitutions, key, value):
return [(k, value + " " + v) if k == key else (k, v) for (k, v) in substitutions]
+def _ensureFlagIsSupported(config, flag):
+ (exitCode, out, err) = tryCompileFlag(config, flag)
+ assert (
+ exitCode == 0
+ ), f"Trying to enable compiler flag {flag}, which is not supported. stdout was:\n{out}\n\nstderr was:\n{err}"
+
class ConfigAction(object):
"""
@@ -427,9 +437,7 @@ class AddFlag(ConfigAction):
def applyTo(self, config):
flag = self._getFlag(config)
- assert hasCompileFlag(
- config, flag
- ), "Trying to enable flag {}, which is not supported".format(flag)
+ _ensureFlagIsSupported(config, flag)
config.substitutions = _appendToSubstitution(
config.substitutions, "%{flags}", flag
)
@@ -473,9 +481,7 @@ class AddCompileFlag(ConfigAction):
def applyTo(self, config):
flag = self._getFlag(config)
- assert hasCompileFlag(
- config, flag
- ), "Trying to enable compile flag {}, which is not supported".format(flag)
+ _ensureFlagIsSupported(config, flag)
config.substitutions = _appendToSubstitution(
config.substitutions, "%{compile_flags}", flag
)
@@ -497,9 +503,7 @@ class AddLinkFlag(ConfigAction):
def applyTo(self, config):
flag = self._getFlag(config)
- assert hasCompileFlag(
- config, flag
- ), "Trying to enable link flag {}, which is not supported".format(flag)
+ _ensureFlagIsSupported(config, flag)
config.substitutions = _appendToSubstitution(
config.substitutions, "%{link_flags}", flag
)
@@ -521,9 +525,7 @@ class PrependLinkFlag(ConfigAction):
def applyTo(self, config):
flag = self._getFlag(config)
- assert hasCompileFlag(
- config, flag
- ), "Trying to enable link flag {}, which is not supported".format(flag)
+ _ensureFlagIsSupported(config, flag)
config.substitutions = _prependToSubstitution(
config.substitutions, "%{link_flags}", flag
)