Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 175eb99

Browse files
committed
Fix distutils tests on Windows (#12678).
- First, support.fixup_build_ext (already used to set proper library_dirs value under Unix shared builds) gains the ability to correctly set the debug attribute under Windows debug builds. - Second, the filename for the extension module gets a _d suffix under debug builds. - Third, the test code properly puts our customized build_ext object into an internal dictionary to make sure that the install command will later use our object instead of re-creating one. That’s the downside of using low-level APIs in our test code: we have to manually push knobs and turn handles that would otherwise be handled behind the scenes. Thanks to Nadeem for the testing.
1 parent 7a08410 commit 175eb99

3 files changed

Lines changed: 30 additions & 23 deletions

File tree

Lib/distutils/tests/support.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -169,23 +169,29 @@ def _get_xxmodule_path():
169169

170170

171171
def fixup_build_ext(cmd):
172-
"""Function needed to make build_ext tests pass on shared builds.
172+
"""Function needed to make build_ext tests pass.
173173
174-
When Python was build with --enable-shared, -L. is not good enough to find
175-
the libpython<blah>.so. This is because regrtest runs it under a tempdir,
176-
not in the top level where the .so lives. By the time we've gotten here,
177-
Python's already been chdir'd to the tempdir. This function work arounds
178-
that. Example use:
174+
When Python was build with --enable-shared on Unix, -L. is not good
175+
enough to find the libpython<blah>.so. This is because regrtest runs
176+
it under a tempdir, not in the top level where the .so lives. By the
177+
time we've gotten here, Python's already been chdir'd to the tempdir.
178+
179+
When Python was built with in debug mode on Windows, build_ext commands
180+
need their debug attribute set, and it is not done automatically for
181+
some reason.
182+
183+
This function handles both of these things. Example use:
179184
180185
cmd = build_ext(dist)
181186
support.fixup_build_ext(cmd)
182187
cmd.ensure_finalized()
183188
"""
184-
# To further add to the fun, we can't just add library_dirs to the
185-
# Extension() instance because that doesn't get plumbed through to the
186-
# final compiler command.
187-
if (sysconfig.get_config_var('Py_ENABLE_SHARED') and
188-
not sys.platform.startswith('win')):
189+
if os.name == 'nt':
190+
cmd.debug = sys.executable.endswith('_d.exe')
191+
elif sysconfig.get_config_var('Py_ENABLE_SHARED'):
192+
# To further add to the shared builds fun on Unix, we can't just add
193+
# library_dirs to the Extension() instance because that doesn't get
194+
# plumbed through to the final compiler command.
189195
runshared = sysconfig.get_config_var('RUNSHARED')
190196
if runshared is None:
191197
cmd.library_dirs = ['.']

Lib/distutils/tests/test_build_ext.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ def test_build_ext(self):
4747
dist.package_dir = self.tmp_dir
4848
cmd = build_ext(dist)
4949
fixup_build_ext(cmd)
50-
if os.name == "nt":
51-
# On Windows, we must build a debug version iff running
52-
# a debug build of Python
53-
cmd.debug = sys.executable.endswith("_d.exe")
5450
cmd.build_lib = self.tmp_dir
5551
cmd.build_temp = self.tmp_dir
5652

@@ -305,9 +301,6 @@ def test_get_outputs(self):
305301
cmd.ensure_finalized()
306302
self.assertEqual(len(cmd.get_outputs()), 1)
307303

308-
if os.name == "nt":
309-
cmd.debug = sys.executable.endswith("_d.exe")
310-
311304
cmd.build_lib = os.path.join(self.tmp_dir, 'build')
312305
cmd.build_temp = os.path.join(self.tmp_dir, 'tempt')
313306

Lib/distutils/tests/test_install.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818

1919
from distutils.tests import support
2020

21+
22+
def _make_ext_name(modname):
23+
if os.name == 'nt':
24+
if sys.executable.endswith('_d.exe'):
25+
modname += '_d'
26+
return modname + sysconfig.get_config_var('SO')
27+
28+
2129
class InstallTestCase(support.TempdirManager,
2230
support.EnvironGuard,
2331
support.LoggingSilencer,
@@ -201,13 +209,13 @@ def test_record_extensions(self):
201209
os.chdir(project_dir)
202210
support.copy_xxmodule_c(project_dir)
203211

204-
buildcmd = build_ext(dist)
205-
support.fixup_build_ext(buildcmd)
206-
buildcmd.ensure_finalized()
207-
buildcmd.run()
212+
buildextcmd = build_ext(dist)
213+
support.fixup_build_ext(buildextcmd)
214+
buildextcmd.ensure_finalized()
208215

209216
cmd = install(dist)
210217
dist.command_obj['install'] = cmd
218+
dist.command_obj['build_ext'] = buildextcmd
211219
cmd.root = install_dir
212220
cmd.record = os.path.join(project_dir, 'RECORD')
213221
cmd.ensure_finalized()
@@ -220,7 +228,7 @@ def test_record_extensions(self):
220228
f.close()
221229

222230
found = [os.path.basename(line) for line in content.splitlines()]
223-
expected = ['xx%s' % sysconfig.get_config_var('SO'),
231+
expected = [_make_ext_name('xx'),
224232
'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
225233
self.assertEqual(found, expected)
226234

0 commit comments

Comments
 (0)