[Scons-users] problem with white space in C -D options

Tom Tanner (BLOOMBERG/ LONDON) ttanner2 at bloomberg.net
Mon Jun 1 10:18:34 EDT 2015


I've been having some fun trying to pass white space in a -D option for a C program.

The program is 

#include <stdio.h>
int main() { printf( ABC ); return 0; }


This:

cc -DABC='"some stuff"' test.c

Works fine.

However, this:

env = Environment()
env['CPPDEFINES'] = [ ( 'ABC', '"some stuff"' ) ]
env.Program('test.c')

produces:
cc -o test.o -c "-DABC="some stuff"" test.c

Which fails with this:
"test.c", line 5: undefined symbol: some

I ended up with this:

env['CPPDEFINES'] = [ ( 'ABC', '\"some stuff\"' ) ]

I am not sure how to deal with this programatically as I don't really know what the 
It seems to me after putting some trace in spawn there's a lot of shell quoting going at various places in scons - for instance, I get this if I add trace in subprocess_spawn

Spawn args ['cc', '-o', '"test.o"', '-c', '"-DABC=\\"some stuff\\""', '"test.c"']


That makes it hard to apply quoting generically in spawn. I tried using ParseFlags:

env.Parseflags(""" -DABC='"some stuff"' """)


Results in:
cc -o test.o -c "-DABC="some stuff"" test.c

again.

I guess when parsing the input I get I'm going to need to replace " with \\" throughout and pray but it's messy. Really I don't think there should be any of these "s until we get down to the ' '.join() in spawn. (which also means that removing the sh -c as I'd like to is going to break horribly)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20150601/03918eab/attachment.html>


More information about the Scons-users mailing list