1818use std:: cell:: RefCell ;
1919use std:: collections:: { HashMap , HashSet } ;
2020
21- use CargoResult ;
21+ use super :: { BuildContext , CompileMode , Kind , Unit } ;
2222use core:: dependency:: Kind as DepKind ;
23- use core:: profiles:: UnitFor ;
24- use core:: { Package , Target , PackageId } ;
2523use core:: package:: Downloads ;
26- use super :: { BuildContext , CompileMode , Kind , Unit } ;
24+ use core:: profiles:: UnitFor ;
25+ use core:: { Package , PackageId , Target } ;
26+ use CargoResult ;
2727
2828struct State < ' a : ' tmp , ' cfg : ' a , ' tmp > {
2929 bcx : & ' tmp BuildContext < ' a , ' cfg > ,
@@ -74,11 +74,11 @@ pub fn build_unit_dependencies<'a, 'cfg>(
7474 deps_of ( unit, & mut state, unit_for) ?;
7575 }
7676
77- if state. waiting_on_download . len ( ) > 0 {
77+ if ! state. waiting_on_download . is_empty ( ) {
7878 state. finish_some_downloads ( ) ?;
7979 state. deps . clear ( ) ;
8080 } else {
81- break
81+ break ;
8282 }
8383 }
8484 trace ! ( "ALL UNIT DEPENDENCIES {:#?}" , state. deps) ;
@@ -128,46 +128,43 @@ fn compute_deps<'a, 'cfg, 'tmp>(
128128
129129 let bcx = state. bcx ;
130130 let id = unit. pkg . package_id ( ) ;
131- let deps = bcx. resolve . deps ( id)
132- . filter ( |& ( _id, deps) | {
133- assert ! ( !deps. is_empty( ) ) ;
134- deps. iter ( ) . any ( |dep| {
135- // If this target is a build command, then we only want build
136- // dependencies, otherwise we want everything *other than* build
137- // dependencies.
138- if unit. target . is_custom_build ( ) != dep. is_build ( ) {
139- return false ;
140- }
131+ let deps = bcx. resolve . deps ( id) . filter ( |& ( _id, deps) | {
132+ assert ! ( !deps. is_empty( ) ) ;
133+ deps. iter ( ) . any ( |dep| {
134+ // If this target is a build command, then we only want build
135+ // dependencies, otherwise we want everything *other than* build
136+ // dependencies.
137+ if unit. target . is_custom_build ( ) != dep. is_build ( ) {
138+ return false ;
139+ }
141140
142- // If this dependency is *not* a transitive dependency, then it
143- // only applies to test/example targets
144- if !dep. is_transitive ( ) &&
145- !unit. target . is_test ( ) &&
146- !unit. target . is_example ( ) &&
147- !unit. mode . is_any_test ( )
148- {
149- return false ;
150- }
141+ // If this dependency is *not* a transitive dependency, then it
142+ // only applies to test/example targets
143+ if !dep. is_transitive ( )
144+ && !unit. target . is_test ( )
145+ && !unit. target . is_example ( )
146+ && !unit. mode . is_any_test ( )
147+ {
148+ return false ;
149+ }
151150
152- // If this dependency is only available for certain platforms,
153- // make sure we're only enabling it for that platform.
154- if !bcx. dep_platform_activated ( dep, unit. kind ) {
155- return false ;
156- }
151+ // If this dependency is only available for certain platforms,
152+ // make sure we're only enabling it for that platform.
153+ if !bcx. dep_platform_activated ( dep, unit. kind ) {
154+ return false ;
155+ }
157156
158- // If the dependency is optional, then we're only activating it
159- // if the corresponding feature was activated
160- if dep. is_optional ( ) &&
161- !bcx. resolve . features ( id) . contains ( & * dep. name_in_toml ( ) )
162- {
163- return false ;
164- }
157+ // If the dependency is optional, then we're only activating it
158+ // if the corresponding feature was activated
159+ if dep. is_optional ( ) && !bcx. resolve . features ( id) . contains ( & * dep. name_in_toml ( ) ) {
160+ return false ;
161+ }
165162
166- // If we've gotten past all that, then this dependency is
167- // actually used!
168- true
169- } )
170- } ) ;
163+ // If we've gotten past all that, then this dependency is
164+ // actually used!
165+ true
166+ } )
167+ } ) ;
171168
172169 let mut ret = Vec :: new ( ) ;
173170 for ( id, _) in deps {
@@ -181,14 +178,7 @@ fn compute_deps<'a, 'cfg, 'tmp>(
181178 } ;
182179 let mode = check_or_build_mode ( unit. mode , lib) ;
183180 let dep_unit_for = unit_for. with_for_host ( lib. for_host ( ) ) ;
184- let unit = new_unit (
185- bcx,
186- pkg,
187- lib,
188- dep_unit_for,
189- unit. kind . for_target ( lib) ,
190- mode,
191- ) ;
181+ let unit = new_unit ( bcx, pkg, lib, dep_unit_for, unit. kind . for_target ( lib) , mode) ;
192182 ret. push ( ( unit, dep_unit_for) ) ;
193183 }
194184
@@ -211,7 +201,8 @@ fn compute_deps<'a, 'cfg, 'tmp>(
211201
212202 // If any integration tests/benches are being run, make sure that
213203 // binaries are built as well.
214- if !unit. mode . is_check ( ) && unit. mode . is_any_test ( )
204+ if !unit. mode . is_check ( )
205+ && unit. mode . is_any_test ( )
215206 && ( unit. target . is_test ( ) || unit. target . is_bench ( ) )
216207 {
217208 ret. extend (
@@ -282,7 +273,8 @@ fn compute_deps_doc<'a, 'cfg, 'tmp>(
282273 state : & mut State < ' a , ' cfg , ' tmp > ,
283274) -> CargoResult < Vec < ( Unit < ' a > , UnitFor ) > > {
284275 let bcx = state. bcx ;
285- let deps = bcx. resolve
276+ let deps = bcx
277+ . resolve
286278 . deps ( unit. pkg . package_id ( ) )
287279 . filter ( |& ( _id, deps) | {
288280 deps. iter ( ) . any ( |dep| match dep. kind ( ) {
@@ -308,14 +300,7 @@ fn compute_deps_doc<'a, 'cfg, 'tmp>(
308300 // However, for plugins/proc-macros, deps should be built like normal.
309301 let mode = check_or_build_mode ( unit. mode , lib) ;
310302 let dep_unit_for = UnitFor :: new_normal ( ) . with_for_host ( lib. for_host ( ) ) ;
311- let lib_unit = new_unit (
312- bcx,
313- dep,
314- lib,
315- dep_unit_for,
316- unit. kind . for_target ( lib) ,
317- mode,
318- ) ;
303+ let lib_unit = new_unit ( bcx, dep, lib, dep_unit_for, unit. kind . for_target ( lib) , mode) ;
319304 ret. push ( ( lib_unit, dep_unit_for) ) ;
320305 if let CompileMode :: Doc { deps : true } = unit. mode {
321306 // Document this lib as well.
@@ -348,14 +333,7 @@ fn maybe_lib<'a>(
348333) -> Option < ( Unit < ' a > , UnitFor ) > {
349334 unit. pkg . targets ( ) . iter ( ) . find ( |t| t. linkable ( ) ) . map ( |t| {
350335 let mode = check_or_build_mode ( unit. mode , t) ;
351- let unit = new_unit (
352- bcx,
353- unit. pkg ,
354- t,
355- unit_for,
356- unit. kind . for_target ( t) ,
357- mode,
358- ) ;
336+ let unit = new_unit ( bcx, unit. pkg , t, unit_for, unit. kind . for_target ( t) , mode) ;
359337 ( unit, unit_for)
360338 } )
361339}
@@ -453,7 +431,8 @@ fn connect_run_custom_build_deps(state: &mut State) {
453431 for ( unit, deps) in state. deps . iter ( ) {
454432 for dep in deps {
455433 if dep. mode == CompileMode :: RunCustomBuild {
456- reverse_deps. entry ( dep)
434+ reverse_deps
435+ . entry ( dep)
457436 . or_insert_with ( HashSet :: new)
458437 . insert ( unit) ;
459438 }
@@ -469,7 +448,11 @@ fn connect_run_custom_build_deps(state: &mut State) {
469448 // `links`, then we depend on that package's build script! Here we use
470449 // `dep_build_script` to manufacture an appropriate build script unit to
471450 // depend on.
472- for unit in state. deps . keys ( ) . filter ( |k| k. mode == CompileMode :: RunCustomBuild ) {
451+ for unit in state
452+ . deps
453+ . keys ( )
454+ . filter ( |k| k. mode == CompileMode :: RunCustomBuild )
455+ {
473456 let reverse_deps = match reverse_deps. get ( unit) {
474457 Some ( set) => set,
475458 None => continue ,
@@ -479,9 +462,9 @@ fn connect_run_custom_build_deps(state: &mut State) {
479462 . iter ( )
480463 . flat_map ( |reverse_dep| state. deps [ reverse_dep] . iter ( ) )
481464 . filter ( |other| {
482- other. pkg != unit. pkg &&
483- other. target . linkable ( ) &&
484- other. pkg . manifest ( ) . links ( ) . is_some ( )
465+ other. pkg != unit. pkg
466+ && other. target . linkable ( )
467+ && other. pkg . manifest ( ) . links ( ) . is_some ( )
485468 } )
486469 . filter_map ( |other| dep_build_script ( other, state. bcx ) . map ( |p| p. 0 ) )
487470 . collect :: < HashSet < _ > > ( ) ;
@@ -502,15 +485,15 @@ impl<'a, 'cfg, 'tmp> State<'a, 'cfg, 'tmp> {
502485 fn get ( & mut self , id : & ' a PackageId ) -> CargoResult < Option < & ' a Package > > {
503486 let mut pkgs = self . pkgs . borrow_mut ( ) ;
504487 if let Some ( pkg) = pkgs. get ( id) {
505- return Ok ( Some ( pkg) )
488+ return Ok ( Some ( pkg) ) ;
506489 }
507490 if !self . waiting_on_download . insert ( id) {
508- return Ok ( None )
491+ return Ok ( None ) ;
509492 }
510493 if let Some ( pkg) = self . downloads . start ( id) ? {
511494 pkgs. insert ( id, pkg) ;
512495 self . waiting_on_download . remove ( id) ;
513- return Ok ( Some ( pkg) )
496+ return Ok ( Some ( pkg) ) ;
514497 }
515498 Ok ( None )
516499 }
@@ -535,7 +518,7 @@ impl<'a, 'cfg, 'tmp> State<'a, 'cfg, 'tmp> {
535518 // less than this let's recompute the whole unit dependency graph
536519 // again and try to find some more packages to download.
537520 if self . downloads . remaining ( ) < 5 {
538- break
521+ break ;
539522 }
540523 }
541524 Ok ( ( ) )
0 commit comments