xref: /DADK/dadk/src/context/manifest.rs (revision eaa67f3cf8881c221a744937c6318444b068a801)
1*eaa67f3cSLoGin use std::{path::PathBuf, str::FromStr};
2*eaa67f3cSLoGin 
3*eaa67f3cSLoGin use crate::utils::abs_path;
4*eaa67f3cSLoGin 
5*eaa67f3cSLoGin use super::DADKExecContextBuilder;
6*eaa67f3cSLoGin use anyhow::{anyhow, Result};
7*eaa67f3cSLoGin use dadk_config::manifest::DadkManifestFile;
8*eaa67f3cSLoGin 
parse_manifest(builder: &mut DADKExecContextBuilder) -> Result<()>9*eaa67f3cSLoGin pub(super) fn parse_manifest(builder: &mut DADKExecContextBuilder) -> Result<()> {
10*eaa67f3cSLoGin     let manifest_path = PathBuf::from_str(&builder.command.as_ref().unwrap().manifest_path)
11*eaa67f3cSLoGin         .map_err(|e| anyhow::anyhow!("Failed to get manifest path: {}", e))?;
12*eaa67f3cSLoGin 
13*eaa67f3cSLoGin     let workdir = builder.command.as_ref().unwrap().workdir.clone();
14*eaa67f3cSLoGin 
15*eaa67f3cSLoGin     // 将相对路径转换为基于workdir的绝对路径
16*eaa67f3cSLoGin     let manifest_path = abs_path(&PathBuf::from(workdir)).join(manifest_path);
17*eaa67f3cSLoGin 
18*eaa67f3cSLoGin     if !manifest_path.exists() || !manifest_path.is_file() {
19*eaa67f3cSLoGin         return Err(anyhow!("Manifest path does not exist or is not a file"));
20*eaa67f3cSLoGin     }
21*eaa67f3cSLoGin     let dadk_manifest_file = DadkManifestFile::load(&manifest_path)?;
22*eaa67f3cSLoGin     builder.manifest = Some(dadk_manifest_file);
23*eaa67f3cSLoGin     Ok(())
24*eaa67f3cSLoGin }
25