diff --git a/builder/frameworks/espidf.py b/builder/frameworks/espidf.py index 8753bbc49..adbb9e720 100644 --- a/builder/frameworks/espidf.py +++ b/builder/frameworks/espidf.py @@ -2587,17 +2587,17 @@ 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: + shutil.copy2(src, dst) + 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 - try: - os.replace(src, dst) - except OSError: - shutil.move(src, dst) + 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)) @@ -2616,15 +2616,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"))):