Skip to content

Commit 634f505

Browse files
authored
[tools] fix env toolchain path parse issue (#8936)
1 parent 151a96c commit 634f505

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

tools/utils.py

+12-15
Original file line numberDiff line numberDiff line change
@@ -311,21 +311,18 @@ def VerTuple(version_str):
311311
return ver
312312

313313
def CmdExists(cmd):
314-
import platform
315-
316-
cmd_list = cmd.split(' ')
317-
cmd = cmd_list[0]
314+
# Check if the path directly points to an existing file.
318315
if os.path.isfile(cmd):
319316
return True
320317
else:
321-
# check cmd(.exe|.bat|.ps1) under Windows
322-
if platform.system() == 'Windows':
323-
if cmd.find('exe') != -1 or cmd.find('bat') != -1 or cmd.find('ps1') != -1:
324-
return False
325-
326-
# add .exe then check whether the cmd exists
327-
cmd = cmd + '.exe'
328-
if os.path.isfile(cmd):
329-
return True
330-
331-
return False
318+
# On Windows systems, check for common script file extensions
319+
# if the file does not exist as specified.
320+
if sys.platform.startswith('win'):
321+
# Loop through possible extensions to cover cases where the extension is omitted in the input.
322+
for ext in ['.exe', '.bat', '.ps1']:
323+
# Append the extension to the command path and check if this file exists.
324+
if os.path.isfile(cmd + ext):
325+
return True
326+
327+
# If none of the checks confirm the file exists, return False.
328+
return False

0 commit comments

Comments
 (0)