12
12
13
13
pub use self :: FileMatch :: * ;
14
14
15
+ use std:: borrow:: Cow ;
15
16
use std:: collections:: HashSet ;
16
17
use std:: env;
17
18
use std:: fs;
@@ -67,33 +68,32 @@ impl<'a> FileSearch<'a> {
67
68
{
68
69
self . for_each_lib_search_path ( |lib_search_path, kind| {
69
70
debug ! ( "searching {}" , lib_search_path. display( ) ) ;
70
- match fs:: read_dir ( lib_search_path) {
71
- Ok ( files) => {
72
- let files = files. filter_map ( |p| p. ok ( ) . map ( |s| s. path ( ) ) )
73
- . collect :: < Vec < _ > > ( ) ;
74
- fn is_rlib ( p : & Path ) -> bool {
75
- p. extension ( ) . and_then ( |s| s. to_str ( ) ) == Some ( "rlib" )
71
+ let files = match fs:: read_dir ( lib_search_path) {
72
+ Ok ( files) => files,
73
+ Err ( ..) => return ,
74
+ } ;
75
+ let files = files. filter_map ( |p| p. ok ( ) . map ( |s| s. path ( ) ) )
76
+ . collect :: < Vec < _ > > ( ) ;
77
+ fn is_rlib ( p : & Path ) -> bool {
78
+ p. extension ( ) == Some ( "rlib" . as_ref ( ) )
79
+ }
80
+ // Reading metadata out of rlibs is faster, and if we find both
81
+ // an rlib and a dylib we only read one of the files of
82
+ // metadata, so in the name of speed, bring all rlib files to
83
+ // the front of the search list.
84
+ let files1 = files. iter ( ) . filter ( |p| is_rlib ( p) ) ;
85
+ let files2 = files. iter ( ) . filter ( |p| !is_rlib ( p) ) ;
86
+ for path in files1. chain ( files2) {
87
+ debug ! ( "testing {}" , path. display( ) ) ;
88
+ let maybe_picked = pick ( path, kind) ;
89
+ match maybe_picked {
90
+ FileMatches => {
91
+ debug ! ( "picked {}" , path. display( ) ) ;
76
92
}
77
- // Reading metadata out of rlibs is faster, and if we find both
78
- // an rlib and a dylib we only read one of the files of
79
- // metadata, so in the name of speed, bring all rlib files to
80
- // the front of the search list.
81
- let files1 = files. iter ( ) . filter ( |p| is_rlib ( p) ) ;
82
- let files2 = files. iter ( ) . filter ( |p| !is_rlib ( p) ) ;
83
- for path in files1. chain ( files2) {
84
- debug ! ( "testing {}" , path. display( ) ) ;
85
- let maybe_picked = pick ( path, kind) ;
86
- match maybe_picked {
87
- FileMatches => {
88
- debug ! ( "picked {}" , path. display( ) ) ;
89
- }
90
- FileDoesntMatch => {
91
- debug ! ( "rejected {}" , path. display( ) ) ;
92
- }
93
- }
93
+ FileDoesntMatch => {
94
+ debug ! ( "rejected {}" , path. display( ) ) ;
94
95
}
95
96
}
96
- Err ( ..) => ( ) ,
97
97
}
98
98
} ) ;
99
99
}
@@ -123,18 +123,18 @@ impl<'a> FileSearch<'a> {
123
123
// Returns a list of directories where target-specific tool binaries are located.
124
124
pub fn get_tools_search_paths ( & self ) -> Vec < PathBuf > {
125
125
let mut p = PathBuf :: from ( self . sysroot ) ;
126
- p. push ( & find_libdir ( self . sysroot ) ) ;
127
- p. push ( & rustlibdir ( ) ) ;
126
+ p. push ( find_libdir ( self . sysroot ) . as_ref ( ) ) ;
127
+ p. push ( RUST_LIB_DIR ) ;
128
128
p. push ( & self . triple ) ;
129
129
p. push ( "bin" ) ;
130
130
vec ! [ p]
131
131
}
132
132
}
133
133
134
134
pub fn relative_target_lib_path ( sysroot : & Path , target_triple : & str ) -> PathBuf {
135
- let mut p = PathBuf :: from ( & find_libdir ( sysroot) ) ;
135
+ let mut p = PathBuf :: from ( find_libdir ( sysroot) . as_ref ( ) ) ;
136
136
assert ! ( p. is_relative( ) ) ;
137
- p. push ( & rustlibdir ( ) ) ;
137
+ p. push ( RUST_LIB_DIR ) ;
138
138
p. push ( target_triple) ;
139
139
p. push ( "lib" ) ;
140
140
p
@@ -166,7 +166,7 @@ pub fn get_or_default_sysroot() -> PathBuf {
166
166
}
167
167
168
168
// The name of the directory rustc expects libraries to be located.
169
- fn find_libdir ( sysroot : & Path ) -> String {
169
+ fn find_libdir ( sysroot : & Path ) -> Cow < ' static , str > {
170
170
// FIXME: This is a quick hack to make the rustc binary able to locate
171
171
// Rust libraries in Linux environments where libraries might be installed
172
172
// to lib64/lib32. This would be more foolproof by basing the sysroot off
@@ -176,31 +176,23 @@ fn find_libdir(sysroot: &Path) -> String {
176
176
// "lib" (i.e. non-default), this value is used (see issue #16552).
177
177
178
178
match option_env ! ( "CFG_LIBDIR_RELATIVE" ) {
179
- Some ( libdir) if libdir != "lib" => return libdir. to_string ( ) ,
180
- _ => if sysroot. join ( & primary_libdir_name ( ) ) . join ( & rustlibdir ( ) ) . exists ( ) {
181
- return primary_libdir_name ( ) ;
179
+ Some ( libdir) if libdir != "lib" => return libdir. into ( ) ,
180
+ _ => if sysroot. join ( PRIMARY_LIB_DIR ) . join ( RUST_LIB_DIR ) . exists ( ) {
181
+ return PRIMARY_LIB_DIR . into ( ) ;
182
182
} else {
183
- return secondary_libdir_name ( ) ;
183
+ return SECONDARY_LIB_DIR . into ( ) ;
184
184
}
185
185
}
186
186
187
187
#[ cfg( target_pointer_width = "64" ) ]
188
- fn primary_libdir_name ( ) -> String {
189
- "lib64" . to_string ( )
190
- }
188
+ const PRIMARY_LIB_DIR : & ' static str = "lib64" ;
191
189
192
190
#[ cfg( target_pointer_width = "32" ) ]
193
- fn primary_libdir_name ( ) -> String {
194
- "lib32" . to_string ( )
195
- }
191
+ const PRIMARY_LIB_DIR : & ' static str = "lib32" ;
196
192
197
- fn secondary_libdir_name ( ) -> String {
198
- "lib" . to_string ( )
199
- }
193
+ const SECONDARY_LIB_DIR : & ' static str = "lib" ;
200
194
}
201
195
202
196
// The name of rustc's own place to organize libraries.
203
197
// Used to be "rustc", now the default is "rustlib"
204
- pub fn rustlibdir ( ) -> String {
205
- "rustlib" . to_string ( )
206
- }
198
+ const RUST_LIB_DIR : & ' static str = "rustlib" ;
0 commit comments