[Distutils] bdist and --compiler

Rene Liebscher R.Liebscher@gmx.de
Thu, 25 May 2000 19:01:02 +0200


This is a multi-part message in MIME format.
--------------B6F1B09420B2FD52D6E9B154
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Greg Ward wrote:
> 
> > The second problem. Why "bdist" doesn't check only the
> > source files against the finished extension modules?
> > Currently it seems to check the source files against
> > the compiled object files.
> 
> Good point, I think.  I'm trying *not* to emulate everything you'd do in
> a real Makefile, since Distutils != make.  But this could be a useful
> addition, if I understand what you're saying -- I'll have to think about
> it.  (Hint: working patches are an excellent way to prod me into
> thinking about something.  They also clarify wonderfully what exactly
> you're talking about.)

You have the following files:

XXXX.c => XXXX.o => XXXX.pyd

(on Windows)

If you remove the object files or use a different compiler, which wants
to see XXXX.obj instead XXXX.o (msvc <=> cygwin), it would try to
rebuild 
all, even if the XXXX.pyd-file is up-to-date.

I have the place in the build_ext.py file to change this, the patch is 
attached. I simple let check it before I start the compiler (which
only can check XXXX.c<=>XXXX.o and XXXX.o<=>XXXX.pyd)

 
> How does a "--help-compilers" global option sound?  (Kind of on the same
> level as "--help-commands".)  It's a bit klugey, but I can't think of a
> better option offhand.

There are more options  which could need such a list (bdist format),
perhaps we should introduce something like --help-option XXXXX 
( XXXXX = compiler,format,...) It could scan all commands for a option
with this name and a more extensive description (string or Callable,
which
generates a string on the fly.)


Kind regards

Rene Liebscher
--------------B6F1B09420B2FD52D6E9B154
Content-Type: text/plain; charset=us-ascii;
 name="build_ext.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="build_ext.patch"

diff -BurN --minimal --exclude=*.pyc distutils.orig/distutils/command/build_ext.py distutils.patched/distutils/command/build_ext.py
--- distutils.orig/distutils/command/build_ext.py	Thu May 25 03:10:04 2000
+++ distutils.patched/distutils/command/build_ext.py	Thu May 25 18:47:24 2000
@@ -12,7 +12,7 @@
 from types import *
 from distutils.core import Command
 from distutils.errors import *
-
+from distutils.dep_util import newer_group
 
 # An extension name is just a dot-separated list of Python NAMEs (ie.
 # the same as a fully-qualified module name).
@@ -285,7 +285,28 @@
                        "a list of source filenames") % extension_name
             sources = list (sources)
 
-            self.announce ("building '%s' extension" % extension_name)
+            fullname = self.get_ext_fullname (extension_name)
+            if self.inplace:
+                # ignore build-lib -- put the compiled extension into
+                # the source tree along with pure Python modules
+
+                modpath = string.split (fullname, '.')
+                package = string.join (modpath[0:-1], '.')
+                base = modpath[-1]
+
+                build_py = self.find_peer ('build_py')
+                package_dir = build_py.get_package_dir (package)
+                ext_filename = os.path.join (package_dir,
+                                             self.get_ext_filename(base))
+            else:
+                ext_filename = os.path.join (self.build_lib,
+                                             self.get_ext_filename(fullname))
+
+	    if not newer_group(sources,ext_filename,'newer'):
+	    	self.announce ("skipping '%s' extension (up-to-date)" % extension_name)
+		continue # 'for' loop over all extensions
+	    else:
+        	self.announce ("building '%s' extension" % extension_name)
 
             # First step: compile the source code to object files.  This
             # drops the object files in the current directory, regardless
@@ -356,23 +377,6 @@
                 extra_args.append ('/IMPLIB:' + implib_file)
                 self.mkpath (os.path.dirname (implib_file))
             # if MSVC
-
-            fullname = self.get_ext_fullname (extension_name)
-            if self.inplace:
-                # ignore build-lib -- put the compiled extension into
-                # the source tree along with pure Python modules
-
-                modpath = string.split (fullname, '.')
-                package = string.join (modpath[0:-1], '.')
-                base = modpath[-1]
-
-                build_py = self.find_peer ('build_py')
-                package_dir = build_py.get_package_dir (package)
-                ext_filename = os.path.join (package_dir,
-                                             self.get_ext_filename(base))
-            else:
-                ext_filename = os.path.join (self.build_lib,
-                                             self.get_ext_filename(fullname))
 
             self.compiler.link_shared_object (objects, ext_filename, 
                                               libraries=libraries,

--------------B6F1B09420B2FD52D6E9B154--