From b12284e6dcb012cad2ac0cb01555806ae848b19e Mon Sep 17 00:00:00 2001 From: bernard Date: Wed, 28 Aug 2024 22:43:46 +0800 Subject: [PATCH 1/2] [tools] fix the SDK path issue in env script. --- tools/env_utility.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tools/env_utility.py b/tools/env_utility.py index dc6425464ac..608ef4fa156 100644 --- a/tools/env_utility.py +++ b/tools/env_utility.py @@ -41,13 +41,22 @@ def GetPkgPath(): else: return None - -def GetSDKPath(name): +def GetSDKPackagePath(): env = GetEnvPath() if env: - # read packages.json under env/tools/packages - with open(os.path.join(env, 'tools', 'packages', 'pkgs.json'), 'r', encoding='utf-8') as f: + return os.path.join(env, "tools", "scripts", "packages") + + return None + +# get SDK path based on name +# for example, GetSDKPath('arm-none-eabi') = '.env/tools/scripts/packages/arm-none-eabi-gcc-v10.3' +def GetSDKPath(name): + sdk_pkgs = GetSDKPackagePath() + + if sdk_pkgs: + # read packages.json under env/tools/scripts/packages + with open(os.path.join(sdk_pkgs, 'pkgs.json'), 'r', encoding='utf-8') as f: # packages_json = f.read() packages = json.load(f) @@ -59,12 +68,11 @@ def GetSDKPath(name): package = json.load(f) if package['name'] == name: - return os.path.join(env, 'tools', 'packages', package['name'] + '-' + item['ver']) + return os.path.join(sdk_pkgs, package['name'] + '-' + item['ver']) # not found named package return None - def help_info(): print( "**********************************************************************************\n" From 395b16c8614fdb86d392cfb35d7951df1c25d5ac Mon Sep 17 00:00:00 2001 From: bernard Date: Thu, 9 Jan 2025 11:22:51 +0800 Subject: [PATCH 2/2] [tools] Add sdk_cfg.json setting for CC detection. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 让工具链检测支持到env/tools/scripts/sdk_cfg.json配置文件。 --- tools/building.py | 19 ++++++++++--------- tools/env_utility.py | 12 +++++++++++- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/tools/building.py b/tools/building.py index 5c8e3941984..c64c393ba00 100644 --- a/tools/building.py +++ b/tools/building.py @@ -210,15 +210,16 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ envm = utils.ImportModule('env_utility') # from env import GetSDKPath exec_path = envm.GetSDKPath(rtconfig.CC) - if 'gcc' in rtconfig.CC: - exec_path = os.path.join(exec_path, 'bin') - - if os.path.exists(exec_path): - Env['log'].debug('set CC to ' + exec_path) - rtconfig.EXEC_PATH = exec_path - os.environ['RTT_EXEC_PATH'] = exec_path - else: - Env['log'].debug('No Toolchain found in path(%s).' % exec_path) + if exec_path != None: + if 'gcc' in rtconfig.CC: + exec_path = os.path.join(exec_path, 'bin') + + if os.path.exists(exec_path): + Env['log'].debug('set CC to ' + exec_path) + rtconfig.EXEC_PATH = exec_path + os.environ['RTT_EXEC_PATH'] = exec_path + else: + Env['log'].debug('No Toolchain found in path(%s).' % exec_path) except Exception as e: # detect failed, ignore Env['log'].debug(e) diff --git a/tools/env_utility.py b/tools/env_utility.py index 608ef4fa156..d950d077334 100644 --- a/tools/env_utility.py +++ b/tools/env_utility.py @@ -55,6 +55,15 @@ def GetSDKPath(name): sdk_pkgs = GetSDKPackagePath() if sdk_pkgs: + # read env/tools/scripts/sdk_cfg.json for curstomized SDK path + if os.path.exists(os.path.join(sdk_pkgs, '..', 'sdk_cfg.json')): + with open(os.path.join(sdk_pkgs, '..', 'sdk_cfg.json'), 'r', encoding='utf-8') as f: + sdk_cfg = json.load(f) + for item in sdk_cfg: + if item['name'] == name: + sdk = os.path.join(sdk_pkgs, item['path']) + return sdk + # read packages.json under env/tools/scripts/packages with open(os.path.join(sdk_pkgs, 'pkgs.json'), 'r', encoding='utf-8') as f: # packages_json = f.read() @@ -68,7 +77,8 @@ def GetSDKPath(name): package = json.load(f) if package['name'] == name: - return os.path.join(sdk_pkgs, package['name'] + '-' + item['ver']) + sdk = os.path.join(sdk_pkgs, package['name'] + '-' + item['ver']) + return sdk # not found named package return None