use shutil.which in check_compiler_ok_for_platform (#129069)

the same as https://github.com/pytorch/pytorch/pull/126060
Pull Request resolved: https://github.com/pytorch/pytorch/pull/129069
Approved by: https://github.com/ezyang
This commit is contained in:
谭九鼎
2024-06-29 11:38:51 +00:00
committed by PyTorch MergeBot
parent 56935684c3
commit b0e5c9514d

View File

@ -308,9 +308,11 @@ def check_compiler_ok_for_platform(compiler: str) -> bool:
"""
if IS_WINDOWS:
return True
which = subprocess.check_output(['which', compiler], stderr=subprocess.STDOUT)
compiler_path = shutil.which(compiler)
if compiler_path is None:
return False
# Use os.path.realpath to resolve any symlinks, in particular from 'c++' to e.g. 'g++'.
compiler_path = os.path.realpath(which.decode(*SUBPROCESS_DECODE_ARGS).strip())
compiler_path = os.path.realpath(compiler_path)
# Check the compiler name
if any(name in compiler_path for name in _accepted_compilers_for_platform()):
return True