| 1 | n/a | import os |
|---|
| 2 | n/a | import sys |
|---|
| 3 | n/a | import site |
|---|
| 4 | n/a | import sysconfig |
|---|
| 5 | n/a | import textwrap |
|---|
| 6 | n/a | from packaging.dist import Distribution |
|---|
| 7 | n/a | from packaging.errors import (UnknownFileError, CompileError, |
|---|
| 8 | n/a | PackagingPlatformError) |
|---|
| 9 | n/a | from packaging.command.build_ext import build_ext |
|---|
| 10 | n/a | from packaging.compiler.extension import Extension |
|---|
| 11 | n/a | |
|---|
| 12 | n/a | from test.script_helper import assert_python_ok |
|---|
| 13 | n/a | from packaging.tests import support, unittest |
|---|
| 14 | n/a | |
|---|
| 15 | n/a | |
|---|
| 16 | n/a | class BuildExtTestCase(support.TempdirManager, |
|---|
| 17 | n/a | support.LoggingCatcher, |
|---|
| 18 | n/a | unittest.TestCase): |
|---|
| 19 | n/a | def setUp(self): |
|---|
| 20 | n/a | super(BuildExtTestCase, self).setUp() |
|---|
| 21 | n/a | self.tmp_dir = self.mkdtemp() |
|---|
| 22 | n/a | self.old_user_base = site.USER_BASE |
|---|
| 23 | n/a | site.USER_BASE = self.mkdtemp() |
|---|
| 24 | n/a | |
|---|
| 25 | n/a | def tearDown(self): |
|---|
| 26 | n/a | site.USER_BASE = self.old_user_base |
|---|
| 27 | n/a | super(BuildExtTestCase, self).tearDown() |
|---|
| 28 | n/a | |
|---|
| 29 | n/a | def test_build_ext(self): |
|---|
| 30 | n/a | support.copy_xxmodule_c(self.tmp_dir) |
|---|
| 31 | n/a | xx_c = os.path.join(self.tmp_dir, 'xxmodule.c') |
|---|
| 32 | n/a | xx_ext = Extension('xx', [xx_c]) |
|---|
| 33 | n/a | dist = Distribution({'name': 'xx', 'ext_modules': [xx_ext]}) |
|---|
| 34 | n/a | dist.package_dir = self.tmp_dir |
|---|
| 35 | n/a | cmd = build_ext(dist) |
|---|
| 36 | n/a | support.fixup_build_ext(cmd) |
|---|
| 37 | n/a | cmd.build_lib = self.tmp_dir |
|---|
| 38 | n/a | cmd.build_temp = self.tmp_dir |
|---|
| 39 | n/a | cmd.ensure_finalized() |
|---|
| 40 | n/a | cmd.run() |
|---|
| 41 | n/a | |
|---|
| 42 | n/a | code = textwrap.dedent("""\ |
|---|
| 43 | n/a | import sys |
|---|
| 44 | n/a | sys.path.insert(0, %r) |
|---|
| 45 | n/a | |
|---|
| 46 | n/a | import xx |
|---|
| 47 | n/a | |
|---|
| 48 | n/a | for attr in ('error', 'foo', 'new', 'roj'): |
|---|
| 49 | n/a | assert hasattr(xx, attr) |
|---|
| 50 | n/a | |
|---|
| 51 | n/a | assert xx.foo(2, 5) == 7 |
|---|
| 52 | n/a | assert xx.foo(13, 15) == 28 |
|---|
| 53 | n/a | assert xx.new().demo() is None |
|---|
| 54 | n/a | doc = 'This is a template module just for instruction.' |
|---|
| 55 | n/a | assert xx.__doc__ == doc |
|---|
| 56 | n/a | assert isinstance(xx.Null(), xx.Null) |
|---|
| 57 | n/a | assert isinstance(xx.Str(), xx.Str) |
|---|
| 58 | n/a | """) |
|---|
| 59 | n/a | code = code % self.tmp_dir |
|---|
| 60 | n/a | assert_python_ok('-c', code) |
|---|
| 61 | n/a | |
|---|
| 62 | n/a | def test_solaris_enable_shared(self): |
|---|
| 63 | n/a | dist = Distribution({'name': 'xx'}) |
|---|
| 64 | n/a | cmd = build_ext(dist) |
|---|
| 65 | n/a | old = sys.platform |
|---|
| 66 | n/a | |
|---|
| 67 | n/a | sys.platform = 'sunos' # fooling finalize_options |
|---|
| 68 | n/a | |
|---|
| 69 | n/a | old_var = sysconfig.get_config_var('Py_ENABLE_SHARED') |
|---|
| 70 | n/a | sysconfig._CONFIG_VARS['Py_ENABLE_SHARED'] = 1 |
|---|
| 71 | n/a | try: |
|---|
| 72 | n/a | cmd.ensure_finalized() |
|---|
| 73 | n/a | finally: |
|---|
| 74 | n/a | sys.platform = old |
|---|
| 75 | n/a | if old_var is None: |
|---|
| 76 | n/a | del sysconfig._CONFIG_VARS['Py_ENABLE_SHARED'] |
|---|
| 77 | n/a | else: |
|---|
| 78 | n/a | sysconfig._CONFIG_VARS['Py_ENABLE_SHARED'] = old_var |
|---|
| 79 | n/a | |
|---|
| 80 | n/a | # make sure we get some library dirs under solaris |
|---|
| 81 | n/a | self.assertGreater(len(cmd.library_dirs), 0) |
|---|
| 82 | n/a | |
|---|
| 83 | n/a | def test_user_site(self): |
|---|
| 84 | n/a | dist = Distribution({'name': 'xx'}) |
|---|
| 85 | n/a | cmd = build_ext(dist) |
|---|
| 86 | n/a | |
|---|
| 87 | n/a | # making sure the user option is there |
|---|
| 88 | n/a | options = [name for name, short, label in |
|---|
| 89 | n/a | cmd.user_options] |
|---|
| 90 | n/a | self.assertIn('user', options) |
|---|
| 91 | n/a | |
|---|
| 92 | n/a | # setting a value |
|---|
| 93 | n/a | cmd.user = True |
|---|
| 94 | n/a | |
|---|
| 95 | n/a | # setting user based lib and include |
|---|
| 96 | n/a | lib = os.path.join(site.USER_BASE, 'lib') |
|---|
| 97 | n/a | incl = os.path.join(site.USER_BASE, 'include') |
|---|
| 98 | n/a | os.mkdir(lib) |
|---|
| 99 | n/a | os.mkdir(incl) |
|---|
| 100 | n/a | |
|---|
| 101 | n/a | # let's run finalize |
|---|
| 102 | n/a | cmd.ensure_finalized() |
|---|
| 103 | n/a | |
|---|
| 104 | n/a | # see if include_dirs and library_dirs |
|---|
| 105 | n/a | # were set |
|---|
| 106 | n/a | self.assertIn(lib, cmd.library_dirs) |
|---|
| 107 | n/a | self.assertIn(lib, cmd.rpath) |
|---|
| 108 | n/a | self.assertIn(incl, cmd.include_dirs) |
|---|
| 109 | n/a | |
|---|
| 110 | n/a | def test_optional_extension(self): |
|---|
| 111 | n/a | |
|---|
| 112 | n/a | # this extension will fail, but let's ignore this failure |
|---|
| 113 | n/a | # with the optional argument. |
|---|
| 114 | n/a | modules = [Extension('foo', ['xxx'], optional=False)] |
|---|
| 115 | n/a | dist = Distribution({'name': 'xx', 'ext_modules': modules}) |
|---|
| 116 | n/a | cmd = build_ext(dist) |
|---|
| 117 | n/a | cmd.ensure_finalized() |
|---|
| 118 | n/a | self.assertRaises((UnknownFileError, CompileError), |
|---|
| 119 | n/a | cmd.run) # should raise an error |
|---|
| 120 | n/a | |
|---|
| 121 | n/a | modules = [Extension('foo', ['xxx'], optional=True)] |
|---|
| 122 | n/a | dist = Distribution({'name': 'xx', 'ext_modules': modules}) |
|---|
| 123 | n/a | cmd = build_ext(dist) |
|---|
| 124 | n/a | cmd.ensure_finalized() |
|---|
| 125 | n/a | cmd.run() # should pass |
|---|
| 126 | n/a | |
|---|
| 127 | n/a | def test_finalize_options(self): |
|---|
| 128 | n/a | # Make sure Python's include directories (for Python.h, pyconfig.h, |
|---|
| 129 | n/a | # etc.) are in the include search path. |
|---|
| 130 | n/a | modules = [Extension('foo', ['xxx'], optional=False)] |
|---|
| 131 | n/a | dist = Distribution({'name': 'xx', 'ext_modules': modules}) |
|---|
| 132 | n/a | cmd = build_ext(dist) |
|---|
| 133 | n/a | cmd.finalize_options() |
|---|
| 134 | n/a | |
|---|
| 135 | n/a | py_include = sysconfig.get_path('include') |
|---|
| 136 | n/a | self.assertIn(py_include, cmd.include_dirs) |
|---|
| 137 | n/a | |
|---|
| 138 | n/a | plat_py_include = sysconfig.get_path('platinclude') |
|---|
| 139 | n/a | self.assertIn(plat_py_include, cmd.include_dirs) |
|---|
| 140 | n/a | |
|---|
| 141 | n/a | # make sure cmd.libraries is turned into a list |
|---|
| 142 | n/a | # if it's a string |
|---|
| 143 | n/a | cmd = build_ext(dist) |
|---|
| 144 | n/a | cmd.libraries = 'my_lib, other_lib lastlib' |
|---|
| 145 | n/a | cmd.finalize_options() |
|---|
| 146 | n/a | self.assertEqual(cmd.libraries, ['my_lib', 'other_lib', 'lastlib']) |
|---|
| 147 | n/a | |
|---|
| 148 | n/a | # make sure cmd.library_dirs is turned into a list |
|---|
| 149 | n/a | # if it's a string |
|---|
| 150 | n/a | cmd = build_ext(dist) |
|---|
| 151 | n/a | cmd.library_dirs = 'my_lib_dir%sother_lib_dir' % os.pathsep |
|---|
| 152 | n/a | cmd.finalize_options() |
|---|
| 153 | n/a | self.assertIn('my_lib_dir', cmd.library_dirs) |
|---|
| 154 | n/a | self.assertIn('other_lib_dir', cmd.library_dirs) |
|---|
| 155 | n/a | |
|---|
| 156 | n/a | # make sure rpath is turned into a list |
|---|
| 157 | n/a | # if it's a string |
|---|
| 158 | n/a | cmd = build_ext(dist) |
|---|
| 159 | n/a | cmd.rpath = 'one%stwo' % os.pathsep |
|---|
| 160 | n/a | cmd.finalize_options() |
|---|
| 161 | n/a | self.assertEqual(cmd.rpath, ['one', 'two']) |
|---|
| 162 | n/a | |
|---|
| 163 | n/a | # XXX more tests to perform for win32 |
|---|
| 164 | n/a | |
|---|
| 165 | n/a | # make sure define is turned into 2-tuples |
|---|
| 166 | n/a | # strings if they are ','-separated strings |
|---|
| 167 | n/a | cmd = build_ext(dist) |
|---|
| 168 | n/a | cmd.define = 'one,two' |
|---|
| 169 | n/a | cmd.finalize_options() |
|---|
| 170 | n/a | self.assertEqual(cmd.define, [('one', '1'), ('two', '1')]) |
|---|
| 171 | n/a | |
|---|
| 172 | n/a | # make sure undef is turned into a list of |
|---|
| 173 | n/a | # strings if they are ','-separated strings |
|---|
| 174 | n/a | cmd = build_ext(dist) |
|---|
| 175 | n/a | cmd.undef = 'one,two' |
|---|
| 176 | n/a | cmd.finalize_options() |
|---|
| 177 | n/a | self.assertEqual(cmd.undef, ['one', 'two']) |
|---|
| 178 | n/a | |
|---|
| 179 | n/a | # make sure swig_opts is turned into a list |
|---|
| 180 | n/a | cmd = build_ext(dist) |
|---|
| 181 | n/a | cmd.swig_opts = None |
|---|
| 182 | n/a | cmd.finalize_options() |
|---|
| 183 | n/a | self.assertEqual(cmd.swig_opts, []) |
|---|
| 184 | n/a | |
|---|
| 185 | n/a | cmd = build_ext(dist) |
|---|
| 186 | n/a | cmd.swig_opts = '1 2' |
|---|
| 187 | n/a | cmd.finalize_options() |
|---|
| 188 | n/a | self.assertEqual(cmd.swig_opts, ['1', '2']) |
|---|
| 189 | n/a | |
|---|
| 190 | n/a | def test_get_source_files(self): |
|---|
| 191 | n/a | modules = [Extension('foo', ['xxx'], optional=False)] |
|---|
| 192 | n/a | dist = Distribution({'name': 'xx', 'ext_modules': modules}) |
|---|
| 193 | n/a | cmd = build_ext(dist) |
|---|
| 194 | n/a | cmd.ensure_finalized() |
|---|
| 195 | n/a | self.assertEqual(cmd.get_source_files(), ['xxx']) |
|---|
| 196 | n/a | |
|---|
| 197 | n/a | def test_compiler_option(self): |
|---|
| 198 | n/a | # cmd.compiler is an option and |
|---|
| 199 | n/a | # should not be overriden by a compiler instance |
|---|
| 200 | n/a | # when the command is run |
|---|
| 201 | n/a | dist = Distribution() |
|---|
| 202 | n/a | cmd = build_ext(dist) |
|---|
| 203 | n/a | cmd.compiler = 'unix' |
|---|
| 204 | n/a | cmd.ensure_finalized() |
|---|
| 205 | n/a | cmd.run() |
|---|
| 206 | n/a | self.assertEqual(cmd.compiler, 'unix') |
|---|
| 207 | n/a | |
|---|
| 208 | n/a | def test_get_outputs(self): |
|---|
| 209 | n/a | tmp_dir = self.mkdtemp() |
|---|
| 210 | n/a | c_file = os.path.join(tmp_dir, 'foo.c') |
|---|
| 211 | n/a | self.write_file(c_file, 'void PyInit_foo(void) {}\n') |
|---|
| 212 | n/a | ext = Extension('foo', [c_file], optional=False) |
|---|
| 213 | n/a | dist = Distribution({'name': 'xx', |
|---|
| 214 | n/a | 'ext_modules': [ext]}) |
|---|
| 215 | n/a | cmd = build_ext(dist) |
|---|
| 216 | n/a | support.fixup_build_ext(cmd) |
|---|
| 217 | n/a | cmd.ensure_finalized() |
|---|
| 218 | n/a | self.assertEqual(len(cmd.get_outputs()), 1) |
|---|
| 219 | n/a | |
|---|
| 220 | n/a | cmd.build_lib = os.path.join(self.tmp_dir, 'build') |
|---|
| 221 | n/a | cmd.build_temp = os.path.join(self.tmp_dir, 'tempt') |
|---|
| 222 | n/a | |
|---|
| 223 | n/a | # issue #5977 : distutils build_ext.get_outputs |
|---|
| 224 | n/a | # returns wrong result with --inplace |
|---|
| 225 | n/a | other_tmp_dir = os.path.realpath(self.mkdtemp()) |
|---|
| 226 | n/a | old_wd = os.getcwd() |
|---|
| 227 | n/a | os.chdir(other_tmp_dir) |
|---|
| 228 | n/a | try: |
|---|
| 229 | n/a | cmd.inplace = True |
|---|
| 230 | n/a | cmd.run() |
|---|
| 231 | n/a | so_file = cmd.get_outputs()[0] |
|---|
| 232 | n/a | finally: |
|---|
| 233 | n/a | os.chdir(old_wd) |
|---|
| 234 | n/a | self.assertTrue(os.path.exists(so_file)) |
|---|
| 235 | n/a | so_ext = sysconfig.get_config_var('SO') |
|---|
| 236 | n/a | self.assertTrue(so_file.endswith(so_ext)) |
|---|
| 237 | n/a | so_dir = os.path.dirname(so_file) |
|---|
| 238 | n/a | self.assertEqual(so_dir, other_tmp_dir) |
|---|
| 239 | n/a | |
|---|
| 240 | n/a | cmd.inplace = False |
|---|
| 241 | n/a | cmd.run() |
|---|
| 242 | n/a | so_file = cmd.get_outputs()[0] |
|---|
| 243 | n/a | self.assertTrue(os.path.exists(so_file)) |
|---|
| 244 | n/a | self.assertTrue(so_file.endswith(so_ext)) |
|---|
| 245 | n/a | so_dir = os.path.dirname(so_file) |
|---|
| 246 | n/a | self.assertEqual(so_dir, cmd.build_lib) |
|---|
| 247 | n/a | |
|---|
| 248 | n/a | # inplace = False, cmd.package = 'bar' |
|---|
| 249 | n/a | build_py = cmd.get_finalized_command('build_py') |
|---|
| 250 | n/a | build_py.package_dir = 'bar' |
|---|
| 251 | n/a | path = cmd.get_ext_fullpath('foo') |
|---|
| 252 | n/a | # checking that the last directory is the build_dir |
|---|
| 253 | n/a | path = os.path.split(path)[0] |
|---|
| 254 | n/a | self.assertEqual(path, cmd.build_lib) |
|---|
| 255 | n/a | |
|---|
| 256 | n/a | # inplace = True, cmd.package = 'bar' |
|---|
| 257 | n/a | cmd.inplace = True |
|---|
| 258 | n/a | other_tmp_dir = os.path.realpath(self.mkdtemp()) |
|---|
| 259 | n/a | old_wd = os.getcwd() |
|---|
| 260 | n/a | os.chdir(other_tmp_dir) |
|---|
| 261 | n/a | try: |
|---|
| 262 | n/a | path = cmd.get_ext_fullpath('foo') |
|---|
| 263 | n/a | finally: |
|---|
| 264 | n/a | os.chdir(old_wd) |
|---|
| 265 | n/a | # checking that the last directory is bar |
|---|
| 266 | n/a | path = os.path.split(path)[0] |
|---|
| 267 | n/a | lastdir = os.path.split(path)[-1] |
|---|
| 268 | n/a | self.assertEqual(lastdir, 'bar') |
|---|
| 269 | n/a | |
|---|
| 270 | n/a | def test_ext_fullpath(self): |
|---|
| 271 | n/a | ext = sysconfig.get_config_vars()['SO'] |
|---|
| 272 | n/a | # building lxml.etree inplace |
|---|
| 273 | n/a | #etree_c = os.path.join(self.tmp_dir, 'lxml.etree.c') |
|---|
| 274 | n/a | #etree_ext = Extension('lxml.etree', [etree_c]) |
|---|
| 275 | n/a | #dist = Distribution({'name': 'lxml', 'ext_modules': [etree_ext]}) |
|---|
| 276 | n/a | dist = Distribution() |
|---|
| 277 | n/a | cmd = build_ext(dist) |
|---|
| 278 | n/a | cmd.inplace = True |
|---|
| 279 | n/a | cmd.distribution.package_dir = 'src' |
|---|
| 280 | n/a | cmd.distribution.packages = ['lxml', 'lxml.html'] |
|---|
| 281 | n/a | curdir = os.getcwd() |
|---|
| 282 | n/a | wanted = os.path.join(curdir, 'src', 'lxml', 'etree' + ext) |
|---|
| 283 | n/a | path = cmd.get_ext_fullpath('lxml.etree') |
|---|
| 284 | n/a | self.assertEqual(wanted, path) |
|---|
| 285 | n/a | |
|---|
| 286 | n/a | # building lxml.etree not inplace |
|---|
| 287 | n/a | cmd.inplace = False |
|---|
| 288 | n/a | cmd.build_lib = os.path.join(curdir, 'tmpdir') |
|---|
| 289 | n/a | wanted = os.path.join(curdir, 'tmpdir', 'lxml', 'etree' + ext) |
|---|
| 290 | n/a | path = cmd.get_ext_fullpath('lxml.etree') |
|---|
| 291 | n/a | self.assertEqual(wanted, path) |
|---|
| 292 | n/a | |
|---|
| 293 | n/a | # building twisted.runner.portmap not inplace |
|---|
| 294 | n/a | build_py = cmd.get_finalized_command('build_py') |
|---|
| 295 | n/a | build_py.package_dir = None |
|---|
| 296 | n/a | cmd.distribution.packages = ['twisted', 'twisted.runner.portmap'] |
|---|
| 297 | n/a | path = cmd.get_ext_fullpath('twisted.runner.portmap') |
|---|
| 298 | n/a | wanted = os.path.join(curdir, 'tmpdir', 'twisted', 'runner', |
|---|
| 299 | n/a | 'portmap' + ext) |
|---|
| 300 | n/a | self.assertEqual(wanted, path) |
|---|
| 301 | n/a | |
|---|
| 302 | n/a | # building twisted.runner.portmap inplace |
|---|
| 303 | n/a | cmd.inplace = True |
|---|
| 304 | n/a | path = cmd.get_ext_fullpath('twisted.runner.portmap') |
|---|
| 305 | n/a | wanted = os.path.join(curdir, 'twisted', 'runner', 'portmap' + ext) |
|---|
| 306 | n/a | self.assertEqual(wanted, path) |
|---|
| 307 | n/a | |
|---|
| 308 | n/a | @unittest.skipUnless(sys.platform == 'darwin', |
|---|
| 309 | n/a | 'test only relevant for Mac OS X') |
|---|
| 310 | n/a | def test_deployment_target_default(self): |
|---|
| 311 | n/a | # Issue 9516: Test that, in the absence of the environment variable, |
|---|
| 312 | n/a | # an extension module is compiled with the same deployment target as |
|---|
| 313 | n/a | # the interpreter. |
|---|
| 314 | n/a | self._try_compile_deployment_target('==', None) |
|---|
| 315 | n/a | |
|---|
| 316 | n/a | @unittest.skipUnless(sys.platform == 'darwin', |
|---|
| 317 | n/a | 'test only relevant for Mac OS X') |
|---|
| 318 | n/a | def test_deployment_target_too_low(self): |
|---|
| 319 | n/a | # Issue 9516: Test that an extension module is not allowed to be |
|---|
| 320 | n/a | # compiled with a deployment target less than that of the interpreter. |
|---|
| 321 | n/a | self.assertRaises(PackagingPlatformError, |
|---|
| 322 | n/a | self._try_compile_deployment_target, '>', '10.1') |
|---|
| 323 | n/a | |
|---|
| 324 | n/a | @unittest.skipUnless(sys.platform == 'darwin', |
|---|
| 325 | n/a | 'test only relevant for Mac OS X') |
|---|
| 326 | n/a | def test_deployment_target_higher_ok(self): |
|---|
| 327 | n/a | # Issue 9516: Test that an extension module can be compiled with a |
|---|
| 328 | n/a | # deployment target higher than that of the interpreter: the ext |
|---|
| 329 | n/a | # module may depend on some newer OS feature. |
|---|
| 330 | n/a | deptarget = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') |
|---|
| 331 | n/a | if deptarget: |
|---|
| 332 | n/a | # increment the minor version number (i.e. 10.6 -> 10.7) |
|---|
| 333 | n/a | deptarget = [int(x) for x in deptarget.split('.')] |
|---|
| 334 | n/a | deptarget[-1] += 1 |
|---|
| 335 | n/a | deptarget = '.'.join(str(i) for i in deptarget) |
|---|
| 336 | n/a | self._try_compile_deployment_target('<', deptarget) |
|---|
| 337 | n/a | |
|---|
| 338 | n/a | def _try_compile_deployment_target(self, operator, target): |
|---|
| 339 | n/a | orig_environ = os.environ |
|---|
| 340 | n/a | os.environ = orig_environ.copy() |
|---|
| 341 | n/a | self.addCleanup(setattr, os, 'environ', orig_environ) |
|---|
| 342 | n/a | |
|---|
| 343 | n/a | if target is None: |
|---|
| 344 | n/a | if os.environ.get('MACOSX_DEPLOYMENT_TARGET'): |
|---|
| 345 | n/a | del os.environ['MACOSX_DEPLOYMENT_TARGET'] |
|---|
| 346 | n/a | else: |
|---|
| 347 | n/a | os.environ['MACOSX_DEPLOYMENT_TARGET'] = target |
|---|
| 348 | n/a | |
|---|
| 349 | n/a | deptarget_c = os.path.join(self.tmp_dir, 'deptargetmodule.c') |
|---|
| 350 | n/a | |
|---|
| 351 | n/a | with open(deptarget_c, 'w') as fp: |
|---|
| 352 | n/a | fp.write(textwrap.dedent('''\ |
|---|
| 353 | n/a | #include <AvailabilityMacros.h> |
|---|
| 354 | n/a | |
|---|
| 355 | n/a | int dummy; |
|---|
| 356 | n/a | |
|---|
| 357 | n/a | #if TARGET %s MAC_OS_X_VERSION_MIN_REQUIRED |
|---|
| 358 | n/a | #else |
|---|
| 359 | n/a | #error "Unexpected target" |
|---|
| 360 | n/a | #endif |
|---|
| 361 | n/a | |
|---|
| 362 | n/a | ''' % operator)) |
|---|
| 363 | n/a | |
|---|
| 364 | n/a | # get the deployment target that the interpreter was built with |
|---|
| 365 | n/a | target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') |
|---|
| 366 | n/a | target = tuple(map(int, target.split('.'))) |
|---|
| 367 | n/a | target = '%02d%01d0' % target |
|---|
| 368 | n/a | |
|---|
| 369 | n/a | deptarget_ext = Extension( |
|---|
| 370 | n/a | 'deptarget', |
|---|
| 371 | n/a | [deptarget_c], |
|---|
| 372 | n/a | extra_compile_args=['-DTARGET=%s' % (target,)], |
|---|
| 373 | n/a | ) |
|---|
| 374 | n/a | dist = Distribution({ |
|---|
| 375 | n/a | 'name': 'deptarget', |
|---|
| 376 | n/a | 'ext_modules': [deptarget_ext], |
|---|
| 377 | n/a | }) |
|---|
| 378 | n/a | dist.package_dir = self.tmp_dir |
|---|
| 379 | n/a | cmd = build_ext(dist) |
|---|
| 380 | n/a | cmd.build_lib = self.tmp_dir |
|---|
| 381 | n/a | cmd.build_temp = self.tmp_dir |
|---|
| 382 | n/a | |
|---|
| 383 | n/a | try: |
|---|
| 384 | n/a | cmd.ensure_finalized() |
|---|
| 385 | n/a | cmd.run() |
|---|
| 386 | n/a | except CompileError: |
|---|
| 387 | n/a | self.fail("Wrong deployment target during compilation") |
|---|
| 388 | n/a | |
|---|
| 389 | n/a | |
|---|
| 390 | n/a | def test_suite(): |
|---|
| 391 | n/a | return unittest.makeSuite(BuildExtTestCase) |
|---|
| 392 | n/a | |
|---|
| 393 | n/a | if __name__ == '__main__': |
|---|
| 394 | n/a | unittest.main(defaultTest='test_suite') |
|---|