Skip to content
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

[fix] Don't crash when diagtool is missing #4399

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bruntib
Copy link
Contributor

@bruntib bruntib commented Dec 9, 2024

For clang-tidy the set of warnings can be queried by a tool named diagtool. In some environments clang is a symlink to ccache. Since CodeChecker tries to find diagtool right next to clang, this logic doesn't work, since diagtool is usually not next to ccache.

In this patch CodeChecker searches diagtool in the next element of PATH environment variable in case clang is a symlink to ccache, since ccache would do the same, too.

Fixes #4371

For clang-tidy the set of warnings can be queried by a tool named
`diagtool`. In some environments `clang` is a symlink to `ccache`.
Since CodeChecker tries to find `diagtool` right next to clang, this
logic doesn't work, since `diagtool` is usually not next to `ccache`.

In this patch CodeChecker searches `diagtool` in the next element of
`PATH` environment variable in case `clang` is a symlink to `ccache`,
since `ccache` would do the same, too.

Fixes Ericsson#4371
@bruntib bruntib added CLI 💻 Related to the command-line interface, such as the cmd, store, etc. commands bugfix 🔨 labels Dec 9, 2024
@bruntib bruntib added this to the release 6.25.0 milestone Dec 9, 2024
@bruntib bruntib requested review from dkrupp and cservakt December 9, 2024 12:02
@bruntib bruntib requested a review from vodorok as a code owner December 9, 2024 12:02
@dkrupp
Copy link
Member

dkrupp commented Dec 10, 2024

I am getting a similar error:

CodeChecker analyze ./compile_commands.json -o reports
[WARNING 2024-12-10 14:13] - 'diagtool' can not be found next to the clang binary (/usr/bin/ccache)!
Traceback (most recent call last):
File "/workspace/codechecker/build/CodeChecker/lib/python3/codechecker_common/cli.py", line 208, in main
sys.exit(args.func(args))
File "/workspace/codechecker/build/CodeChecker/lib/python3/codechecker_analyzer/cmd/analyze.py", line 1286, in main
analyzer.perform_analysis(args, skip_handlers, filter_handlers,
File "/workspace/codechecker/build/CodeChecker/lib/python3/codechecker_analyzer/analyzer.py", line 167, in perform_analysis
config_map = analyzer_types.build_config_handlers(args, analyzers)
File "/workspace/codechecker/build/CodeChecker/lib/python3/codechecker_analyzer/analyzers/analyzer_types.py", line 258, in build_config_handlers
config_handler = supported_analyzers[ea].construct_config_handler(args)
File "/workspace/codechecker/build/CodeChecker/lib/python3/codechecker_analyzer/analyzers/clangtidy/analyzer.py", line 709, in construct_config_handler
checkers = ClangTidy.get_analyzer_checkers()
File "/workspace/codechecker/build/CodeChecker/lib/python3/codechecker_analyzer/analyzers/clangtidy/analyzer.py", line 307, in get_analyzer_checkers
for warning in get_warnings())
File "/workspace/codechecker/build/CodeChecker/lib/python3/codechecker_analyzer/analyzers/clangtidy/analyzer.py", line 169, in get_warnings
environment = analyzer_context.get_context().get_env_for_bin(diagtool_bin)
File "/workspace/codechecker/build/CodeChecker/lib/python3/codechecker_analyzer/analyzer_context.py", line 207, in get_env_for_bin
bin_path = Path(binary).resolve()
File "/usr/lib/python3.8/pathlib.py", line 1042, in new
self = cls._from_parts(args, init=False)
File "/usr/lib/python3.8/pathlib.py", line 683, in _from_parts
drv, root, parts = self._parse_args(args)
File "/usr/lib/python3.8/pathlib.py", line 667, in _parse_args
a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType
(CodeChecker venv-dev) [14:13][workspace/test-projects/tmux]$ which clang
/usr/lib/ccache/clang
(CodeChecker venv-dev) [14:14][workspace/test-projects/tmux]$ which diagtool
(CodeChecker venv-dev) [14:14][workspace/test-projects/tmux]$ diagtool-10
Display all 351 possibilities? (y or n)
(CodeChecker venv-dev) [14:14][workspace/test-projects/tmux]$ which diagtool-10
/bin/diagtool-10

Copy link
Contributor

@vodorok vodorok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some discussion starter comments

@@ -13,8 +13,10 @@
import ast
import json
import os
from pathlib import Path
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kudos for using pathlib

@@ -128,12 +130,28 @@ def get_diagtool_bin():
if not clang_bin:
return None

path_env = os.environ['PATH'].split(os.pathsep)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So then we are always expecting PATH to be present?

path_env = os.environ['PATH'].split(os.pathsep)
clang_path = Path(clang_bin)

if clang_path.resolve().name == 'ccache':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the problem only defined to ccache?
Shouldnt you check if clang_bin is a symlink?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix 🔨 CLI 💻 Related to the command-line interface, such as the cmd, store, etc. commands
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CodeChecker crahes while searching for the diag-tool
3 participants