diff --git a/src/main.rs b/src/main.rs index 933e250..48feeb9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -264,20 +264,20 @@ fn monitor_chip(_args: ArgMonitor, target: &mut PhysicalTarget) -> Result<(), Er } fn run_chip(args: ArgRun, target: &mut PhysicalTarget) -> Result<(), Error> { - let parent_path = args.path.parent().unwrap().join("tulflash"); - let base_file = parent_path.join( - args.path.file_name().ok_or(Error::other("invalid path to compilation source"))?); - let path = base_file.with_extension("ihx"); - let sdcc_file = args.path.file_name().ok_or(Error::other("invalid path to compilation source"))?; - let cmd = Some(OsString::from( - format!("sdcc \"{}\"", sdcc_file.to_str().ok_or(Error::other("invalid path to compilation source"))?) - )); - let cmd_path = Some(parent_path.clone()); - std::fs::create_dir_all(parent_path)?; - std::fs::copy(args.path, &base_file)?; + let build_dir = args.path.parent().unwrap().join("tulflash"); + + let source_file_name = args.path.file_name().ok_or(Error::other("invalid path to compilation source"))?; + let source_file = build_dir.join(&source_file_name); + let output_file = source_file.with_extension("ihx"); + + let cmd = Some(OsString::from(format!("sdcc \"{}\"", source_file_name.to_string_lossy()))); + let cmd_path = Some(build_dir.clone()); + + std::fs::create_dir_all(build_dir)?; + std::fs::copy(args.path, &source_file)?; write_chip(ArgWrite { - path: path.into_os_string(), + path: output_file.into_os_string(), cmd_path, cmd, start: 0,