0

I use scons (V1.1.0) for a project that contains a build step that involves the flex tool.

The definition for the flex command in the scons default rules is:

env["LEX"]      = env.Detect("flex") or "lex"
env["LEXFLAGS"] = SCons.Util.CLVar("")
env["LEXCOM"]   = "$LEX $LEXFLAGS -t $SOURCES > $TARGET"

which I don't want to change.

However, since -t causes #line directives to be created in the output file that refer to the file "<stdout>", this confuses the subsequent gcov processing.

As a solution, I found that -o can be used to override the file name flex produces into the #line directives (it still produces its output on stdout due to the -t option which apparently has precedence).

To achieve that, I added this in the project's SConscript file:

env.AppendUnique(LEXFLAGS = ['-o $TARGET','-c'],delete_existing=1)

I added the -c option (which does nothing) only to show the difference between how it is treated compared to -o.

An according debug print in the SConscript file results in the following (as expected):

repr(env["LEXFLAGS"]) = ['-o $TARGET', '-c']

This results in the following command line, according to the scons log:

flex "-o build/myfile.cpp" -c -t src/myfile.ll > build/myfile.cpp

So the -c option gets into the command line as desired, but the -o option and its filename parameter has double quotes around it, that must have been created by scons when expanding the LEXFLAGS variable.

When I use this definition for LEXFLAGS instead:

env.AppendUnique(LEXFLAGS = ['--outfile=$TARGET','-c'],delete_existing=1)

the resulting command line works as desired:

flex --outfile=build/myfile.cpp -c -t src/myfile.ll > build/myfile.cpp

So one could speculate that the blank in the -o case caused the double quotes to be used, maybe in an attempt to bind the content together into one logical parameter for the command.

So while my immediate problem is solved by using --outfile, my question is still is it possible to rid of the double quotes in the -o case?

Thanks, Andy

Andreas Maier
  • 2,724
  • 1
  • 26
  • 30

1 Answers1

0

SCons 1.1.0 is extremely old at this point. I'd recommend trying 2.3.0. But your analysis is correct; if an option (a single option, that is) has a space in it, SCons will quote it so it stays a single option. But you don't have a single option; you really have two, '-o' and '$TARGET'. Just break it up like that and it'll work.

GaryO
  • 5,873
  • 1
  • 36
  • 61