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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
//! The bundle that names one implementation of every port a pipeline uses.
//!
//! Its own file because it is a different kind of trait from the ports themselves: it has no
//! methods, only associated types, and it exists so that a pipeline takes one type parameter
//! instead of one per port.
//!
//! Responsibilities: [`Ports`].
//!
//! Non-responsibilities: choosing the implementations. A composition root does that, by
//! implementing this trait.
//!
//! This file holds only a trait definition, so it carries no logic to unit-test.
use crate;
/// One implementation of each port, chosen together.
///
/// # Examples
///
/// A bundle for a workspace with no build files, on a machine with nothing in it:
///
/// ```
/// use std::collections::BTreeSet;
/// use std::sync::{Mutex, PoisonError};
///
/// use buildl_core::{
/// ActionCache, Approval, Approver, Attribution, BuildFile, CacheRow, Captured, Ceiling,
/// Channel, Clock, ContentStore, DeclarationSource, Diagnostic, Digest, Digester, Directory,
/// Discovered, Dispatcher, EnvName, EnvValue, Error, Evaluated, EventLog, ExecStrategy,
/// FileMode, Found, GraphRecord, Host, InputStat, Label, LiveSink, LogLine, Manifest,
/// NoRemote, NothingIgnored, OutcomeEvent, OutputPath, Platform, PortName, Ports, Program,
/// RawOutcome, ReadyAction, RemoteNotice, Reporter, Result, RunHistory, SourcePath, StatCache,
/// StatEntry, Summary, TargetGraph, Timestamp, ToolResolver, Turn, WantedSet, Workspace,
/// };
///
/// /// Every port at once, each answering that there is nothing.
/// struct Nothing;
///
/// /// The failure of a port that has nothing to work with.
/// fn nothing(port: PortName) -> Error {
/// Error::Adapter {
/// port,
/// diagnostic: Diagnostic::new("there is nothing here"),
/// }
/// }
///
/// impl DeclarationSource for Nothing {
/// fn evaluate(&self, _file: &BuildFile, _discovered: &Discovered) -> Result<Evaluated> {
/// Ok(Evaluated::Absent)
/// }
/// }
///
/// impl Manifest for Nothing {
/// fn workspace(&self) -> Result<Workspace> {
/// Ok(Workspace {
/// out: Directory::parse("out")?,
/// state: Directory::parse(".buildl")?,
/// ceiling: Ceiling {
/// run: BTreeSet::new(),
/// env: BTreeSet::new(),
/// unkeyed: BTreeSet::new(),
/// read: BTreeSet::new(),
/// write: BTreeSet::new(),
/// },
/// execution: buildl_core::Execution::default(),
/// approver: buildl_core::ApproverMode::Manifest,
/// plugins: std::collections::BTreeMap::new(),
/// remote: None,
/// })
/// }
/// }
///
/// impl Host for Nothing {
/// fn platform(&self) -> Platform {
/// Platform::parse("linux/x86_64").unwrap_or_else(|_| unreachable!("a valid platform"))
/// }
///
/// fn env(&self, _name: &EnvName) -> Result<Option<EnvValue>> {
/// Ok(None)
/// }
///
/// fn machine_folders(&self) -> buildl_core::MachineFolders {
/// buildl_core::MachineFolders::default()
/// }
/// }
///
/// impl Digester for Nothing {
/// fn stat(&self, _path: &SourcePath) -> Result<InputStat> {
/// Ok(InputStat::Missing)
/// }
///
/// fn digest(&self, _paths: &[SourcePath]) -> Result<Vec<Digest>> {
/// Ok(Vec::new())
/// }
/// }
///
/// impl StatCache for Nothing {
/// fn entry(&self, _path: &SourcePath) -> Option<StatEntry> {
/// None
/// }
///
/// fn record(&mut self, _path: SourcePath, _entry: StatEntry) {}
///
/// fn commit(&mut self) -> Result<()> {
/// Ok(())
/// }
/// }
///
/// impl ToolResolver for Nothing {
/// fn fingerprint(&self, _program: &Program) -> Result<Option<Digest>> {
/// Ok(None)
/// }
/// }
///
/// impl ActionCache for Nothing {
/// fn row(&self, _label: &Label) -> Option<&CacheRow> {
/// None
/// }
///
/// fn labels(&self) -> Vec<Label> {
/// Vec::new()
/// }
///
/// fn record(&mut self, _label: Label, _row: CacheRow) -> Result<()> {
/// Err(nothing(PortName::ActionCache))
/// }
///
/// fn forget(&mut self, _label: &Label) -> Result<()> {
/// Ok(())
/// }
/// }
///
/// impl ContentStore for Nothing {
/// fn put(&self, _bytes: &[u8]) -> Result<Digest> {
/// Err(nothing(PortName::ContentStore))
/// }
///
/// fn contains(&self, _digest: &Digest) -> bool {
/// false
/// }
///
/// fn get(&self, _digest: &Digest) -> Result<Option<Vec<u8>>> {
/// Ok(None)
/// }
///
/// fn clear(&self, _at: &OutputPath) -> Result<()> {
/// Err(nothing(PortName::ContentStore))
/// }
///
/// fn place(&self, _digest: &Digest, _mode: FileMode, _at: &OutputPath) -> Result<()> {
/// Err(nothing(PortName::ContentStore))
/// }
/// }
///
/// impl EventLog for Nothing {
/// fn append(&mut self, _event: &OutcomeEvent) -> Result<()> {
/// Err(nothing(PortName::EventLog))
/// }
/// }
///
/// impl RunHistory for Nothing {
/// fn lines(&self) -> Result<Vec<LogLine>> {
/// Err(nothing(PortName::RunHistory))
/// }
/// }
///
/// impl ExecStrategy for Nothing {
/// type Dir = ();
///
/// fn prepare(&self, _action: &ReadyAction) -> Result<()> {
/// Err(nothing(PortName::ExecStrategy))
/// }
///
/// fn run(
/// &self,
/// _dir: &(),
/// _action: &ReadyAction,
/// _live: Option<LiveSink<'_>>,
/// ) -> Result<RawOutcome> {
/// Err(nothing(PortName::ExecStrategy))
/// }
///
/// fn collect<C: ContentStore>(
/// &self,
/// _dir: &(),
/// _action: &ReadyAction,
/// _cas: &C,
/// ) -> Result<Vec<Found>> {
/// Err(nothing(PortName::ExecStrategy))
/// }
/// }
///
/// /// Runs every task on the calling thread, one at a time, and hands over what a task said
/// /// once the task is done.
/// impl Dispatcher for Nothing {
/// fn dispatch<T, M, R, W, S>(&mut self, work: W, mut step: S) -> Result<()>
/// where
/// T: Send,
/// M: Send,
/// R: Send,
/// W: Fn(T, &(dyn Fn(M) + Sync)) -> R + Sync,
/// S: FnMut(Turn<M, R>) -> Vec<T>,
/// {
/// let mut waiting = step(Turn::Begin);
/// while let Some(task) = waiting.pop() {
/// let said = Mutex::new(Vec::new());
/// let result = work(task, &|message| {
/// said.lock().unwrap_or_else(PoisonError::into_inner).push(message);
/// });
/// for message in said.into_inner().unwrap_or_else(PoisonError::into_inner) {
/// waiting.extend(step(Turn::Told(message)));
/// }
/// waiting.extend(step(Turn::Done(result)));
/// }
/// Ok(())
/// }
/// }
///
/// impl GraphRecord for Nothing {
/// fn record(&mut self, _graph: &TargetGraph) -> Result<()> {
/// Err(nothing(PortName::GraphRecord))
/// }
/// }
///
/// impl Reporter for Nothing {
/// fn begun(&mut self, _targets: usize) {}
///
/// fn started(&mut self, _action: &ReadyAction) {}
///
/// fn printed(&mut self, _label: &Label, _channel: Channel, _bytes: &[u8]) {}
///
/// fn finished(&mut self, _event: &OutcomeEvent, _printed: Captured<'_>) {}
///
/// fn remote(&mut self, _notice: &RemoteNotice) {}
///
/// fn summary(&mut self, _summary: Summary) {}
/// }
///
/// impl Approver for Nothing {
/// fn approve(&mut self, _wanted: &WantedSet, _attribution: &Attribution) -> Result<Approval> {
/// Ok(Approval::Granted)
/// }
/// }
///
/// impl Clock for Nothing {
/// fn now(&self) -> Timestamp {
/// Timestamp::UNIX_EPOCH
/// }
/// }
///
/// /// A bundle choosing it for every port.
/// struct NothingPorts;
///
/// impl Ports for NothingPorts {
/// type Source = Nothing;
/// type Manifest = Nothing;
/// type Host = Nothing;
/// type Digester = Nothing;
/// type StatCache = Nothing;
/// type Tools = Nothing;
/// type Cache = Nothing;
/// type Cas = Nothing;
/// type Log = Nothing;
/// type Strategy = Nothing;
/// type Dispatcher = Nothing;
/// type Clock = Nothing;
/// type Graph = Nothing;
/// type Reporter = Nothing;
/// type Approver = Nothing;
/// type Ignore = NothingIgnored;
/// type Remote = NoRemote;
/// }
/// ```