patch for msvccompiler.py and build_ext.py, debug flag

This patch against the current CVS version implements the --debug flag. Also I've included the def-file kludge again, because I still think if a def-file is present, it should be used, but I would still like to hear opinions from more windows people here. Other notes: - The python15.lib is no longer set in msvccompiler - We can still argue about the debug-flags to be used I've tested this (with and without def-files, with and without the debug flag) on numpy-15.2. It builds nicely in normal and debug mode, and testwin.bat completes successfully. Thomas Heller PS: I'm still new to diff. If I've done somthing wrong, please complain! diff -cr c:\distutils\distutils/command/build_ext.py distutils/command/build_ext.py *** c:\distutils\distutils/command/build_ext.py Wed Feb 9 09:10:32 2000 --- distutils/command/build_ext.py Wed Feb 9 11:54:04 2000 *************** *** 241,249 **** libraries = build_info.get ('libraries') library_dirs = build_info.get ('library_dirs') extra_args = build_info.get ('extra_link_args') or [] if self.compiler.compiler_type == 'msvc': ! mod_name = string.split (extension_name, '.')[-1] ! extra_args.append ('/export:init%s' % mod_name) ext_filename = self.extension_filename \ (extension_name, self.package) --- 241,263 ---- libraries = build_info.get ('libraries') library_dirs = build_info.get ('library_dirs') extra_args = build_info.get ('extra_link_args') or [] + if self.compiler.compiler_type == 'msvc': ! def_file = build_info.get ('def_file') ! if def_file is None: ! source_dir = os.path.dirname (sources[0]) ! ext_base = (string.split (extension_name, '.'))[-1] ! def_file = os.path.join (source_dir, "%s.def" % ext_base) ! if not os.path.exists (def_file): ! ## self.warn ("file '%s' not found: " % def_file + ! ## "might have problems building DLL") ! def_file = None ! ! if def_file is not None: ! extra_args.append ('/DEF:' + def_file) ! else: ! modname = string.split (extension_name, '.')[-1] ! extra_args.append('/export:init%s'%modname) ext_filename = self.extension_filename \ (extension_name, self.package) diff -cr c:\distutils\distutils/msvccompiler.py distutils/msvccompiler.py *** c:\distutils\distutils/msvccompiler.py Wed Feb 9 09:10:32 2000 --- distutils/msvccompiler.py Wed Feb 9 11:47:16 2000 *************** *** 114,123 **** CCompiler.__init__ (self, verbose, dry_run, force) - # XXX This is a nasty dependency to add on something otherwise - # pretty clean. move it to build_ext under an nt specific part. - # shared libraries need to link against python15.lib - self.add_library ( "python" + sys.version[0] + sys.version[2] ) self.add_library_dir( os.path.join( sys.exec_prefix, 'libs' ) ) self.cc = _find_exe("cl.exe") --- 114,119 ---- *************** *** 133,140 **** --- 129,142 ---- os.environ['path'] = string.join(path,';') self.preprocess_options = None self.compile_options = [ '/nologo', '/Ox', '/MD' ] + self.compile_options_debug = [ + '/nologo', '/Od', '/MDd', '/Z7', '/D_DEBUG' + ] self.ldflags_shared = ['/DLL', '/nologo', '/INCREMENTAL:NO'] + self.ldflags_shared_debug = [ + '/DLL', '/nologo', '/INCREMENTAL:no', '/pdb:None', '/DEBUG' + ] self.ldflags_static = [ '/nologo'] *************** *** 176,181 **** --- 178,188 ---- base_pp_opts.append('/c') + if debug: + compile_options = self.compile_options_debug + else: + compile_options = self.compile_options + for srcFile in sources: base,ext = os.path.splitext(srcFile) objFile = base + ".obj" *************** *** 188,198 **** inputOpt = fileOpt + srcFile outputOpt = "/Fo" + objFile ! cc_args = self.compile_options + \ base_pp_opts + \ [outputOpt, inputOpt] ! if debug: ! pass # XXX what goes here? if extra_preargs: cc_args[:0] = extra_preargs if extra_postargs: --- 195,204 ---- inputOpt = fileOpt + srcFile outputOpt = "/Fo" + objFile ! cc_args = compile_options + \ base_pp_opts + \ [outputOpt, inputOpt] ! if extra_preargs: cc_args[:0] = extra_preargs if extra_postargs: *************** *** 250,257 **** # XXX should we sanity check the library name? (eg. no # slashes) ! self.link_shared_object (objects, ! self.shared_library_name(output_libname)) def link_shared_object (self, objects, --- 256,270 ---- # XXX should we sanity check the library name? (eg. no # slashes) ! self.link_shared_object (objects=objects, ! output_libname=\ ! self.shared_library_name(output_libname), ! output_dir=output_dir, ! libraries=libraries, ! library_dirs=library_dirs, ! debug=debug, ! extra_preargs=extra_preargs, ! extra_postargs=extra_postargs) def link_shared_object (self, objects, *************** *** 259,264 **** --- 272,278 ---- output_dir=None, libraries=None, library_dirs=None, + debug=0, extra_preargs=None, extra_postargs=None): """Link a bunch of stuff together to create a shared object *************** *** 273,282 **** self.library_dirs + library_dirs, self.libraries + libraries) - ld_args = self.ldflags_shared + lib_opts + \ - objects + ['/OUT:' + output_filename] if debug: ! pass # XXX what goes here? if extra_preargs: ld_args[:0] = extra_preargs if extra_postargs: --- 287,304 ---- self.library_dirs + library_dirs, self.libraries + libraries) if debug: ! ldflags = self.ldflags_shared_debug ! basename, ext = os.path.splitext (output_filename) ! #XXX not sure this belongs here ! # extensions in debug_mode are named 'module_d.pyd' ! output_filename = basename + '_d' + ext ! else: ! ldflags = self.ldflags_shared ! ! ld_args = ldflags + lib_opts + \ ! objects + ['/OUT:' + output_filename] ! if extra_preargs: ld_args[:0] = extra_preargs if extra_postargs:

On 09 February 2000, Thomas Heller said:
This patch against the current CVS version implements the --debug flag. Also I've included the def-file kludge again, because I still think if a def-file is present, it should be used, but I would still like to hear opinions from more windows people here.
OK, I buy the arguments you and Robin have put forth since I took the .def file kludge out -- it's back in again. Sigh.
- The python15.lib is no longer set in msvccompiler
Fine; thanks for the explanation of how that works, BTW.
- We can still argue about the debug-flags to be used
Argue away. I'll sit back, marvel at the never-ending stream of weird command-line options, and accept patches that seem to be the consensus of the Windows/MSVC++ crowd.
I've tested this (with and without def-files, with and without the debug flag) on numpy-15.2. It builds nicely in normal and debug mode, and testwin.bat completes successfully.
Gee, a *tested* patch even! I should try testing my code sometime. ;-) BTW, at least one bug slipped past: the "if MSVC" block in build_ext.py was improperly indented; I've fixed it to: if self.compiler.compiler_type == 'msvc': def_file = build_info.get ('def_file') if def_file is None: source_dir = os.path.dirname (sources[0]) ext_base = (string.split (extension_name, '.'))[-1] def_file = os.path.join (source_dir, "%s.def" % ext_base) if not os.path.exists (def_file): def_file = None if def_file is not None: extra_args.append ('/DEF:' + def_file) else: modname = string.split (extension_name, '.')[-1] extra_args.append('/export:init%s'%modname) i.e. *everything* MSVC-specific is under that top if statement! Also I deleted the commented out warning about the missing .def file.
PS: I'm still new to diff. If I've done somthing wrong, please complain!
There were some problems. Specifically:
diff -cr c:\distutils\distutils/command/build_ext.py distutils/command/build_ext.py
Not-too-surprisingly, `patch' on my Linux system doesn't know how to interpret "c:\..." -- I had to tell it which file to patch manually. Unfortunately, the obvious way to work when changing several files and doing "diff -r" is to keep the pristine sources in one place, and hack on them in another place -- which leads to absolute pathnames in "diff" output. I don't know how to get around that. There was a more serious problem in the msvccompiler.py patch: a long line got wrapped around:
--- 256,270 ----
# XXX should we sanity check the library name? (eg. no # slashes) ! self.link_shared_object (objects=objects, ! output_libname=\ ! self.shared_library_name(output_libname), ! output_dir=output_dir, ! libraries=libraries, ! library_dirs=library_dirs, ! debug=debug, ! extra_preargs=extra_preargs, ! extra_postargs=extra_postargs)
Easy to see how it happened, but it made `patch' complain of a malformed patch. Turns out I had to patch that "hunk", and one other, manually; I'm not sure why. Oh well, the other 5 hunks in the patch succeeded. Actually, I'm kinda new to the receiving patches end of things as well. I've certainly *generated* a number of patches in the past, but haven't had much software that was popular with the sort of people (ie. Real Hackers) who generate patches. Hey, what would life be without new experiences... Anyways, your changes are in CVS now. Please try it out and make sure I got the patches right -- thanks! Greg -- Greg War - just another Perl hacker gward@python.net http://starship.python.net/~gward/ No problem is so formidable that you can't just walk away from it.
participants (2)
-
Greg Ward
-
Thomas Heller