@@ -19,7 +19,6 @@ use crate::core::compiler::unit_graph::{UnitDep, UnitGraph};
19
19
use crate :: core:: compiler:: Unit ;
20
20
use crate :: core:: compiler:: { BuildContext , CompileKind , CompileMode } ;
21
21
use crate :: core:: dependency:: DepKind ;
22
- use crate :: core:: package:: Downloads ;
23
22
use crate :: core:: profiles:: { Profile , UnitFor } ;
24
23
use crate :: core:: resolver:: features:: { FeaturesFor , ResolvedFeatures } ;
25
24
use crate :: core:: resolver:: Resolve ;
@@ -31,10 +30,7 @@ use std::collections::{HashMap, HashSet};
31
30
/// Collection of stuff used while creating the `UnitGraph`.
32
31
struct State < ' a , ' cfg > {
33
32
bcx : & ' a BuildContext < ' a , ' cfg > ,
34
- waiting_on_download : HashSet < PackageId > ,
35
- downloads : Downloads < ' a , ' cfg > ,
36
33
unit_dependencies : UnitGraph < ' a > ,
37
- package_cache : HashMap < PackageId , & ' a Package > ,
38
34
usr_resolve : & ' a Resolve ,
39
35
usr_features : & ' a ResolvedFeatures ,
40
36
std_resolve : Option < & ' a Resolve > ,
@@ -58,10 +54,7 @@ pub fn build_unit_dependencies<'a, 'cfg>(
58
54
} ;
59
55
let mut state = State {
60
56
bcx,
61
- downloads : bcx. packages . enable_download ( ) ?,
62
- waiting_on_download : HashSet :: new ( ) ,
63
57
unit_dependencies : HashMap :: new ( ) ,
64
- package_cache : HashMap :: new ( ) ,
65
58
usr_resolve : resolve,
66
59
usr_features : features,
67
60
std_resolve,
@@ -141,44 +134,32 @@ fn attach_std_deps<'a, 'cfg>(
141
134
/// Compute all the dependencies of the given root units.
142
135
/// The result is stored in state.unit_dependencies.
143
136
fn deps_of_roots < ' a , ' cfg > ( roots : & [ Unit < ' a > ] , mut state : & mut State < ' a , ' cfg > ) -> CargoResult < ( ) > {
144
- // Loop because we are downloading while building the dependency graph.
145
- // The partially-built unit graph is discarded through each pass of the
146
- // loop because it is incomplete because not all required Packages have
147
- // been downloaded.
148
- loop {
149
- for unit in roots. iter ( ) {
150
- state. get ( unit. pkg . package_id ( ) ) ?;
151
-
152
- // Dependencies of tests/benches should not have `panic` set.
153
- // We check the global test mode to see if we are running in `cargo
154
- // test` in which case we ensure all dependencies have `panic`
155
- // cleared, and avoid building the lib thrice (once with `panic`, once
156
- // without, once for `--test`). In particular, the lib included for
157
- // Doc tests and examples are `Build` mode here.
158
- let unit_for = if unit. mode . is_any_test ( ) || state. bcx . build_config . test ( ) {
159
- UnitFor :: new_test ( state. bcx . config )
160
- } else if unit. target . is_custom_build ( ) {
161
- // This normally doesn't happen, except `clean` aggressively
162
- // generates all units.
163
- UnitFor :: new_host ( false )
164
- } else if unit. target . proc_macro ( ) {
165
- UnitFor :: new_host ( true )
166
- } else if unit. target . for_host ( ) {
167
- // Plugin should never have panic set.
168
- UnitFor :: new_compiler ( )
169
- } else {
170
- UnitFor :: new_normal ( )
171
- } ;
172
- deps_of ( unit, & mut state, unit_for) ?;
173
- }
174
-
175
- if !state. waiting_on_download . is_empty ( ) {
176
- state. finish_some_downloads ( ) ?;
177
- state. unit_dependencies . clear ( ) ;
137
+ for unit in roots. iter ( ) {
138
+ state. get ( unit. pkg . package_id ( ) ) ;
139
+
140
+ // Dependencies of tests/benches should not have `panic` set.
141
+ // We check the global test mode to see if we are running in `cargo
142
+ // test` in which case we ensure all dependencies have `panic`
143
+ // cleared, and avoid building the lib thrice (once with `panic`, once
144
+ // without, once for `--test`). In particular, the lib included for
145
+ // Doc tests and examples are `Build` mode here.
146
+ let unit_for = if unit. mode . is_any_test ( ) || state. bcx . build_config . test ( ) {
147
+ UnitFor :: new_test ( state. bcx . config )
148
+ } else if unit. target . is_custom_build ( ) {
149
+ // This normally doesn't happen, except `clean` aggressively
150
+ // generates all units.
151
+ UnitFor :: new_host ( false )
152
+ } else if unit. target . proc_macro ( ) {
153
+ UnitFor :: new_host ( true )
154
+ } else if unit. target . for_host ( ) {
155
+ // Plugin should never have panic set.
156
+ UnitFor :: new_compiler ( )
178
157
} else {
179
- break ;
180
- }
158
+ UnitFor :: new_normal ( )
159
+ } ;
160
+ deps_of ( unit, & mut state, unit_for) ?;
181
161
}
162
+
182
163
Ok ( ( ) )
183
164
}
184
165
@@ -269,10 +250,7 @@ fn compute_deps<'a, 'cfg>(
269
250
270
251
let mut ret = Vec :: new ( ) ;
271
252
for ( id, _) in filtered_deps {
272
- let pkg = match state. get ( id) ? {
273
- Some ( pkg) => pkg,
274
- None => continue ,
275
- } ;
253
+ let pkg = state. get ( id) ;
276
254
let lib = match pkg. targets ( ) . iter ( ) . find ( |t| t. is_lib ( ) ) {
277
255
Some ( t) => t,
278
256
None => continue ,
@@ -419,10 +397,7 @@ fn compute_deps_doc<'a, 'cfg>(
419
397
// the documentation of the library being built.
420
398
let mut ret = Vec :: new ( ) ;
421
399
for ( id, _deps) in deps {
422
- let dep = match state. get ( id) ? {
423
- Some ( dep) => dep,
424
- None => continue ,
425
- } ;
400
+ let dep = state. get ( id) ;
426
401
let lib = match dep. targets ( ) . iter ( ) . find ( |t| t. is_lib ( ) ) {
427
402
Some ( lib) => lib,
428
403
None => continue ,
@@ -730,44 +705,10 @@ impl<'a, 'cfg> State<'a, 'cfg> {
730
705
features. activated_features ( pkg_id, features_for)
731
706
}
732
707
733
- fn get ( & mut self , id : PackageId ) -> CargoResult < Option < & ' a Package > > {
734
- if let Some ( pkg) = self . package_cache . get ( & id) {
735
- return Ok ( Some ( pkg) ) ;
736
- }
737
- if !self . waiting_on_download . insert ( id) {
738
- return Ok ( None ) ;
739
- }
740
- if let Some ( pkg) = self . downloads . start ( id) ? {
741
- self . package_cache . insert ( id, pkg) ;
742
- self . waiting_on_download . remove ( & id) ;
743
- return Ok ( Some ( pkg) ) ;
744
- }
745
- Ok ( None )
746
- }
747
-
748
- /// Completes at least one downloading, maybe waiting for more to complete.
749
- ///
750
- /// This function will block the current thread waiting for at least one
751
- /// crate to finish downloading. The function may continue to download more
752
- /// crates if it looks like there's a long enough queue of crates to keep
753
- /// downloading. When only a handful of packages remain this function
754
- /// returns, and it's hoped that by returning we'll be able to push more
755
- /// packages to download into the queue.
756
- fn finish_some_downloads ( & mut self ) -> CargoResult < ( ) > {
757
- assert ! ( self . downloads. remaining( ) > 0 ) ;
758
- loop {
759
- let pkg = self . downloads . wait ( ) ?;
760
- self . waiting_on_download . remove ( & pkg. package_id ( ) ) ;
761
- self . package_cache . insert ( pkg. package_id ( ) , pkg) ;
762
-
763
- // Arbitrarily choose that 5 or more packages concurrently download
764
- // is a good enough number to "fill the network pipe". If we have
765
- // less than this let's recompute the whole unit dependency graph
766
- // again and try to find some more packages to download.
767
- if self . downloads . remaining ( ) < 5 {
768
- break ;
769
- }
770
- }
771
- Ok ( ( ) )
708
+ fn get ( & self , id : PackageId ) -> & ' a Package {
709
+ self . bcx
710
+ . packages
711
+ . get_one ( id)
712
+ . unwrap_or_else ( |_| panic ! ( "expected {} to be downloaded" , id) )
772
713
}
773
714
}
0 commit comments