1
pub mod build;
2
pub mod compiler;
3
pub mod modules;
4
pub mod project;
5
pub mod sourceset;
6
pub mod target;
7

            
8
use color_eyre::eyre::Context;
9
use color_eyre::Result;
10
use indexmap::IndexMap;
11
use serde::{Deserialize, Serialize};
12
use std::fmt::Debug;
13

            
14
use crate::utils::constants::error_messages;
15
use crate::{cache::ZorkCache, domain::target::TargetIdentifier};
16

            
17
use crate::utils;
18

            
19
use self::{
20
    build::BuildModel, compiler::CompilerModel, modules::ModulesModel, project::ProjectModel,
21
    target::TargetModel,
22
};
23

            
24
4
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
25
pub struct ZorkModel<'a> {
26
1
    pub project: ProjectModel<'a>,
27
1
    pub compiler: CompilerModel<'a>,
28
1
    pub build: BuildModel,
29
1
    pub modules: ModulesModel<'a>,
30
1
    pub targets: IndexMap<TargetIdentifier<'a>, TargetModel<'a>>,
31
}
32

            
33
/// Loads the mapped [`ZorkModel`] for a concrete [`ZorkConfigFile`] from the [`ZorkCache`]
34
pub fn load<'a>(cache: &ZorkCache<'a>) -> Result<ZorkModel<'a>> {
35
    utils::fs::load_and_deserialize::<ZorkModel, _>(&cache.metadata.project_model_file_path)
36
        .with_context(|| error_messages::PROJECT_MODEL_LOAD)
37
}
38

            
39
/// Saves the mapped [`ZorkModel`] for a concrete [`ZorkConfigFile`] on the [`ZorkCache`]
40
2
pub fn save(program_data: &ZorkModel, cache: &ZorkCache) -> Result<()> {
41
2
    utils::fs::save_file(&cache.metadata.project_model_file_path, program_data)
42
        .with_context(|| error_messages::PROJECT_MODEL_SAVE)
43
2
}