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
Open
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
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

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['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?

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?

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
Loading