3
3
use std:: path:: { Path , PathBuf } ;
4
4
use std:: { env, fs} ;
5
5
6
- use rustc_fs_util:: { fix_windows_verbatim_for_gcc , try_canonicalize} ;
6
+ use rustc_fs_util:: try_canonicalize;
7
7
use rustc_target:: spec:: Target ;
8
8
use smallvec:: { SmallVec , smallvec} ;
9
9
@@ -87,7 +87,7 @@ fn current_dll_path() -> Result<PathBuf, String> {
87
87
} ;
88
88
let bytes = CStr :: from_ptr ( fname_ptr) . to_bytes ( ) ;
89
89
let os = OsStr :: from_bytes ( bytes) ;
90
- Ok ( PathBuf :: from ( os) )
90
+ try_canonicalize ( Path :: new ( os) ) . map_err ( |e| e . to_string ( ) )
91
91
}
92
92
93
93
#[ cfg( target_os = "aix" ) ]
@@ -122,7 +122,7 @@ fn current_dll_path() -> Result<PathBuf, String> {
122
122
if ( data_base..data_end) . contains ( & addr) {
123
123
let bytes = CStr :: from_ptr ( & ( * current) . ldinfo_filename [ 0 ] ) . to_bytes ( ) ;
124
124
let os = OsStr :: from_bytes ( bytes) ;
125
- return Ok ( PathBuf :: from ( os) ) ;
125
+ return try_canonicalize ( Path :: new ( os) ) . map_err ( |e| e . to_string ( ) ) ;
126
126
}
127
127
if ( * current) . ldinfo_next == 0 {
128
128
break ;
@@ -169,7 +169,12 @@ fn current_dll_path() -> Result<PathBuf, String> {
169
169
170
170
filename. truncate ( n) ;
171
171
172
- Ok ( OsString :: from_wide ( & filename) . into ( ) )
172
+ let path = try_canonicalize ( OsString :: from_wide ( & filename) ) . map_err ( |e| e. to_string ( ) ) ?;
173
+
174
+ // See comments on this target function, but the gist is that
175
+ // gcc chokes on verbatim paths which fs::canonicalize generates
176
+ // so we try to avoid those kinds of paths.
177
+ Ok ( rustc_fs_util:: fix_windows_verbatim_for_gcc ( & path) )
173
178
}
174
179
175
180
#[ cfg( target_os = "wasi" ) ]
@@ -178,10 +183,8 @@ fn current_dll_path() -> Result<PathBuf, String> {
178
183
}
179
184
180
185
pub fn sysroot_candidates ( ) -> SmallVec < [ PathBuf ; 2 ] > {
181
- let target = crate :: config:: host_tuple ( ) ;
182
186
let mut sysroot_candidates: SmallVec < [ PathBuf ; 2 ] > = smallvec ! [ get_or_default_sysroot( ) ] ;
183
- let path = current_dll_path ( ) . and_then ( |s| try_canonicalize ( s) . map_err ( |e| e. to_string ( ) ) ) ;
184
- if let Ok ( dll) = path {
187
+ if let Ok ( dll) = current_dll_path ( ) {
185
188
// use `parent` twice to chop off the file name and then also the
186
189
// directory containing the dll which should be either `lib` or `bin`.
187
190
if let Some ( path) = dll. parent ( ) . and_then ( |p| p. parent ( ) ) {
@@ -196,7 +199,7 @@ pub fn sysroot_candidates() -> SmallVec<[PathBuf; 2]> {
196
199
// assume that we may be in the main libdir.
197
200
sysroot_candidates. push ( path. to_owned ( ) ) ;
198
201
199
- if path. ends_with ( target ) {
202
+ if path. ends_with ( crate :: config :: host_tuple ( ) ) {
200
203
sysroot_candidates. extend (
201
204
path. parent ( ) // chop off `$target`
202
205
. and_then ( |p| p. parent ( ) ) // chop off `rustlib`
@@ -219,17 +222,8 @@ pub fn materialize_sysroot(maybe_sysroot: Option<PathBuf>) -> PathBuf {
219
222
/// This function checks if sysroot is found using env::args().next(), and if it
220
223
/// is not found, finds sysroot from current rustc_driver dll.
221
224
pub fn get_or_default_sysroot ( ) -> PathBuf {
222
- // Follow symlinks. If the resolved path is relative, make it absolute.
223
- fn canonicalize ( path : PathBuf ) -> PathBuf {
224
- let path = try_canonicalize ( & path) . unwrap_or ( path) ;
225
- // See comments on this target function, but the gist is that
226
- // gcc chokes on verbatim paths which fs::canonicalize generates
227
- // so we try to avoid those kinds of paths.
228
- fix_windows_verbatim_for_gcc ( & path)
229
- }
230
-
231
225
fn default_from_rustc_driver_dll ( ) -> Result < PathBuf , String > {
232
- let dll = current_dll_path ( ) . map ( |s| canonicalize ( s ) ) ?;
226
+ let dll = current_dll_path ( ) ?;
233
227
234
228
// `dll` will be in one of the following two:
235
229
// - compiler's libdir: $sysroot/lib/*.dll
0 commit comments