-
Notifications
You must be signed in to change notification settings - Fork 385
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -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': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the problem only defined to ccache? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say that checking if clang_bin a symlink at all, would be a too sensitive check. In most cases clang is a symlink to a specific clang version, for example to clang-10. |
||
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( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kudos for using pathlib