@@ -10,14 +10,14 @@ use jobserver::Client;
10
10
use crate :: core:: compiler:: { self , compilation, Unit } ;
11
11
use crate :: core:: PackageId ;
12
12
use crate :: util:: errors:: { CargoResult , CargoResultExt } ;
13
- use crate :: util:: { profile, Config } ;
13
+ use crate :: util:: profile;
14
14
15
15
use super :: build_plan:: BuildPlan ;
16
16
use super :: custom_build:: { self , BuildDeps , BuildScriptOutputs , BuildScripts } ;
17
17
use super :: fingerprint:: Fingerprint ;
18
18
use super :: job_queue:: JobQueue ;
19
19
use super :: layout:: Layout ;
20
- use super :: unit_graph:: { UnitDep , UnitGraph } ;
20
+ use super :: unit_graph:: UnitDep ;
21
21
use super :: { BuildContext , Compilation , CompileKind , CompileMode , Executor , FileFlavor } ;
22
22
23
23
mod compilation_files;
@@ -53,8 +53,6 @@ pub struct Context<'a, 'cfg> {
53
53
/// with `-p` flags. If no flags are specified, then it is the defaults
54
54
/// based on the current directory and the default workspace members.
55
55
primary_packages : HashSet < PackageId > ,
56
- /// The dependency graph of units to compile.
57
- unit_dependencies : UnitGraph < ' a > ,
58
56
/// An abstraction of the files and directories that will be generated by
59
57
/// the compilation. This is `None` until after `unit_dependencies` has
60
58
/// been computed.
@@ -78,12 +76,7 @@ pub struct Context<'a, 'cfg> {
78
76
}
79
77
80
78
impl < ' a , ' cfg > Context < ' a , ' cfg > {
81
- pub fn new (
82
- config : & ' cfg Config ,
83
- bcx : & ' a BuildContext < ' a , ' cfg > ,
84
- unit_dependencies : UnitGraph < ' a > ,
85
- default_kind : CompileKind ,
86
- ) -> CargoResult < Self > {
79
+ pub fn new ( bcx : & ' a BuildContext < ' a , ' cfg > ) -> CargoResult < Self > {
87
80
// Load up the jobserver that we'll use to manage our parallelism. This
88
81
// is the same as the GNU make implementation of a jobserver, and
89
82
// intentionally so! It's hoped that we can interact with GNU make and
@@ -92,7 +85,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
92
85
// Note that if we don't have a jobserver in our environment then we
93
86
// create our own, and we create it with `n` tokens, but immediately
94
87
// acquire one, because one token is ourself, a running process.
95
- let jobserver = match config. jobserver_from_env ( ) {
88
+ let jobserver = match bcx . config . jobserver_from_env ( ) {
96
89
Some ( c) => c. clone ( ) ,
97
90
None => {
98
91
let client = Client :: new ( bcx. build_config . jobs as usize )
@@ -106,7 +99,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
106
99
107
100
Ok ( Self {
108
101
bcx,
109
- compilation : Compilation :: new ( bcx, default_kind ) ?,
102
+ compilation : Compilation :: new ( bcx) ?,
110
103
build_script_outputs : Arc :: new ( Mutex :: new ( BuildScriptOutputs :: default ( ) ) ) ,
111
104
fingerprints : HashMap :: new ( ) ,
112
105
mtime_cache : HashMap :: new ( ) ,
@@ -115,7 +108,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
115
108
build_explicit_deps : HashMap :: new ( ) ,
116
109
jobserver,
117
110
primary_packages : HashSet :: new ( ) ,
118
- unit_dependencies,
119
111
files : None ,
120
112
rmeta_required : HashSet :: new ( ) ,
121
113
rustc_clients : HashMap :: new ( ) ,
@@ -125,21 +117,16 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
125
117
126
118
/// Starts compilation, waits for it to finish, and returns information
127
119
/// about the result of compilation.
128
- pub fn compile (
129
- mut self ,
130
- units : & [ Unit < ' a > ] ,
131
- export_dir : Option < PathBuf > ,
132
- exec : & Arc < dyn Executor > ,
133
- ) -> CargoResult < Compilation < ' cfg > > {
134
- let mut queue = JobQueue :: new ( self . bcx , units) ;
120
+ pub fn compile ( mut self , exec : & Arc < dyn Executor > ) -> CargoResult < Compilation < ' cfg > > {
121
+ let mut queue = JobQueue :: new ( self . bcx ) ;
135
122
let mut plan = BuildPlan :: new ( ) ;
136
123
let build_plan = self . bcx . build_config . build_plan ;
137
- self . prepare_units ( export_dir , units ) ?;
124
+ self . prepare_units ( ) ?;
138
125
self . prepare ( ) ?;
139
- custom_build:: build_map ( & mut self , units ) ?;
126
+ custom_build:: build_map ( & mut self ) ?;
140
127
self . check_collistions ( ) ?;
141
128
142
- for unit in units . iter ( ) {
129
+ for unit in & self . bcx . roots {
143
130
// Build up a list of pending jobs, each of which represent
144
131
// compiling a particular package. No actual work is executed as
145
132
// part of this, that's all done next as part of the `execute`
@@ -168,7 +155,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
168
155
}
169
156
170
157
// Collect the result of the build into `self.compilation`.
171
- for unit in units . iter ( ) {
158
+ for unit in & self . bcx . roots {
172
159
// Collect tests and executables.
173
160
for output in self . outputs ( unit) ?. iter ( ) {
174
161
if output. flavor == FileFlavor :: DebugInfo || output. flavor == FileFlavor :: Auxiliary
@@ -192,7 +179,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
192
179
// If the unit has a build script, add `OUT_DIR` to the
193
180
// environment variables.
194
181
if unit. target . is_lib ( ) {
195
- for dep in & self . unit_dependencies [ unit] {
182
+ for dep in & self . bcx . unit_graph [ unit] {
196
183
if dep. unit . mode . is_run_custom_build ( ) {
197
184
let out_dir = self
198
185
. files ( )
@@ -283,11 +270,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
283
270
Ok ( None )
284
271
}
285
272
286
- pub fn prepare_units (
287
- & mut self ,
288
- export_dir : Option < PathBuf > ,
289
- units : & [ Unit < ' a > ] ,
290
- ) -> CargoResult < ( ) > {
273
+ pub fn prepare_units ( & mut self ) -> CargoResult < ( ) > {
291
274
let dest = self . bcx . profiles . get_dir_name ( ) ;
292
275
let host_layout = Layout :: new ( self . bcx . ws , None , & dest) ?;
293
276
let mut targets = HashMap :: new ( ) ;
@@ -296,12 +279,11 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
296
279
targets. insert ( target, layout) ;
297
280
}
298
281
self . primary_packages
299
- . extend ( units . iter ( ) . map ( |u| u. pkg . package_id ( ) ) ) ;
282
+ . extend ( self . bcx . roots . iter ( ) . map ( |u| u. pkg . package_id ( ) ) ) ;
300
283
301
284
self . record_units_requiring_metadata ( ) ;
302
285
303
- let files =
304
- CompilationFiles :: new ( units, host_layout, targets, export_dir, self . bcx . ws , self ) ;
286
+ let files = CompilationFiles :: new ( self , host_layout, targets) ;
305
287
self . files = Some ( files) ;
306
288
Ok ( ( ) )
307
289
}
@@ -345,7 +327,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
345
327
346
328
/// Direct dependencies for the given unit.
347
329
pub fn unit_deps ( & self , unit : & Unit < ' a > ) -> & [ UnitDep < ' a > ] {
348
- & self . unit_dependencies [ unit]
330
+ & self . bcx . unit_graph [ unit]
349
331
}
350
332
351
333
/// Returns the RunCustomBuild Unit associated with the given Unit.
@@ -355,7 +337,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
355
337
if unit. mode . is_run_custom_build ( ) {
356
338
return Some ( unit) ;
357
339
}
358
- self . unit_dependencies [ & unit]
340
+ self . bcx . unit_graph [ & unit]
359
341
. iter ( )
360
342
. find ( |unit_dep| {
361
343
unit_dep. unit . mode . is_run_custom_build ( )
@@ -391,7 +373,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
391
373
// Keep sorted for consistency.
392
374
let mut inputs = BTreeSet :: new ( ) ;
393
375
// Note: dev-deps are skipped if they are not present in the unit graph.
394
- for unit in self . unit_dependencies . keys ( ) {
376
+ for unit in self . bcx . unit_graph . keys ( ) {
395
377
inputs. insert ( unit. pkg . manifest_path ( ) . to_path_buf ( ) ) ;
396
378
}
397
379
Ok ( inputs. into_iter ( ) . collect ( ) )
@@ -458,7 +440,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
458
440
} ;
459
441
460
442
let mut keys = self
461
- . unit_dependencies
443
+ . bcx
444
+ . unit_graph
462
445
. keys ( )
463
446
. filter ( |unit| !unit. mode . is_run_custom_build ( ) )
464
447
. collect :: < Vec < _ > > ( ) ;
@@ -502,7 +485,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
502
485
/// Units which depend only on the metadata of others requires the others to
503
486
/// actually produce metadata, so we'll record that here.
504
487
fn record_units_requiring_metadata ( & mut self ) {
505
- for ( key, deps) in self . unit_dependencies . iter ( ) {
488
+ for ( key, deps) in self . bcx . unit_graph . iter ( ) {
506
489
for dep in deps {
507
490
if self . only_requires_rmeta ( key, & dep. unit ) {
508
491
self . rmeta_required . insert ( dep. unit ) ;
0 commit comments