I'm using SCons to build a project at work, and I'm trying to parse through the textual output from GCC to make a summary report of all the compiler warnings for each target because our build scripts are quite long, and there is a lot of text output to the console.
I've searched Google and this site for quite a while, and I can't find a method built-in to SCons to accomplish this. I've tried redirecting the entire stdout and stderr stream to a file per this example, but only the output from SCons itself is captured and not that of any tools it calls.
My next thought was to find where SCons compiles the arguments to send to GCC and add redirection to the end of the arguments string. After reading the documentation, it seems that the construction variables CCCOM
and CXXCOM
contain the command line used to compile. However, when I added the lines below to my SConstruct, nothing changed in the command lines SCons is executing.
baseEnv['CCCOM'] += " 2> gcc-c-output.txt"
baseEnv['CXXCOM'] += " 2> gcc-cxx-output.txt"
One thing that did work was redirecting the stderr stream on the entire SCons command:
scons 2> stderr.txt
I would like to avoid this, however, and contain everything within SCons if possible. The output also doesn't necessarily have to go to a file. It can be saved anywhere as long as I can access it to parse and save to a file at the end of the build.
I've searched for so long and come up with nothing, so I don't know what else to try. I have to believe that I'm not the first one who has wanted to do something like this.
I'm going to answer my own question here as I figured out what I was doing wrong. The CCCOM
and CXXCOM
variables were the correct ones to be modified, but the problem was I was creating shared-library objects, so these variables were not being used. The ones I should have been modifying are SHCCCOM
and SHCXXCOM
.
The following code got the job done for redirecting the GCC warning output (warnings and errors are written to stderr only):
baseEnv['SHCCCOM'] += " 2> gcc-c-output.txt"
baseEnv['SHCXXCOM'] += " 2> gcc-cxx-output.txt"
Hopefully this answer will help others as I could not find much information on this topic when searching.