@@ -118,9 +118,23 @@ pub struct Output {
118
118
fn relative_command_path ( command : & Path ) -> crate :: Result < PathBuf > {
119
119
match platform:: current_exe ( ) ?. parent ( ) {
120
120
#[ cfg( windows) ]
121
- Some ( exe_dir) => Ok ( exe_dir. join ( command) . with_extension ( "exe" ) ) ,
121
+ Some ( exe_dir) => {
122
+ let mut command_path = exe_dir. join ( command) ;
123
+ let already_exe = command_path. extension ( ) . is_some_and ( |ext| ext == "exe" ) ;
124
+ if !already_exe {
125
+ // do not use with_extension to retain dots in the command filename
126
+ command_path. as_mut_os_string ( ) . push ( ".exe" ) ;
127
+ }
128
+ Ok ( command_path)
129
+ }
122
130
#[ cfg( not( windows) ) ]
123
- Some ( exe_dir) => Ok ( exe_dir. join ( command) ) ,
131
+ Some ( exe_dir) => {
132
+ let mut command_path = exe_dir. join ( command) ;
133
+ if command_path. extension ( ) . is_some_and ( |ext| ext == "exe" ) {
134
+ command_path. set_extension ( "" ) ;
135
+ }
136
+ Ok ( command_path)
137
+ }
124
138
None => Err ( crate :: Error :: CurrentExeHasNoParent ) ,
125
139
}
126
140
}
@@ -133,6 +147,10 @@ impl From<Command> for StdCommand {
133
147
134
148
impl Command {
135
149
pub ( crate ) fn new < S : AsRef < OsStr > > ( program : S ) -> Self {
150
+ log:: debug!(
151
+ "Creating sidecar {}" ,
152
+ program. as_ref( ) . to_str( ) . unwrap_or( "" )
153
+ ) ;
136
154
let mut command = StdCommand :: new ( program) ;
137
155
138
156
command. stdout ( Stdio :: piped ( ) ) ;
@@ -451,9 +469,33 @@ fn spawn_pipe_reader<F: Fn(Vec<u8>) -> CommandEvent + Send + Copy + 'static>(
451
469
// tests for the commands functions.
452
470
#[ cfg( test) ]
453
471
mod tests {
454
- #[ cfg( not( windows) ) ]
455
472
use super :: * ;
456
473
474
+ #[ test]
475
+ fn relative_command_path_resolves ( ) {
476
+ let cwd_parent = platform:: current_exe ( )
477
+ . unwrap ( )
478
+ . parent ( )
479
+ . unwrap ( )
480
+ . to_owned ( ) ;
481
+ assert_eq ! (
482
+ relative_command_path( Path :: new( "Tauri.Example" ) ) . unwrap( ) ,
483
+ cwd_parent. join( if cfg!( windows) {
484
+ "Tauri.Example.exe"
485
+ } else {
486
+ "Tauri.Example"
487
+ } )
488
+ ) ;
489
+ assert_eq ! (
490
+ relative_command_path( Path :: new( "Tauri.Example.exe" ) ) . unwrap( ) ,
491
+ cwd_parent. join( if cfg!( windows) {
492
+ "Tauri.Example.exe"
493
+ } else {
494
+ "Tauri.Example"
495
+ } )
496
+ ) ;
497
+ }
498
+
457
499
#[ cfg( not( windows) ) ]
458
500
#[ test]
459
501
fn test_cmd_spawn_output ( ) {
0 commit comments