Cannot generate XML output from cppcheck

I use cppcheck to statically parse C code but cannot get XML. I require jenkins xml file

Here is what I have tried so far:

runcppcheck.sh

#!/bin/sh cd obj/msc cppcheck --enable=all -I. -I. -I. -I. -I. -I. -I. -I. -I. -I. -I. /usr/include/ -I. obj/fap/ \ -DSUNOS -DSS -DSS_MT -DANSI -D_GNU_SOURCE -DSS_LINUX -D_REENTRANT -D__EXTENSIONS__ -DSUNOS -DCNS_PH1 -DDBG_TIMESTAMP -DLX_PRNT_TIMESTAMP \ -DDEBUGP -DLX -DLCLXT -DLXT_V1 -DLCLXUILXT -DLCXULILXT -DXU -DLX -DLCLLX -DSM -DLWLCLLX -DLCLXMILLX -DLCSMLXMILLX -DHR -DLX -DLCHRT \ -DLCHRUIHRT -DLCHRLIHIT -DLCLXLIHRT -DXU -DLCXULIHRT -DLX -DLX_RTP -DLX_FASTRC -DCMINET_BSDCOMPAT -DSS_TICKS_SEC=100 -DCMFILE_REORG_1 \ -DCM_INET2 -D_GNU_SOURCE -DCMFILE_REORG_2 -DSSINT2 -DCMKV2 -DHI_MULTI_THREADED -DxCM_PASN_DBG -DxCCPU_DEBUG -DxRNC_OUTPUT_CONSOLE \ -DxCCPU_DEBUG_TRACE -DCCPU_DEBUG1 -DSS_PERF -DNO_ERRCLS -DNOERRCHK -DSS_M_PROTO_REGION -DxCCPU_DEBUG_TRACE1 -DxCCPU_DEBUG_TRACE2 \ -DCCPU_MEAS_CPU -DSTD_CCPU_IU -UMULTIPLE_CN_SUPPORT -DLONG_MSG -DTEST_CNS -UDCM_RTP_SESSID_ARRAY -DHR *.c *.h --xml ../../cppcheck-result.xml 

i DO GET XML on stdout, but just NOT in the file

+6
source share
3 answers

I am a Cppcheck developer.

You need to transfer the report to a file.

 cppcheck file1.c --xml 2> cppcheck-result.xml 

A small hint of your command line, in most cases it is better to use it. instead of * .c * .h.

+7
source

Actually, here is the command to get the correct xml output.

 cppcheck --xml --xml-version=2 --enable=all <path1> <path2> 2>samplecppcheck.xml 
+2
source

This part 2> is obviously shell syntax and is intended only to work from the context of the shell interpreter. So, what to do when it is NOT run from the shell, just a simple "command with arguments" interface (for example, env , xargs , docker run , etc.)?

Needless to say, the obvious workaround wrapping it all in sh -c is a terrible antipattern: quoting and escaping is hard to do right, most programmers won't even try, resulting in a fragile code and a potential security hole. This would be an unreasonable complication to indicate the output file and a clear sign that you are doing something wrong.

A wrapper script allows you to solve the problem correctly.

 #!/bin/sh exec " $@ " 2> result.xml 

... but it will be a file, and this can be a complication in itself. Fortunately, this script can be written as a string:

 sh -c 'exec "$0" " $@ " 2> result.xml' cppcheck … 

Now it is presented in the form of a simple list of arguments and, therefore, works in all shells, as well as in non-shells such as docker run .

0
source

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


All Articles