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

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions analyzer/codechecker_analyzer/analyzers/clangtidy/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import ast
import json
import os
from pathlib import Path
vodorok marked this conversation as resolved.
Show resolved Hide resolved
import re
import shlex
import shutil
import subprocess
from typing import Iterable, List, Set, Tuple

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

path_env = os.environ.get('PATH', '').split(os.pathsep)
clang_path = Path(clang_bin)

if clang_path.resolve().name == 'ccache':
vodorok marked this conversation as resolved.
Show resolved Hide resolved
for i, path in enumerate(path_env):
if Path(path) == clang_path.parent:
pos = i
break

clang_bin = shutil.which(
clang_path.name,
path=os.pathsep.join(path_env[pos + 1:]))

if not clang_bin:
return None

# Resolve symlink.
clang_bin = os.path.realpath(clang_bin)
clang_bin = Path(clang_bin).resolve()

# Find diagtool next to the clang binary.
diagtool_bin = os.path.join(os.path.dirname(clang_bin), 'diagtool')
if os.path.exists(diagtool_bin):
diagtool_bin = clang_bin.parent / 'diagtool'
if diagtool_bin.exists():
return diagtool_bin

LOG.warning(
Expand Down