[Distutils] Proposed change to ccompiler classes

Thomas Heller theller at python.net
Thu Nov 6 14:53:57 EST 2003

While hacking on a setup script for the win32all extensions, I
encountered a problem with the distutils' ccompiler class(es).

The compile() method determines which files have to be compiled, and
constructs a dictionary 'build'.  This contains as keys the object
filename, the corresponding values are 2-tuples containing the source
filename and the extension of the source filename.

Later, the files are compiled using this loop:

    for obj, (src, ext) in build.items():

So, the files are compiled in a random order.

For Windows, however, there may be the requirement that a certain build
order is required, because the compilation of some files creates other
files, which may be included by the following compilation steps.

To give an example, there are '.mc' files which are first compiled by
the so called messagecompiler.  A '.h' file is also created, which is
included by other source files.

The essence is that a certain compile order is required.

I can see two solutions:
- Enhance the compiler classes with a method which will bring the files
into the correct order, then make sure that they are actually compiled
in this order.

- Change the code so that the files are compiled in the order of the
sequence passed to the compiler, and let the setup script writer take
care that the order is correct.

The latter is the easiest option, and this change would enable this -
although it must be done in each compiler class:

    #for obj, (src, ext) in build.items():
    for obj in objects:
            src, ext = build[obj]
        except KeyError:

Any thoughts?


More information about the Distutils-SIG mailing list