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

Vasily just.one.man at yandex.ru
Mon Jun 1 11:51:43 EDT 2015


Hi Tom,

Did you try the (IMHO) easiest method of dealing with white space, i.e.
*not dealing* with it?
Most likely doing just

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

would do the trick.

Thanks,
Vasily

2015-06-01 17:18 GMT+03:00 Tom Tanner (BLOOMBERG/ LONDON) <
ttanner2 at bloomberg.net>:

> 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)
>
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20150601/ae805ef1/attachment.html>


More information about the Scons-users mailing list