From ad6bacff5557b5aa88853c33050ee8a2e5a9d0e0 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Fri, 21 Nov 2025 13:27:37 +0100 Subject: [PATCH 1/4] HybridCompile: replace move operations with copy Dont delete exiting *.a libs to avoid linker errors with unused libs --- builder/frameworks/espidf.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/builder/frameworks/espidf.py b/builder/frameworks/espidf.py index 8753bbc49..39b3a58a0 100644 --- a/builder/frameworks/espidf.py +++ b/builder/frameworks/espidf.py @@ -2587,17 +2587,13 @@ def _skip_prj_source_files(node): if ("arduino" in env.subst("$PIOFRAMEWORK")) and ("espidf" not in env.subst("$PIOFRAMEWORK")): def idf_lib_copy(source, target, env): - def _replace_move(src, dst): + def _replace_copy(src, dst): dst_p = Path(dst) dst_p.parent.mkdir(parents=True, exist_ok=True) - try: - os.remove(dst) - except FileNotFoundError: - pass try: os.replace(src, dst) - except OSError: - shutil.move(src, dst) + except: + pass env_build = str(Path(env["PROJECT_BUILD_DIR"]) / env["PIOENV"]) sdkconfig_h_path = str(Path(env_build) / "config" / "sdkconfig.h") arduino_libs = str(Path(ARDUINO_FRMWRK_LIB_DIR)) @@ -2616,15 +2612,15 @@ def _replace_move(src, dst): if file.strip().endswith(".a"): shutil.copyfile(file, str(Path(lib_dst) / file.split(os.path.sep)[-1])) - _replace_move(str(Path(lib_dst) / "libspi_flash.a"), str(Path(mem_var) / "libspi_flash.a")) - _replace_move(str(Path(env_build) / "memory.ld"), str(Path(ld_dst) / "memory.ld")) + _replace_copy(str(Path(lib_dst) / "libspi_flash.a"), str(Path(mem_var) / "libspi_flash.a")) + _replace_copy(str(Path(env_build) / "memory.ld"), str(Path(ld_dst) / "memory.ld")) if mcu == "esp32s3": - _replace_move(str(Path(lib_dst) / "libesp_psram.a"), str(Path(mem_var) / "libesp_psram.a")) - _replace_move(str(Path(lib_dst) / "libesp_system.a"), str(Path(mem_var) / "libesp_system.a")) - _replace_move(str(Path(lib_dst) / "libfreertos.a"), str(Path(mem_var) / "libfreertos.a")) - _replace_move(str(Path(lib_dst) / "libbootloader_support.a"), str(Path(mem_var) / "libbootloader_support.a")) - _replace_move(str(Path(lib_dst) / "libesp_hw_support.a"), str(Path(mem_var) / "libesp_hw_support.a")) - _replace_move(str(Path(lib_dst) / "libesp_lcd.a"), str(Path(mem_var) / "libesp_lcd.a")) + _replace_copy(str(Path(lib_dst) / "libesp_psram.a"), str(Path(mem_var) / "libesp_psram.a")) + _replace_copy(str(Path(lib_dst) / "libesp_system.a"), str(Path(mem_var) / "libesp_system.a")) + _replace_copy(str(Path(lib_dst) / "libfreertos.a"), str(Path(mem_var) / "libfreertos.a")) + _replace_copy(str(Path(lib_dst) / "libbootloader_support.a"), str(Path(mem_var) / "libbootloader_support.a")) + _replace_copy(str(Path(lib_dst) / "libesp_hw_support.a"), str(Path(mem_var) / "libesp_hw_support.a")) + _replace_copy(str(Path(lib_dst) / "libesp_lcd.a"), str(Path(mem_var) / "libesp_lcd.a")) shutil.copyfile(sdkconfig_h_path, str(Path(mem_var) / "include" / "sdkconfig.h")) if not bool(os.path.isfile(str(Path(arduino_libs) / chip_variant / "sdkconfig.orig"))): From 32d3aff10a2f7ed2a849a3a2be40d851414fcfcb Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Fri, 21 Nov 2025 13:53:14 +0100 Subject: [PATCH 2/4] Enhance file copy error handling in espidf.py Improve error handling for file copy operations. --- builder/frameworks/espidf.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/builder/frameworks/espidf.py b/builder/frameworks/espidf.py index 39b3a58a0..17e80e939 100644 --- a/builder/frameworks/espidf.py +++ b/builder/frameworks/espidf.py @@ -2591,9 +2591,13 @@ def _replace_copy(src, dst): dst_p = Path(dst) dst_p.parent.mkdir(parents=True, exist_ok=True) try: - os.replace(src, dst) - except: + shutil.copy2(src, dst) + except (OSError, IOError) as e: + # Gracefully handle missing source files (e.g., PSRAM libs in non-PSRAM builds) + # This is expected when copying variant-specific libraries pass + except Exception as e: + print(f"Warning: Failed to copy {src} to {dst}: {e}") env_build = str(Path(env["PROJECT_BUILD_DIR"]) / env["PIOENV"]) sdkconfig_h_path = str(Path(env_build) / "config" / "sdkconfig.h") arduino_libs = str(Path(ARDUINO_FRMWRK_LIB_DIR)) From 103b99e24f39063537938053fdfb8c8a68ee4b36 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Fri, 21 Nov 2025 14:07:37 +0100 Subject: [PATCH 3/4] Simplify exception handling in espidf.py Removed exception variable usage in error handling. --- builder/frameworks/espidf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builder/frameworks/espidf.py b/builder/frameworks/espidf.py index 17e80e939..570f37fa2 100644 --- a/builder/frameworks/espidf.py +++ b/builder/frameworks/espidf.py @@ -2592,11 +2592,11 @@ def _replace_copy(src, dst): dst_p.parent.mkdir(parents=True, exist_ok=True) try: shutil.copy2(src, dst) - except (OSError, IOError) as e: + except (OSError, IOError): # Gracefully handle missing source files (e.g., PSRAM libs in non-PSRAM builds) # This is expected when copying variant-specific libraries pass - except Exception as e: + except Exception: print(f"Warning: Failed to copy {src} to {dst}: {e}") env_build = str(Path(env["PROJECT_BUILD_DIR"]) / env["PIOENV"]) sdkconfig_h_path = str(Path(env_build) / "config" / "sdkconfig.h") From 095e392cf30adfd379f5aca74820251c7f0ea31e Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Fri, 21 Nov 2025 14:09:04 +0100 Subject: [PATCH 4/4] Improve exception handling in espidf.py --- builder/frameworks/espidf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/frameworks/espidf.py b/builder/frameworks/espidf.py index 570f37fa2..adbb9e720 100644 --- a/builder/frameworks/espidf.py +++ b/builder/frameworks/espidf.py @@ -2596,7 +2596,7 @@ def _replace_copy(src, dst): # Gracefully handle missing source files (e.g., PSRAM libs in non-PSRAM builds) # This is expected when copying variant-specific libraries pass - except Exception: + except Exception as e: print(f"Warning: Failed to copy {src} to {dst}: {e}") env_build = str(Path(env["PROJECT_BUILD_DIR"]) / env["PIOENV"]) sdkconfig_h_path = str(Path(env_build) / "config" / "sdkconfig.h")