@@ -35,7 +35,8 @@ fn read_crates(sess: session::session, crate: &ast::crate) {
35
35
let e =
36
36
@{ sess: sess,
37
37
crate_cache: @std:: map:: new_str_hash :: < int > ( ) ,
38
- library_search_paths: sess. get_opts ( ) . library_search_paths ,
38
+ library_search_paths:
39
+ istr:: from_estrs ( sess. get_opts ( ) . library_search_paths ) ,
39
40
mutable next_crate_num: 1 } ;
40
41
let v =
41
42
visit:: mk_simple_visitor ( @{ visit_view_item:
@@ -48,7 +49,7 @@ fn read_crates(sess: session::session, crate: &ast::crate) {
48
49
type env =
49
50
@{ sess : session:: session ,
50
51
crate_cache : @hashmap < istr , int > ,
51
- library_search_paths : [ str ] ,
52
+ library_search_paths : [ istr ] ,
52
53
mutable next_crate_num: ast:: crate_num } ;
53
54
54
55
fn visit_view_item ( e : env , i : & @ast:: view_item ) {
@@ -69,12 +70,12 @@ fn visit_item(e: env, i: &@ast::item) {
69
70
}
70
71
let cstore = e. sess . get_cstore ( ) ;
71
72
if !cstore:: add_used_library ( cstore,
72
- istr :: to_estr ( m. native_name ) ) { ret; }
73
+ m. native_name ) { ret; }
73
74
for a: ast:: attribute in
74
75
attr:: find_attrs_by_name ( i. attrs , ~"link_args") {
75
76
alt attr:: get_meta_item_value_str ( attr:: attr_meta ( a) ) {
76
77
some ( linkarg) {
77
- cstore:: add_used_link_args ( cstore, istr :: to_estr ( linkarg) ) ;
78
+ cstore:: add_used_link_args ( cstore, linkarg) ;
78
79
}
79
80
none. { /* fallthrough */ }
80
81
}
@@ -85,12 +86,12 @@ fn visit_item(e: env, i: &@ast::item) {
85
86
}
86
87
87
88
// A diagnostic function for dumping crate metadata to an output stream
88
- fn list_file_metadata ( path : str , out : io:: writer ) {
89
+ fn list_file_metadata ( path : & istr , out : io:: writer ) {
89
90
alt get_metadata_section ( path) {
90
91
option:: some ( bytes) { decoder:: list_crate_metadata ( bytes, out) ; }
91
92
option:: none. {
92
93
out . write_str (
93
- istr :: from_estr ( "Could not find metadata in " + path + ".\n " ) ) ;
94
+ ~ "Could not find metadata in " + path + ~ " . \n ") ;
94
95
}
95
96
}
96
97
}
@@ -112,18 +113,18 @@ fn metadata_matches(crate_data: &@[u8], metas: &[@ast::meta_item]) -> bool {
112
113
}
113
114
114
115
fn default_native_lib_naming ( sess : session:: session , static : bool ) ->
115
- { prefix : str , suffix : str } {
116
- if static { ret { prefix : "lib" , suffix : ".rlib" } ; }
116
+ { prefix : istr , suffix : istr } {
117
+ if static { ret { prefix : ~ "lib", suffix : ~ ". rlib"} ; }
117
118
alt sess. get_targ_cfg ( ) . os {
118
- session:: os_win32. { ret { prefix : "" , suffix : ".dll" } ; }
119
- session:: os_macos. { ret { prefix : "lib" , suffix : ".dylib" } ; }
120
- session:: os_linux. { ret { prefix : "lib" , suffix : ".so" } ; }
119
+ session:: os_win32. { ret { prefix: ~ "", suffix : ~ ". dll"} ; }
120
+ session:: os_macos. { ret { prefix : ~ "lib", suffix : ~ ". dylib"} ; }
121
+ session:: os_linux. { ret { prefix : ~ "lib", suffix : ~ ". so"} ; }
121
122
}
122
123
}
123
124
124
125
fn find_library_crate ( sess : & session:: session , ident : & ast:: ident ,
125
- metas : & [ @ast:: meta_item ] , library_search_paths : & [ str ] )
126
- -> option:: t < { ident: str , data : @[ u8 ] } > {
126
+ metas : & [ @ast:: meta_item ] , library_search_paths : & [ istr ] )
127
+ -> option:: t < { ident: istr , data : @[ u8 ] } > {
127
128
128
129
attr:: require_unique_names ( sess, metas) ;
129
130
@@ -145,48 +146,49 @@ fn find_library_crate(sess: &session::session, ident: &ast::ident,
145
146
146
147
let nn = default_native_lib_naming ( sess, sess. get_opts ( ) . static ) ;
147
148
let x =
148
- find_library_crate_aux ( nn, istr :: to_estr ( crate_name) ,
149
+ find_library_crate_aux ( nn, crate_name,
149
150
metas, library_search_paths) ;
150
151
if x != none || sess. get_opts ( ) . static { ret x; }
151
152
let nn2 = default_native_lib_naming ( sess, true ) ;
152
- ret find_library_crate_aux ( nn2, istr :: to_estr ( crate_name) ,
153
+ ret find_library_crate_aux ( nn2, crate_name,
153
154
metas, library_search_paths) ;
154
155
}
155
156
156
- fn find_library_crate_aux ( nn : & { prefix : str , suffix : str } , crate_name : str ,
157
+ fn find_library_crate_aux ( nn : & { prefix : istr, suffix : istr } ,
158
+ crate_name : & istr ,
157
159
metas : & [ @ast:: meta_item ] ,
158
- library_search_paths : & [ str ] ) ->
159
- option:: t < { ident: str , data : @[ u8 ] } > {
160
- let prefix: istr = istr :: from_estr ( nn. prefix + crate_name) ;
161
- let suffix: istr = istr :: from_estr ( nn. suffix ) ;
160
+ library_search_paths : & [ istr ] ) ->
161
+ option:: t < { ident: istr , data : @[ u8 ] } > {
162
+ let prefix: istr = nn. prefix + crate_name;
163
+ let suffix: istr = nn. suffix ;
162
164
// FIXME: we could probably use a 'glob' function in std::fs but it will
163
165
// be much easier to write once the unsafe module knows more about FFI
164
166
// tricks. Currently the glob(3) interface is a bit more than we can
165
167
// stomach from here, and writing a C++ wrapper is more work than just
166
168
// manually filtering fs::list_dir here.
167
169
168
- for library_search_path: str in library_search_paths {
169
- log #fmt[ "searching %s" , library_search_path] ;
170
- let library_search_path = istr:: from_estr ( library_search_path) ;
170
+ for library_search_path: istr in library_search_paths {
171
+ log #fmt[ "searching %s" , istr:: to_estr ( library_search_path) ] ;
171
172
for path: istr in fs:: list_dir ( library_search_path) {
172
173
log #fmt[ "searching %s" , istr:: to_estr ( path) ] ;
173
174
let f: istr = fs:: basename ( path) ;
174
- let path = istr:: to_estr ( path) ;
175
175
if !( istr:: starts_with ( f, prefix) && istr:: ends_with ( f, suffix) )
176
176
{
177
177
log #fmt[ "skipping %s, doesn't look like %s*%s" ,
178
- path,
178
+ istr :: to_estr ( path) ,
179
179
istr:: to_estr ( prefix) ,
180
180
istr:: to_estr ( suffix) ] ;
181
181
cont;
182
182
}
183
183
alt get_metadata_section ( path) {
184
184
option:: some ( cvec) {
185
185
if !metadata_matches ( cvec, metas) {
186
- log #fmt[ "skipping %s, metadata doesn't match" , path] ;
186
+ log #fmt[ "skipping %s, metadata doesn't match" ,
187
+ istr:: to_estr ( path) ] ;
187
188
cont;
188
189
}
189
- log #fmt[ "found %s with matching metadata" , path] ;
190
+ log #fmt[ "found %s with matching metadata" ,
191
+ istr:: to_estr ( path) ] ;
190
192
ret some( { ident: path, data: cvec} ) ;
191
193
}
192
194
_ { }
@@ -196,8 +198,8 @@ fn find_library_crate_aux(nn: &{prefix: str, suffix: str}, crate_name: str,
196
198
ret none;
197
199
}
198
200
199
- fn get_metadata_section ( filename : str ) -> option:: t < @[ u8 ] > {
200
- let mb = istr:: as_buf ( istr :: from_estr ( filename) , { |buf|
201
+ fn get_metadata_section ( filename : & istr ) -> option:: t < @[ u8 ] > {
202
+ let mb = istr:: as_buf ( filename, { |buf|
201
203
llvm:: LLVMRustCreateMemoryBufferWithContentsOfFile ( buf)
202
204
} ) ;
203
205
if mb as int == 0 { ret option:: none :: < @[ u8 ] > ; }
@@ -218,8 +220,9 @@ fn get_metadata_section(filename: str) -> option::t<@[u8]> {
218
220
}
219
221
220
222
fn load_library_crate ( sess : & session:: session , span : span , ident : & ast:: ident ,
221
- metas : & [ @ast:: meta_item ] , library_search_paths : & [ str ] )
222
- -> { ident: str , data: @[ u8] } {
223
+ metas : & [ @ast:: meta_item ] ,
224
+ library_search_paths : & [ istr ] )
225
+ -> { ident: istr, data: @[ u8] } {
223
226
224
227
225
228
alt find_library_crate ( sess, ident, metas, library_search_paths) {
@@ -249,12 +252,13 @@ fn resolve_crate(e: env, ident: &ast::ident, metas: [@ast::meta_item],
249
252
// Now resolve the crates referenced by this crate
250
253
let cnum_map = resolve_crate_deps ( e, cdata) ;
251
254
252
- let cmeta = { name: istr :: to_estr ( ident) ,
255
+ let cmeta = { name: ident,
253
256
data: cdata, cnum_map: cnum_map} ;
254
257
255
258
let cstore = e. sess . get_cstore ( ) ;
256
259
cstore:: set_crate_data ( cstore, cnum, cmeta) ;
257
- cstore:: add_used_crate_file ( cstore, cfilename) ;
260
+ cstore:: add_used_crate_file ( cstore,
261
+ cfilename) ;
258
262
ret cnum;
259
263
} else { ret e. crate_cache . get ( ident) ; }
260
264
}
@@ -268,19 +272,19 @@ fn resolve_crate_deps(e: env, cdata: &@[u8]) -> cstore::cnum_map {
268
272
for dep: decoder:: crate_dep in decoder:: get_crate_deps ( cdata) {
269
273
let extrn_cnum = dep. cnum ;
270
274
let cname = dep. ident ;
271
- log #fmt[ "resolving dep %s" , cname] ;
272
- if e. crate_cache . contains_key ( istr :: from_estr ( cname) ) {
275
+ log #fmt[ "resolving dep %s" , istr :: to_estr ( cname) ] ;
276
+ if e. crate_cache . contains_key ( cname) {
273
277
log "already have it" ;
274
278
// We've already seen this crate
275
- let local_cnum = e. crate_cache . get ( istr :: from_estr ( cname) ) ;
279
+ let local_cnum = e. crate_cache . get ( cname) ;
276
280
cnum_map. insert ( extrn_cnum, local_cnum) ;
277
281
} else {
278
282
log "need to load it" ;
279
283
// This is a new one so we've got to load it
280
284
// FIXME: Need better error reporting than just a bogus span
281
285
let fake_span = ast_util:: dummy_sp ( ) ;
282
286
let local_cnum = resolve_crate ( e,
283
- istr :: from_estr ( cname) ,
287
+ cname,
284
288
[ ] , fake_span) ;
285
289
cnum_map. insert ( extrn_cnum, local_cnum) ;
286
290
}
0 commit comments