espforge_lib/parse/
project.rs1use crate::parse::processor::SectionProcessor;
2use anyhow::{Context, Result};
3use espforge_configuration::EspforgeConfiguration;
4use serde::Deserialize;
5use serde_yaml_ng::Value;
6
7#[derive(Deserialize)]
8struct ProjectConfig {
9 name: String,
10 chip: Option<String>,
11 platform: Option<String>,
12 runtime: Option<String>,
13 #[serde(default)]
14 alloc: bool,
15}
16
17pub struct ProjectInfoProvisioner;
18
19impl SectionProcessor for ProjectInfoProvisioner {
20 fn section_key(&self) -> &'static str {
21 "espforge"
22 }
23
24 fn priority(&self) -> u32 {
25 1000
26 }
27
28 fn process(&self, content: &Value, model: &mut EspforgeConfiguration) -> Result<()> {
29 let config: ProjectConfig = serde_yaml_ng::from_value(content.clone())
30 .context("Failed to deserialize espforge configuration")?;
31
32 model.espforge.insert("name".to_string(), config.name);
33
34 if let Some(chip) = config.platform.or(config.chip) {
35 model.espforge.insert("platform".to_string(), chip);
36 }
37
38 if let Some(runtime) = config.runtime {
39 if runtime == "embassy" {
40 model.espforge.insert("runtime".to_string(), runtime);
41 }
42 }
43
44 if config.alloc {
45 model.espforge.insert("alloc".to_string(), "true".to_string());
46 }
47
48 println!("✓ Project configuration valid and processed.");
49 Ok(())
50 }
51}