summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/tests/test_build_ext.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/distutils/tests/test_build_ext.py')
-rw-r--r--Lib/distutils/tests/test_build_ext.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/Lib/distutils/tests/test_build_ext.py b/Lib/distutils/tests/test_build_ext.py
index 52479d7..4351c0f 100644
--- a/Lib/distutils/tests/test_build_ext.py
+++ b/Lib/distutils/tests/test_build_ext.py
@@ -1,17 +1,16 @@
import sys
import os
-import tempfile
import shutil
from io import StringIO
-from distutils.core import Extension, Distribution
+from distutils.core import Distribution
from distutils.command.build_ext import build_ext
from distutils import sysconfig
from distutils.tests.support import TempdirManager
from distutils.tests.support import LoggingSilencer
from distutils.extension import Extension
-from distutils.errors import (UnknownFileError, DistutilsSetupError,
- CompileError)
+from distutils.errors import (
+ CompileError, DistutilsSetupError, UnknownFileError)
import unittest
from test import support
@@ -42,6 +41,20 @@ class BuildExtTestCase(TempdirManager,
from distutils.command import build_ext
build_ext.USER_BASE = site.USER_BASE
+ def _fixup_command(self, cmd):
+ # When Python was build with --enable-shared, -L. is not good enough
+ # to find the libpython<blah>.so. This is because regrtest runs it
+ # under a tempdir, not in the top level where the .so lives. By the
+ # time we've gotten here, Python's already been chdir'd to the
+ # tempdir.
+ #
+ # To further add to the fun, we can't just add library_dirs to the
+ # Extension() instance because that doesn't get plumbed through to the
+ # final compiler command.
+ if not sys.platform.startswith('win'):
+ library_dir = sysconfig.get_config_var('srcdir')
+ cmd.library_dirs = [('.' if library_dir is None else library_dir)]
+
def test_build_ext(self):
global ALREADY_TESTED
xx_c = os.path.join(self.tmp_dir, 'xxmodule.c')
@@ -49,6 +62,7 @@ class BuildExtTestCase(TempdirManager,
dist = Distribution({'name': 'xx', 'ext_modules': [xx_ext]})
dist.package_dir = self.tmp_dir
cmd = build_ext(dist)
+ self._fixup_command(cmd)
if os.name == "nt":
# On Windows, we must build a debug version iff running
# a debug build of Python
@@ -235,7 +249,8 @@ class BuildExtTestCase(TempdirManager,
cmd.finalize_options()
#'extensions' option must be a list of Extension instances
- self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, 'foo')
+ self.assertRaises(DistutilsSetupError,
+ cmd.check_extensions_list, 'foo')
# each element of 'ext_modules' option must be an
# Extension instance or 2-tuple
@@ -302,6 +317,7 @@ class BuildExtTestCase(TempdirManager,
dist = Distribution({'name': 'xx',
'ext_modules': [ext]})
cmd = build_ext(dist)
+ self._fixup_command(cmd)
cmd.ensure_finalized()
self.assertEquals(len(cmd.get_outputs()), 1)