From 1ce50b75d38f696a2ae46f994c5e3d4f93136042 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Sun, 3 Mar 2019 11:33:28 -0700 Subject: [PYPY] fix way exit status is retrieved in main MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When scons exits, it wants to take the opportunity to print any diagnostics and statistics that may have been requested, so the main routine traps the various ways it can quit. If code somewhere calls sys.exit(), that generates a SystemExit exception. The handling of that has not been quite correct - it simply takes the exception instance, saves it, and later quits with sys.exit(saved). This seemingly works fine for all other tested versions of Python, but has interesting side effects with PyPy3. Per the Python documentation: If the value is an integer, it specifies the system exit status (passed to C’s exit() function); if it is None, the exit status is zero; if it has another type (such as a string), the object’s value is printed and the exit status is one. And in fact, PyPy3 does this: if the original call to sys.exit took a value of 2, then the SystemExit exception triggers with a class instance which does have an exit code of 2, which turns up if you take the string repr of the instance, but when passed to the final sys.exit, as it's not an integer it *prints* the 2, and returns with an exit code of 1, just as in the documentation snip. Not really sure if PyPy3 is wrong here, or the other Pythons are letting something slide, but it's an easy fix: save off the code stored in the exception instance for later use as the exit code, instead of using the instance itself for that. Signed-off-by: Mats Wichmann --- src/CHANGES.txt | 1 + src/engine/SCons/Script/Main.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 0a80095..4d24611 100755 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -33,6 +33,7 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER not using a context manager around Popen.stdout - Add the textfile tool to the default tool list - Fix syntax on is/is not clauses: should not use with a literal + - Properly retrieve exit code when catching SystemExit From Bernhard M. Wiedemann: - Do not store build host+user name if reproducible builds are wanted diff --git a/src/engine/SCons/Script/Main.py b/src/engine/SCons/Script/Main.py index 2c59808..f3475f2 100644 --- a/src/engine/SCons/Script/Main.py +++ b/src/engine/SCons/Script/Main.py @@ -1376,7 +1376,7 @@ def main(): revert_io() except SystemExit as s: if s: - exit_status = s + exit_status = s.code except KeyboardInterrupt: print("scons: Build interrupted.") sys.exit(2) -- cgit v0.12