diff options
| author | Meco Man <[email protected]> | 2024-05-11 04:06:23 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-05-11 16:06:23 +0800 |
| commit | 634f50572e19bd8a0195f9c2a5444c49bae65ec5 (patch) | |
| tree | b579a66edd2eb201f0ec9de1d379240e4f2cbc54 /tools/utils.py | |
| parent | 151a96cb88328c46133971cc9deef24f6ddfeede (diff) | |
[tools] fix env toolchain path parse issue (#8936)
Diffstat (limited to 'tools/utils.py')
| -rw-r--r-- | tools/utils.py | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/tools/utils.py b/tools/utils.py index 761aa07b0c..758e561940 100644 --- a/tools/utils.py +++ b/tools/utils.py @@ -311,21 +311,18 @@ def VerTuple(version_str): return ver def CmdExists(cmd): - import platform - - cmd_list = cmd.split(' ') - cmd = cmd_list[0] + # Check if the path directly points to an existing file. if os.path.isfile(cmd): return True else: - # check cmd(.exe|.bat|.ps1) under Windows - if platform.system() == 'Windows': - if cmd.find('exe') != -1 or cmd.find('bat') != -1 or cmd.find('ps1') != -1: - return False - - # add .exe then check whether the cmd exists - cmd = cmd + '.exe' - if os.path.isfile(cmd): - return True + # On Windows systems, check for common script file extensions + # if the file does not exist as specified. + if sys.platform.startswith('win'): + # Loop through possible extensions to cover cases where the extension is omitted in the input. + for ext in ['.exe', '.bat', '.ps1']: + # Append the extension to the command path and check if this file exists. + if os.path.isfile(cmd + ext): + return True - return False + # If none of the checks confirm the file exists, return False. + return False |
