Skip to content

cppcheck options: add --output-file-type option #3350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from

Conversation

RobertWak
Copy link

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


[...]



[...]

    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>
@RobertWak RobertWak closed this Jul 29, 2021
@RobertWak
Copy link
Author

superseeded by #3365

the 3365 git history is much cleaner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant