From 7e129810f6fcaeaccf30a3ca6cea19df266bdae7 Mon Sep 17 00:00:00 2001 From: bernard Date: Wed, 8 May 2024 09:18:45 +0800 Subject: [PATCH] [tools] fix the issue of cc detection failure in Windows --- tools/building.py | 2 +- tools/utils.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tools/building.py b/tools/building.py index 6e9a81cf1f7..b7d36c0b015 100644 --- a/tools/building.py +++ b/tools/building.py @@ -195,7 +195,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ os.environ['RTT_CC_PREFIX'] = exec_prefix # auto change the 'RTT_EXEC_PATH' when 'rtconfig.EXEC_PATH' get failed - if not os.path.exists(os.path.join(rtconfig.EXEC_PATH, rtconfig.CC)): + if not utils.CmdExists(os.path.join(rtconfig.EXEC_PATH, rtconfig.CC)): if 'RTT_EXEC_PATH' in os.environ: # del the 'RTT_EXEC_PATH' and using the 'EXEC_PATH' setting on rtconfig.py del os.environ['RTT_EXEC_PATH'] diff --git a/tools/utils.py b/tools/utils.py index d76720a850e..761aa07b0cd 100644 --- a/tools/utils.py +++ b/tools/utils.py @@ -309,3 +309,23 @@ def VerTuple(version_str): ver = tuple(int(part) for part in ver_parts) return ver + +def CmdExists(cmd): + import platform + + cmd_list = cmd.split(' ') + cmd = cmd_list[0] + 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 + + return False