1 use super::UnitParser; 2 use super::graph::Graph; 3 use super::parse_util::UnitParseUtil; 4 use crate::error::parse_error::ParseError; 5 use crate::manager::GLOBAL_UNIT_MANAGER; 6 use crate::unit::target::TargetUnit; 7 8 #[cfg(target_os = "dragonos")] 9 use drstd as std; 10 11 use std::rc::Rc; 12 use std::sync::Arc; 13 14 pub struct TargetParser; 15 16 impl TargetParser { 17 /// @brief 解析Service类型Unit的 18 /// 19 /// 从path解析Service类型Unit 20 /// 21 /// @param path 需解析的文件路径 22 /// 23 /// @return 成功则返回Ok(Rc<ServiceUnit>),否则返回Err 24 pub fn parse(path: &str) -> Result<Arc<TargetUnit>, ParseError> { 25 //预先检查是否存在循环依赖 26 let mut graph = Graph::construct_graph(path.to_string())?; 27 let ret = graph.topological_sort()?; 28 for p in ret { 29 let temp_unit = UnitParseUtil::parse_unit_no_type(&p)?; 30 } 31 32 let manager = GLOBAL_UNIT_MANAGER.read().unwrap(); 33 let result = manager.get_unit_with_path(path).unwrap(); 34 35 let result : TargetUnit = result.as_any().downcast_ref::<TargetUnit>().unwrap().clone(); 36 return Ok(Arc::new(result)); 37 } 38 }