@@ -10,14 +10,14 @@ use jobserver::Client;
1010use crate :: core:: compiler:: { self , compilation, Unit } ;
1111use crate :: core:: PackageId ;
1212use crate :: util:: errors:: { CargoResult , CargoResultExt } ;
13- use crate :: util:: { profile, Config } ;
13+ use crate :: util:: profile;
1414
1515use super :: build_plan:: BuildPlan ;
1616use super :: custom_build:: { self , BuildDeps , BuildScriptOutputs , BuildScripts } ;
1717use super :: fingerprint:: Fingerprint ;
1818use super :: job_queue:: JobQueue ;
1919use super :: layout:: Layout ;
20- use super :: unit_graph:: { UnitDep , UnitGraph } ;
20+ use super :: unit_graph:: UnitDep ;
2121use super :: { BuildContext , Compilation , CompileKind , CompileMode , Executor , FileFlavor } ;
2222
2323mod compilation_files;
@@ -53,8 +53,6 @@ pub struct Context<'a, 'cfg> {
5353 /// with `-p` flags. If no flags are specified, then it is the defaults
5454 /// based on the current directory and the default workspace members.
5555 primary_packages : HashSet < PackageId > ,
56- /// The dependency graph of units to compile.
57- unit_dependencies : UnitGraph < ' a > ,
5856 /// An abstraction of the files and directories that will be generated by
5957 /// the compilation. This is `None` until after `unit_dependencies` has
6058 /// been computed.
@@ -78,12 +76,7 @@ pub struct Context<'a, 'cfg> {
7876}
7977
8078impl < ' 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 > {
8780 // Load up the jobserver that we'll use to manage our parallelism. This
8881 // is the same as the GNU make implementation of a jobserver, and
8982 // intentionally so! It's hoped that we can interact with GNU make and
@@ -92,7 +85,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
9285 // Note that if we don't have a jobserver in our environment then we
9386 // create our own, and we create it with `n` tokens, but immediately
9487 // 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 ( ) {
9689 Some ( c) => c. clone ( ) ,
9790 None => {
9891 let client = Client :: new ( bcx. build_config . jobs as usize )
@@ -106,7 +99,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
10699
107100 Ok ( Self {
108101 bcx,
109- compilation : Compilation :: new ( bcx, default_kind ) ?,
102+ compilation : Compilation :: new ( bcx) ?,
110103 build_script_outputs : Arc :: new ( Mutex :: new ( BuildScriptOutputs :: default ( ) ) ) ,
111104 fingerprints : HashMap :: new ( ) ,
112105 mtime_cache : HashMap :: new ( ) ,
@@ -115,7 +108,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
115108 build_explicit_deps : HashMap :: new ( ) ,
116109 jobserver,
117110 primary_packages : HashSet :: new ( ) ,
118- unit_dependencies,
119111 files : None ,
120112 rmeta_required : HashSet :: new ( ) ,
121113 rustc_clients : HashMap :: new ( ) ,
@@ -125,21 +117,16 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
125117
126118 /// Starts compilation, waits for it to finish, and returns information
127119 /// 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 ) ;
135122 let mut plan = BuildPlan :: new ( ) ;
136123 let build_plan = self . bcx . build_config . build_plan ;
137- self . prepare_units ( export_dir , units ) ?;
124+ self . prepare_units ( ) ?;
138125 self . prepare ( ) ?;
139- custom_build:: build_map ( & mut self , units ) ?;
126+ custom_build:: build_map ( & mut self ) ?;
140127 self . check_collistions ( ) ?;
141128
142- for unit in units . iter ( ) {
129+ for unit in & self . bcx . roots {
143130 // Build up a list of pending jobs, each of which represent
144131 // compiling a particular package. No actual work is executed as
145132 // part of this, that's all done next as part of the `execute`
@@ -168,7 +155,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
168155 }
169156
170157 // Collect the result of the build into `self.compilation`.
171- for unit in units . iter ( ) {
158+ for unit in & self . bcx . roots {
172159 // Collect tests and executables.
173160 for output in self . outputs ( unit) ?. iter ( ) {
174161 if output. flavor == FileFlavor :: DebugInfo || output. flavor == FileFlavor :: Auxiliary
@@ -192,7 +179,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
192179 // If the unit has a build script, add `OUT_DIR` to the
193180 // environment variables.
194181 if unit. target . is_lib ( ) {
195- for dep in & self . unit_dependencies [ unit] {
182+ for dep in & self . bcx . unit_graph [ unit] {
196183 if dep. unit . mode . is_run_custom_build ( ) {
197184 let out_dir = self
198185 . files ( )
@@ -283,11 +270,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
283270 Ok ( None )
284271 }
285272
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 < ( ) > {
291274 let dest = self . bcx . profiles . get_dir_name ( ) ;
292275 let host_layout = Layout :: new ( self . bcx . ws , None , & dest) ?;
293276 let mut targets = HashMap :: new ( ) ;
@@ -296,12 +279,11 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
296279 targets. insert ( target, layout) ;
297280 }
298281 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 ( ) ) ) ;
300283
301284 self . record_units_requiring_metadata ( ) ;
302285
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) ;
305287 self . files = Some ( files) ;
306288 Ok ( ( ) )
307289 }
@@ -345,7 +327,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
345327
346328 /// Direct dependencies for the given unit.
347329 pub fn unit_deps ( & self , unit : & Unit < ' a > ) -> & [ UnitDep < ' a > ] {
348- & self . unit_dependencies [ unit]
330+ & self . bcx . unit_graph [ unit]
349331 }
350332
351333 /// Returns the RunCustomBuild Unit associated with the given Unit.
@@ -355,7 +337,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
355337 if unit. mode . is_run_custom_build ( ) {
356338 return Some ( unit) ;
357339 }
358- self . unit_dependencies [ & unit]
340+ self . bcx . unit_graph [ & unit]
359341 . iter ( )
360342 . find ( |unit_dep| {
361343 unit_dep. unit . mode . is_run_custom_build ( )
@@ -391,7 +373,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
391373 // Keep sorted for consistency.
392374 let mut inputs = BTreeSet :: new ( ) ;
393375 // 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 ( ) {
395377 inputs. insert ( unit. pkg . manifest_path ( ) . to_path_buf ( ) ) ;
396378 }
397379 Ok ( inputs. into_iter ( ) . collect ( ) )
@@ -458,7 +440,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
458440 } ;
459441
460442 let mut keys = self
461- . unit_dependencies
443+ . bcx
444+ . unit_graph
462445 . keys ( )
463446 . filter ( |unit| !unit. mode . is_run_custom_build ( ) )
464447 . collect :: < Vec < _ > > ( ) ;
@@ -502,7 +485,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
502485 /// Units which depend only on the metadata of others requires the others to
503486 /// actually produce metadata, so we'll record that here.
504487 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 ( ) {
506489 for dep in deps {
507490 if self . only_requires_rmeta ( key, & dep. unit ) {
508491 self . rmeta_required . insert ( dep. unit ) ;
0 commit comments