[Distutils] Patch for NT

Thomas Heller thomas.heller@ion-tof.com
Wed, 29 Mar 2000 21:26:05 +0200


The attached patch fixes the followoing problems:
1. self.build_extensions - (which I reported already)
2. The python library directory is now again used (also already reported by me)
3. Debug and Release versions of python extensions under windows are now
compiled in different directories (as it should be!).
4. Unneeded junk from the MSVC linker (.lib and .exp files) are now created in the
temporary build directory.

diff -cr distutils/command/build_ext.py distutils.new/command/build_ext.py
*** distutils/command/build_ext.py Wed Mar 29 10:33:48 2000
--- distutils.new/command/build_ext.py Wed Mar 29 21:16:16 2000
***************
*** 125,130 ****
--- 125,141 ----
          # XXX how the heck are 'self.define' and 'self.undef' supposed to
          # be set?
  
+         if self.library_dirs is None:
+             self.library_dirs = []
+         # for extensions under windows use different directories
+         # for Release and Debug builds.
+         # also Python's library directory must be appended to library_dirs
+         if os.name == 'nt':
+             self.library_dirs.append (os.path.join(sys.exec_prefix, 'libs'))
+             if self.debug:
+                 self.build_temp = os.path.join (self.build_temp, "Debug")
+             else:
+                 self.build_temp = os.path.join (self.build_temp, "Release")
      # finalize_options ()
      
  
***************
*** 189,195 ****
              self.compiler.set_link_objects (self.link_objects)
  
          # Now actually compile and link everything.
!         self.build_extensions ()
  
      # run ()
  
--- 200,206 ----
              self.compiler.set_link_objects (self.link_objects)
  
          # Now actually compile and link everything.
!         self.build_extensions (self.extensions)
  
      # run ()
  
***************
*** 313,318 ****
--- 324,336 ----
                  else:
                      modname = string.split (extension_name, '.')[-1]
                      extra_args.append('/export:init%s'%modname)
+                 # the MSVC linker generates unneeded .lib and .exp files,
+                 # which cannot be suppressed by any linker switches.
+                 # So make sure they are generated in the temporary
+                 # build directory
+                 implib_dir = os.path.join(self.build_temp,\
+                                           self.get_ext_libname(extension_name))
+                 extra_args.append ('/IMPLIB:' + implib_dir)
              # if MSVC
  
              fullname = self.get_ext_fullname (extension_name)
***************
*** 351,356 ****
--- 369,385 ----
      def get_ext_filename (self, ext_name):
          from distutils import sysconfig
          ext_path = string.split (ext_name, '.')
+         # extensions in debug_mode are named 'module_d.pyd' under windows
+         if os.name == 'nt' and self.debug:
+             return apply (os.path.join, ext_path) + '_d' + sysconfig.SO
          return apply (os.path.join, ext_path) + sysconfig.SO
+ 
+     def get_ext_libname (self, ext_name):
+         # create a filename for the (unneeded) lib-file.
+         # extensions in debug_mode are named 'module_d.pyd' under windows
+         ext_path = string.split (ext_name, '.')
+         if os.name == 'nt' and self.debug:
+             return apply (os.path.join, ext_path) + '_d.lib'
+         return apply (os.path.join, ext_path) + '.lib'
  
  # class BuildExt
diff -cr distutils/msvccompiler.py distutils.new/msvccompiler.py
*** distutils/msvccompiler.py Wed Mar 29 09:01:40 2000
--- distutils.new/msvccompiler.py Wed Mar 29 20:58:54 2000
***************
*** 319,333 ****
              raise TypeError, "'output_dir' must be a string or None"
          if output_dir is not None:
              output_filename = os.path.join (output_dir, output_filename)
  
          if self._need_link (objects, output_filename):
  
              if debug:
                  ldflags = self.ldflags_shared_debug
-                 # XXX not sure this belongs here
-                 # extensions in debug_mode are named 'module_d.pyd'
-                 basename, ext = os.path.splitext (output_filename)
-                 output_filename = basename + '_d' + ext
              else:
                  ldflags = self.ldflags_shared
  
--- 319,331 ----
              raise TypeError, "'output_dir' must be a string or None"
          if output_dir is not None:
              output_filename = os.path.join (output_dir, output_filename)
+         else:
+             output_dir = os.path.dirname (output_filename)
  
          if self._need_link (objects, output_filename):
  
              if debug:
                  ldflags = self.ldflags_shared_debug
              else:
                  ldflags = self.ldflags_shared
  


Thomas Heller
ION-TOF GmbH