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> Transaction<'_, C> {
7 pub fn materialized_output<T>(
9 &mut self,
10 debug_name: impl Into<String>,
11 scope: crate::ScopeId,
12 dependencies: DependencyList,
13 materialize: impl for<'ctx> Fn(&OutputContext<'ctx, C>) -> Result<T, OutputError>
14 + Send
15 + Sync
16 + 'static,
17 ) -> GraphResult<MaterializedOutput<T>>
18 where
19 T: Clone + PartialEq + Send + Sync + 'static,
20 {
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<T>(
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>) -> Result<T, OutputError>
38 + Send
39 + Sync
40 + 'static,
41 ) -> GraphResult<MaterializedOutput<T>>
42 where
43 T: Clone + PartialEq + Send + Sync + 'static,
44 {
45 self.ensure_open()?;
46 self.working.require_scope_open(scope)?;
47 let key = self.graph.allocate_output_key();
48 self.working.validate_output_dependencies(&dependencies)?;
49 self.working.outputs.insert(
50 key,
51 OutputMeta::new(
52 key,
53 debug_name,
54 scope,
55 dependencies.clone(),
56 options,
57 self.working.revision,
58 ),
59 );
60 self.working
61 .output_specs
62 .insert(key, OutputSpec::new(materialize));
63 self.graph_mutated = true;
64 Ok(MaterializedOutput::new(key))
65 }
66
67 pub fn rebaseline_output<T>(&mut self, output: MaterializedOutput<T>) -> GraphResult<()> {
69 self.ensure_open()?;
70 let meta = self
71 .working
72 .output_meta(output.key())
73 .ok_or(GraphError::UnknownOutput(output.key()))?;
74 self.working.require_scope_open(meta.scope())?;
75 self.staged_output_rebaselines
76 .insert(output.key(), RebaselineReason::Requested);
77 self.graph_mutated = true;
78 Ok(())
79 }
80}