codechecker icon indicating copy to clipboard operation
codechecker copied to clipboard

CodeChecker and ninja compatibility

Open ChGen opened this issue 1 year ago • 0 comments

Describe the bug There's a compatibility bug between ninja builder output and CodeCheckers, which leads to CodeCheckers crash.

CodeChecker version

[INFO 2024-08-22 13:05] - CodeChecker analyzer version:
---------------------------------------------------------------
Kind                 | Version
---------------------------------------------------------------
Base package version | 6.23.1
Package build date   | 2023-12-14T14:38
Git commit ID (hash) | 2a8fa6e711a4ff591280a79fe8798dee2507d984
Git tag information  | 6.23.1
---------------------------------------------------------------

[INFO 2024-08-22 13:05] - CodeChecker web version:
------------------------------------------------------------------------------
Kind                                | Version
------------------------------------------------------------------------------
Base package version                | 6.23.1
Package build date                  | 2023-12-14T14:38
Git commit ID (hash)                | 2a8fa6e711a4ff591280a79fe8798dee2507d984
Git tag information                 | 6.23.1
Server supported Thrift API version | 6.54
Client Thrift API version           | 6.54
------------------------------------------------------------------------------

To Reproduce Steps to reproduce the behaviour:

  1. Unpack source code. Reproduced with https://github.com/mysql/mysql-server/archive/refs/tags/mysql-cluster-8.0.39.tar.gz -o mysql.tgz
  2. Run command 'cmake -GNinja path/to/cmake/file' to generate ninja build file.
  3. Run ninja to generate compilation database. ninja -t compdb > ./compile_commands.json
  4. Run CodeChecker analyze ./compile_commands.json -o ./result_tidy .... See the error. Interestingly, generating via cmake for this project works correctly.
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/codechecker_common/cli.py", line 209, in main
    sys.exit(args.func(args))
  File "/usr/local/lib/python3.10/dist-packages/codechecker_analyzer/cmd/analyze.py", line 1056, in main
    actions, skipped_cmp_cmd_count = log_parser.parse_unique_log(
  File "/usr/local/lib/python3.10/dist-packages/codechecker_analyzer/buildlog/log_parser.py", line 1299, in parse_unique_log
    action = parse_options(entry,
  File "/usr/local/lib/python3.10/dist-packages/codechecker_analyzer/buildlog/log_parser.py", line 970, in parse_options
    determine_compiler(gcc_command,
  File "/usr/local/lib/python3.10/dist-packages/codechecker_analyzer/buildlog/log_parser.py", line 662, in determine_compiler
    if gcc_command[0].endswith('ccache'):
IndexError: list index out of range

problematic json example:

{'analyzer_options': [], 'compiler_includes': [], 'compiler_standard': '', 'compilation_target': '', 'analyzer_type': -1, 'original_command': '', 'directory': '/root/mysql-server-mysql-cluster-8.0.39/bld', 'output': '', 'lang': None, 'arch': '', 'target': '', 'source': '', 'action_type': None} ; {'directory': '/root/mysql-server-mysql-cluster-8.0.39/bld', 'command': '', 'file': '/root/mysql-server-mysql-cluster-8.0.39/bld/CMakeFiles/show_boost_patches', 'output': 'show_boost_patches'}

As I understand, log_parser.py doesn't handle correctly the case when command item exist in json, but contains empty string, which leads to empty gcc_command and IndexError in the log_parser.py:662.

Expected behaviour CodeChecker proceeds without crash.

Desktop (please complete the following information)

  • OS: Ubuntu 22.04
  • Python 3.10.12
  • ninja 1.10.1
  • CodeChecker 6.23.1
pip install -U pip setuptools
pip install codechecker 
...
cmake .. -GNinja
ninja -t compdb > ./compile_commands.json
CodeChecker analyze ./compile_commands.json -o ./result_tidy

ChGen avatar Aug 22 '24 13:08 ChGen