
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

3. Debug and Release versions of python extensions under windows are now compiled in different directories (as it should be!).
How about using the same convention Python itself does? * Debug and release outputs go into the same directory (as they have different names - _d for debug). This allows people to add the build directory to their sys.path, and have it work for both debug and release. * Build\Temp\Release and Build\Temp\Debug are where the intermediate files go. This makes it easy to manually clean your file system - one directory and all temp files are gone. Mark.

3. Debug and Release versions of python extensions under windows are now compiled in different directories (as it should be!).
How about using the same convention Python itself does?
* Debug and release outputs go into the same directory (as they have different names - _d for debug). This allows people to add the build directory to their sys.path, and have it work for both debug and release.
* Build\Temp\Release and Build\Temp\Debug are where the intermediate files go. This makes it easy to manually clean your file system - one directory and all temp files are gone.
Mark.
It seems my description was unclear: Intermediate files go into build\temp.win32\Release\... or build\temp.win32\Debug\... These are: .obj, .lib, .exp files. Debug and Release outputs go into the same directory, debug versions have _d appended. Cleaning files: distutils now has a clean command (which will delete build\temp.win32 directory): Manual cleaning not needed. Thomas

On 29 March 2000, Thomas Heller said:
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.
Thanks! I see a few potential problems here (maybe -- remember, I'm not a Windows user, so if these sound like trying to apply The Unix Way to Windows, tell me).
+ if self.debug: + self.build_temp = os.path.join (self.build_temp, "Debug") + else: + self.build_temp = os.path.join (self.build_temp, "Release")
So you'll have build directories build/temp.nt/Debug and build/temp.nt/Release -- is that somehow better than build/temp.nt-debug and build/temp.nt-release? I was kinda thinking along the latter lines; I don't *think* it makes any difference, apart from aesthetics. Does it? I'm guessing that The Microsoft Way would be to create an unnecessarily deep hierarchy.
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,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)
What does this add? The name 'output_dir' isn't referenced anywhere after this point. I fixed the stupid 'build_extensions' bug differently, so that part of your patch is unneeded. (Thanks anyway. ;-) There, I've just applied your patch, discarded the unneeded 'build_extensions' and 'output_dir' bits, and checked it all in. Looks like it all still works for me under Linux... Thanks again! Greg -- Greg Ward - Unix bigot gward@python.net http://starship.python.net/~gward/ God is real, unless declared integer.

So you'll have build directories build/temp.nt/Debug and build/temp.nt/Release -- is that somehow better than build/temp.nt-debug and build/temp.nt-release? I was kinda thinking along the latter lines; I don't *think* it makes any difference, apart from aesthetics. Does
Nope - just aesthetics. This is my preference, as it is a single directory to ignore, rather than 2 :-)
I'm guessing that The Microsoft Way would be to create an unnecessarily deep hierarchy.
Actually, by default it is very shallow - all temp and output files go into either ".\Release" or ".\Debug" - adding the intermediate layers (and sneaking them into Python itself) is my doing :-) But given the 2 alternatives above, my preference is so slight it is barely worth mentioning :-) I can't answer your other question... Mark.

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,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)
What does this add? The name 'output_dir' isn't referenced anywhere after this point. Not needed any longer. You are right.
There, I've just applied your patch, discarded the unneeded 'build_extensions' and 'output_dir' bits, and checked it all in. Looks like it all still works for me under Linux...
I did an cvs update this morning, and it works. Thanks! Thomas
participants (3)
-
Greg Ward
-
Mark Hammond
-
Thomas Heller