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
//! The port through which Load evaluates one build file.
//!
//! Its own file because evaluating a build file is the one thing Load cannot do itself: it means
//! reading a file and running a language this crate does not know. Everything around that one call
//! — which files to evaluate, in what order, and what their results mean — stays in Load.
//!
//! Responsibilities: [`DeclarationSource`].
//!
//! Non-responsibilities: implementing it. The real implementation belongs in an adapter crate.
//!
//! This file holds only a trait definition, so it carries no logic to unit-test.
use crateResult;
use crate;
/// Evaluates one build file and returns what it staged, exactly as written.
///
/// The [`Discovered`] map holds what discovery targets last produced; a build file that asks for
/// one gets its bytes, or nothing when the map holds none. Load passes the same map to every file
/// it evaluates.
///
/// An implementation reports a missing file as [`Evaluated::Absent`] rather than as an error:
/// what a missing file means depends on who asked for it, which only the caller knows.
///
/// `Sync` because several build files are evaluated at once, each on the thread that took it.
///
/// # Examples
///
/// An implementation needs nothing but this crate's public API:
///
/// ```
/// use std::path::PathBuf;
///
/// use buildl_core::{
/// BuildFile, DeclarationOrder, DeclarationSource, Directory, Discovered, Evaluated,
/// Provenance, Result, StagedFile, StagedSubdir, Written,
/// };
///
/// /// A source in which only the workspace root has a build file, requesting `lib`.
/// struct RootOnly;
///
/// impl DeclarationSource for RootOnly {
/// fn evaluate(&self, file: &BuildFile, _discovered: &Discovered) -> Result<Evaluated> {
/// if !file.directory().is_root() {
/// return Ok(Evaluated::Absent);
/// }
/// Ok(Evaluated::Staged(StagedFile {
/// declarations: Vec::new(),
/// subdirs: vec![StagedSubdir {
/// path: Written::new("lib"),
/// order: DeclarationOrder::new(0),
/// }],
/// }))
/// }
/// }
///
/// let lib = BuildFile::new(Provenance::new(
/// PathBuf::from("lib/build.lua"),
/// Directory::parse("lib")?,
/// ));
/// assert_eq!(RootOnly.evaluate(&lib, &Discovered::empty())?, Evaluated::Absent);
/// # Ok::<(), buildl_core::Error>(())
/// ```