trellis_core/
output_build.rs1use crate::{
2 DependencyList, GraphError, GraphResult, MaterializedOutput, OutputContext, OutputError,
3 OutputMeta, OutputOptions, RebaselineReason, Transaction, output::OutputSpec,
4};
5
6impl<C: 'static, O> Transaction<'_, C, O>
7where
8 O: Clone + PartialEq + 'static,
9{
10 pub fn materialized_output(
12 &mut self,
13 debug_name: impl Into<String>,
14 scope: crate::ScopeId,
15 dependencies: DependencyList,
16 materialize: impl for<'ctx> Fn(&OutputContext<'ctx, C, O>) -> Result<O, OutputError>
17 + Send
18 + Sync
19 + 'static,
20 ) -> GraphResult<MaterializedOutput<O>> {
21 self.materialized_output_with_options(
22 debug_name,
23 scope,
24 dependencies,
25 OutputOptions::default(),
26 materialize,
27 )
28 }
29
30 pub fn materialized_output_with_options(
32 &mut self,
33 debug_name: impl Into<String>,
34 scope: crate::ScopeId,
35 dependencies: DependencyList,
36 options: OutputOptions,
37 materialize: impl for<'ctx> Fn(&OutputContext<'ctx, C, O>) -> Result<O, OutputError>
38 + Send
39 + Sync
40 + 'static,
41 ) -> GraphResult<MaterializedOutput<O>> {
42 self.ensure_open()?;
43 self.working.require_scope_open(scope)?;
44 let key = self.graph.allocate_output_key();
45 self.working.validate_output_dependencies(&dependencies)?;
46 self.working.outputs.insert(
47 key,
48 OutputMeta::new(
49 key,
50 debug_name,
51 scope,
52 dependencies.clone(),
53 options,
54 self.working.revision,
55 ),
56 );
57 self.working
58 .output_specs
59 .insert(key, OutputSpec::new(materialize));
60 self.graph_mutated = true;
61 Ok(MaterializedOutput::new(key))
62 }
63
64 pub fn rebaseline_output(&mut self, output: MaterializedOutput<O>) -> GraphResult<()> {
66 self.ensure_open()?;
67 let meta = self
68 .working
69 .output_meta(output.key())
70 .ok_or(GraphError::UnknownOutput(output.key()))?;
71 self.working.require_scope_open(meta.scope())?;
72 self.staged_output_rebaselines
73 .insert(output.key(), RebaselineReason::Requested);
74 self.graph_mutated = true;
75 Ok(())
76 }
77}