[Distutils] Bug/patch question, WinNT, Borland C linker, spaces in paths

Rafal Dowgird Rafal Dowgird <dowgird@bms.com.pl>
Tue Dec 3 05:14:04 2002


Hello,

There  is  a  bug in distutils that breaks Borland C linker. Distutils
tries to pass search paths to the linker as
"/LD:/Program Files/samplepath"

This  causes  the  linker to bail out with an error message suggesting
that  the path argument is mistreated as an object file. It seems that
the  linker  expects  a  different quoting scheme that the one used by
distutils. I have done some experimenting and it turns out that:

/L"D:/Program Files/samplepath"
/LD:/Program" "Files/samplepath

are both OK. Unfortunately:

/L "D:/Program Files/samplepath"

does  not  work  -  there should be no whitespace between '/L' and the
path,  so  passing  '/L'  and  the path as separate arguments does not
work.

The  piece  of  code  responsible  for  the  quoting is _nt_quote_args
function  in spawn.py. The following patch 'fixes' the quoting scheme.
This is the output from 'cvs diff spawn.py':

Index: spawn.py
===================================================================
RCS file: /cvsroot/python/distutils/distutils/spawn.py,v
retrieving revision 1.16
diff -r1.16 spawn.py
62,63c62
<         if string.find(args[i], ' ') != -1:
<             args[i] = '"%s"' % args[i]
---
>         args[i] = args[i].replace(' ','" "')

Instead of putting the whole space-containing argument into quotes, it
only quotes spaces.

Unfortunately  there  is  no  reason  for  this  not  to  break  other
compilers. Due to infelicities in WinApi (child process gets the whole
command line, not split into arguments) it's up to the compiler/linker
to  parse  the  command line and as far as I know there is no standard
way of encoding arguments that contain spaces.

  Now, the questions:

1.  Can  anyone test the above patch with other compilers? I only have
Borland.

2.  I think that one 'standard' argument quoting function might not be
sufficient.  Perhaps  _nt_quote_args  should  be  moved into CCompiler
class  hierarchy?  This way every compiler could override the standard
quoting function without the risk of breaking other compilers.
   
3.  I  have just started looking at the distutils source code and I am
not  a Python guru, so perhaps there is another simple way to fix this
bug?

      Regards,
        
         Rafal Dowgird