scons: Fix scons 'readCommand' non-zero exits (#1587)

There appears to have been an assumption here that `Popen` would raise
an exception if the command run returned non-zero. This is not the case.
This commit fixes this by obtaining the return code and throwing an
exception if it is non-zero.

This bug caused some minor issues as Exception handling code to handle
the non-zero case elsewhere in Scons was never executed.
This commit is contained in:
Bobby R. Bruce
2024-09-23 10:09:23 -07:00
committed by GitHub
parent 9b83fc8736
commit e85592da14

View File

@@ -82,14 +82,18 @@ def readCommand(cmd, **kwargs):
kwargs.setdefault("stdout", PIPE) kwargs.setdefault("stdout", PIPE)
kwargs.setdefault("stderr", STDOUT) kwargs.setdefault("stderr", STDOUT)
kwargs.setdefault("close_fds", True) kwargs.setdefault("close_fds", True)
try:
subp = Popen(cmd, **kwargs)
except Exception as e:
if no_exception:
return -1, exception
raise
output = subp.communicate()[0].decode("utf-8") p = Popen(cmd, **kwargs)
return_code = p.wait()
output = p.communicate()[0].decode("utf-8")
if return_code != 0:
if no_exception:
return return_code, None
raise Exception(
f"Command '{cmd}' failed with return code {return_code}:\n{output}"
)
return output return output