11
11
//! obtained from the wrapper's name as the first two arguments.
12
12
//! On Windows it spawns a `..\rust-lld.exe` child process.
13
13
14
+ use std:: env:: { self , consts:: EXE_SUFFIX } ;
14
15
use std:: fmt:: Display ;
15
16
use std:: path:: { Path , PathBuf } ;
16
- use std:: { env , process} ;
17
+ use std:: process;
17
18
18
19
trait UnwrapOrExitWith < T > {
19
20
fn unwrap_or_exit_with ( self , context : & str ) -> T ;
@@ -42,7 +43,7 @@ impl<T, E: Display> UnwrapOrExitWith<T> for Result<T, E> {
42
43
/// Exits if the parent directory cannot be determined.
43
44
fn get_rust_lld_path ( current_exe_path : & Path ) -> PathBuf {
44
45
let mut rust_lld_exe_name = "rust-lld" . to_owned ( ) ;
45
- rust_lld_exe_name. push_str ( env :: consts :: EXE_SUFFIX ) ;
46
+ rust_lld_exe_name. push_str ( EXE_SUFFIX ) ;
46
47
let mut rust_lld_path = current_exe_path
47
48
. parent ( )
48
49
. unwrap_or_exit_with ( "directory containing current executable could not be determined" )
@@ -55,13 +56,14 @@ fn get_rust_lld_path(current_exe_path: &Path) -> PathBuf {
55
56
56
57
/// Extract LLD flavor name from the lld-wrapper executable name.
57
58
fn get_lld_flavor ( current_exe_path : & Path ) -> Result < & ' static str , String > {
58
- let stem = current_exe_path. file_stem ( ) ;
59
- Ok ( match stem. and_then ( |s| s. to_str ( ) ) {
59
+ let file = current_exe_path. file_name ( ) ;
60
+ let stem = file. and_then ( |s| s. to_str ( ) ) . map ( |s| s. trim_end_matches ( EXE_SUFFIX ) ) ;
61
+ Ok ( match stem {
60
62
Some ( "ld.lld" ) => "gnu" ,
61
63
Some ( "ld64.lld" ) => "darwin" ,
62
64
Some ( "lld-link" ) => "link" ,
63
65
Some ( "wasm-ld" ) => "wasm" ,
64
- _ => return Err ( format ! ( "{:?}" , stem ) ) ,
66
+ _ => return Err ( format ! ( "{:?}" , file ) ) ,
65
67
} )
66
68
}
67
69
0 commit comments