From aa1982c0852de539eeddd742f7c41bd1a873a53c Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 30 Jul 2023 09:37:17 +0200 Subject: refactor(tvix/derivation): move comma writing business up write_input_derivations shouldn't need to write a comma to separate it from the previous output from write_outputs. This is better placed in the function calling all of these helper functions. Change-Id: I9ccc440e4665b52369ef39e75151b9a29469ce48 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8995 Reviewed-by: raitobezarius Autosubmit: flokli Tested-by: BuildkiteCI --- tvix/nix-compat/src/derivation/mod.rs | 12 ++++++++++++ tvix/nix-compat/src/derivation/write.rs | 9 +-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/tvix/nix-compat/src/derivation/mod.rs b/tvix/nix-compat/src/derivation/mod.rs index b416e745a565..6a1eee4a81c3 100644 --- a/tvix/nix-compat/src/derivation/mod.rs +++ b/tvix/nix-compat/src/derivation/mod.rs @@ -51,11 +51,23 @@ impl Derivation { write::write_char(writer, write::PAREN_OPEN)?; write::write_outputs(writer, &self.outputs)?; + write::write_char(writer, write::COMMA)?; + write::write_input_derivations(writer, &self.input_derivations)?; + write::write_char(writer, write::COMMA)?; + write::write_input_sources(writer, &self.input_sources)?; + write::write_char(writer, write::COMMA)?; + write::write_system(writer, &self.system)?; + write::write_char(writer, write::COMMA)?; + write::write_builder(writer, &self.builder)?; + write::write_char(writer, write::COMMA)?; + write::write_arguments(writer, &self.arguments)?; + write::write_char(writer, write::COMMA)?; + write::write_enviroment(writer, &self.environment)?; write::write_char(writer, write::PAREN_CLOSE)?; diff --git a/tvix/nix-compat/src/derivation/write.rs b/tvix/nix-compat/src/derivation/write.rs index 22985fb4b55f..223ba9ff3fd9 100644 --- a/tvix/nix-compat/src/derivation/write.rs +++ b/tvix/nix-compat/src/derivation/write.rs @@ -107,7 +107,6 @@ pub fn write_input_derivations( writer: &mut impl Write, input_derivations: &BTreeMap>, ) -> Result<(), io::Error> { - write_char(writer, COMMA)?; write_char(writer, BRACKET_OPEN)?; for (ii, (input_derivation_path, input_derivation)) in input_derivations.into_iter().enumerate() @@ -142,8 +141,6 @@ pub fn write_input_sources( writer: &mut impl Write, input_sources: &BTreeSet, ) -> Result<(), io::Error> { - write_char(writer, COMMA)?; - write_char(writer, BRACKET_OPEN)?; write_array_elements( writer, @@ -158,19 +155,16 @@ pub fn write_input_sources( } pub fn write_system(writer: &mut impl Write, platform: &str) -> Result<(), Error> { - write_char(writer, COMMA)?; write_field(writer, platform, true)?; Ok(()) } pub fn write_builder(writer: &mut impl Write, builder: &str) -> Result<(), Error> { - write_char(writer, COMMA)?; write_field(writer, builder, true)?; Ok(()) } -pub fn write_arguments(writer: &mut impl Write, arguments: &[String]) -> Result<(), io::Error> { - write_char(writer, COMMA)?; +pub fn write_arguments(writer: &mut impl Write, arguments: &[String]) -> Result<(), io::Error> { write_char(writer, BRACKET_OPEN)?; write_array_elements( writer, @@ -188,7 +182,6 @@ pub fn write_enviroment( writer: &mut impl Write, environment: &BTreeMap, ) -> Result<(), io::Error> { - write_char(writer, COMMA)?; write_char(writer, BRACKET_OPEN)?; for (i, (k, v)) in environment.into_iter().enumerate() { -- cgit 1.4.1