Commit f88b5e54 authored by Barry Warsaw's avatar Barry Warsaw

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.
parent 8a775b19
...@@ -754,9 +754,9 @@ class build_ext(Command): ...@@ -754,9 +754,9 @@ class build_ext(Command):
else: else:
from distutils import sysconfig from distutils import sysconfig
if sysconfig.get_config_var('Py_ENABLE_SHARED'): if sysconfig.get_config_var('Py_ENABLE_SHARED'):
template = "python%d.%d" pythonlib = 'python{}.{}{}'.format(
pythonlib = (template % sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff,
(sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) sys.abiflags)
return ext.libraries + [pythonlib] return ext.libraries + [pythonlib]
else: else:
return ext.libraries return ext.libraries
import sys import sys
import os import os
import tempfile
import shutil import shutil
from io import StringIO 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.command.build_ext import build_ext
from distutils import sysconfig from distutils import sysconfig
from distutils.tests.support import TempdirManager from distutils.tests.support import TempdirManager
from distutils.tests.support import LoggingSilencer from distutils.tests.support import LoggingSilencer
from distutils.extension import Extension from distutils.extension import Extension
from distutils.errors import (UnknownFileError, DistutilsSetupError, from distutils.errors import (
CompileError) CompileError, DistutilsSetupError, UnknownFileError)
import unittest import unittest
from test import support from test import support
...@@ -42,6 +41,20 @@ class BuildExtTestCase(TempdirManager, ...@@ -42,6 +41,20 @@ class BuildExtTestCase(TempdirManager,
from distutils.command import build_ext from distutils.command import build_ext
build_ext.USER_BASE = site.USER_BASE 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): def test_build_ext(self):
global ALREADY_TESTED global ALREADY_TESTED
xx_c = os.path.join(self.tmp_dir, 'xxmodule.c') xx_c = os.path.join(self.tmp_dir, 'xxmodule.c')
...@@ -49,6 +62,7 @@ class BuildExtTestCase(TempdirManager, ...@@ -49,6 +62,7 @@ class BuildExtTestCase(TempdirManager,
dist = Distribution({'name': 'xx', 'ext_modules': [xx_ext]}) dist = Distribution({'name': 'xx', 'ext_modules': [xx_ext]})
dist.package_dir = self.tmp_dir dist.package_dir = self.tmp_dir
cmd = build_ext(dist) cmd = build_ext(dist)
self._fixup_command(cmd)
if os.name == "nt": if os.name == "nt":
# On Windows, we must build a debug version iff running # On Windows, we must build a debug version iff running
# a debug build of Python # a debug build of Python
...@@ -235,7 +249,8 @@ class BuildExtTestCase(TempdirManager, ...@@ -235,7 +249,8 @@ class BuildExtTestCase(TempdirManager,
cmd.finalize_options() cmd.finalize_options()
#'extensions' option must be a list of Extension instances #'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 # each element of 'ext_modules' option must be an
# Extension instance or 2-tuple # Extension instance or 2-tuple
...@@ -302,6 +317,7 @@ class BuildExtTestCase(TempdirManager, ...@@ -302,6 +317,7 @@ class BuildExtTestCase(TempdirManager,
dist = Distribution({'name': 'xx', dist = Distribution({'name': 'xx',
'ext_modules': [ext]}) 'ext_modules': [ext]})
cmd = build_ext(dist) cmd = build_ext(dist)
self._fixup_command(cmd)
cmd.ensure_finalized() cmd.ensure_finalized()
self.assertEquals(len(cmd.get_outputs()), 1) self.assertEquals(len(cmd.get_outputs()), 1)
......
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