Skip to main content

trellis_core/
output_build.rs

1use 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    /// Stages creation of a materialized output with default options.
11    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> + 'static,
17    ) -> GraphResult<MaterializedOutput<O>> {
18        self.materialized_output_with_options(
19            debug_name,
20            scope,
21            dependencies,
22            OutputOptions::default(),
23            materialize,
24        )
25    }
26
27    /// Stages creation of a materialized output with explicit options.
28    pub fn materialized_output_with_options(
29        &mut self,
30        debug_name: impl Into<String>,
31        scope: crate::ScopeId,
32        dependencies: DependencyList,
33        options: OutputOptions,
34        materialize: impl for<'ctx> Fn(&OutputContext<'ctx, C, O>) -> Result<O, OutputError> + 'static,
35    ) -> GraphResult<MaterializedOutput<O>> {
36        self.ensure_open()?;
37        self.working.require_scope_open(scope)?;
38        let key = self.graph.allocate_output_key();
39        self.working.validate_output_dependencies(&dependencies)?;
40        self.working.outputs.insert(
41            key,
42            OutputMeta::new(
43                key,
44                debug_name,
45                scope,
46                dependencies.clone(),
47                options,
48                self.working.revision,
49            ),
50        );
51        self.working
52            .output_specs
53            .insert(key, OutputSpec::new(materialize));
54        self.graph_mutated = true;
55        Ok(MaterializedOutput::new(key))
56    }
57
58    /// Stages an explicit output rebaseline.
59    pub fn rebaseline_output(&mut self, output: MaterializedOutput<O>) -> GraphResult<()> {
60        self.ensure_open()?;
61        let meta = self
62            .working
63            .output_meta(output.key())
64            .ok_or(GraphError::UnknownOutput(output.key()))?;
65        self.working.require_scope_open(meta.scope())?;
66        self.staged_output_rebaselines
67            .insert(output.key(), RebaselineReason::Requested);
68        self.graph_mutated = true;
69        Ok(())
70    }
71}