2023-01-02 21:00:59 +01:00
|
|
|
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 {
|
2023-01-04 12:26:37 +01:00
|
|
|
pub fn serialize(&self, writer: &mut impl Write) -> Result<(), fmt::Error> {
|
2023-01-02 21:00:59 +01:00
|
|
|
writer.write_str(write::DERIVATION_PREFIX)?;
|
|
|
|
writer.write_char(write::PAREN_OPEN)?;
|
|
|
|
|
2023-01-04 12:26:37 +01:00
|
|
|
write::write_outputs(writer, &self.outputs)?;
|
|
|
|
write::write_input_derivations(writer, &self.input_derivations)?;
|
|
|
|
write::write_input_sources(writer, &self.input_sources)?;
|
2023-01-02 21:00:59 +01:00
|
|
|
write::write_platfrom(writer, &self.platform)?;
|
|
|
|
write::write_builder(writer, &self.builder)?;
|
2023-01-04 12:26:37 +01:00
|
|
|
write::write_arguments(writer, &self.arguments)?;
|
|
|
|
write::write_enviroment(writer, &self.environment)?;
|
2023-01-02 21:00:59 +01:00
|
|
|
|
|
|
|
writer.write_char(write::PAREN_CLOSE)?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
2023-01-04 12:26:37 +01:00
|
|
|
|
|
|
|
impl fmt::Display for Derivation {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
self.serialize(f)
|
|
|
|
}
|
|
|
|
}
|