SCons: saving / redirecting gcc text output (warnings)

I use SCons to create a project at work, and I try to parse text output from GCC to compile a summary report of all compiler warnings for each purpose, because our build scripts are quite long and there is a lot of text output to the console.

I searched Google and this site for quite a while, and I cannot find the method built into SCons for this. I tried to redirect the entire stream of stdout and stderr to a file for this example , but only the output from SCons itself is captured, and not any tools that it calls.

My next thought was to find where SCons compiles the arguments to send to GCC and adds a redirect to the end of the argument string. After reading the documentation, it seems that the CCCOM and CXXCOM construct variables contain the command line used for compilation. However, when I added the lines below to my SConstruct, nothing changed on the command lines that SCons executes.

 baseEnv['CCCOM'] += " 2> gcc-c-output.txt" baseEnv['CXXCOM'] += " 2> gcc-cxx-output.txt" 

One thing that worked was stderr thread redirection in the entire SCons team:

 scons 2> stderr.txt 

However, I would like to avoid this and keep everything possible in SCons. The output also does not have to go to a file. It can be saved anywhere, as long as I can access it for parsing and saving to a file at the end of the assembly.

I searched for so long and did not come up with anything, so I do not know what else to try. I have to believe that I am not the first to want to do something like this.

+6
source share
5 answers

I am going to answer my own question here, as I understood what I am doing wrong. The CCCOM and CXXCOM were correct for the change, but the problem was that I was creating shared library objects, so these variables were not used. The ones I had to change are SHCCCOM and SHCXXCOM .

The following code received a job to redirect the output of the GCC warning (warnings and errors are recorded only in stderr):

 baseEnv['SHCCCOM'] += " 2> gcc-c-output.txt" baseEnv['SHCXXCOM'] += " 2> gcc-cxx-output.txt" 

Hope this answer helps others, as I could not find much information on this topic when searching.

+5
source

For complete control, you can override the env['SPAWN'] construct variable. Then you will provide a Python method that will be responsible for executing the command line provided by the argument. Usually you take this argument and spawn a subprocess (using some form of subprocess.Popen ). This would make the default transitional replacement env['SPAWN'] .

But now you have full control over the subprocess.Popen call. You can redirect STDOUT , STDERR or both to any buffer / file. You can also do post-processing on this output before printing it to the console and / or saving it to a file. I used this for color warnings in yellow and, for example, red errors.

For sample code on how to override env['SPAWN'] , check out this page on the Wiki Scons.

+3
source

Instead of the CCCOM and CXXCOM , did you try to use the CC and CXX ? Below is a complete list of SCons build variables just in case.

You might even consider installing CC and CXX scripts on your system that internally redirect.

EDIT: I forgot to mention that the CCCOM and CXXCOM are the commands used to actually compile the source files with all CFlags, etc. Im surprised you were able to set them as I thought they were read-only variables.

0
source

Use the following:

baseEnv['CCCOM'][0] += " 2> gcc-c-output.txt"

0
source

What about:

 baseEnv['SHCCCOM'] += " 2> ${SOURCE}gcc-c-output.txt" baseEnv['SHCXXCOM'] += " 2> ${SOURCE}gcc-cxx-output.txt" 

This will give you a separate file for each source file.

0
source

Source: https://habr.com/ru/post/918662/


All Articles