First (uncontroversial) part of issue 9807.

* Expose the build flags to Python as sys.abiflags
* Shared library libpythonX.Y<abiflags>.so
* python-config --abiflags
* Make two distutils tests that failed with --enable-shared (even before this
  patch) succeed.
* Fix a few small style issues.
This commit is contained in:
Barry Warsaw 2010-10-16 01:04:07 +00:00
parent d8d835bd1d
commit 8cf4eae522
9 changed files with 386 additions and 299 deletions

View file

@ -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)