diff options
author | Jürgen Hahn <mail.jhahn@gmail.com> | 2023-01-02T20·00+0100 |
---|---|---|
committer | jrhahn <mail.jhahn@gmail.com> | 2023-01-02T20·55+0000 |
commit | 31973890a9ee60f50c1426ef7173bd4238234268 (patch) | |
tree | ef5cf4964fe08b2e0391769c0590738eb184c258 /tvix/derivation/src/derivation.rs | |
parent | e6862413ca032acc94615bd969c8fec49a1a1dc5 (diff) |
refactor(tvix/derivation): refactor the derivation serialization r/5564
This refactors the code to serialize a derivation. The original code has beed moved to seperate crates for better code structure. Change-Id: I3b1a6b134428fcbc9930c330bced8ec3610cfb4c Reviewed-on: https://cl.tvl.fyi/c/depot/+/7733 Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/derivation/src/derivation.rs')
-rw-r--r-- | tvix/derivation/src/derivation.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tvix/derivation/src/derivation.rs b/tvix/derivation/src/derivation.rs new file mode 100644 index 000000000000..142fa3c9f309 --- /dev/null +++ b/tvix/derivation/src/derivation.rs @@ -0,0 +1,34 @@ +use crate::output::Output; +use crate::write; +use serde::{Deserialize, Serialize}; +use std::{collections::BTreeMap, fmt, fmt::Write}; + +#[derive(Serialize, Deserialize)] +pub struct Derivation { + outputs: BTreeMap<String, Output>, + input_sources: Vec<String>, + input_derivations: BTreeMap<String, Vec<String>>, + platform: String, + builder: String, + arguments: Vec<String>, + environment: BTreeMap<String, String>, +} + +impl Derivation { + pub fn serialize(self: Self, writer: &mut impl Write) -> Result<(), fmt::Error> { + writer.write_str(write::DERIVATION_PREFIX)?; + writer.write_char(write::PAREN_OPEN)?; + + write::write_outputs(writer, self.outputs)?; + write::write_input_derivations(writer, self.input_derivations)?; + write::write_input_sources(writer, self.input_sources)?; + write::write_platfrom(writer, &self.platform)?; + write::write_builder(writer, &self.builder)?; + write::write_arguments(writer, self.arguments)?; + write::write_enviroment(writer, self.environment)?; + + writer.write_char(write::PAREN_CLOSE)?; + + Ok(()) + } +} |