1
- use std:: collections:: hash_map :: { Entry , HashMap } ;
1
+ use std:: collections:: HashMap ;
2
2
use std:: env;
3
3
use std:: fmt;
4
4
use std:: hash:: { Hash , Hasher , SipHasher } ;
@@ -9,7 +9,7 @@ use lazycell::LazyCell;
9
9
10
10
use core:: { TargetKind , Workspace } ;
11
11
use ops:: cargo_rustc:: layout:: Layout ;
12
- use ops:: cargo_rustc:: TargetFileType ;
12
+ use ops:: cargo_rustc:: FileFlavor ;
13
13
use ops:: { Context , Kind , Unit } ;
14
14
use util:: { self , CargoResult } ;
15
15
@@ -29,13 +29,19 @@ pub struct CompilationFiles<'a, 'cfg: 'a> {
29
29
pub ( super ) target : Option < Layout > ,
30
30
ws : & ' a Workspace < ' cfg > ,
31
31
metas : HashMap < Unit < ' a > , Option < Metadata > > ,
32
- /// For each Unit, a list all files produced as a triple of
33
- ///
34
- /// - File name that will be produced by the build process (in `deps`)
35
- /// - If it should be linked into `target`, and what it should be called (e.g. without
36
- /// metadata).
37
- /// - Type of the file (library / debug symbol / else)
38
- outputs : HashMap < Unit < ' a > , LazyCell < Arc < Vec < ( PathBuf , Option < PathBuf > , TargetFileType ) > > > > ,
32
+ /// For each Unit, a list all files produced.
33
+ outputs : HashMap < Unit < ' a > , LazyCell < Arc < Vec < OutputFile > > > > ,
34
+ }
35
+
36
+ #[ derive( Debug ) ]
37
+ pub struct OutputFile {
38
+ /// File name that will be produced by the build process (in `deps`).
39
+ pub path : PathBuf ,
40
+ /// If it should be linked into `target`, and what it should be called
41
+ /// (e.g. without metadata).
42
+ pub hardlink : Option < PathBuf > ,
43
+ /// Type of the file (library / debug symbol / else).
44
+ pub flavor : FileFlavor ,
39
45
}
40
46
41
47
impl < ' a , ' cfg : ' a > CompilationFiles < ' a , ' cfg > {
@@ -153,13 +159,13 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
153
159
}
154
160
}
155
161
156
- pub ( super ) fn target_filenames (
162
+ pub ( super ) fn outputs (
157
163
& self ,
158
164
unit : & Unit < ' a > ,
159
165
cx : & Context < ' a , ' cfg > ,
160
- ) -> CargoResult < Arc < Vec < ( PathBuf , Option < PathBuf > , TargetFileType ) > > > {
166
+ ) -> CargoResult < Arc < Vec < OutputFile > > > {
161
167
self . outputs [ unit]
162
- . try_borrow_with ( || self . calc_target_filenames ( unit, cx) )
168
+ . try_borrow_with ( || self . calc_outputs ( unit, cx) )
163
169
. map ( Arc :: clone)
164
170
}
165
171
@@ -181,20 +187,20 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
181
187
/// Returns an Option because in some cases we don't want to link
182
188
/// (eg a dependent lib)
183
189
fn link_stem ( & self , unit : & Unit < ' a > ) -> Option < ( PathBuf , String ) > {
184
- let src_dir = self . out_dir ( unit) ;
190
+ let out_dir = self . out_dir ( unit) ;
185
191
let bin_stem = self . bin_stem ( unit) ;
186
192
let file_stem = self . file_stem ( unit) ;
187
193
188
194
// We currently only lift files up from the `deps` directory. If
189
195
// it was compiled into something like `example/` or `doc/` then
190
196
// we don't want to link it up.
191
- if src_dir . ends_with ( "deps" ) {
197
+ if out_dir . ends_with ( "deps" ) {
192
198
// Don't lift up library dependencies
193
199
if self . ws . members ( ) . find ( |& p| p == unit. pkg ) . is_none ( ) && !unit. target . is_bin ( ) {
194
200
None
195
201
} else {
196
202
Some ( (
197
- src_dir . parent ( ) . unwrap ( ) . to_owned ( ) ,
203
+ out_dir . parent ( ) . unwrap ( ) . to_owned ( ) ,
198
204
if unit. profile . test {
199
205
file_stem
200
206
} else {
@@ -204,20 +210,20 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
204
210
}
205
211
} else if bin_stem == file_stem {
206
212
None
207
- } else if src_dir . ends_with ( "examples" ) || src_dir . parent ( ) . unwrap ( ) . ends_with ( "build" ) {
208
- Some ( ( src_dir , bin_stem) )
213
+ } else if out_dir . ends_with ( "examples" ) || out_dir . parent ( ) . unwrap ( ) . ends_with ( "build" ) {
214
+ Some ( ( out_dir , bin_stem) )
209
215
} else {
210
216
None
211
217
}
212
218
}
213
219
214
- fn calc_target_filenames (
220
+ fn calc_outputs (
215
221
& self ,
216
222
unit : & Unit < ' a > ,
217
223
cx : & Context < ' a , ' cfg > ,
218
- ) -> CargoResult < Arc < Vec < ( PathBuf , Option < PathBuf > , TargetFileType ) > > > {
224
+ ) -> CargoResult < Arc < Vec < OutputFile > > > {
219
225
let out_dir = self . out_dir ( unit) ;
220
- let stem = self . file_stem ( unit) ;
226
+ let file_stem = self . file_stem ( unit) ;
221
227
let link_stem = self . link_stem ( unit) ;
222
228
let info = if unit. target . for_host ( ) {
223
229
& cx. host_info
@@ -229,68 +235,47 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
229
235
let mut unsupported = Vec :: new ( ) ;
230
236
{
231
237
if unit. profile . check {
232
- let filename = out_dir. join ( format ! ( "lib{}.rmeta" , stem ) ) ;
233
- let link_dst = link_stem
238
+ let path = out_dir. join ( format ! ( "lib{}.rmeta" , file_stem ) ) ;
239
+ let hardlink = link_stem
234
240
. clone ( )
235
241
. map ( |( ld, ls) | ld. join ( format ! ( "lib{}.rmeta" , ls) ) ) ;
236
- ret. push ( ( filename, link_dst, TargetFileType :: Linkable ) ) ;
242
+ ret. push ( OutputFile {
243
+ path,
244
+ hardlink,
245
+ flavor : FileFlavor :: Linkable ,
246
+ } ) ;
237
247
} else {
238
- let mut add = |crate_type : & str , file_type : TargetFileType | -> CargoResult < ( ) > {
248
+ let mut add = |crate_type : & str , flavor : FileFlavor | -> CargoResult < ( ) > {
239
249
let crate_type = if crate_type == "lib" {
240
250
"rlib"
241
251
} else {
242
252
crate_type
243
253
} ;
244
- let mut crate_types = info. crate_types . borrow_mut ( ) ;
245
- let entry = crate_types. entry ( crate_type. to_string ( ) ) ;
246
- let crate_type_info = match entry {
247
- Entry :: Occupied ( o) => & * o. into_mut ( ) ,
248
- Entry :: Vacant ( v) => {
249
- let value = info. discover_crate_type ( v. key ( ) ) ?;
250
- & * v. insert ( value)
251
- }
252
- } ;
253
- match * crate_type_info {
254
- Some ( ( ref prefix, ref suffix) ) => {
255
- let suffixes = add_target_specific_suffixes (
256
- cx. target_triple ( ) ,
257
- crate_type,
258
- unit. target . kind ( ) ,
259
- suffix,
260
- file_type,
261
- ) ;
262
- for ( suffix, file_type, should_replace_hyphens) in suffixes {
263
- // wasm bin target will generate two files in deps such as
264
- // "web-stuff.js" and "web_stuff.wasm". Note the different usages of
265
- // "-" and "_". should_replace_hyphens is a flag to indicate that
266
- // we need to convert the stem "web-stuff" to "web_stuff", so we
267
- // won't miss "web_stuff.wasm".
268
- let conv = |s : String | {
269
- if should_replace_hyphens {
270
- s. replace ( "-" , "_" )
271
- } else {
272
- s
273
- }
274
- } ;
275
- let filename = out_dir. join ( format ! (
276
- "{}{}{}" ,
277
- prefix,
278
- conv( stem. clone( ) ) ,
279
- suffix
280
- ) ) ;
281
- let link_dst = link_stem. clone ( ) . map ( |( ld, ls) | {
282
- ld. join ( format ! ( "{}{}{}" , prefix, conv( ls) , suffix) )
283
- } ) ;
284
- ret. push ( ( filename, link_dst, file_type) ) ;
285
- }
286
- Ok ( ( ) )
287
- }
254
+ let file_types = info. file_types (
255
+ crate_type,
256
+ flavor,
257
+ unit. target . kind ( ) ,
258
+ cx. target_triple ( ) ,
259
+ ) ?;
260
+
261
+ match file_types {
262
+ Some ( types) => for file_type in types {
263
+ let path = out_dir. join ( file_type. filename ( & file_stem) ) ;
264
+ let hardlink = link_stem
265
+ . as_ref ( )
266
+ . map ( |& ( ref ld, ref ls) | ld. join ( file_type. filename ( ls) ) ) ;
267
+ ret. push ( OutputFile {
268
+ path,
269
+ hardlink,
270
+ flavor : file_type. flavor ,
271
+ } ) ;
272
+ } ,
288
273
// not supported, don't worry about it
289
274
None => {
290
275
unsupported. push ( crate_type. to_string ( ) ) ;
291
- Ok ( ( ) )
292
276
}
293
277
}
278
+ Ok ( ( ) )
294
279
} ;
295
280
//info!("{:?}", unit);
296
281
match * unit. target . kind ( ) {
@@ -299,19 +284,19 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
299
284
| TargetKind :: ExampleBin
300
285
| TargetKind :: Bench
301
286
| TargetKind :: Test => {
302
- add ( "bin" , TargetFileType :: Normal ) ?;
287
+ add ( "bin" , FileFlavor :: Normal ) ?;
303
288
}
304
289
TargetKind :: Lib ( ..) | TargetKind :: ExampleLib ( ..) if unit. profile . test => {
305
- add ( "bin" , TargetFileType :: Normal ) ?;
290
+ add ( "bin" , FileFlavor :: Normal ) ?;
306
291
}
307
292
TargetKind :: ExampleLib ( ref kinds) | TargetKind :: Lib ( ref kinds) => {
308
293
for kind in kinds {
309
294
add (
310
295
kind. crate_type ( ) ,
311
296
if kind. linkable ( ) {
312
- TargetFileType :: Linkable
297
+ FileFlavor :: Linkable
313
298
} else {
314
- TargetFileType :: Normal
299
+ FileFlavor :: Normal
315
300
} ,
316
301
) ?;
317
302
}
@@ -450,45 +435,3 @@ fn compute_metadata<'a, 'cfg>(
450
435
}
451
436
Some ( Metadata ( hasher. finish ( ) ) )
452
437
}
453
-
454
- // (not a rustdoc)
455
- // Return a list of 3-tuples (suffix, file_type, should_replace_hyphens).
456
- //
457
- // should_replace_hyphens will be used by the caller to replace "-" with "_"
458
- // in a bin_stem. See the caller side (calc_target_filenames()) for details.
459
- fn add_target_specific_suffixes (
460
- target_triple : & str ,
461
- crate_type : & str ,
462
- target_kind : & TargetKind ,
463
- suffix : & str ,
464
- file_type : TargetFileType ,
465
- ) -> Vec < ( String , TargetFileType , bool ) > {
466
- let mut ret = vec ! [ ( suffix. to_string( ) , file_type, false ) ] ;
467
-
468
- // rust-lang/cargo#4500
469
- if target_triple. ends_with ( "pc-windows-msvc" ) && crate_type. ends_with ( "dylib" )
470
- && suffix == ".dll"
471
- {
472
- ret. push ( ( ".dll.lib" . to_string ( ) , TargetFileType :: Normal , false ) ) ;
473
- }
474
-
475
- // rust-lang/cargo#4535
476
- if target_triple. starts_with ( "wasm32-" ) && crate_type == "bin" && suffix == ".js" {
477
- ret. push ( ( ".wasm" . to_string ( ) , TargetFileType :: Normal , true ) ) ;
478
- }
479
-
480
- // rust-lang/cargo#4490, rust-lang/cargo#4960
481
- // - only uplift debuginfo for binaries.
482
- // tests are run directly from target/debug/deps/
483
- // and examples are inside target/debug/examples/ which already have symbols next to them
484
- // so no need to do anything.
485
- if * target_kind == TargetKind :: Bin {
486
- if target_triple. contains ( "-apple-" ) {
487
- ret. push ( ( ".dSYM" . to_string ( ) , TargetFileType :: DebugInfo , false ) ) ;
488
- } else if target_triple. ends_with ( "-msvc" ) {
489
- ret. push ( ( ".pdb" . to_string ( ) , TargetFileType :: DebugInfo , false ) ) ;
490
- }
491
- }
492
-
493
- ret
494
- }
0 commit comments