use std::fmt;
use crate::ports::Ports;
pub struct PortSet<P: Ports> {
pub source: P::Source,
pub manifest: P::Manifest,
pub host: P::Host,
pub digester: P::Digester,
pub stat_cache: P::StatCache,
pub tools: P::Tools,
pub cache: P::Cache,
pub cas: P::Cas,
pub log: P::Log,
pub strategy: P::Strategy,
pub dispatcher: P::Dispatcher,
pub clock: P::Clock,
pub graph: P::Graph,
pub reporter: P::Reporter,
pub approver: P::Approver,
pub ignore: P::Ignore,
pub remote: P::Remote,
}
impl<P: Ports> fmt::Debug for PortSet<P>
where
P::Source: fmt::Debug,
P::Manifest: fmt::Debug,
P::Host: fmt::Debug,
P::Digester: fmt::Debug,
P::StatCache: fmt::Debug,
P::Tools: fmt::Debug,
P::Cache: fmt::Debug,
P::Cas: fmt::Debug,
P::Log: fmt::Debug,
P::Strategy: fmt::Debug,
P::Dispatcher: fmt::Debug,
P::Clock: fmt::Debug,
P::Graph: fmt::Debug,
P::Reporter: fmt::Debug,
P::Approver: fmt::Debug,
P::Ignore: fmt::Debug,
P::Remote: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("PortSet")
.field("source", &self.source)
.field("manifest", &self.manifest)
.field("host", &self.host)
.field("digester", &self.digester)
.field("stat_cache", &self.stat_cache)
.field("tools", &self.tools)
.field("cache", &self.cache)
.field("cas", &self.cas)
.field("log", &self.log)
.field("strategy", &self.strategy)
.field("dispatcher", &self.dispatcher)
.field("clock", &self.clock)
.field("graph", &self.graph)
.field("reporter", &self.reporter)
.field("approver", &self.approver)
.field("ignore", &self.ignore)
.field("remote", &self.remote)
.finish()
}
}
#[cfg(test)]
mod tests {
#![expect(
clippy::unwrap_used,
reason = "tests unwrap known-valid fixtures; a panic is the intended failure signal"
)]
use std::collections::BTreeSet;
use super::PortSet;
use crate::error::Result;
use crate::ports::{
ActionCache, Approver, Clock, ContentStore, DeclarationSource, Digester, Dispatcher,
EventLog, ExecStrategy, GraphRecord, Host, Manifest, NoRemote, NothingIgnored, Ports,
Reporter, RunHistory, StatCache, ToolResolver,
};
use crate::types::{
Approval, Attribution, BuildFile, CacheRow, Captured, Ceiling, Channel, Digest, Directory,
Discovered, EnvName, EnvValue, Evaluated, Exit, FileMode, Found, InputStat, Label,
LiveSink, LogLine, OutcomeEvent, OutputPath, Platform, Program, RawOutcome, ReadyAction,
RemoteNotice, SourcePath, StatEntry, Summary, TargetGraph, Timestamp, Turn, WantedSet,
Workspace,
};
#[derive(Debug)]
struct Stub;
impl DeclarationSource for Stub {
fn evaluate(&self, _file: &BuildFile, _discovered: &Discovered) -> Result<Evaluated> {
Ok(Evaluated::Absent)
}
}
impl Manifest for Stub {
fn workspace(&self) -> Result<Workspace> {
Ok(Workspace {
out: Directory::parse("out")?,
state: Directory::parse(".buildl")?,
ceiling: Ceiling {
unkeyed: BTreeSet::new(),
run: BTreeSet::new(),
env: BTreeSet::new(),
read: BTreeSet::new(),
write: BTreeSet::new(),
},
execution: crate::types::Execution::default(),
approver: crate::types::ApproverMode::Manifest,
plugins: std::collections::BTreeMap::new(),
remote: None,
})
}
}
impl Host for Stub {
fn platform(&self) -> Platform {
Platform::parse("linux/x86_64").unwrap()
}
fn env(&self, _name: &EnvName) -> Result<Option<EnvValue>> {
Ok(None)
}
fn machine_folders(&self) -> crate::types::MachineFolders {
crate::types::MachineFolders::default()
}
}
impl Digester for Stub {
fn stat(&self, _path: &SourcePath) -> Result<InputStat> {
Ok(InputStat::Missing)
}
fn digest(&self, _paths: &[SourcePath]) -> Result<Vec<Digest>> {
Ok(Vec::new())
}
}
impl StatCache for Stub {
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 Stub {
fn fingerprint(&self, _program: &Program) -> Result<Option<Digest>> {
Ok(None)
}
}
impl ActionCache for Stub {
fn row(&self, _label: &Label) -> Option<&CacheRow> {
None
}
fn labels(&self) -> Vec<Label> {
Vec::new()
}
fn record(&mut self, _label: Label, _row: CacheRow) -> Result<()> {
Ok(())
}
fn forget(&mut self, _label: &Label) -> Result<()> {
Ok(())
}
}
impl ContentStore for Stub {
fn put(&self, bytes: &[u8]) -> Result<Digest> {
Ok(Digest::of(bytes))
}
fn contains(&self, _digest: &Digest) -> bool {
false
}
fn get(&self, _digest: &Digest) -> Result<Option<Vec<u8>>> {
Ok(None)
}
fn clear(&self, _at: &OutputPath) -> Result<()> {
Ok(())
}
fn place(&self, _digest: &Digest, _mode: FileMode, _at: &OutputPath) -> Result<()> {
Ok(())
}
}
impl EventLog for Stub {
fn append(&mut self, _event: &OutcomeEvent) -> Result<()> {
Ok(())
}
}
impl RunHistory for Stub {
fn lines(&self) -> Result<Vec<LogLine>> {
Ok(Vec::new())
}
}
impl ExecStrategy for Stub {
type Dir = ();
fn prepare(&self, _action: &ReadyAction) -> Result<()> {
Ok(())
}
fn run(
&self,
_dir: &(),
_action: &ReadyAction,
_live: Option<LiveSink<'_>>,
) -> Result<RawOutcome> {
Ok(RawOutcome {
exit: Exit::Exited(0),
stdout: Vec::new(),
stderr: Vec::new(),
})
}
fn collect<C: ContentStore>(
&self,
_dir: &(),
_action: &ReadyAction,
_cas: &C,
) -> Result<Vec<Found>> {
Ok(Vec::new())
}
}
impl Dispatcher for Stub {
fn dispatch<T, M, R, W, S>(&mut self, _work: W, _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>,
{
Ok(())
}
}
impl GraphRecord for Stub {
fn record(&mut self, _graph: &TargetGraph) -> Result<()> {
Ok(())
}
}
impl Reporter for Stub {
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 Stub {
fn approve(&mut self, _wanted: &WantedSet, _attribution: &Attribution) -> Result<Approval> {
Ok(Approval::Granted)
}
}
impl Clock for Stub {
fn now(&self) -> Timestamp {
Timestamp::UNIX_EPOCH
}
}
struct UndebuggableBundle;
impl Ports for UndebuggableBundle {
type Source = Stub;
type Manifest = Stub;
type Host = Stub;
type Digester = Stub;
type StatCache = Stub;
type Tools = Stub;
type Cache = Stub;
type Cas = Stub;
type Log = Stub;
type Strategy = Stub;
type Dispatcher = Stub;
type Clock = Stub;
type Graph = Stub;
type Reporter = Stub;
type Approver = Stub;
type Ignore = NothingIgnored;
type Remote = NoRemote;
}
#[test]
fn debug_renders_every_port_without_the_bundle_being_debug() {
let set = PortSet::<UndebuggableBundle> {
source: Stub,
manifest: Stub,
host: Stub,
digester: Stub,
stat_cache: Stub,
tools: Stub,
cache: Stub,
cas: Stub,
log: Stub,
strategy: Stub,
dispatcher: Stub,
clock: Stub,
graph: Stub,
reporter: Stub,
approver: Stub,
ignore: NothingIgnored,
remote: NoRemote,
};
let text = format!("{set:?}");
assert!(text.starts_with("PortSet"), "unexpected rendering: {text}");
for field in [
"source",
"manifest",
"host",
"digester",
"stat_cache",
"tools",
"cache",
"cas",
"log",
"strategy",
"dispatcher",
"clock",
"graph",
"reporter",
"approver",
] {
assert!(
text.contains(&format!("{field}: Stub")),
"field `{field}` missing from: {text}"
);
}
assert!(
text.contains("ignore: NothingIgnored"),
"field `ignore` missing from: {text}"
);
assert!(
text.contains("remote: NoRemote"),
"field `remote` missing from: {text}"
);
}
}