cppcheck options: add --output-file-type option by RobertWak · Pull Request #3365 · cppcheck-opensource/cppcheck
added 6 commits
When used with tools such as cmake, cppcheck doesn't provide an convenient way to output into files.
I've added two values for new --output-file-type option:
uniq: this will create a output file name based on the --output-file and the current file(s) that are analyzed
append: this will open the --output-file file in append mode and add the content to it
example:
Not using the new option:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml cli/cmdlineparser.cpp
$ ls -la output_files/
total 12
drwxrwxr-x 2 user user 4096 Jul 22 14:47 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 1283 Jul 22 14:47 cppcheck.xml
Using the option with value "uniq" for one file:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=uniq cli/cmdlineparser.cpp
$ ls -la output_files/
total 12
drwxrwxr-x 2 user user 4096 Jul 22 14:48 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 1283 Jul 22 14:48 cppcheck_cmdlineparser_cpp.xml
Using the option with value "uniq" for two files:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=uniq cli/cmdlineparser.cpp cli/cppcheckexecutor.cpp
$ ls -la output_files/
total 16
drwxrwxr-x 2 user user 4096 Jul 22 14:49 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 4308 Jul 22 14:49 cppcheck_cmdlineparser_cpp_cppcheckexecutor_cpp.xml
Using the option with value "append" for one file on a empty/non-existing file:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp
$ ls -la output_files/
total 12
drwxrwxr-x 2 user user 4096 Jul 22 14:51 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 1283 Jul 22 14:51 cppcheck.xml
Using the option with value "append" for two files on a empty/non-existing file:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp cli/cppcheckexecutor.cpp
$ ls -la output_files/
total 16
drwxrwxr-x 2 user user 4096 Jul 22 14:53 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 4308 Jul 22 14:53 cppcheck.xml
Using the option with value twise "append" for one file on a empty/non-existing file:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cppcheckexecutor.cpp
$ ls -la output_files/
total 16
drwxrwxr-x 2 user user 4096 Jul 22 14:54 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 5613 Jul 22 14:55 cppcheck.xml
/!\ the file is a pure concatenation of the files created without the "append" value which means that it's no more a valid XML file as it will have twice the "<?xml version="1.0" encoding="UTF-8"?>" entry
$ cat output_files/cppcheck.xml
<?xml version="1.0" encoding="UTF-8"?>
<results version="2">
[...]
</results>
<?xml version="1.0" encoding="UTF-8"?>
<results version="2">
[...]
</results>
Signed-off-by: Robert Wakim <robert.wakim@arm.com>
When used with tools such as cmake, cppcheck doesn't provide an convenient way to output into files.
I've added two values for new --output-file-type option:
uniq: this will create a output file name based on the --output-file and the current file(s) that are analyzed
append: this will open the --output-file file in append mode and add the content to it
example:
Not using the new option:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml cli/cmdlineparser.cpp
$ ls -la output_files/
total 12
drwxrwxr-x 2 user user 4096 Jul 22 14:47 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 1283 Jul 22 14:47 cppcheck.xml
Using the option with value "uniq" for one file:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=uniq cli/cmdlineparser.cpp
$ ls -la output_files/
total 12
drwxrwxr-x 2 user user 4096 Jul 22 14:48 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 1283 Jul 22 14:48 cppcheck_cmdlineparser_cpp.xml
Using the option with value "uniq" for two files:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=uniq cli/cmdlineparser.cpp cli/cppcheckexecutor.cpp
$ ls -la output_files/
total 16
drwxrwxr-x 2 user user 4096 Jul 22 14:49 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 4308 Jul 22 14:49 cppcheck_cmdlineparser_cpp_cppcheckexecutor_cpp.xml
Using the option with value "append" for one file on a empty/non-existing file:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp
$ ls -la output_files/
total 12
drwxrwxr-x 2 user user 4096 Jul 22 14:51 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 1283 Jul 22 14:51 cppcheck.xml
Using the option with value "append" for two files on a empty/non-existing file:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp cli/cppcheckexecutor.cpp
$ ls -la output_files/
total 16
drwxrwxr-x 2 user user 4096 Jul 22 14:53 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 4308 Jul 22 14:53 cppcheck.xml
Using the option with value twise "append" for one file on a empty/non-existing file:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cppcheckexecutor.cpp
$ ls -la output_files/
total 16
drwxrwxr-x 2 user user 4096 Jul 22 14:54 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 5613 Jul 22 14:55 cppcheck.xml
/!\ the file is a pure concatenation of the files created without the "append" value which means that it's no more a valid XML file as it will have twice the "<?xml version="1.0" encoding="UTF-8"?>" entry
$ cat output_files/cppcheck.xml
<?xml version="1.0" encoding="UTF-8"?>
<results version="2">
[...]
</results>
<?xml version="1.0" encoding="UTF-8"?>
<results version="2">
[...]
</results>
Signed-off-by: Robert Wakim <robert.wakim@arm.com>
When used with tools such as cmake, cppcheck doesn't provide an convenient way to output into files.
I've added two values for new --output-file-type option:
uniq: this will create a output file name based on the --output-file and the current file(s) that are analyzed
append: this will open the --output-file file in append mode and add the content to it
example:
Not using the new option:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml cli/cmdlineparser.cpp
$ ls -la output_files/
total 12
drwxrwxr-x 2 user user 4096 Jul 22 14:47 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 1283 Jul 22 14:47 cppcheck.xml
Using the option with value "uniq" for one file:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=uniq cli/cmdlineparser.cpp
$ ls -la output_files/
total 12
drwxrwxr-x 2 user user 4096 Jul 22 14:48 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 1283 Jul 22 14:48 cppcheck_cmdlineparser_cpp.xml
Using the option with value "uniq" for one file without extension:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck --output-file-type=uniq cli/cmdlineparser.cpp
$ ls -la output_files/
total 12
drwxrwxr-x 2 user user 4096 Jul 22 14:48 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 1283 Jul 22 14:48 cppcheck_cmdlineparser_cpp
Using the option with value "uniq" for two files:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=uniq cli/cmdlineparser.cpp cli/cppcheckexecutor.cpp
$ ls -la output_files/
total 16
drwxrwxr-x 2 user user 4096 Jul 22 14:49 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 4308 Jul 22 14:49 cppcheck_cmdlineparser_cpp_cppcheckexecutor_cpp.xml
Using the option with value "append" for one file on a empty/non-existing file:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp
$ ls -la output_files/
total 12
drwxrwxr-x 2 user user 4096 Jul 22 14:51 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 1283 Jul 22 14:51 cppcheck.xml
Using the option with value "append" for two files on a empty/non-existing file:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp cli/cppcheckexecutor.cpp
$ ls -la output_files/
total 16
drwxrwxr-x 2 user user 4096 Jul 22 14:53 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 4308 Jul 22 14:53 cppcheck.xml
Using the option with value twise "append" for one file on a empty/non-existing file:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cppcheckexecutor.cpp
$ ls -la output_files/
total 16
drwxrwxr-x 2 user user 4096 Jul 22 14:54 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 5613 Jul 22 14:55 cppcheck.xml
/!\ the file is a pure concatenation of the files created without the "append" value which means that it's no more a valid XML file as it will have twice the "<?xml version="1.0" encoding="UTF-8"?>" entry
$ cat output_files/cppcheck.xml
<?xml version="1.0" encoding="UTF-8"?>
<results version="2">
[...]
</results>
<?xml version="1.0" encoding="UTF-8"?>
<results version="2">
[...]
</results>
Signed-off-by: Robert Wakim <robert.wakim@arm.com>
Robert Wakim added 2 commits
When used with tools such as cmake, cppcheck doesn't provide an convenient way to output into files.
I've added two values for new --output-file-type option:
uniq: this will create a output file name based on the --output-file and the current file(s) that are analyzed
append: this will open the --output-file file in append mode and add the content to it
example:
Not using the new option:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml cli/cmdlineparser.cpp
$ ls -la output_files/
total 12
drwxrwxr-x 2 user user 4096 Jul 22 14:47 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 1283 Jul 22 14:47 cppcheck.xml
Using the option with value "uniq" for one file:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=uniq cli/cmdlineparser.cpp
$ ls -la output_files/
total 12
drwxrwxr-x 2 user user 4096 Jul 22 14:48 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 1283 Jul 22 14:48 cppcheck_cmdlineparser_cpp.xml
Using the option with value "uniq" for one file without extension:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck --output-file-type=uniq cli/cmdlineparser.cpp
$ ls -la output_files/
total 12
drwxrwxr-x 2 user user 4096 Jul 22 14:48 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 1283 Jul 22 14:48 cppcheck_cmdlineparser_cpp
Using the option with value "uniq" for two files:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=uniq cli/cmdlineparser.cpp cli/cppcheckexecutor.cpp
$ ls -la output_files/
total 16
drwxrwxr-x 2 user user 4096 Jul 22 14:49 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 4308 Jul 22 14:49 cppcheck_cmdlineparser_cpp_cppcheckexecutor_cpp.xml
Using the option with value "append" for one file on a empty/non-existing file:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp
$ ls -la output_files/
total 12
drwxrwxr-x 2 user user 4096 Jul 22 14:51 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 1283 Jul 22 14:51 cppcheck.xml
Using the option with value "append" for two files on a empty/non-existing file:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp cli/cppcheckexecutor.cpp
$ ls -la output_files/
total 16
drwxrwxr-x 2 user user 4096 Jul 22 14:53 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 4308 Jul 22 14:53 cppcheck.xml
Using the option with value twise "append" for one file on a empty/non-existing file:
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp
$ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cppcheckexecutor.cpp
$ ls -la output_files/
total 16
drwxrwxr-x 2 user user 4096 Jul 22 14:54 .
drwxrwxr-x 26 user user 4096 Jul 22 14:36 ..
-rw-rw-r-- 1 user user 5613 Jul 22 14:55 cppcheck.xml
/!\ the file is a pure concatenation of the files created without the "append" value which means that it's no more a valid XML file as it will have twice the "<?xml version="1.0" encoding="UTF-8"?>" entry
$ cat output_files/cppcheck.xml
<?xml version="1.0" encoding="UTF-8"?>
<results version="2">
[...]
</results>
<?xml version="1.0" encoding="UTF-8"?>
<results version="2">
[...]
</results>
Signed-off-by: Robert Wakim <robert.wakim@arm.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters