1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//! The assembly: from a target graph, and what the ports report, to one plan.
//!
//! Its own file because it is where this phase's steps meet and where their order is fixed:
//! read the manifest, check the overrides, place every output, check every want of a plugin's
//! targets against its plugins, check every want against the ceiling, refuse a variable the
//! strategy pins, and only then ask the machine anything — find the tools, digest the inputs,
//! read the environment — before keying every target and comparing each key with the one its
//! last build recorded. The plugins behind the wants are named from the same graph once the
//! ceiling has passed.
//!
//! Responsibilities: [`plan`].
//!
//! Non-responsibilities: what each step decides. Each has its own sibling file.
//!
//! This file holds no test module: it only passes values between its siblings and the ports,
//! so it is exercised by the crate's integration tests, against in-memory ports.
use BTreeMap;
use crateResult;
use crateattribution;
use cratesites;
use crateLayout;
use crate;
use crate;
use cratedigests;
use cratetopological;
use cratepinned;
use crateeffective;
use crate;
use crateverdict;
use crate;
use crate;
/// Plans a build of `graph`: one verdict per target, what the build wants, and the settings in
/// force.
///
/// `overrides` gives values to build settings for this run: the plan holds every setting `graph`
/// declares with its override, or else its default, and nothing after the plan reads an override
/// again. Every target is given an action key from its command, the digests of its inputs, its
/// environment, the tool it runs, the settings it names, the platform, and what its dependencies
/// produced; the key is compared with the one the target's last build recorded. A target is
/// clean when the two are equal, dirty when they differ, and conditional when all that could
/// still differ is the output of a dependency that is about to run. When `rerun` asks for the
/// tests to run again, a test not declared to always run is dirty with
/// [`DirtyReason::Rerun`](crate::DirtyReason::Rerun) whatever its key, and every other target is
/// judged as before.
///
/// The tool a target runs is the program its command's first argument names once each `$opt:`
/// reference in it is replaced by the setting's value for this run. So a program named through
/// a setting is looked up and keyed exactly as one written out. A first argument that still
/// holds a `$` after that, as one running what the build produced does, names no tool here.
///
/// Every program a command runs is held to the ceiling, whichever way it is named: written out,
/// through a setting, or through `$in` or `$out`. A program one of the target's dependencies
/// builds, written out, named through a setting or taken from `$deps`, is held to nothing, and
/// is neither looked up nor part of the key.
///
/// Nothing runs. The one thing a plan writes is the stat cache, and only when it had to hash a
/// file.
///
/// # Errors
///
/// Returns the first failure met, in this order:
///
/// 1. whatever the manifest port returns;
/// 2. [`Error::UnknownOverride`](crate::Error::UnknownOverride) for an override naming no
/// declared setting;
/// 3. [`Error::OutputConflict`](crate::Error::OutputConflict) for two outputs of the planned
/// graph that would be written to one place;
/// 4. [`Error::PluginRefused`](crate::Error::PluginRefused) for a want of a plugin's target that
/// one of the plugins holding it does not allow;
/// 5. [`Error::Refused`](crate::Error::Refused) for a want outside the workspace's ceiling,
/// a program named through `$in`, `$out` or `$deps` included; nothing is asked of any other
/// port before this check has passed;
/// 6. [`Error::PinnedEnv`](crate::Error::PinnedEnv) for a target that declares a variable the
/// workspace's strategy pins;
/// 7. [`Error::MissingTool`](crate::Error::MissingTool) for a program that cannot be found;
/// 8. [`Error::MissingInput`](crate::Error::MissingInput) for an input that does not exist, and
/// [`Error::InputNotAFile`](crate::Error::InputNotAFile) for one that is not a regular file;
/// 9. [`Error::MachinePathInSetting`](crate::Error::MachinePathInSetting) for a setting a command
/// names whose value holds one of the host's folders, then whatever the host port returns for
/// an environment variable, or
/// [`Error::MachinePathInVariable`](crate::Error::MachinePathInVariable) for a `key` variable
/// whose value holds one.
///
/// A port's own failure is returned from the step that met it.