@@ -3,7 +3,7 @@ use std::collections::{HashMap, HashSet};
3
3
use std:: ffi:: OsStr ;
4
4
use std:: fmt:: Write ;
5
5
use std:: path:: PathBuf ;
6
- use std:: sync:: Arc ;
6
+ use std:: sync:: { Arc , Mutex } ;
7
7
8
8
use filetime:: FileTime ;
9
9
use jobserver:: Client ;
@@ -15,7 +15,7 @@ use crate::util::errors::{CargoResult, CargoResultExt};
15
15
use crate :: util:: { internal, profile, Config } ;
16
16
17
17
use super :: build_plan:: BuildPlan ;
18
- use super :: custom_build:: { self , BuildDeps , BuildScripts , BuildState } ;
18
+ use super :: custom_build:: { self , BuildDeps , BuildScriptOutputs , BuildScripts } ;
19
19
use super :: fingerprint:: Fingerprint ;
20
20
use super :: job_queue:: JobQueue ;
21
21
use super :: layout:: Layout ;
@@ -28,21 +28,45 @@ mod compilation_files;
28
28
use self :: compilation_files:: CompilationFiles ;
29
29
pub use self :: compilation_files:: { Metadata , OutputFile } ;
30
30
31
+ /// Collection of all the stuff that is needed to perform a build.
31
32
pub struct Context < ' a , ' cfg > {
33
+ /// Mostly static information about the build task.
32
34
pub bcx : & ' a BuildContext < ' a , ' cfg > ,
35
+ /// A large collection of information about the result of the entire compilation.
33
36
pub compilation : Compilation < ' cfg > ,
34
- pub build_state : Arc < BuildState > ,
35
- pub build_script_overridden : HashSet < ( PackageId , Kind ) > ,
37
+ /// Output from build scripts, updated after each build script runs.
38
+ pub build_script_outputs : Arc < Mutex < BuildScriptOutputs > > ,
39
+ /// Dependencies (like rerun-if-changed) declared by a build script.
40
+ /// This is *only* populated from the output from previous runs.
41
+ /// If the build script hasn't ever been run, then it must be run.
36
42
pub build_explicit_deps : HashMap < Unit < ' a > , BuildDeps > ,
43
+ /// Fingerprints used to detect if a unit is out-of-date.
37
44
pub fingerprints : HashMap < Unit < ' a > , Arc < Fingerprint > > ,
45
+ /// Cache of file mtimes to reduce filesystem hits.
38
46
pub mtime_cache : HashMap < PathBuf , FileTime > ,
47
+ /// A set used to track which units have been compiled.
48
+ /// A unit may appear in the job graph multiple times as a dependency of
49
+ /// multiple packages, but it only needs to run once.
39
50
pub compiled : HashSet < Unit < ' a > > ,
51
+ /// Linking information for each `Unit`.
52
+ /// See `build_map` for details.
40
53
pub build_scripts : HashMap < Unit < ' a > , Arc < BuildScripts > > ,
54
+ /// Used to check the `links` field in the manifest is not duplicated and
55
+ /// is used correctly.
41
56
pub links : Links ,
57
+ /// Job server client to manage concurrency with other processes.
42
58
pub jobserver : Client ,
59
+ /// "Primary" packages are the ones the user selected on the command-line
60
+ /// with `-p` flags. If no flags are specified, then it is the defaults
61
+ /// based on the current directory and the default workspace members.
43
62
primary_packages : HashSet < PackageId > ,
63
+ /// The dependency graph of units to compile.
44
64
unit_dependencies : HashMap < Unit < ' a > , Vec < Unit < ' a > > > ,
65
+ /// An abstraction of the files and directories that will be generated by
66
+ /// the compilation. This is `None` until after `unit_dependencies` has
67
+ /// been computed.
45
68
files : Option < CompilationFiles < ' a , ' cfg > > ,
69
+ /// Cache of packages, populated when they are downloaded.
46
70
package_cache : HashMap < PackageId , & ' a Package > ,
47
71
48
72
/// A flag indicating whether pipelining is enabled for this compilation
@@ -82,16 +106,14 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
82
106
Ok ( Self {
83
107
bcx,
84
108
compilation : Compilation :: new ( bcx) ?,
85
- build_state : Arc :: new ( BuildState :: new ( & bcx . host_config , & bcx . target_config ) ) ,
109
+ build_script_outputs : Arc :: new ( Mutex :: new ( BuildScriptOutputs :: default ( ) ) ) ,
86
110
fingerprints : HashMap :: new ( ) ,
87
111
mtime_cache : HashMap :: new ( ) ,
88
112
compiled : HashSet :: new ( ) ,
89
113
build_scripts : HashMap :: new ( ) ,
90
114
build_explicit_deps : HashMap :: new ( ) ,
91
115
links : Links :: new ( ) ,
92
116
jobserver,
93
- build_script_overridden : HashSet :: new ( ) ,
94
-
95
117
primary_packages : HashSet :: new ( ) ,
96
118
unit_dependencies : HashMap :: new ( ) ,
97
119
files : None ,
@@ -228,7 +250,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
228
250
super :: output_depinfo ( & mut self , unit) ?;
229
251
}
230
252
231
- for ( & ( ref pkg, _) , output) in self . build_state . outputs . lock ( ) . unwrap ( ) . iter ( ) {
253
+ for ( & ( ref pkg, _) , output) in self . build_script_outputs . lock ( ) . unwrap ( ) . iter ( ) {
232
254
self . compilation
233
255
. cfgs
234
256
. entry ( pkg. clone ( ) )
@@ -338,22 +360,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
338
360
//
339
361
// TODO: this ideally should be `-> &[Unit<'a>]`.
340
362
pub fn dep_targets ( & self , unit : & Unit < ' a > ) -> Vec < Unit < ' a > > {
341
- // If this build script's execution has been overridden then we don't
342
- // actually depend on anything, we've reached the end of the dependency
343
- // chain as we've got all the info we're gonna get.
344
- //
345
- // Note there's a subtlety about this piece of code! The
346
- // `build_script_overridden` map here is populated in
347
- // `custom_build::build_map` which you need to call before inspecting
348
- // dependencies. However, that code itself calls this method and
349
- // gets a full pre-filtered set of dependencies. This is not super
350
- // obvious, and clear, but it does work at the moment.
351
- if unit. target . is_custom_build ( ) {
352
- let key = ( unit. pkg . package_id ( ) , unit. kind ) ;
353
- if self . build_script_overridden . contains ( & key) {
354
- return Vec :: new ( ) ;
355
- }
356
- }
357
363
self . unit_dependencies [ unit] . clone ( )
358
364
}
359
365
0 commit comments