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

Skip to content

Commit f46a688

Browse files
committed
Fixed the "pre-link hook" so it actually works, mainly by renaming it
to 'msvc_prelink_hack()', adding the parameters that it actually needs, and only calling it for MSVC compiler objects. Generally gave up on the idea of a general "hook" mechanism: deleted the empty 'precompile_hook()'.
1 parent 68ff615 commit f46a688

1 file changed

Lines changed: 33 additions & 41 deletions

File tree

Lib/distutils/command/build_ext.py

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ def run (self):
188188

189189
# Setup the CCompiler object that we'll use to do all the
190190
# compiling and linking
191-
self.compiler = new_compiler (compiler=self.compiler,
191+
self.compiler = new_compiler (#compiler=self.compiler,
192+
compiler="msvc",
192193
verbose=self.verbose,
193194
dry_run=self.dry_run,
194195
force=self.force)
@@ -402,11 +403,6 @@ def build_extensions (self):
402403
if os.environ.has_key('CFLAGS'):
403404
extra_args.extend(string.split(os.environ['CFLAGS']))
404405

405-
# Run any platform/compiler-specific hooks needed before
406-
# compiling (currently none, but any hypothetical subclasses
407-
# might find it useful to override this).
408-
self.precompile_hook()
409-
410406
objects = self.compiler.compile (sources,
411407
output_dir=self.build_temp,
412408
#macros=macros,
@@ -421,9 +417,9 @@ def build_extensions (self):
421417
objects.extend (ext.extra_objects)
422418
extra_args = ext.extra_link_args
423419

424-
# Run any platform/compiler-specific hooks needed between
425-
# compiling and linking (currently needed only on Windows).
426-
self.prelink_hook()
420+
# Bunch of fixing-up we have to do for Microsoft's linker.
421+
if self.compiler.compiler_type == 'msvc':
422+
self.msvc_prelink_hack(sources, ext, extra_args)
427423

428424
self.compiler.link_shared_object (
429425
objects, ext_filename,
@@ -504,12 +500,9 @@ def find_swig (self):
504500
# find_swig ()
505501

506502

507-
# -- Hooks ---------------------------------------------------------
508-
509-
def precompile_hook (self):
510-
pass
503+
# -- Hooks 'n hacks ------------------------------------------------
511504

512-
def prelink_hook (self):
505+
def msvc_prelink_hack (self, sources, ext, extra_args):
513506

514507
# XXX this is a kludge! Knowledge of specific compilers or
515508
# platforms really doesn't belong here; in an ideal world, the
@@ -521,33 +514,32 @@ def prelink_hook (self):
521514
# Thus, kludges like this slip in occasionally. (This is no
522515
# excuse for committing more platform- and compiler-specific
523516
# kludges; they are to be avoided if possible!)
524-
if self.compiler.compiler_type == 'msvc':
525-
def_file = ext.export_symbol_file
526-
if def_file is None:
527-
source_dir = os.path.dirname (sources[0])
528-
ext_base = (string.split (ext.name, '.'))[-1]
529-
def_file = os.path.join (source_dir, "%s.def" % ext_base)
530-
if not os.path.exists (def_file):
531-
def_file = None
532-
533-
if def_file is not None:
534-
extra_args.append ('/DEF:' + def_file)
535-
else:
536-
modname = string.split (ext.name, '.')[-1]
537-
extra_args.append('/export:init%s'%modname)
538-
539-
# The MSVC linker generates unneeded .lib and .exp files,
540-
# which cannot be suppressed by any linker switches. So
541-
# make sure they are generated in the temporary build
542-
# directory.
543-
implib_file = os.path.join (
544-
self.build_temp,
545-
self.get_ext_libname (ext.name))
546-
extra_args.append ('/IMPLIB:' + implib_file)
547-
self.mkpath (os.path.dirname (implib_file))
548-
# if MSVC
549-
550-
# prelink_hook ()
517+
518+
def_file = ext.export_symbol_file
519+
if def_file is None:
520+
source_dir = os.path.dirname (sources[0])
521+
ext_base = (string.split (ext.name, '.'))[-1]
522+
def_file = os.path.join (source_dir, "%s.def" % ext_base)
523+
if not os.path.exists (def_file):
524+
def_file = None
525+
526+
if def_file is not None:
527+
extra_args.append ('/DEF:' + def_file)
528+
else:
529+
modname = string.split (ext.name, '.')[-1]
530+
extra_args.append('/export:init%s' % modname)
531+
532+
# The MSVC linker generates unneeded .lib and .exp files,
533+
# which cannot be suppressed by any linker switches. So
534+
# make sure they are generated in the temporary build
535+
# directory.
536+
implib_file = os.path.join (
537+
self.build_temp,
538+
self.get_ext_libname (ext.name))
539+
extra_args.append ('/IMPLIB:' + implib_file)
540+
self.mkpath (os.path.dirname (implib_file))
541+
542+
# msvc_prelink_hack ()
551543

552544

553545
# -- Name generators -----------------------------------------------

0 commit comments

Comments
 (0)