Commit 303c2b4c authored by Ned Deily's avatar Ned Deily

Issue #9516: Correct and expand OS X deployment target tests in distutils

test_build_ext.
parent d6e07e40
...@@ -9,7 +9,8 @@ from distutils.core import Extension, Distribution ...@@ -9,7 +9,8 @@ from distutils.core import Extension, Distribution
from distutils.command.build_ext import build_ext from distutils.command.build_ext import build_ext
from distutils import sysconfig from distutils import sysconfig
from distutils.tests import support from distutils.tests import support
from distutils.errors import DistutilsSetupError, CompileError from distutils.errors import (DistutilsSetupError, CompileError,
DistutilsPlatformError)
import unittest import unittest
from test import test_support from test import test_support
...@@ -437,18 +438,43 @@ class BuildExtTestCase(support.TempdirManager, ...@@ -437,18 +438,43 @@ class BuildExtTestCase(support.TempdirManager,
self.assertEqual(ext_path, wanted) self.assertEqual(ext_path, wanted)
@unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for MacOSX') @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for MacOSX')
def test_deployment_target(self): def test_deployment_target_default(self):
self._try_compile_deployment_target() # Issue 9516: Test that, in the absence of the environment variable,
# an extension module is compiled with the same deployment target as
# the interpreter.
self._try_compile_deployment_target('==', None)
@unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for MacOSX')
def test_deployment_target_too_low(self):
# Issue 9516: Test that an extension module is not allowed to be
# compiled with a deployment target less than that of the interpreter.
self.assertRaises(DistutilsPlatformError,
self._try_compile_deployment_target, '>', '10.1')
@unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for MacOSX')
def test_deployment_target_higher_ok(self):
# Issue 9516: Test that an extension module can be compiled with a
# deployment target higher than that of the interpreter: the ext
# module may depend on some newer OS feature.
deptarget = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
if deptarget:
# increment the minor version number (i.e. 10.6 -> 10.7)
deptarget = [int(x) for x in deptarget.split('.')]
deptarget[-1] += 1
deptarget = '.'.join(str(i) for i in deptarget)
self._try_compile_deployment_target('<', deptarget)
def _try_compile_deployment_target(self, operator, target):
orig_environ = os.environ orig_environ = os.environ
os.environ = orig_environ.copy() os.environ = orig_environ.copy()
self.addCleanup(setattr, os, 'environ', orig_environ) self.addCleanup(setattr, os, 'environ', orig_environ)
os.environ['MACOSX_DEPLOYMENT_TARGET']='10.1' if target is None:
self._try_compile_deployment_target() if os.environ.get('MACOSX_DEPLOYMENT_TARGET'):
del os.environ['MACOSX_DEPLOYMENT_TARGET']
else:
os.environ['MACOSX_DEPLOYMENT_TARGET'] = target
def _try_compile_deployment_target(self):
deptarget_c = os.path.join(self.tmp_dir, 'deptargetmodule.c') deptarget_c = os.path.join(self.tmp_dir, 'deptargetmodule.c')
with open(deptarget_c, 'w') as fp: with open(deptarget_c, 'w') as fp:
...@@ -457,16 +483,17 @@ class BuildExtTestCase(support.TempdirManager, ...@@ -457,16 +483,17 @@ class BuildExtTestCase(support.TempdirManager,
int dummy; int dummy;
#if TARGET != MAC_OS_X_VERSION_MIN_REQUIRED #if TARGET %s MAC_OS_X_VERSION_MIN_REQUIRED
#else
#error "Unexpected target" #error "Unexpected target"
#endif #endif
''')) ''' % operator))
# get the deployment target that the interpreter was built with
target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
target = tuple(map(int, target.split('.'))) target = tuple(map(int, target.split('.')))
target = '%02d%01d0' % target target = '%02d%01d0' % target
deptarget_ext = Extension( deptarget_ext = Extension(
'deptarget', 'deptarget',
[deptarget_c], [deptarget_c],
......
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