diff --git a/crates/fbuild-build-esp/src/esp32/esp32_linker.rs b/crates/fbuild-build-esp/src/esp32/esp32_linker.rs index b685d6b6..23e76a1d 100644 --- a/crates/fbuild-build-esp/src/esp32/esp32_linker.rs +++ b/crates/fbuild-build-esp/src/esp32/esp32_linker.rs @@ -10,6 +10,7 @@ use std::path::{Path, PathBuf}; +use fbuild_core::path::NormalizedPath; use fbuild_core::subprocess::run_command; use fbuild_core::{BuildProfile, Result, SizeInfo}; @@ -146,11 +147,11 @@ pub(crate) fn esptool_spawn_failure_message(esptool_bin: Option<&Path>, error: & /// ESP32-specific linker using RISC-V or Xtensa GCC as the link driver. pub struct Esp32Linker { - gcc_path: PathBuf, - ar_path: PathBuf, + gcc_path: NormalizedPath, + ar_path: NormalizedPath, #[allow(dead_code)] // Used later for esptool elf2image - objcopy_path: PathBuf, - size_path: PathBuf, + objcopy_path: NormalizedPath, + size_path: NormalizedPath, /// MCU config (used for profile-specific flags as fallback). mcu_config: Esp32McuConfig, /// SDK linker flags from `flags/ld_flags` (undefined symbols, wrap directives, etc.). @@ -169,7 +170,7 @@ pub struct Esp32Linker { max_ram: Option, /// Path to the provisioned standalone esptool binary, if available. `None` /// falls back to an `esptool` on PATH. See FastLED/fbuild#954. - esptool_bin: Option, + esptool_bin: Option, verbose: bool, /// The CLI caller's PATH, so the bare-`esptool` fallback resolves /// against the caller's environment instead of the daemon's @@ -183,10 +184,10 @@ pub struct Esp32Linker { impl Esp32Linker { #[allow(clippy::too_many_arguments)] pub fn new( - gcc_path: PathBuf, - ar_path: PathBuf, - objcopy_path: PathBuf, - size_path: PathBuf, + gcc_path: NormalizedPath, + ar_path: NormalizedPath, + objcopy_path: NormalizedPath, + size_path: NormalizedPath, mcu_config: Esp32McuConfig, sdk_ld_flags: Vec, sdk_lib_flags: Vec, @@ -196,7 +197,7 @@ impl Esp32Linker { flash_freq: &str, max_flash: Option, max_ram: Option, - esptool_bin: Option, + esptool_bin: Option, verbose: bool, ) -> Self { let flash_mode = flash_mode.unwrap_or_else(|| mcu_config.default_flash_mode().to_string()); @@ -574,19 +575,19 @@ impl Linker for Esp32Linker { } fn size_tool_path(&self) -> &Path { - &self.size_path + self.size_path.as_path() } fn ar_tool_path(&self) -> Option<&Path> { - Some(&self.ar_path) + Some(self.ar_path.as_path()) } fn objcopy_tool_path(&self) -> Option<&Path> { - Some(&self.objcopy_path) + Some(self.objcopy_path.as_path()) } fn link_driver_path(&self) -> Option<&Path> { - Some(&self.gcc_path) + Some(self.gcc_path.as_path()) } async fn report_size(&self, elf_path: &Path) -> Result { diff --git a/crates/fbuild-build-esp/src/esp32/esp32_linker_tests.rs b/crates/fbuild-build-esp/src/esp32/esp32_linker_tests.rs index 9cf29594..4dcce24a 100644 --- a/crates/fbuild-build-esp/src/esp32/esp32_linker_tests.rs +++ b/crates/fbuild-build-esp/src/esp32/esp32_linker_tests.rs @@ -5,10 +5,10 @@ fn test_linker(mcu: &str) -> Esp32Linker { let config = get_mcu_config(mcu).unwrap(); let prefix = config.toolchain_prefix(); Esp32Linker::new( - PathBuf::from(format!("/usr/bin/{}gcc", prefix)), - PathBuf::from(format!("/usr/bin/{}ar", prefix)), - PathBuf::from(format!("/usr/bin/{}objcopy", prefix)), - PathBuf::from(format!("/usr/bin/{}size", prefix)), + NormalizedPath::new(format!("/usr/bin/{}gcc", prefix)), + NormalizedPath::new(format!("/usr/bin/{}ar", prefix)), + NormalizedPath::new(format!("/usr/bin/{}objcopy", prefix)), + NormalizedPath::new(format!("/usr/bin/{}size", prefix)), config, vec![ "-nostartfiles".to_string(), @@ -70,7 +70,10 @@ fn pinned_esptool_v4_uses_underscore_elf2image_options() { assert!(v5.iter().any(|arg| arg == "--flash-mode")); } -fn test_linker_with(esptool_bin: Option, caller_path: Option) -> Esp32Linker { +fn test_linker_with( + esptool_bin: Option, + caller_path: Option, +) -> Esp32Linker { let mut linker = test_linker("esp32c6"); linker.esptool_bin = esptool_bin; linker.caller_path = caller_path; @@ -121,7 +124,7 @@ fn absolute_esptool_bin_reuse_ignores_caller_path() { let elf = tmp.path().join("firmware.elf"); std::fs::write(&elf, b"elf").unwrap(); - let esptool = PathBuf::from("C:\\tools\\esptool.exe"); + let esptool = NormalizedPath::new("C:\\tools\\esptool.exe"); let linker_a = test_linker_with(Some(esptool.clone()), Some("C:\\venv-a".to_string())); let flash_size = linker_a.flash_size(); @@ -145,10 +148,10 @@ fn test_flash_size_uses_board_max_flash_for_elf2image_and_cache() { let config = get_mcu_config("esp32c6").unwrap(); let prefix = config.toolchain_prefix(); let linker = Esp32Linker::new( - PathBuf::from(format!("/usr/bin/{}gcc", prefix)), - PathBuf::from(format!("/usr/bin/{}ar", prefix)), - PathBuf::from(format!("/usr/bin/{}objcopy", prefix)), - PathBuf::from(format!("/usr/bin/{}size", prefix)), + NormalizedPath::new(format!("/usr/bin/{}gcc", prefix)), + NormalizedPath::new(format!("/usr/bin/{}ar", prefix)), + NormalizedPath::new(format!("/usr/bin/{}objcopy", prefix)), + NormalizedPath::new(format!("/usr/bin/{}size", prefix)), config, vec![], vec![], @@ -182,7 +185,7 @@ fn test_esp32_link_command_emits_linker_map_next_to_elf() { let args = linker.build_link_args( &[], &[], - &PathBuf::from("/build/firmware.elf"), + Path::new("/build/firmware.elf"), &LinkExtraArgs::default(), ); assert!( @@ -239,10 +242,10 @@ fn test_linker_flags_fallback_to_config() { let prefix = config.toolchain_prefix(); // Empty sdk_ld_flags → falls back to MCU config let linker = Esp32Linker::new( - PathBuf::from(format!("/usr/bin/{}gcc", prefix)), - PathBuf::from(format!("/usr/bin/{}ar", prefix)), - PathBuf::from(format!("/usr/bin/{}objcopy", prefix)), - PathBuf::from(format!("/usr/bin/{}size", prefix)), + NormalizedPath::new(format!("/usr/bin/{}gcc", prefix)), + NormalizedPath::new(format!("/usr/bin/{}ar", prefix)), + NormalizedPath::new(format!("/usr/bin/{}objcopy", prefix)), + NormalizedPath::new(format!("/usr/bin/{}size", prefix)), config, vec![], vec!["-lfreertos".to_string()], @@ -283,10 +286,10 @@ fn test_xtensa_linker_flags() { let config = get_mcu_config("esp32").unwrap(); let prefix = config.toolchain_prefix(); let linker = Esp32Linker::new( - PathBuf::from(format!("/usr/bin/{}gcc", prefix)), - PathBuf::from(format!("/usr/bin/{}ar", prefix)), - PathBuf::from(format!("/usr/bin/{}objcopy", prefix)), - PathBuf::from(format!("/usr/bin/{}size", prefix)), + NormalizedPath::new(format!("/usr/bin/{}gcc", prefix)), + NormalizedPath::new(format!("/usr/bin/{}ar", prefix)), + NormalizedPath::new(format!("/usr/bin/{}objcopy", prefix)), + NormalizedPath::new(format!("/usr/bin/{}size", prefix)), config, vec!["-mlongcalls".to_string()], vec![], @@ -423,7 +426,7 @@ async fn link_runs_the_linker_under_the_c_locale() { fbuild_core::platform::fs::set_executable(&staging).unwrap(); std::fs::rename(&staging, &fake_gcc).unwrap(); let mut linker = test_linker("esp32s3"); - linker.gcc_path = fake_gcc; + linker.gcc_path = fake_gcc.into(); linker .link(&[], &[], &tmp.path().join("out"), &LinkExtraArgs::default()) diff --git a/crates/fbuild-build-esp/src/esp32/orchestrator/build.rs b/crates/fbuild-build-esp/src/esp32/orchestrator/build.rs index e212b3ce..c7a8d4f0 100644 --- a/crates/fbuild-build-esp/src/esp32/orchestrator/build.rs +++ b/crates/fbuild-build-esp/src/esp32/orchestrator/build.rs @@ -846,10 +846,10 @@ impl BuildOrchestrator for Esp32Orchestrator { all_archives.extend(library_archives); let linker = Esp32Linker::new( - toolchain.get_gcc_path(), - toolchain.get_ar_path(), - toolchain.get_objcopy_path(), - toolchain.get_size_path(), + toolchain.get_gcc_path().into(), + toolchain.get_ar_path().into(), + toolchain.get_objcopy_path().into(), + toolchain.get_size_path().into(), mcu_config.clone(), sdk_ld_flags, sdk_lib_flags, @@ -859,7 +859,7 @@ impl BuildOrchestrator for Esp32Orchestrator { &flash_freq, ctx.board.max_flash, ctx.board.max_ram, - esptool_bin.clone().map(|path| path.into_path_buf()), + esptool_bin.clone(), params.verbose, ) .with_caller_path(params.caller_path.clone()) diff --git a/dylints/ban_std_pathbuf/src/allowlist.txt b/dylints/ban_std_pathbuf/src/allowlist.txt index 459e2bd3..d38b3615 100644 --- a/dylints/ban_std_pathbuf/src/allowlist.txt +++ b/dylints/ban_std_pathbuf/src/allowlist.txt @@ -38,9 +38,6 @@ crates/fbuild-build-engine/src/compiler.rs crates/fbuild-build-engine/src/compiler_tests.rs crates/fbuild-build-esp/src/esp32/esp32_compiler.rs crates/fbuild-build-esp/src/esp32/esp32_linker.rs -# Existing ESP32 linker test fixtures construct raw paths to match the legacy -# production linker's PathBuf API; migrate together with that API (#1501). -crates/fbuild-build-esp/src/esp32/esp32_linker_tests.rs crates/fbuild-build-esp/src/esp32/orchestrator/build.rs crates/fbuild-build-esp/src/esp32/orchestrator/embed.rs crates/fbuild-build-esp/src/esp32/orchestrator/embed_stage.rs