2021年2月25日木曜日

cppcheck html report

 久しぶりに cppcheck を使ってみたら HTML レポートができるようになっていたのでメモ。

環境セットアップ

HTML レポートを作成するには python 環境が必要です。
https://github.com/danmar/cppcheck/tree/main/htmlreport
バージョンは 2.7 以上であれば大丈夫なようです。
また pygments に依存してるので pip install pygments もしておきましょう。

Cppcheck を実行

HTML レポートは cppcheck の結果 xml から作成するので、まずは cppcheck をかけて xml を出力します。

e.g.
cppcheck --enable=all --xml myproject 2> result.xml

Cppcheck 自体の使い方は(かなり昔に書いた記事ですが)こちら「ブログズミ: Cppcheck を使ってみた」、もしくは公式ドキュメントを参照してください。

HTML レポート

xml ができたらいよいよ html にします。

cppcheck-htmlreport --file=result.xml --title=iutest --report-dir=./html

--file で cppcheck で出力した xml を指定します。(複数指定可能)
その他のオプションは下記のヘルプを参考にしてください。

Usage: cppcheck-htmlreport [options]

Options:
  -h, --help            show this help message and exit
  --title=TITLE         The title of the project.
  --file=FILE           The cppcheck xml output file to read defects from. You
                        can combine results from several xml reports i.e. "--
                        file file1.xml --file file2.xml ..". Default is
                        reading from stdin.
  --report-dir=REPORT_DIR
                        The directory where the HTML report content is
                        written.
  --source-dir=SOURCE_DIR
                        Base directory where source code files can be found.
  --source-encoding=SOURCE_ENCODING
                        Encoding of source code.

結果

iutest の結果を gh-pages に入れておいたのでそちらを参考にしてみてください。
https://srz-zumix.github.io/iutest/test/cppcheck/



ソースコードも HTML ページ上で確認できます。

今回はこれで以上です。



0 件のコメント:

コメントを投稿