@@ -178,7 +178,7 @@ fn deps_of_roots<'a, 'cfg>(roots: &[Unit<'a>], mut state: &mut State<'a, 'cfg>)
178
178
} else if unit. target . is_custom_build ( ) {
179
179
// This normally doesn't happen, except `clean` aggressively
180
180
// generates all units.
181
- UnitFor :: new_build ( )
181
+ UnitFor :: new_build ( false )
182
182
} else if unit. target . for_host ( ) {
183
183
// Proc macro / plugin should never have panic set.
184
184
UnitFor :: new_compiler ( )
@@ -230,53 +230,48 @@ fn compute_deps<'a, 'cfg>(
230
230
unit_for : UnitFor ,
231
231
) -> CargoResult < Vec < UnitDep < ' a > > > {
232
232
if unit. mode . is_run_custom_build ( ) {
233
- return compute_deps_custom_build ( unit, unit_for. dep_kind ( ) , state) ;
233
+ return compute_deps_custom_build ( unit, unit_for, state) ;
234
234
} else if unit. mode . is_doc ( ) {
235
235
// Note: this does not include doc test.
236
236
return compute_deps_doc ( unit, state) ;
237
237
}
238
238
239
239
let bcx = state. bcx ;
240
240
let id = unit. pkg . package_id ( ) ;
241
- let filtered_deps = state
242
- . resolve ( )
243
- . deps ( id)
244
- . map ( |( id, deps) | {
245
- assert ! ( !deps. is_empty( ) ) ;
246
- let filtered_deps = deps. iter ( ) . filter ( |dep| {
247
- // If this target is a build command, then we only want build
248
- // dependencies, otherwise we want everything *other than* build
249
- // dependencies.
250
- if unit. target . is_custom_build ( ) != dep. is_build ( ) {
251
- return false ;
252
- }
241
+ let filtered_deps = state. resolve ( ) . deps ( id) . filter ( |& ( _id, deps) | {
242
+ assert ! ( !deps. is_empty( ) ) ;
243
+ deps. iter ( ) . any ( |dep| {
244
+ // If this target is a build command, then we only want build
245
+ // dependencies, otherwise we want everything *other than* build
246
+ // dependencies.
247
+ if unit. target . is_custom_build ( ) != dep. is_build ( ) {
248
+ return false ;
249
+ }
253
250
254
- // If this dependency is **not** a transitive dependency, then it
255
- // only applies to test/example targets.
256
- if !dep. is_transitive ( )
257
- && !unit. target . is_test ( )
258
- && !unit. target . is_example ( )
259
- && !unit. mode . is_any_test ( )
260
- {
261
- return false ;
262
- }
251
+ // If this dependency is **not** a transitive dependency, then it
252
+ // only applies to test/example targets.
253
+ if !dep. is_transitive ( )
254
+ && !unit. target . is_test ( )
255
+ && !unit. target . is_example ( )
256
+ && !unit. mode . is_any_test ( )
257
+ {
258
+ return false ;
259
+ }
263
260
264
- // If this dependency is only available for certain platforms,
265
- // make sure we're only enabling it for that platform.
266
- if !bcx. target_data . dep_platform_activated ( dep, unit. kind ) {
267
- return false ;
268
- }
261
+ // If this dependency is only available for certain platforms,
262
+ // make sure we're only enabling it for that platform.
263
+ if !bcx. target_data . dep_platform_activated ( dep, unit. kind ) {
264
+ return false ;
265
+ }
269
266
270
- // If we've gotten past all that, then this dependency is
271
- // actually used!
272
- true
273
- } ) ;
274
- ( id, filtered_deps. collect :: < Vec < _ > > ( ) )
267
+ // If we've gotten past all that, then this dependency is
268
+ // actually used!
269
+ true
275
270
} )
276
- . filter ( | ( _id , deps ) | !deps . is_empty ( ) ) ;
271
+ } ) ;
277
272
278
273
let mut ret = Vec :: new ( ) ;
279
- for ( id, deps ) in filtered_deps {
274
+ for ( id, _ ) in filtered_deps {
280
275
let pkg = match state. get ( id) ? {
281
276
Some ( pkg) => pkg,
282
277
None => continue ,
@@ -286,23 +281,10 @@ fn compute_deps<'a, 'cfg>(
286
281
None => continue ,
287
282
} ;
288
283
let mode = check_or_build_mode ( unit. mode , lib) ;
289
- let dep_kind = if unit. target . is_custom_build ( ) {
290
- // Custom build scripts can *only* have build-dependencies.
291
- DepKind :: Build
292
- } else if deps. iter ( ) . any ( |dep| !dep. is_transitive ( ) ) {
293
- // A dependency can be listed in both [dependencies] and
294
- // [dev-dependencies], so this checks if any of the deps are
295
- // listed in dev-dependencies. Note that `filtered_deps` has
296
- // already removed dev-dependencies if it is not a
297
- // test/bench/example, so it is not necessary to check `unit`
298
- // here.
299
- DepKind :: Development
300
- } else {
301
- DepKind :: Normal
302
- } ;
303
284
let dep_unit_for = unit_for
304
285
. with_for_host ( lib. for_host ( ) )
305
- . with_dep_kind ( dep_kind) ;
286
+ // If it is a custom build script, then it *only* has build dependencies.
287
+ . with_build_dep ( unit. target . is_custom_build ( ) ) ;
306
288
307
289
if bcx. config . cli_unstable ( ) . dual_proc_macros && lib. proc_macro ( ) && !unit. kind . is_host ( ) {
308
290
let unit_dep = new_unit_dep ( state, unit, pkg, lib, dep_unit_for, unit. kind , mode) ?;
@@ -330,7 +312,7 @@ fn compute_deps<'a, 'cfg>(
330
312
if unit. target . is_custom_build ( ) {
331
313
return Ok ( ret) ;
332
314
}
333
- ret. extend ( dep_build_script ( unit, unit_for. dep_kind ( ) , state) ?) ;
315
+ ret. extend ( dep_build_script ( unit, unit_for, state) ?) ;
334
316
335
317
// If this target is a binary, test, example, etc, then it depends on
336
318
// the library of the same package. The call to `resolve.deps` above
@@ -382,14 +364,9 @@ fn compute_deps<'a, 'cfg>(
382
364
///
383
365
/// The `unit` provided must represent an execution of a build script, and
384
366
/// the returned set of units must all be run before `unit` is run.
385
- ///
386
- /// `dep_kind` is the dependency kind of the package this build script is
387
- /// being built for. This ensures that the build script is built with the same
388
- /// features the package is built with (if the build script has cfg!()
389
- /// checks).
390
367
fn compute_deps_custom_build < ' a , ' cfg > (
391
368
unit : & Unit < ' a > ,
392
- dep_kind : DepKind ,
369
+ unit_for : UnitFor ,
393
370
state : & mut State < ' a , ' cfg > ,
394
371
) -> CargoResult < Vec < UnitDep < ' a > > > {
395
372
if let Some ( links) = unit. pkg . manifest ( ) . links ( ) {
@@ -400,7 +377,7 @@ fn compute_deps_custom_build<'a, 'cfg>(
400
377
}
401
378
// All dependencies of this unit should use profiles for custom
402
379
// builds.
403
- let unit_for = UnitFor :: new_build ( ) . with_dep_kind ( dep_kind ) ;
380
+ let script_unit_for = UnitFor :: new_build ( unit_for . is_for_build_dep ( ) ) ;
404
381
// When not overridden, then the dependencies to run a build script are:
405
382
//
406
383
// 1. Compiling the build script itself.
@@ -415,7 +392,7 @@ fn compute_deps_custom_build<'a, 'cfg>(
415
392
unit,
416
393
unit. pkg ,
417
394
unit. target ,
418
- unit_for ,
395
+ script_unit_for ,
419
396
// Build scripts always compiled for the host.
420
397
CompileKind :: Host ,
421
398
CompileMode :: Build ,
@@ -482,7 +459,7 @@ fn compute_deps_doc<'a, 'cfg>(
482
459
}
483
460
484
461
// Be sure to build/run the build script for documented libraries.
485
- ret. extend ( dep_build_script ( unit, DepKind :: Normal , state) ?) ;
462
+ ret. extend ( dep_build_script ( unit, UnitFor :: new_normal ( ) , state) ?) ;
486
463
487
464
// If we document a binary/example, we need the library available.
488
465
if unit. target . is_bin ( ) || unit. target . is_example ( ) {
@@ -524,7 +501,7 @@ fn maybe_lib<'a>(
524
501
/// build script.
525
502
fn dep_build_script < ' a > (
526
503
unit : & Unit < ' a > ,
527
- dep_kind : DepKind ,
504
+ unit_for : UnitFor ,
528
505
state : & State < ' a , ' _ > ,
529
506
) -> CargoResult < Option < UnitDep < ' a > > > {
530
507
unit. pkg
@@ -538,7 +515,7 @@ fn dep_build_script<'a>(
538
515
. bcx
539
516
. profiles
540
517
. get_profile_run_custom_build ( & unit. profile ) ;
541
- let script_unit_for = UnitFor :: new_build ( ) . with_dep_kind ( dep_kind ) ;
518
+ let script_unit_for = UnitFor :: new_build ( unit_for . is_for_build_dep ( ) ) ;
542
519
new_unit_dep_with_profile (
543
520
state,
544
521
unit,
@@ -609,7 +586,7 @@ fn new_unit_dep_with_profile<'a>(
609
586
let public = state
610
587
. resolve ( )
611
588
. is_public_dep ( parent. pkg . package_id ( ) , pkg. package_id ( ) ) ;
612
- let features = state. activated_features ( pkg. package_id ( ) , unit_for. dep_kind ( ) , kind ) ;
589
+ let features = state. activated_features ( pkg. package_id ( ) , unit_for. is_for_build_dep ( ) ) ;
613
590
let unit = state
614
591
. bcx
615
592
. units
@@ -714,18 +691,13 @@ impl<'a, 'cfg> State<'a, 'cfg> {
714
691
}
715
692
}
716
693
717
- fn activated_features (
718
- & self ,
719
- pkg_id : PackageId ,
720
- dep_kind : DepKind ,
721
- compile_kind : CompileKind ,
722
- ) -> Vec < InternedString > {
694
+ fn activated_features ( & self , pkg_id : PackageId , for_build_dep : bool ) -> Vec < InternedString > {
723
695
let features = if self . is_std {
724
696
self . std_features . unwrap ( )
725
697
} else {
726
698
self . usr_features
727
699
} ;
728
- features. activated_features ( pkg_id, dep_kind , compile_kind )
700
+ features. activated_features ( pkg_id, for_build_dep )
729
701
}
730
702
731
703
fn get ( & mut self , id : PackageId ) -> CargoResult < Option < & ' a Package > > {
0 commit comments