[pushed]PR modula2/126911: Build fix to prevent Python hanging

Gaius Mulley <[email protected]>
Newsgroups gmane.comp.gcc.patches
Message-ID <[email protected]>
This patch fixes mktargetsrc.py if gm2 fails to run.  With this
patch mktargetsrc.py will remove any output file and any temporary
file before exiting with a non zero status.  This prevents def2doc.py
from spinning attempting to read the first 8192 bytes of a zero
length file.  mktargetsrc.py now defensively invokes gm2 with -S
preventing the driver from invoking an assembler which might not be
installed.  Bootstrapped on Debian x86_64 and FreeBSD15.  The build
fails appropriately when configured with --target=nvptx-none.

gcc/m2/ChangeLog:

	PR modula2/126911
	* tools-src/mktargetsrc.py (quietSystem): Add temporaryFile
	parameter.
	Tidy up if result is non zero by removing temporaryFile
	and args.outputfile.

Signed-off-by: Gaius Mulley <[email protected]>
---
 gcc/m2/tools-src/mktargetsrc.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/gcc/m2/tools-src/mktargetsrc.py b/gcc/m2/tools-src/mktargetsrc.py
index cd61ecec87c..34c19233043 100644
--- a/gcc/m2/tools-src/mktargetsrc.py
+++ b/gcc/m2/tools-src/mktargetsrc.py
@@ -38,7 +38,7 @@ def printf (format, *args):
     print(str(format) % args, end=' ')
 
 
-def quietSystem(args, commandLine):
+def quietSystem(args, commandLine, temporaryFile):
     # Execute commandline and exit if unsuccessful.  It will run
     # gdb on the command line if --gdb is set in args.
     if args.gdb:
@@ -46,6 +46,9 @@ def quietSystem(args, commandLine):
     else:
         result = os.system(commandLine + " 2>&1 /dev/null")
     if result != 0:
+        os.remove(temporaryFile)
+        if (args.outputfile != None) and os.path.exists(args.outputfile):
+            os.remove(args.outputfile)
         printf("failed to execute: %s with an exit code: %d\n",
                commandLine, result)
         sys.exit(result)
@@ -397,14 +400,14 @@ def determineBuiltins(args, includePath):
     if args.fiso or (not args.fpim):
         dialect = '-fiso'
     compiler = stripBackslash(args.compiler)
-    commandLine = "%s %s %s %s -c -fdump-system-exports -o /dev/null %s > %s" % (
+    commandLine = "%s %s %s %s -S -fdump-system-exports -o /dev/null %s > %s" % (
         compiler, dialect, includePath, minimalCommandLine,
         args.modinputfile, temporaryFile)
-    quietSystem(args, commandLine)
-    commandLine = "%s %s %s %s -c -fdump-builtins %s >> %s" % (
+    quietSystem(args, commandLine, temporaryFile)
+    commandLine = "%s %s %s %s -S -fdump-builtins %s >> %s" % (
         compiler, dialect, includePath, minimalCommandLine,
         args.modinputfile, temporaryFile)
-    quietSystem(args, commandLine)
+    quietSystem(args, commandLine, temporaryFile)
     generateSource(args, temporaryFile)
     os.remove(temporaryFile)
 
-- 
2.47.3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.