Skip to content

Commit

Permalink
Merge pull request #4399 from bruntib/diagtool_not_found
Browse files Browse the repository at this point in the history
[fix] Don't crash when diagtool is missing
  • Loading branch information
bruntib authored Jan 23, 2025
2 parents 3386978 + 8717583 commit eb42b5d
Showing 1 changed file with 21 additions and 3 deletions.
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
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':
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

0 comments on commit eb42b5d

Please sign in to comment.