[libcxx-commits] [PATCH] D114010: [libc++] Properly handle errors happening during Lit configuration

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Nov 16 09:40:39 PST 2021


ldionne created this revision.
ldionne added a reviewer: Mordante.
Herald added a subscriber: arichardson.
ldionne requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Instead of silently swallowing errors that happen during Lit configuration
(for example trying to obtain compiler macros but compiling fails), raise
an exception with some amount of helpful information.

This should avoid the possibility of silently configuring Lit in a bogus
way, and also provides more helpful information when things fail.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114010

Files:
  libcxx/utils/libcxx/test/dsl.py


Index: libcxx/utils/libcxx/test/dsl.py
===================================================================
--- libcxx/utils/libcxx/test/dsl.py
+++ libcxx/utils/libcxx/test/dsl.py
@@ -20,6 +20,8 @@
 import lit.TestRunner
 import lit.util
 
+class ConfigurationError(Exception):
+  pass
 
 def _memoizeExpensiveOperation(extractCacheKey):
   """
@@ -105,7 +107,7 @@
   with _makeConfigTest(config) as test:
     with open(test.getSourcePath(), 'w') as sourceFile:
       sourceFile.write(source)
-    out, err, exitCode, timeoutInfo = _executeScriptInternal(test, ['%{build}'])
+    _, _, exitCode, _ = _executeScriptInternal(test, ['%{build}'])
     _executeScriptInternal(test, ['rm %t.exe'])
     return exitCode == 0
 
@@ -115,9 +117,9 @@
   Compiles a program for the test target, run it on the test target and return
   the output.
 
-  If the program fails to compile or run, None is returned instead. Note that
-  execution of the program is done through the %{exec} substitution, which means
-  that the program may be run on a remote host depending on what %{exec} does.
+  Note that execution of the program is done through the %{exec} substitution,
+  which means that the program may be run on a remote host depending on what
+  %{exec} does.
   """
   if args is None:
     args = []
@@ -125,13 +127,13 @@
     with open(test.getSourcePath(), 'w') as source:
       source.write(program)
     try:
-      _, _, exitCode, _ = _executeScriptInternal(test, ['%{build}'])
+      _, err, exitCode, _ = _executeScriptInternal(test, ['%{build}'])
       if exitCode != 0:
-        return None
+        raise ConfigurationError("Failed to build program, stderr is:\n{}".format(err))
 
       out, err, exitCode, _ = _executeScriptInternal(test, ["%{{run}} {}".format(' '.join(args))])
       if exitCode != 0:
-        return None
+        raise ConfigurationError("Failed to run program, stderr is:\n{}".format(err))
 
       actualOut = re.search("# command output:\n(.+)\n$", out, flags=re.DOTALL)
       actualOut = actualOut.group(1) if actualOut else ""
@@ -194,20 +196,17 @@
 
   If the optional `flags` argument (a string) is provided, these flags will
   be added to the compiler invocation when generating the macros.
-
-  If we fail to extract the compiler macros because of a compiler error, None
-  is returned instead.
   """
   with _makeConfigTest(config) as test:
     with open(test.getSourcePath(), 'w') as sourceFile:
       # Make sure files like <__config> are included, since they can define
       # additional macros.
       sourceFile.write("#include <stddef.h>")
-    unparsedOutput, err, exitCode, timeoutInfo = _executeScriptInternal(test, [
+    unparsedOutput, err, exitCode, _ = _executeScriptInternal(test, [
       "%{{cxx}} %s -dM -E %{{flags}} %{{compile_flags}} {}".format(flags)
     ])
     if exitCode != 0:
-      return None
+      raise ConfigurationError("Failed to retrieve compiler macros, stderr is:\n{}".format(err))
     parsedMacros = dict()
     defines = (l.strip() for l in unparsedOutput.split('\n') if l.startswith('#define '))
     for line in defines:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114010.387689.patch
Type: text/x-patch
Size: 3113 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211116/7adb9a01/attachment.bin>


More information about the libcxx-commits mailing list