Issue #9516: Change distutils to no longer globally attempt to check and
set the MACOSX_DEPLOYMENT_TARGET env variable for the interpreter process on OS X. This could cause failures in non-distutils subprocesses and was unreliable since tests or user programs could modify the interpreter environment after distutils set it. Instead, have distutils set the the deployment target only in the environment of each build subprocess. Continue to use the previous algorithm for deriving the deployment target value: if MACOSX_DEPLOYMENT_TARGET is not set in the interpreter's env: use the interpreter build configure MACOSX_DEPLOYMENT_TARGET elif the MACOSX_DEPLOYMENT_TARGET env value >= configure value: use the env MACOSX_DEPLOYMENT_TARGET else: # env value less than interpreter build configure value raise exception This allows building extensions that can only run on newer versions of the OS than the version python was built for, for example with a python built for 10.3 or later and an extension that needs to be built for 10.5.
This commit is contained in:
parent
d13007fa11
commit
a8f8b50bd7
|
@ -96,15 +96,42 @@ def _spawn_os2(cmd, search_path=1, verbose=0, dry_run=0):
|
||||||
raise DistutilsExecError(
|
raise DistutilsExecError(
|
||||||
"command '%s' failed with exit status %d" % (cmd[0], rc))
|
"command '%s' failed with exit status %d" % (cmd[0], rc))
|
||||||
|
|
||||||
|
if sys.platform == 'darwin':
|
||||||
|
from distutils import sysconfig
|
||||||
|
_cfg_target = None
|
||||||
|
_cfg_target_split = None
|
||||||
|
|
||||||
def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0):
|
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
|
||||||
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]
|
||||||
|
if sys.platform == 'darwin':
|
||||||
|
global _cfg_target, _cfg_target_split
|
||||||
|
if _cfg_target is None:
|
||||||
|
_cfg_target = sysconfig.get_config_var(
|
||||||
|
'MACOSX_DEPLOYMENT_TARGET') or ''
|
||||||
|
if _cfg_target:
|
||||||
|
_cfg_target_split = [int(x) for x in _cfg_target.split('.')]
|
||||||
|
if _cfg_target:
|
||||||
|
# ensure that the deployment target of build process is not less
|
||||||
|
# than that used when the interpreter was built. This ensures
|
||||||
|
# extension modules are built with correct compatibility values
|
||||||
|
cur_target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', _cfg_target)
|
||||||
|
if _cfg_target_split > [int(x) for x in cur_target.split('.')]:
|
||||||
|
my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: '
|
||||||
|
'now "%s" but "%s" during configure'
|
||||||
|
% (cur_target, _cfg_target))
|
||||||
|
raise DistutilsPlatformError(my_msg)
|
||||||
|
env = dict(os.environ,
|
||||||
|
MACOSX_DEPLOYMENT_TARGET=cur_target)
|
||||||
|
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(cmd[0], cmd)
|
exec_fn(*exec_args)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
sys.stderr.write("unable to execute %s: %s\n"
|
sys.stderr.write("unable to execute %s: %s\n"
|
||||||
% (cmd[0], e.strerror))
|
% (cmd[0], e.strerror))
|
||||||
|
|
|
@ -419,21 +419,6 @@ def _init_posix():
|
||||||
|
|
||||||
raise DistutilsPlatformError(my_msg)
|
raise DistutilsPlatformError(my_msg)
|
||||||
|
|
||||||
# On MacOSX we need to check the setting of the environment variable
|
|
||||||
# MACOSX_DEPLOYMENT_TARGET: configure bases some choices on it so
|
|
||||||
# it needs to be compatible.
|
|
||||||
# If it isn't set we set it to the configure-time value
|
|
||||||
if sys.platform == 'darwin' and 'MACOSX_DEPLOYMENT_TARGET' in g:
|
|
||||||
cfg_target = g['MACOSX_DEPLOYMENT_TARGET']
|
|
||||||
cur_target = os.getenv('MACOSX_DEPLOYMENT_TARGET', '')
|
|
||||||
if cur_target == '':
|
|
||||||
cur_target = cfg_target
|
|
||||||
os.environ['MACOSX_DEPLOYMENT_TARGET'] = cfg_target
|
|
||||||
elif [int(x) for x in cfg_target.split('.')] > [int(x) for x in cur_target.split('.')]:
|
|
||||||
my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: now "%s" but "%s" during configure'
|
|
||||||
% (cur_target, cfg_target))
|
|
||||||
raise DistutilsPlatformError(my_msg)
|
|
||||||
|
|
||||||
# On AIX, there are wrong paths to the linker scripts in the Makefile
|
# On AIX, there are wrong paths to the linker scripts in the Makefile
|
||||||
# -- these paths are relative to the Python source, but when installed
|
# -- these paths are relative to the Python source, but when installed
|
||||||
# the scripts are in another directory.
|
# the scripts are in another directory.
|
||||||
|
|
Loading…
Reference in New Issue