[tools] fix env toolchain path parse issue (#8936)

This commit is contained in:
Meco Man 2024-05-11 04:06:23 -04:00 committed by GitHub
parent 151a96cb88
commit 634f50572e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 14 deletions

View File

@ -311,21 +311,18 @@ def VerTuple(version_str):
return ver return ver
def CmdExists(cmd): def CmdExists(cmd):
import platform # Check if the path directly points to an existing file.
cmd_list = cmd.split(' ')
cmd = cmd_list[0]
if os.path.isfile(cmd): if os.path.isfile(cmd):
return True return True
else: else:
# check cmd(.exe|.bat|.ps1) under Windows # On Windows systems, check for common script file extensions
if platform.system() == 'Windows': # if the file does not exist as specified.
if cmd.find('exe') != -1 or cmd.find('bat') != -1 or cmd.find('ps1') != -1: if sys.platform.startswith('win'):
return False # Loop through possible extensions to cover cases where the extension is omitted in the input.
for ext in ['.exe', '.bat', '.ps1']:
# add .exe then check whether the cmd exists # Append the extension to the command path and check if this file exists.
cmd = cmd + '.exe' if os.path.isfile(cmd + ext):
if os.path.isfile(cmd):
return True return True
# If none of the checks confirm the file exists, return False.
return False return False