|
1 | 1 | import sys |
2 | 2 | import os |
3 | | -import tempfile |
4 | 3 | import shutil |
5 | 4 | from io import StringIO |
6 | 5 |
|
7 | | -from distutils.core import Extension, Distribution |
| 6 | +from distutils.core import Distribution |
8 | 7 | from distutils.command.build_ext import build_ext |
9 | 8 | from distutils import sysconfig |
10 | 9 | from distutils.tests.support import TempdirManager |
11 | 10 | from distutils.tests.support import LoggingSilencer |
12 | 11 | from distutils.extension import Extension |
13 | | -from distutils.errors import (UnknownFileError, DistutilsSetupError, |
14 | | - CompileError) |
| 12 | +from distutils.errors import ( |
| 13 | + CompileError, DistutilsSetupError, UnknownFileError) |
15 | 14 |
|
16 | 15 | import unittest |
17 | 16 | from test import support |
@@ -42,13 +41,28 @@ def setUp(self): |
42 | 41 | from distutils.command import build_ext |
43 | 42 | build_ext.USER_BASE = site.USER_BASE |
44 | 43 |
|
| 44 | + def _fixup_command(self, cmd): |
| 45 | + # When Python was build with --enable-shared, -L. is not good enough |
| 46 | + # to find the libpython<blah>.so. This is because regrtest runs it |
| 47 | + # under a tempdir, not in the top level where the .so lives. By the |
| 48 | + # time we've gotten here, Python's already been chdir'd to the |
| 49 | + # tempdir. |
| 50 | + # |
| 51 | + # To further add to the fun, we can't just add library_dirs to the |
| 52 | + # Extension() instance because that doesn't get plumbed through to the |
| 53 | + # final compiler command. |
| 54 | + if not sys.platform.startswith('win'): |
| 55 | + library_dir = sysconfig.get_config_var('srcdir') |
| 56 | + cmd.library_dirs = [('.' if library_dir is None else library_dir)] |
| 57 | + |
45 | 58 | def test_build_ext(self): |
46 | 59 | global ALREADY_TESTED |
47 | 60 | xx_c = os.path.join(self.tmp_dir, 'xxmodule.c') |
48 | 61 | xx_ext = Extension('xx', [xx_c]) |
49 | 62 | dist = Distribution({'name': 'xx', 'ext_modules': [xx_ext]}) |
50 | 63 | dist.package_dir = self.tmp_dir |
51 | 64 | cmd = build_ext(dist) |
| 65 | + self._fixup_command(cmd) |
52 | 66 | if os.name == "nt": |
53 | 67 | # On Windows, we must build a debug version iff running |
54 | 68 | # a debug build of Python |
@@ -235,7 +249,8 @@ def test_check_extensions_list(self): |
235 | 249 | cmd.finalize_options() |
236 | 250 |
|
237 | 251 | #'extensions' option must be a list of Extension instances |
238 | | - self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, 'foo') |
| 252 | + self.assertRaises(DistutilsSetupError, |
| 253 | + cmd.check_extensions_list, 'foo') |
239 | 254 |
|
240 | 255 | # each element of 'ext_modules' option must be an |
241 | 256 | # Extension instance or 2-tuple |
@@ -302,6 +317,7 @@ def test_get_outputs(self): |
302 | 317 | dist = Distribution({'name': 'xx', |
303 | 318 | 'ext_modules': [ext]}) |
304 | 319 | cmd = build_ext(dist) |
| 320 | + self._fixup_command(cmd) |
305 | 321 | cmd.ensure_finalized() |
306 | 322 | self.assertEquals(len(cmd.get_outputs()), 1) |
307 | 323 |
|
|
0 commit comments