Commit bc0f8b67 authored by Éric Araujo's avatar Éric Araujo

Merge 3.3 (#11599)

parents ade88cb3 fd9aa757
...@@ -10,6 +10,7 @@ import sys ...@@ -10,6 +10,7 @@ import sys
import os import os
from distutils.errors import DistutilsPlatformError, DistutilsExecError from distutils.errors import DistutilsPlatformError, DistutilsExecError
from distutils.debug import DEBUG
from distutils import log from distutils import log
def spawn(cmd, search_path=1, verbose=0, dry_run=0): def spawn(cmd, search_path=1, verbose=0, dry_run=0):
...@@ -28,10 +29,15 @@ def spawn(cmd, search_path=1, verbose=0, dry_run=0): ...@@ -28,10 +29,15 @@ def spawn(cmd, search_path=1, verbose=0, dry_run=0):
Raise DistutilsExecError if running the program fails in any way; just Raise DistutilsExecError if running the program fails in any way; just
return on success. return on success.
""" """
# cmd is documented as a list, but just in case some code passes a tuple
# in, protect our %-formatting code against horrible death
cmd = list(cmd)
if os.name == 'posix': if os.name == 'posix':
_spawn_posix(cmd, search_path, dry_run=dry_run) _spawn_posix(cmd, search_path, dry_run=dry_run)
elif os.name == 'nt': elif os.name == 'nt':
_spawn_nt(cmd, search_path, dry_run=dry_run) _spawn_nt(cmd, search_path, dry_run=dry_run)
elif os.name == 'os2':
_spawn_os2(cmd, search_path, dry_run=dry_run)
else: else:
raise DistutilsPlatformError( raise DistutilsPlatformError(
"don't know how to spawn programs on platform '%s'" % os.name) "don't know how to spawn programs on platform '%s'" % os.name)
...@@ -65,12 +71,16 @@ def _spawn_nt(cmd, search_path=1, verbose=0, dry_run=0): ...@@ -65,12 +71,16 @@ def _spawn_nt(cmd, search_path=1, verbose=0, dry_run=0):
rc = os.spawnv(os.P_WAIT, executable, cmd) rc = os.spawnv(os.P_WAIT, executable, cmd)
except OSError as exc: except OSError as exc:
# this seems to happen when the command isn't found # this seems to happen when the command isn't found
if not DEBUG:
cmd = executable
raise DistutilsExecError( raise DistutilsExecError(
"command '%s' failed: %s" % (cmd[0], exc.args[-1])) "command %r failed: %s" % (cmd, exc.args[-1]))
if rc != 0: if rc != 0:
# and this reflects the command running but failing # and this reflects the command running but failing
if not DEBUG:
cmd = executable
raise DistutilsExecError( raise DistutilsExecError(
"command '%s' failed with exit status %d" % (cmd[0], rc)) "command %r failed with exit status %d" % (cmd, rc))
if sys.platform == 'darwin': if sys.platform == 'darwin':
from distutils import sysconfig from distutils import sysconfig
...@@ -81,8 +91,9 @@ def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0): ...@@ -81,8 +91,9 @@ def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0):
log.info(' '.join(cmd)) log.info(' '.join(cmd))
if dry_run: if dry_run:
return return
executable = cmd[0]
exec_fn = search_path and os.execvp or os.execv exec_fn = search_path and os.execvp or os.execv
exec_args = [cmd[0], cmd] env = None
if sys.platform == 'darwin': if sys.platform == 'darwin':
global _cfg_target, _cfg_target_split global _cfg_target, _cfg_target_split
if _cfg_target is None: if _cfg_target is None:
...@@ -103,17 +114,23 @@ def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0): ...@@ -103,17 +114,23 @@ def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0):
env = dict(os.environ, env = dict(os.environ,
MACOSX_DEPLOYMENT_TARGET=cur_target) MACOSX_DEPLOYMENT_TARGET=cur_target)
exec_fn = search_path and os.execvpe or os.execve exec_fn = search_path and os.execvpe or os.execve
exec_args.append(env)
pid = os.fork() pid = os.fork()
if pid == 0: # in the child if pid == 0: # in the child
try: try:
exec_fn(*exec_args) if env is None:
exec_fn(executable, cmd)
else:
exec_fn(executable, cmd, env)
except OSError as e: except OSError as e:
sys.stderr.write("unable to execute %s: %s\n" if not DEBUG:
% (cmd[0], e.strerror)) cmd = executable
sys.stderr.write("unable to execute %r: %s\n"
% (cmd, e.strerror))
os._exit(1) os._exit(1)
sys.stderr.write("unable to execute %s for unknown reasons" % cmd[0]) if not DEBUG:
cmd = executable
sys.stderr.write("unable to execute %r for unknown reasons" % cmd)
os._exit(1) os._exit(1)
else: # in the parent else: # in the parent
# Loop until the child either exits or is terminated by a signal # Loop until the child either exits or is terminated by a signal
...@@ -125,26 +142,34 @@ def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0): ...@@ -125,26 +142,34 @@ def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0):
import errno import errno
if exc.errno == errno.EINTR: if exc.errno == errno.EINTR:
continue continue
if not DEBUG:
cmd = executable
raise DistutilsExecError( raise DistutilsExecError(
"command '%s' failed: %s" % (cmd[0], exc.args[-1])) "command %r failed: %s" % (cmd, exc.args[-1]))
if os.WIFSIGNALED(status): if os.WIFSIGNALED(status):
if not DEBUG:
cmd = executable
raise DistutilsExecError( raise DistutilsExecError(
"command '%s' terminated by signal %d" "command %r terminated by signal %d"
% (cmd[0], os.WTERMSIG(status))) % (cmd, os.WTERMSIG(status)))
elif os.WIFEXITED(status): elif os.WIFEXITED(status):
exit_status = os.WEXITSTATUS(status) exit_status = os.WEXITSTATUS(status)
if exit_status == 0: if exit_status == 0:
return # hey, it succeeded! return # hey, it succeeded!
else: else:
if not DEBUG:
cmd = executable
raise DistutilsExecError( raise DistutilsExecError(
"command '%s' failed with exit status %d" "command %r failed with exit status %d"
% (cmd[0], exit_status)) % (cmd, exit_status))
elif os.WIFSTOPPED(status): elif os.WIFSTOPPED(status):
continue continue
else: else:
if not DEBUG:
cmd = executable
raise DistutilsExecError( raise DistutilsExecError(
"unknown error executing '%s': termination status %d" "unknown error executing %r: termination status %d"
% (cmd[0], status)) % (cmd, status))
def find_executable(executable, path=None): def find_executable(executable, path=None):
"""Tries to find 'executable' in the directories listed in 'path'. """Tries to find 'executable' in the directories listed in 'path'.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment