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