diff --git a/core/src/ten_manager/src/cmd/cmd_delete.rs b/core/src/ten_manager/src/cmd/cmd_delete.rs index f4ba97518..1d637b897 100644 --- a/core/src/ten_manager/src/cmd/cmd_delete.rs +++ b/core/src/ten_manager/src/cmd/cmd_delete.rs @@ -13,7 +13,6 @@ use console::Emoji; use indicatif::HumanDuration; use semver::Version; -use ten_rust::pkg_info::pkg_identity::PkgIdentity; use ten_rust::pkg_info::pkg_type::PkgType; use crate::log::tman_verbose_println; @@ -85,10 +84,8 @@ pub async fn execute_cmd( delete_package( tman_config, - &PkgIdentity { - pkg_type: PkgType::from_str(&command_data.package_type)?, - name: command_data.package_name, - }, + PkgType::from_str(&command_data.package_type)?, + &command_data.package_name, &Version::parse(&command_data.version)?, &command_data.hash, ) diff --git a/core/src/ten_manager/src/cmd/cmd_install.rs b/core/src/ten_manager/src/cmd/cmd_install.rs index 9cee8c81c..0e317d8be 100644 --- a/core/src/ten_manager/src/cmd/cmd_install.rs +++ b/core/src/ten_manager/src/cmd/cmd_install.rs @@ -27,8 +27,8 @@ use ten_rust::pkg_info::{ dependencies::{DependencyRelationship, PkgDependency}, find_to_be_replaced_local_pkgs, find_untracked_local_packages, get_pkg_info_from_path, - pkg_identity::PkgIdentity, pkg_type::PkgType, + pkg_type_and_name::PkgTypeAndName, supports::{is_pkg_supports_compatible_with, Arch, Os, PkgSupport}, PkgInfo, }; @@ -228,22 +228,22 @@ fn update_package_manifest( base_pkg_info.manifest.as_mut().unwrap().dependencies { let is_present = dependencies.iter().any(|dep| { - dep.pkg_type == added_pkg_info.pkg_identity.pkg_type.to_string() - && dep.name == added_pkg_info.pkg_identity.name + dep.pkg_type == added_pkg_info.pkg_type.to_string() + && dep.name == added_pkg_info.name }); if !is_present { dependencies.push(ManifestDependency { - pkg_type: added_pkg_info.pkg_identity.pkg_type.to_string(), - name: added_pkg_info.pkg_identity.name.clone(), + pkg_type: added_pkg_info.pkg_type.to_string(), + name: added_pkg_info.name.clone(), version: added_pkg_info.version.to_string(), }); } } else { base_pkg_info.manifest.clone().unwrap().dependencies = Some(vec![ManifestDependency { - pkg_type: added_pkg_info.pkg_identity.pkg_type.to_string(), - name: added_pkg_info.pkg_identity.name.clone(), + pkg_type: added_pkg_info.pkg_type.to_string(), + name: added_pkg_info.name.clone(), version: added_pkg_info.version.to_string(), }]); } @@ -298,7 +298,7 @@ fn parse_pkg_name_version( fn filter_compatible_pkgs_to_candidates( tman_config: &TmanConfig, all_existing_local_pkgs: &Vec, - all_candidates: &mut HashMap>, + all_candidates: &mut HashMap>, support: &PkgSupport, ) { for existed_pkg in all_existing_local_pkgs.to_owned().iter_mut() { @@ -317,12 +317,12 @@ fn filter_compatible_pkgs_to_candidates( tman_verbose_println!( tman_config, "The existed {} package {} is compatible with the current system.", - existed_pkg.pkg_identity.pkg_type, - existed_pkg.pkg_identity.name + existed_pkg.pkg_type, + existed_pkg.name ); all_candidates - .entry(existed_pkg.pkg_identity.clone()) + .entry((&*existed_pkg).into()) .or_default() .insert(existed_pkg.clone()); } else { @@ -332,8 +332,8 @@ fn filter_compatible_pkgs_to_candidates( tman_config, "The existed {} package {} is not compatible \ with the current system.", - existed_pkg.pkg_identity.pkg_type, - existed_pkg.pkg_identity.name + existed_pkg.pkg_type, + existed_pkg.name ); } } @@ -376,10 +376,7 @@ appear in the dependency tree:", Emoji("💡", "") ); for pkg in untracked_local_pkgs { - println!( - " {}:{}@{}", - pkg.pkg_identity.pkg_type, pkg.pkg_identity.name, pkg.version - ); + println!(" {}:{}@{}", pkg.pkg_type, pkg.name, pkg.version); } } @@ -402,23 +399,23 @@ appear in the dependency tree:", if old_supports_str != new_supports_str { println!( " {}:{}@{}{} -> {}:{}@{}{}", - old_pkg.pkg_identity.pkg_type, - old_pkg.pkg_identity.name, + old_pkg.pkg_type, + old_pkg.name, old_pkg.version, old_supports_str, - new_pkg.pkg_identity.pkg_type, - new_pkg.pkg_identity.name, + new_pkg.pkg_type, + new_pkg.name, new_pkg.version, new_supports_str ); } else { println!( " {}:{}@{} -> {}:{}@{}", - old_pkg.pkg_identity.pkg_type, - old_pkg.pkg_identity.name, + old_pkg.pkg_type, + old_pkg.name, old_pkg.version, - new_pkg.pkg_identity.pkg_type, - new_pkg.pkg_identity.name, + new_pkg.pkg_type, + new_pkg.name, new_pkg.version ); } @@ -458,7 +455,7 @@ pub async fn execute_cmd( // those addons (extensions, extension_groups, ...) installed in the app // directory are all considered initial_input_pkgs. let mut initial_input_pkgs = vec![]; - let mut all_candidates: HashMap> = + let mut all_candidates: HashMap> = HashMap::new(); // 'all_existing_local_pkgs' contains all the packages which are already @@ -499,7 +496,7 @@ pub async fn execute_cmd( let template_data = serde_json::to_value(&command_data.template_data)?; // The locked_pkgs comes from a lock file in the app folder. - let mut locked_pkgs: Option> = None; + let mut locked_pkgs: Option> = None; if command_data.template_mode { template_ctx = Some(&template_data); @@ -522,7 +519,7 @@ pub async fn execute_cmd( desired_pkg_src_version_, ) = parse_pkg_name_version(&command_data.package_name.unwrap())?; - desired_pkg_type = Some(desired_pkg_type_.clone()); + desired_pkg_type = Some(desired_pkg_type_); desired_pkg_src_name = Some(desired_pkg_src_name_.clone()); // First, check that the package we want to install can be installed @@ -532,7 +529,7 @@ pub async fn execute_cmd( is_standalone_installing = is_installing_package_standalone(&cwd, &desired_pkg_type_)?; if is_standalone_installing { - affected_pkg_type = desired_pkg_type_.clone(); + affected_pkg_type = desired_pkg_type_; affected_pkg_name = desired_pkg_src_name_.clone(); if let Some(desired_pkg_dest_name) = desired_pkg_dest_name { @@ -546,7 +543,7 @@ pub async fn execute_cmd( // If it is not a standalone install, then the `cwd` must be within // the base directory of a TEN app. let app_pkg_ = get_pkg_info_from_path(&cwd)?; - affected_pkg_name = app_pkg_.pkg_identity.name.clone(); + affected_pkg_name = app_pkg_.name.clone(); // Push the app itself into the initial_input_pkgs. initial_input_pkgs.push(get_pkg_info_from_path(&cwd)?); @@ -564,13 +561,12 @@ pub async fn execute_cmd( ); let extra_dependency_relationship = DependencyRelationship { - pkg_identity: app_pkg_.pkg_identity.clone(), + pkg_type: app_pkg_.pkg_type, + name: app_pkg_.name.clone(), version: app_pkg_.version.clone(), dependency: PkgDependency { - pkg_identity: PkgIdentity { - pkg_type: desired_pkg_type_.clone(), - name: desired_pkg_src_name_.clone(), - }, + pkg_type: desired_pkg_type_, + name: desired_pkg_src_name_.clone(), version_req: desired_pkg_src_version_.clone(), version_req_str: desired_pkg_src_version_str_, }, @@ -581,7 +577,7 @@ pub async fn execute_cmd( } let dep = PkgDependency::new( - desired_pkg_type_.clone(), + desired_pkg_type_, desired_pkg_src_name_.clone(), desired_pkg_src_version_, ); @@ -589,14 +585,9 @@ pub async fn execute_cmd( if let Some(desired_pkg_dest_name) = desired_pkg_dest_name { let pkg_identity_mapping = PkgIdentityMapping { - src_pkg_identity: PkgIdentity { - pkg_type: desired_pkg_type_.clone(), - name: desired_pkg_src_name_, - }, - dest_pkg_identity: PkgIdentity { - pkg_type: desired_pkg_type_, - name: desired_pkg_dest_name.to_string(), - }, + pkg_type: desired_pkg_type_, + src_pkg_name: desired_pkg_src_name_, + dest_pkg_name: desired_pkg_dest_name.to_string(), }; pkg_identity_mappings.push(pkg_identity_mapping); } diff --git a/core/src/ten_manager/src/dep_and_candidate/mod.rs b/core/src/ten_manager/src/dep_and_candidate/mod.rs index acede36e6..b49519b00 100644 --- a/core/src/ten_manager/src/dep_and_candidate/mod.rs +++ b/core/src/ten_manager/src/dep_and_candidate/mod.rs @@ -11,8 +11,8 @@ use anyhow::{anyhow, Result}; use semver::{Version, VersionReq}; use ten_rust::pkg_info::dependencies::PkgDependency; -use ten_rust::pkg_info::pkg_identity::PkgIdentity; use ten_rust::pkg_info::pkg_type::PkgType; +use ten_rust::pkg_info::pkg_type_and_name::PkgTypeAndName; use ten_rust::pkg_info::supports::{ is_pkg_supports_compatible_with, PkgSupport, }; @@ -53,19 +53,21 @@ impl MergedVersionReq { } struct FoundDependency { - pkg_identity: PkgIdentity, + pkg_type: PkgType, + name: String, version_reqs: MergedVersionReq, } impl Hash for FoundDependency { fn hash(&self, state: &mut H) { - self.pkg_identity.hash(state); + self.pkg_type.hash(state); + self.name.hash(state); } } impl PartialEq for FoundDependency { fn eq(&self, other: &Self) -> bool { - self.pkg_identity == other.pkg_identity + self.pkg_type == other.pkg_type && self.name == other.name } } @@ -81,7 +83,8 @@ fn merge_dependency_to_dependencies( dependency: &PkgDependency, ) -> Result { let searched_target = FoundDependency { - pkg_identity: dependency.pkg_identity.clone(), + pkg_type: dependency.pkg_type, + name: dependency.name.clone(), version_reqs: MergedVersionReq::default(), }; @@ -101,7 +104,8 @@ fn merge_dependency_to_dependencies( // This is the first time seeing this dependency. merged_dependencies.insert(FoundDependency { - pkg_identity: dependency.pkg_identity.clone(), + pkg_type: dependency.pkg_type, + name: dependency.name.clone(), version_reqs: MergedVersionReq::new(&dependency.version_req), }); } @@ -131,7 +135,7 @@ async fn process_dependencies_to_get_candidates( support: &PkgSupport, input_dependencies: &Vec, merged_dependencies: &mut HashSet, - all_candidates: &mut HashMap>, + all_candidates: &mut HashMap>, new_pkgs_to_be_searched: &mut Vec, ) -> Result<()> { for dependency in input_dependencies { @@ -154,9 +158,13 @@ async fn process_dependencies_to_get_candidates( // Retrieve all packages from the registry that meet the specified // criteria. - let results = - get_package_list(tman_config, &dependency.pkg_identity, &criteria) - .await?; + let results = get_package_list( + tman_config, + dependency.pkg_type, + &dependency.name, + &criteria, + ) + .await?; let mut candidate_pkg_infos: Vec = vec![]; @@ -186,7 +194,7 @@ async fn process_dependencies_to_get_candidates( // searching through `all_candidates` allows those locally installed // packages to be added to `new_pkgs_to_be_searched`, ensuring that the // dependencies within those packages are processed. - if let Some(candidates) = all_candidates.get(&dependency.pkg_identity) { + if let Some(candidates) = all_candidates.get(&dependency.into()) { for candidate in candidates { if dependency.version_req.matches(&candidate.version) { tman_verbose_println!( @@ -226,7 +234,7 @@ async fn process_dependencies_to_get_candidates( ); all_candidates - .entry(dependency.pkg_identity.clone()) + .entry(dependency.into()) .or_default() .insert(candidate_pkg_info.clone()); @@ -242,15 +250,15 @@ async fn process_dependencies_to_get_candidates( /// suitable one is the package with the highest compatible_score. If there are /// multiple packages with the highest score, just pick one at random. fn clean_up_all_candidates( - all_candidates: &mut HashMap>, - locked_pkgs: Option<&HashMap>, + all_candidates: &mut HashMap>, + locked_pkgs: Option<&HashMap>, ) { - for (pkg_identity, pkg_infos) in all_candidates.iter_mut() { + for (pkg_type_name, pkg_infos) in all_candidates.iter_mut() { let mut version_map: HashMap = HashMap::new(); let mut locked_pkgs_map: HashMap = HashMap::new(); let locked_pkg = - locked_pkgs.and_then(|locked_pkgs| locked_pkgs.get(pkg_identity)); + locked_pkgs.and_then(|locked_pkgs| locked_pkgs.get(pkg_type_name)); for pkg_info in pkg_infos.iter() { // Check if the candidate is a locked one. @@ -286,10 +294,10 @@ pub async fn get_all_candidates_from_deps( tman_config: &TmanConfig, support: &PkgSupport, mut pkgs_to_be_searched: Vec, - mut all_candidates: HashMap>, + mut all_candidates: HashMap>, extra_dependencies: &Vec, - locked_pkgs: Option<&HashMap>, -) -> Result>> { + locked_pkgs: Option<&HashMap>, +) -> Result>> { let mut merged_dependencies = HashSet::::new(); let mut processed_pkgs = HashSet::::new(); @@ -351,16 +359,15 @@ pub fn get_pkg_info_from_candidates( pkg_type: &str, pkg_name: &str, version: &str, - all_candidates: &HashMap>, + all_candidates: &HashMap>, ) -> Result { - let pkg_type_enum = pkg_type.parse::()?; - let pkg_identity = PkgIdentity { - pkg_type: pkg_type_enum, + let pkg_type_name = PkgTypeAndName { + pkg_type: pkg_type.parse::()?, name: pkg_name.to_string(), }; let version_parsed = Version::parse(version)?; let pkg_info = all_candidates - .get(&pkg_identity) + .get(&pkg_type_name) .and_then(|set| set.iter().find(|pkg| pkg.version == version_parsed)) .ok_or_else(|| { anyhow!( diff --git a/core/src/ten_manager/src/designer/addons/extensions.rs b/core/src/ten_manager/src/designer/addons/extensions.rs index fdc96093e..f8ba49bff 100644 --- a/core/src/ten_manager/src/designer/addons/extensions.rs +++ b/core/src/ten_manager/src/designer/addons/extensions.rs @@ -47,7 +47,7 @@ fn retrieve_extension_addons( if let Some(all_pkgs) = &state.all_pkgs { let extensions = all_pkgs .iter() - .filter(|pkg| pkg.pkg_identity.pkg_type == PkgType::Extension) + .filter(|pkg| pkg.pkg_type == PkgType::Extension) .map(|pkg_info_with_src| { map_pkg_to_extension_addon(pkg_info_with_src) }) @@ -68,7 +68,7 @@ fn map_pkg_to_extension_addon( pkg_info_with_src: &PkgInfo, ) -> DesignerExtensionAddon { DesignerExtensionAddon { - addon_name: pkg_info_with_src.pkg_identity.name.clone(), + addon_name: pkg_info_with_src.name.clone(), url: pkg_info_with_src.url.clone(), api: pkg_info_with_src.api.as_ref().map(|api| DesignerApi { property: if api.property.is_empty() { diff --git a/core/src/ten_manager/src/designer/graphs/connections.rs b/core/src/ten_manager/src/designer/graphs/connections.rs index e0a91a757..d2d48f2d2 100644 --- a/core/src/ten_manager/src/designer/graphs/connections.rs +++ b/core/src/ten_manager/src/designer/graphs/connections.rs @@ -128,9 +128,8 @@ pub async fn get_graph_connections( } if let Some(pkgs) = &state.all_pkgs { - if let Some(app_pkg) = pkgs - .iter() - .find(|pkg| pkg.pkg_identity.pkg_type == PkgType::App) + if let Some(app_pkg) = + pkgs.iter().find(|pkg| pkg.pkg_type == PkgType::App) { // If the app package has predefined graphs, find the one with the // specified graph_name. diff --git a/core/src/ten_manager/src/designer/graphs/mod.rs b/core/src/ten_manager/src/designer/graphs/mod.rs index 48c8d0f3b..5bfe188be 100644 --- a/core/src/ten_manager/src/designer/graphs/mod.rs +++ b/core/src/ten_manager/src/designer/graphs/mod.rs @@ -42,7 +42,7 @@ pub async fn get_graphs( if let Some(all_pkgs) = &state.all_pkgs { if let Some(app_pkg) = all_pkgs .iter() - .find(|pkg| pkg.pkg_identity.pkg_type == PkgType::App) + .find(|pkg| pkg.pkg_type == PkgType::App) { let graphs: Vec = app_pkg .get_predefined_graphs() diff --git a/core/src/ten_manager/src/designer/graphs/update.rs b/core/src/ten_manager/src/designer/graphs/update.rs index 7fb743c30..5a2c09541 100644 --- a/core/src/ten_manager/src/designer/graphs/update.rs +++ b/core/src/ten_manager/src/designer/graphs/update.rs @@ -46,7 +46,7 @@ pub async fn update_graph( if let Some(pkgs) = &mut state.all_pkgs { if let Some(app_pkg) = pkgs .iter_mut() - .find(|pkg| pkg.pkg_identity.pkg_type == PkgType::App) + .find(|pkg| pkg.pkg_type == PkgType::App) { let new_graph = match get_pkg_predefined_graph_from_nodes_and_connections( @@ -185,7 +185,7 @@ mod tests { Some(pkgs) => { let app_pkg = pkgs .iter() - .find(|pkg| pkg.pkg_identity.pkg_type == PkgType::App) + .find(|pkg| pkg.pkg_type == PkgType::App) .unwrap(); let predefined_graphs = diff --git a/core/src/ten_manager/src/designer/manifest/check.rs b/core/src/ten_manager/src/designer/manifest/check.rs index cbbb8b2fc..d9c6ca7e1 100644 --- a/core/src/ten_manager/src/designer/manifest/check.rs +++ b/core/src/ten_manager/src/designer/manifest/check.rs @@ -39,7 +39,7 @@ pub async fn check_manifest( if let Some(pkgs) = &mut state.all_pkgs { if let Some(app_pkg) = pkgs .iter_mut() - .find(|pkg| pkg.pkg_identity.pkg_type == PkgType::App) + .find(|pkg| pkg.pkg_type == PkgType::App) { match query.0.check_type.as_str() { "dirty" => match app_pkg.is_manifest_equal_to_fs() { diff --git a/core/src/ten_manager/src/designer/manifest/dump.rs b/core/src/ten_manager/src/designer/manifest/dump.rs index e3a81c11a..49182edac 100644 --- a/core/src/ten_manager/src/designer/manifest/dump.rs +++ b/core/src/ten_manager/src/designer/manifest/dump.rs @@ -44,7 +44,7 @@ pub async fn dump_manifest( if let Some(pkgs) = &mut state.all_pkgs { if let Some(app_pkg) = pkgs .iter_mut() - .find(|pkg| pkg.pkg_identity.pkg_type == PkgType::App) + .find(|pkg| pkg.pkg_type == PkgType::App) { let new_manifest_str = app_pkg.manifest.clone().unwrap().to_string(); diff --git a/core/src/ten_manager/src/designer/property/check.rs b/core/src/ten_manager/src/designer/property/check.rs index f63b605db..ae953d9d6 100644 --- a/core/src/ten_manager/src/designer/property/check.rs +++ b/core/src/ten_manager/src/designer/property/check.rs @@ -37,9 +37,8 @@ pub async fn check_property( } if let Some(pkgs) = &mut state.all_pkgs { - if let Some(app_pkg) = pkgs - .iter_mut() - .find(|pkg| pkg.pkg_identity.pkg_type == PkgType::App) + if let Some(app_pkg) = + pkgs.iter_mut().find(|pkg| pkg.pkg_type == PkgType::App) { match query.0.check_type.as_str() { "dirty" => match app_pkg.is_property_equal_to_fs() { diff --git a/core/src/ten_manager/src/designer/property/dump.rs b/core/src/ten_manager/src/designer/property/dump.rs index e6db5b5a7..8cb9e5eef 100644 --- a/core/src/ten_manager/src/designer/property/dump.rs +++ b/core/src/ten_manager/src/designer/property/dump.rs @@ -46,9 +46,8 @@ pub async fn dump_property( ); if let Some(pkgs) = &mut state.all_pkgs { - if let Some(app_pkg) = pkgs - .iter_mut() - .find(|pkg| pkg.pkg_identity.pkg_type == PkgType::App) + if let Some(app_pkg) = + pkgs.iter_mut().find(|pkg| pkg.pkg_type == PkgType::App) { let response = ApiResponse { status: Status::Ok, diff --git a/core/src/ten_manager/src/install/mod.rs b/core/src/ten_manager/src/install/mod.rs index 307ceab48..f3ecabbe0 100644 --- a/core/src/ten_manager/src/install/mod.rs +++ b/core/src/ten_manager/src/install/mod.rs @@ -15,9 +15,7 @@ use installed_paths::{ }; use tempfile::NamedTempFile; -use ten_rust::pkg_info::{ - pkg_identity::PkgIdentity, pkg_type::PkgType, PkgInfo, -}; +use ten_rust::pkg_info::{pkg_type::PkgType, PkgInfo}; use super::{config::TmanConfig, fs::merge_folders, registry::get_package}; use crate::{ @@ -25,8 +23,10 @@ use crate::{ }; pub struct PkgIdentityMapping { - pub src_pkg_identity: PkgIdentity, - pub dest_pkg_identity: PkgIdentity, + pub pkg_type: PkgType, + + pub src_pkg_name: String, + pub dest_pkg_name: String, } pub async fn install_pkg_info( @@ -40,8 +40,8 @@ pub async fn install_pkg_info( tman_verbose_println!( tman_config, "{}:{} has already been installed.\n", - pkg_info.pkg_identity.pkg_type, - pkg_info.pkg_identity.name + pkg_info.pkg_type, + pkg_info.name ); return Ok(()); } @@ -50,7 +50,9 @@ pub async fn install_pkg_info( let mut found_pkg_identity_mapping = None; for pkg_identity_mapping in pkg_identity_mappings { - if pkg_info.pkg_identity == pkg_identity_mapping.src_pkg_identity { + if pkg_info.pkg_type == pkg_identity_mapping.pkg_type + && pkg_info.name == pkg_identity_mapping.src_pkg_name + { found_pkg_identity_mapping = Some(pkg_identity_mapping); } } @@ -58,10 +60,9 @@ pub async fn install_pkg_info( let path; if let Some(found_pkg_identity_mapping) = found_pkg_identity_mapping { path = Path::new(&base_dir) - .join(found_pkg_identity_mapping.dest_pkg_identity.name.clone()); + .join(found_pkg_identity_mapping.dest_pkg_name.clone()); } else { - path = - PathBuf::from(&base_dir).join(pkg_info.pkg_identity.name.clone()); + path = PathBuf::from(&base_dir).join(pkg_info.name.clone()); } let output_dir = path.to_string_lossy().to_string(); @@ -81,8 +82,8 @@ pub async fn install_pkg_info( .map_err(|e| { anyhow::anyhow!( "Failed to check property.json for {}:{}, {}", - pkg_info.pkg_identity.pkg_type, - pkg_info.pkg_identity.name, + pkg_info.pkg_type, + pkg_info.name, e ) })?; @@ -92,7 +93,7 @@ pub async fn install_pkg_info( // NOTE: This feature is not currently in use, but a command-line argument // could be added to copy the lib/ or include/ from the system package to // ten_packages/system/. This would reduce the number of rpaths. - if pkg_info.pkg_identity.pkg_type == PkgType::System { + if pkg_info.pkg_type == PkgType::System { let inclusions = vec![]; merge_folders( Path::new(&output_dir), @@ -111,8 +112,8 @@ pub async fn install_pkg_info( tman_verbose_println!( tman_config, "Install files for {}:{}", - pkg_info.pkg_identity.pkg_type, - pkg_info.pkg_identity.name + pkg_info.pkg_type, + pkg_info.name ); for install_path in &installed_paths.paths { tman_verbose_println!(tman_config, "{}", install_path); diff --git a/core/src/ten_manager/src/manifest_lock/mod.rs b/core/src/ten_manager/src/manifest_lock/mod.rs index f18635e44..e57515b0e 100644 --- a/core/src/ten_manager/src/manifest_lock/mod.rs +++ b/core/src/ten_manager/src/manifest_lock/mod.rs @@ -18,7 +18,7 @@ use ten_rust::pkg_info::supports::{ get_manifest_supports_from_pkg, get_pkg_supports_from_manifest_supports, }; use ten_rust::pkg_info::{ - pkg_identity::PkgIdentity, pkg_type::PkgType, PkgInfo, + pkg_type::PkgType, pkg_type_and_name::PkgTypeAndName, PkgInfo, }; use super::constants::MANIFEST_LOCK_JSON_FILENAME; @@ -63,14 +63,14 @@ impl FromStr for ManifestLock { } impl ManifestLock { - pub fn get_pkgs(&self) -> HashMap { + pub fn get_pkgs(&self) -> HashMap { self.packages .as_ref() .map(|pkgs| { pkgs.iter() .map(|pkg| { let pkg_info: PkgInfo = pkg.into(); - (pkg_info.pkg_identity.clone(), pkg_info) + ((&pkg_info).into(), pkg_info) }) .collect() }) @@ -109,7 +109,7 @@ impl ManifestLock { println!( "{} Adding package {} v{}", Emoji("➕", ""), - pkg.pkg_identity.name, + pkg.name, pkg.version ); } @@ -120,7 +120,7 @@ impl ManifestLock { println!( "{} Removing package {} v{}", Emoji("🗑️", ""), - pkg.pkg_identity.name, + pkg.name, pkg.version ); } @@ -131,7 +131,7 @@ impl ManifestLock { println!( "{} Updating package {} v{} to v{}", Emoji("🔄", ""), - old_pkg.pkg_identity.name, + old_pkg.name, old_pkg.version, new_pkg.version ); @@ -217,8 +217,8 @@ fn get_encodable_deps_from_pkg_deps( impl<'a> From<&'a PkgInfo> for ManifestLockItem { fn from(pkg_info: &'a PkgInfo) -> Self { ManifestLockItem { - pkg_type: pkg_info.pkg_identity.pkg_type.to_string(), - name: pkg_info.pkg_identity.name.clone(), + pkg_type: pkg_info.pkg_type.to_string(), + name: pkg_info.name.clone(), version: pkg_info.version.to_string(), hash: pkg_info.hash.to_string(), dependencies: if pkg_info.dependencies.is_empty() { @@ -236,10 +236,8 @@ impl<'a> From<&'a PkgInfo> for ManifestLockItem { impl<'a> From<&'a ManifestLockItem> for PkgInfo { fn from(val: &'a ManifestLockItem) -> Self { PkgInfo { - pkg_identity: PkgIdentity { - pkg_type: PkgType::from_str(&val.pkg_type).unwrap(), - name: val.name.clone(), - }, + pkg_type: PkgType::from_str(&val.pkg_type).unwrap(), + name: val.name.clone(), version: Version::parse(&val.version).unwrap(), dependencies: val .clone() @@ -247,11 +245,8 @@ impl<'a> From<&'a ManifestLockItem> for PkgInfo { .map(|deps| { deps.into_iter() .map(|dep| PkgDependency { - pkg_identity: PkgIdentity { - pkg_type: PkgType::from_str(&dep.pkg_type) - .unwrap(), - name: dep.name, - }, + pkg_type: PkgType::from_str(&dep.pkg_type).unwrap(), + name: dep.name, version_req: VersionReq::STAR, version_req_str: None, }) @@ -285,8 +280,8 @@ pub struct ManifestLockItemDependencyItem { impl From for ManifestLockItemDependencyItem { fn from(pkg_dep: PkgDependency) -> Self { ManifestLockItemDependencyItem { - pkg_type: pkg_dep.pkg_identity.pkg_type.to_string(), - name: pkg_dep.pkg_identity.name, + pkg_type: pkg_dep.pkg_type.to_string(), + name: pkg_dep.name, } } } diff --git a/core/src/ten_manager/src/package_file/mod.rs b/core/src/ten_manager/src/package_file/mod.rs index 250482baa..24e1b063e 100644 --- a/core/src/ten_manager/src/package_file/mod.rs +++ b/core/src/ten_manager/src/package_file/mod.rs @@ -28,9 +28,7 @@ use crate::{ pub fn get_package_zip_file_name(pkg_info: &PkgInfo) -> Result { let output_zip_file_name = format!( "{}_{}.{}", - pkg_info.pkg_identity.name, - pkg_info.version, - TEN_PACKAGE_FILE_EXTENSION + pkg_info.name, pkg_info.version, TEN_PACKAGE_FILE_EXTENSION ); Ok(output_zip_file_name) diff --git a/core/src/ten_manager/src/package_info/mod.rs b/core/src/ten_manager/src/package_info/mod.rs index edb5dc064..dc6aea1d5 100644 --- a/core/src/ten_manager/src/package_info/mod.rs +++ b/core/src/ten_manager/src/package_info/mod.rs @@ -6,14 +6,14 @@ // pub mod predefined_graphs; -use std::{collections::HashSet, path::Path}; +use std::path::Path; use anyhow::Result; use crate::{config::TmanConfig, registry::found_result::RegistryPackageData}; use ten_rust::pkg_info::{ dependencies::get_pkg_dependencies_from_manifest_dependencies, - get_all_existed_pkgs_info_of_app_to_hashset, pkg_identity::PkgIdentity, + get_all_existed_pkgs_info_of_app_to_hashmap, supports::get_pkg_supports_from_manifest_supports, PkgInfo, }; @@ -21,10 +21,8 @@ pub fn pkg_info_from_find_package_data( package_data: &RegistryPackageData, ) -> Result { Ok(PkgInfo { - pkg_identity: PkgIdentity { - pkg_type: package_data.pkg_type.clone(), - name: package_data.name.clone(), - }, + pkg_type: package_data.pkg_type, + name: package_data.name.clone(), version: package_data.version.clone(), dependencies: get_pkg_dependencies_from_manifest_dependencies( &package_data.dependencies, @@ -45,22 +43,11 @@ pub fn pkg_info_from_find_package_data( }) } -fn tman_get_all_existed_pkgs_info_of_app_to_hashset( - tman_config: &TmanConfig, - app_path: &Path, -) -> Result> { - let pkgs_info = get_all_existed_pkgs_info_of_app_to_hashset(app_path); - crate::log::tman_verbose_println!(tman_config, "{:?}", pkgs_info); - pkgs_info -} - pub fn tman_get_all_existed_pkgs_info_of_app( tman_config: &TmanConfig, app_path: &Path, ) -> Result> { - let pkgs_info = tman_get_all_existed_pkgs_info_of_app_to_hashset( - tman_config, - app_path, - )?; - Ok(pkgs_info.into_iter().collect()) + let pkgs_info = get_all_existed_pkgs_info_of_app_to_hashmap(app_path)?; + crate::log::tman_verbose_println!(tman_config, "{:?}", pkgs_info); + Ok(pkgs_info.into_values().collect()) } diff --git a/core/src/ten_manager/src/registry/local.rs b/core/src/ten_manager/src/registry/local.rs index 83e9186d2..ff9e9135b 100644 --- a/core/src/ten_manager/src/registry/local.rs +++ b/core/src/ten_manager/src/registry/local.rs @@ -16,7 +16,6 @@ use walkdir::WalkDir; use zip::ZipArchive; use ten_rust::pkg_info::manifest::Manifest; -use ten_rust::pkg_info::pkg_identity::PkgIdentity; use ten_rust::pkg_info::pkg_type::PkgType; use ten_rust::pkg_info::PkgInfo; @@ -47,10 +46,7 @@ pub async fn upload_package( // Construct the directory path. let dir_path = PathBuf::from(format!( "{}{}/{}/{}/", - path_url, - pkg_info.pkg_identity.pkg_type, - pkg_info.pkg_identity.name, - pkg_info.version + path_url, pkg_info.pkg_type, pkg_info.name, pkg_info.version )); // Check if the directory exists, and only create it if it doesn't. @@ -117,12 +113,11 @@ pub async fn get_package( fn find_file_with_criteria( base_url: &Path, - pkg_identity: &PkgIdentity, + pkg_type: PkgType, + name: &String, criteria: &SearchCriteria, ) -> Result> { - let target_path = base_url - .join(pkg_identity.pkg_type.to_string()) - .join(&pkg_identity.name); + let target_path = base_url.join(pkg_type.to_string()).join(&name); let mut results = Vec::::new(); @@ -205,7 +200,8 @@ fn find_file_with_criteria( pub async fn get_package_list( _tman_config: &TmanConfig, base_url: &str, - pkg_identity: &PkgIdentity, + pkg_type: PkgType, + name: &String, criteria: &SearchCriteria, ) -> Result> { let mut path_url = url::Url::parse(base_url) @@ -222,15 +218,20 @@ pub async fn get_package_list( format!("{}/", path_url) }; - let result = - find_file_with_criteria(Path::new(&path_url), pkg_identity, criteria)?; + let result = find_file_with_criteria( + Path::new(&path_url), + pkg_type, + name, + criteria, + )?; Ok(result) } pub async fn delete_package( base_url: &str, - pkg_identity: &PkgIdentity, + pkg_type: PkgType, + name: &String, version: &Version, hash: &String, ) -> Result<()> { @@ -251,7 +252,7 @@ pub async fn delete_package( // Construct the directory path. let dir_path = PathBuf::from(format!( "{}{}/{}/{}/", - path_url, pkg_identity.pkg_type, pkg_identity.name, version + path_url, pkg_type, name, version )); if dir_path.exists() { diff --git a/core/src/ten_manager/src/registry/mod.rs b/core/src/ten_manager/src/registry/mod.rs index f861c655f..b016e427f 100644 --- a/core/src/ten_manager/src/registry/mod.rs +++ b/core/src/ten_manager/src/registry/mod.rs @@ -12,12 +12,11 @@ use anyhow::{anyhow, Result}; use semver::{Version, VersionReq}; use tempfile::NamedTempFile; -use ten_rust::pkg_info::{pkg_identity::PkgIdentity, PkgInfo}; +use ten_rust::pkg_info::{pkg_type::PkgType, PkgInfo}; use super::config::TmanConfig; use found_result::FoundResult; - pub struct SearchCriteria { pub version_req: VersionReq, // Future search fields can be added here. @@ -82,7 +81,8 @@ pub async fn get_package( pub async fn get_package_list( tman_config: &TmanConfig, - pkg_identity: &PkgIdentity, + pkg_type: PkgType, + name: &String, criteria: &SearchCriteria, ) -> Result> { // Retrieve the default registry URL @@ -101,7 +101,8 @@ pub async fn get_package_list( local::get_package_list( tman_config, &default_registry_url, - pkg_identity, + pkg_type, + name, criteria, ) .await? @@ -110,7 +111,8 @@ pub async fn get_package_list( remote::get_package_list( tman_config, &default_registry_url, - pkg_identity, + pkg_type, + name, criteria, ) .await? @@ -128,7 +130,8 @@ pub async fn get_package_list( pub async fn delete_package( tman_config: &TmanConfig, - pkg_identity: &PkgIdentity, + pkg_type: PkgType, + name: &String, version: &Version, hash: &String, ) -> Result<()> { @@ -147,7 +150,8 @@ pub async fn delete_package( "file" => { local::delete_package( &default_registry_url, - pkg_identity, + pkg_type, + name, version, hash, ) @@ -157,7 +161,8 @@ pub async fn delete_package( remote::delete_package( tman_config, &default_registry_url, - pkg_identity, + pkg_type, + name, version, hash, ) diff --git a/core/src/ten_manager/src/registry/remote.rs b/core/src/ten_manager/src/registry/remote.rs index a76c78774..7596c6164 100644 --- a/core/src/ten_manager/src/registry/remote.rs +++ b/core/src/ten_manager/src/registry/remote.rs @@ -13,13 +13,11 @@ use semver::Version; use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; use tempfile::NamedTempFile; +use ten_rust::pkg_info::pkg_type::PkgType; use tokio::sync::RwLock; use tokio::time::sleep; -use ten_rust::pkg_info::{ - pkg_identity::PkgIdentity, supports::get_manifest_supports_from_pkg, - PkgInfo, -}; +use ten_rust::pkg_info::{supports::get_manifest_supports_from_pkg, PkgInfo}; use super::{FoundResult, SearchCriteria}; use crate::constants::{ @@ -104,8 +102,8 @@ async fn get_package_upload_info( Box::pin(async move { let payload = json!(RegistryPackageData { - pkg_type: pkg_info.pkg_identity.pkg_type.clone(), - name: pkg_info.pkg_identity.name.clone(), + pkg_type: pkg_info.pkg_type, + name: pkg_info.name.clone(), version: pkg_info.version.clone(), dependencies: pkg_info .dependencies @@ -336,10 +334,10 @@ fn parse_content_range(content_range: &str) -> Option<(u64, u64, u64)> { None } -pub async fn get_package<'a>( +pub async fn get_package( tman_config: &TmanConfig, url: &str, - temp_file: &'a mut NamedTempFile, + temp_file: &mut NamedTempFile, ) -> Result<()> { let client = reqwest::Client::new(); @@ -478,7 +476,8 @@ struct RegistryPackagesData { pub async fn get_package_list( tman_config: &TmanConfig, base_url: &str, - pkg_identity: &PkgIdentity, + pkg_type: PkgType, + name: &String, criteria: &SearchCriteria, ) -> Result> { let max_retries = REMOTE_REGISTRY_MAX_RETRIES; @@ -486,7 +485,6 @@ pub async fn get_package_list( retry_async(tman_config, max_retries, retry_delay, || { let base_url = base_url.to_string(); - let pkg_identity = pkg_identity.clone(); let client = reqwest::Client::new(); Box::pin(async move { @@ -497,8 +495,8 @@ pub async fn get_package_list( loop { let mut url = reqwest::Url::parse(&base_url)?; url.query_pairs_mut() - .append_pair("type", &pkg_identity.pkg_type.to_string()) - .append_pair("name", &pkg_identity.name) + .append_pair("type", &pkg_type.to_string()) + .append_pair("name", name) .append_pair("version", &criteria.version_req.to_string()) .append_pair("pageSize", "10") .append_pair("page", ¤t_page.to_string()); @@ -569,8 +567,8 @@ pub async fn get_package_list( &tman_config, "Fetched {} packages for {}:{}", results.len(), - pkg_identity.pkg_type, - pkg_identity.name, + pkg_type, + name, ); Ok(results) @@ -582,7 +580,8 @@ pub async fn get_package_list( pub async fn delete_package( tman_config: &TmanConfig, base_url: &str, - pkg_identity: &PkgIdentity, + pkg_type: PkgType, + name: &String, version: &Version, hash: &str, ) -> Result<()> { @@ -591,7 +590,6 @@ pub async fn delete_package( retry_async(tman_config, max_retries, retry_delay, || { let base_url = base_url.to_string(); - let pkg_identity = pkg_identity.clone(); let version = version.clone(); let client = reqwest::Client::new(); @@ -610,8 +608,8 @@ pub async fn delete_package( let url = url .join(&format!( "{}/{}/{}/{}", - &pkg_identity.pkg_type.to_string(), - &pkg_identity.name, + &pkg_type.to_string(), + &name, version, hash, )) diff --git a/core/src/ten_manager/src/solver/introducer.rs b/core/src/ten_manager/src/solver/introducer.rs index a0d1d089a..a7c9d0a15 100644 --- a/core/src/ten_manager/src/solver/introducer.rs +++ b/core/src/ten_manager/src/solver/introducer.rs @@ -9,14 +9,14 @@ use std::collections::{HashMap, HashSet}; use anyhow::Result; use regex::Regex; -use ten_rust::pkg_info::{pkg_identity::PkgIdentity, PkgInfo}; +use ten_rust::pkg_info::{pkg_type_and_name::PkgTypeAndName, PkgInfo}; use crate::dep_and_candidate::get_pkg_info_from_candidates; /// Returns a map from a package to its introducer and the requested version. pub fn extract_introducer_relations_from_raw_solver_results( results: &[String], - all_candidates: &HashMap>, + all_candidates: &HashMap>, ) -> Result)>> { let re = Regex::new( r#"introducer\("([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]*)","([^"]*)"\)"#, @@ -88,9 +88,9 @@ pub fn extract_introducer_relations_from_raw_solver_results( pub fn get_dependency_chain( introducer: &PkgInfo, - conflict_pkg_identity: &PkgIdentity, + conflict_pkg_identity: &PkgTypeAndName, introducer_relations: &HashMap)>, -) -> Vec<(String, PkgIdentity)> { +) -> Vec<(String, PkgTypeAndName)> { let mut chain = Vec::new(); let mut current_pkg = introducer.clone(); let mut visited = HashSet::new(); @@ -124,18 +124,12 @@ pub fn get_dependency_chain( // `current_pkg`@`requested_version`, i.e., the // `requested_version` is used to declared the `current_pkg` in // the manifest.json of `introducer_pkg`. - chain.push(( - requested_version.clone(), - current_pkg.pkg_identity.clone(), - )); + chain.push((requested_version.clone(), (¤t_pkg).into())); current_pkg = introducer_pkg.clone(); } Some((requested_version, None)) => { // Reached the root. - chain.push(( - requested_version.clone(), - current_pkg.pkg_identity.clone(), - )); + chain.push((requested_version.clone(), (¤t_pkg).into())); break; } None => { diff --git a/core/src/ten_manager/src/solver/solve.rs b/core/src/ten_manager/src/solver/solve.rs index 89d897036..f53e710ba 100644 --- a/core/src/ten_manager/src/solver/solve.rs +++ b/core/src/ten_manager/src/solver/solve.rs @@ -13,8 +13,8 @@ use clingo::{ }; use ten_rust::pkg_info::{ - dependencies::DependencyRelationship, pkg_identity::PkgIdentity, - pkg_type::PkgType, PkgInfo, + dependencies::DependencyRelationship, pkg_type::PkgType, + pkg_type_and_name::PkgTypeAndName, PkgInfo, }; use crate::{ @@ -155,11 +155,13 @@ fn print_statistics( } } +type UsableModel = Option>; +type NonUsableModels = Vec>; +type SolveOutcome = (UsableModel, NonUsableModels); +type SolveResult = Result; + #[allow(unused_assignments)] -fn solve( - tman_config: &TmanConfig, - input: &str, -) -> Result<(Option>, Vec>)> { +fn solve(tman_config: &TmanConfig, input: &str) -> SolveResult { // Create a control object. // i.e., clingo_control_new let mut ctl = control({ @@ -292,11 +294,11 @@ fn solve( fn create_input_str_for_dependency_relationship( input_str: &mut String, dependency_relationships: &Vec, - all_candidates: &HashMap>, + all_candidates: &HashMap>, ) -> Result<()> { for dependency_relationship in dependency_relationships { - let candidates = all_candidates - .get(&dependency_relationship.dependency.pkg_identity); + let candidates = + all_candidates.get(&(&dependency_relationship.dependency).into()); if let Some(candidates) = candidates { for candidate in candidates.iter() { @@ -307,11 +309,11 @@ fn create_input_str_for_dependency_relationship( { input_str.push_str(&format!( "depends_on_declared(\"{}\", \"{}\", \"{}\", \"{}\", \"{}\", \"{}\").\n", - dependency_relationship.pkg_identity.pkg_type, - dependency_relationship.pkg_identity.name, + dependency_relationship.pkg_type, + dependency_relationship.name, dependency_relationship.version, - candidate.pkg_identity.pkg_type, - candidate.pkg_identity.name, + candidate.pkg_type, + candidate.name, candidate.version, )); } @@ -320,8 +322,8 @@ fn create_input_str_for_dependency_relationship( return Err(TmanError::Custom( format!( "Failed to find candidates for {}:{}@{}", - dependency_relationship.dependency.pkg_identity.pkg_type, - dependency_relationship.dependency.pkg_identity.name, + dependency_relationship.dependency.pkg_type, + dependency_relationship.dependency.name, dependency_relationship.version, ) .to_string(), @@ -337,7 +339,7 @@ fn create_input_str_for_pkg_info_dependencies( input_str: &mut String, pkg_info: &PkgInfo, dumped_pkgs_info: &mut HashSet, - all_candidates: &HashMap>, + all_candidates: &HashMap>, ) -> Result<()> { // If this package has already been dumped, skip it. if dumped_pkgs_info.contains(pkg_info) { @@ -346,7 +348,7 @@ fn create_input_str_for_pkg_info_dependencies( dumped_pkgs_info.insert(pkg_info.clone()); for dependency in &pkg_info.dependencies { - let candidates = all_candidates.get(&dependency.pkg_identity); + let candidates = all_candidates.get(&(dependency).into()); if let Some(candidates) = candidates { let mut found_matched = false; @@ -355,11 +357,11 @@ fn create_input_str_for_pkg_info_dependencies( if dependency.version_req.matches(&candidate.version) { input_str.push_str(&format!( "depends_on_declared(\"{}\", \"{}\", \"{}\", \"{}\", \"{}\", \"{}\").\n", - pkg_info.pkg_identity.pkg_type, - pkg_info.pkg_identity.name, + pkg_info.pkg_type, + pkg_info.name, pkg_info.version, - candidate.pkg_identity.pkg_type, - candidate.pkg_identity.name, + candidate.pkg_type, + candidate.name, candidate.version, )); @@ -378,8 +380,8 @@ fn create_input_str_for_pkg_info_dependencies( return Err(TmanError::Custom( format!( "Failed to find candidates for [{}]{}({})", - dependency.pkg_identity.pkg_type, - dependency.pkg_identity.name, + dependency.pkg_type, + dependency.name, dependency.version_req ) .to_string(), @@ -390,8 +392,8 @@ fn create_input_str_for_pkg_info_dependencies( return Err(TmanError::Custom( format!( "Failed to find candidates for {}:{}@{}", - dependency.pkg_identity.pkg_type, - dependency.pkg_identity.name, + dependency.pkg_type, + dependency.name, dependency.version_req ) .to_string(), @@ -410,10 +412,7 @@ fn create_input_str_for_pkg_info_without_dependencies( ) -> Result<()> { input_str.push_str(&format!( "version_declared(\"{}\", \"{}\", \"{}\", {}).\n", - pkg_info.pkg_identity.pkg_type, - pkg_info.pkg_identity.name, - pkg_info.version, - weight + pkg_info.pkg_type, pkg_info.name, pkg_info.version, weight )); Ok(()) @@ -421,8 +420,8 @@ fn create_input_str_for_pkg_info_without_dependencies( fn create_input_str_for_all_possible_pkgs_info( input_str: &mut String, - all_candidates: &HashMap>, - locked_pkgs: Option<&HashMap>, + all_candidates: &HashMap>, + locked_pkgs: Option<&HashMap>, ) -> Result<()> { for candidates in all_candidates { let mut candidates_vec: Vec<_> = candidates.1.iter().collect(); @@ -467,8 +466,8 @@ fn create_input_str( pkg_name: &String, pkg_type: &PkgType, extra_dependency_relationships: &Vec, - all_candidates: &HashMap>, - locked_pkgs: Option<&HashMap>, + all_candidates: &HashMap>, + locked_pkgs: Option<&HashMap>, ) -> Result { let mut input_str = String::new(); @@ -520,9 +519,9 @@ pub fn solve_all( pkg_name: &String, pkg_type: &PkgType, extra_dependency_relationships: &Vec, - all_candidates: &HashMap>, - locked_pkgs: Option<&HashMap>, -) -> Result<(Option>, Vec>)> { + all_candidates: &HashMap>, + locked_pkgs: Option<&HashMap>, +) -> SolveResult { let input_str = create_input_str( tman_config, pkg_name, diff --git a/core/src/ten_manager/src/solver/solver_error.rs b/core/src/ten_manager/src/solver/solver_error.rs index 204a44142..4b52be2d8 100644 --- a/core/src/ten_manager/src/solver/solver_error.rs +++ b/core/src/ten_manager/src/solver/solver_error.rs @@ -10,7 +10,7 @@ use anyhow::{anyhow, Result}; use console::Emoji; use regex::Regex; -use ten_rust::pkg_info::{pkg_identity::PkgIdentity, PkgInfo}; +use ten_rust::pkg_info::{pkg_type_and_name::PkgTypeAndName, PkgInfo}; use crate::{ dep_and_candidate::get_pkg_info_from_candidates, @@ -120,7 +120,7 @@ pub fn parse_error_statement(clingo_output: &[String]) -> Result { } fn print_dependency_chain( - chain: &[(String, PkgIdentity)], + chain: &[(String, PkgTypeAndName)], pkg_type: &str, pkg_name: &str, version: &str, @@ -145,7 +145,7 @@ fn print_dependency_chain( pub fn print_conflict_info( conflict_info: &ConflictInfo, introducer_relations: &HashMap)>, - all_candidates: &HashMap>, + all_candidates: &HashMap>, ) -> Result<()> { println!( "{} Error: {}", @@ -170,7 +170,7 @@ pub fn print_conflict_info( // The introducer_pkg_info_1/introducer_pkg_info_2 (i.e., the introducer) // depends on the pkg identified by `conflict_pkg_identity`. - let conflict_pkg_identity = PkgIdentity { + let conflict_pkg_identity = PkgTypeAndName { pkg_type: conflict_info.conflict_pkg_type.parse()?, name: conflict_info.conflict_pkg_name.clone(), }; diff --git a/core/src/ten_manager/src/solver/solver_result.rs b/core/src/ten_manager/src/solver/solver_result.rs index 87e29e35b..1e1f5dba7 100644 --- a/core/src/ten_manager/src/solver/solver_result.rs +++ b/core/src/ten_manager/src/solver/solver_result.rs @@ -16,7 +16,7 @@ use regex::Regex; use semver::Version; use ten_rust::pkg_info::{ - pkg_identity::PkgIdentity, pkg_type::PkgType, PkgInfo, + pkg_type::PkgType, pkg_type_and_name::PkgTypeAndName, PkgInfo, }; use crate::{ @@ -30,7 +30,7 @@ use crate::{ pub fn extract_solver_results_from_raw_solver_results( results: &[String], - all_candidates: &HashMap>, + all_candidates: &HashMap>, ) -> Result> { let re = Regex::new(r#"selected_pkg_version\("([^"]+)","([^"]+)","([^"]+)"\)"#) @@ -48,15 +48,13 @@ pub fn extract_solver_results_from_raw_solver_results( let semver = semver_str.parse::()?; for candidate in all_candidates - .get(&PkgIdentity { - pkg_type: pkg_type.clone(), + .get(&PkgTypeAndName { + pkg_type, name: name.to_string(), }) .unwrap() { - if candidate.pkg_identity.pkg_type != pkg_type - || candidate.pkg_identity.name != name - { + if candidate.pkg_type != pkg_type || candidate.name != name { panic!("Should not happen."); } @@ -80,10 +78,8 @@ pub fn filter_solver_results_by_type_and_name<'a>( let mut filtered_results: Vec<&PkgInfo> = vec![]; for result in solver_results.iter() { - let matches_type = - pkg_type.map_or(true, |pt| result.pkg_identity.pkg_type == *pt); - let matches_name = - name.map_or(true, |n| result.pkg_identity.name == *n); + let matches_type = pkg_type.map_or(true, |pt| result.pkg_type == *pt); + let matches_name = name.map_or(true, |n| result.name == *n); let matches = matches_type && matches_name; @@ -119,11 +115,10 @@ pub async fn install_solver_results_in_app_folder( bar.inc(1); bar.set_message(format!( "{}/{}", - solver_result.pkg_identity.pkg_type, - solver_result.pkg_identity.name + solver_result.pkg_type, solver_result.name )); - let base_dir = match solver_result.pkg_identity.pkg_type { + let base_dir = match solver_result.pkg_type { PkgType::Extension => { app_dir.join(TEN_PACKAGES_DIR).join(EXTENSION_DIR) } diff --git a/core/src/ten_rust/src/pkg_info/dependencies.rs b/core/src/ten_rust/src/pkg_info/dependencies.rs index 89faf2d8e..c002e17fb 100644 --- a/core/src/ten_rust/src/pkg_info/dependencies.rs +++ b/core/src/ten_rust/src/pkg_info/dependencies.rs @@ -13,12 +13,13 @@ use anyhow::Result; use semver::{Version, VersionReq}; use serde::{Deserialize, Serialize}; -use super::{pkg_identity::PkgIdentity, pkg_type::PkgType}; +use super::{pkg_type::PkgType, pkg_type_and_name::PkgTypeAndName}; use crate::pkg_info::manifest::{dependency::ManifestDependency, Manifest}; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct PkgDependency { - pub pkg_identity: PkgIdentity, + pub pkg_type: PkgType, + pub name: String, // The version requirement of this dependency, ex: the `version` // field declared in the `dependencies` section in the manifest.json, or @@ -30,6 +31,15 @@ pub struct PkgDependency { pub version_req_str: Option, } +impl From<&PkgDependency> for PkgTypeAndName { + fn from(dependency: &PkgDependency) -> Self { + PkgTypeAndName { + pkg_type: dependency.pkg_type, + name: dependency.name.clone(), + } + } +} + pub fn get_pkg_dependencies_from_manifest( manifest: &Manifest, ) -> Result> { @@ -54,7 +64,8 @@ pub fn get_pkg_dependencies_from_manifest_dependencies( let version_req = VersionReq::parse(&manifest_dependency.version)?; dependencies.push(PkgDependency { - pkg_identity: PkgIdentity { pkg_type, name }, + pkg_type, + name, version_req, version_req_str: Some(manifest_dependency.version.clone()), }); @@ -67,13 +78,14 @@ pub fn get_pkg_dependencies_from_manifest_dependencies( /// type and name. impl Hash for PkgDependency { fn hash(&self, state: &mut H) { - self.pkg_identity.hash(state); + self.pkg_type.hash(state); + self.name.hash(state); } } impl PartialEq for PkgDependency { fn eq(&self, other: &Self) -> bool { - self.pkg_identity == other.pkg_identity + self.pkg_type == other.pkg_type && self.name == other.name } } @@ -84,7 +96,8 @@ impl PkgDependency { version_req: VersionReq, ) -> Self { PkgDependency { - pkg_identity: PkgIdentity { pkg_type, name }, + pkg_type, + name, version_req, version_req_str: None, } @@ -95,7 +108,8 @@ impl Eq for PkgDependency {} #[derive(Debug)] pub struct DependencyRelationship { - pub pkg_identity: PkgIdentity, + pub pkg_type: PkgType, + pub name: String, pub version: Version, pub dependency: PkgDependency, } diff --git a/core/src/ten_rust/src/pkg_info/graph/check/connections_are_compatible.rs b/core/src/ten_rust/src/pkg_info/graph/check/connections_are_compatible.rs index d0e26111a..2b9897c20 100644 --- a/core/src/ten_rust/src/pkg_info/graph/check/connections_are_compatible.rs +++ b/core/src/ten_rust/src/pkg_info/graph/check/connections_are_compatible.rs @@ -300,10 +300,7 @@ fn find_cmd_schema_from_all_pkgs_info<'a>( ) -> Option<&'a CmdSchema> { let addon_pkg = existed_pkgs_of_app .iter() - .find(|pkg| { - pkg.pkg_identity.pkg_type == PkgType::Extension - && pkg.pkg_identity.name == addon - }) + .find(|pkg| pkg.pkg_type == PkgType::Extension && pkg.name == addon) .unwrap_or_else(|| { panic!("should not happen."); }); @@ -331,10 +328,7 @@ fn find_msg_schema_from_all_pkgs_info<'a>( let addon_pkg = existed_pkgs_of_app .iter() - .find(|pkg| { - pkg.pkg_identity.pkg_type == PkgType::Extension - && pkg.pkg_identity.name == addon - }) + .find(|pkg| pkg.pkg_type == PkgType::Extension && pkg.name == addon) .unwrap_or_else(|| { panic!("should not happen."); }); diff --git a/core/src/ten_rust/src/pkg_info/graph/check/nodes_are_installed.rs b/core/src/ten_rust/src/pkg_info/graph/check/nodes_are_installed.rs index 36f1996e6..765ca9b0e 100644 --- a/core/src/ten_rust/src/pkg_info/graph/check/nodes_are_installed.rs +++ b/core/src/ten_rust/src/pkg_info/graph/check/nodes_are_installed.rs @@ -41,8 +41,8 @@ impl Graph { // Check if the graph node exists in the specified app. let found = existed_pkgs_of_app.iter().find(|pkg| { - pkg.pkg_identity.pkg_type == node.node_type - && pkg.pkg_identity.name == node.addon + pkg.pkg_type == node.node_type + && pkg.name == node.addon && pkg.is_local_installed }); if found.is_none() { diff --git a/core/src/ten_rust/src/pkg_info/hash.rs b/core/src/ten_rust/src/pkg_info/hash.rs index b91afc118..128666874 100644 --- a/core/src/ten_rust/src/pkg_info/hash.rs +++ b/core/src/ten_rust/src/pkg_info/hash.rs @@ -16,8 +16,8 @@ use super::{ impl PkgInfo { pub fn gen_hash_hex(&self) -> Result { gen_hash_hex( - &self.pkg_identity.pkg_type, - &self.pkg_identity.name, + &self.pkg_type, + &self.name, &self.version, &self.dependencies, &self.supports, @@ -47,10 +47,8 @@ pub fn gen_hash_hex( // Hash dependencies. for dep in dependencies { - let dep_string = format!( - "{}:{}@{}", - dep.pkg_identity.pkg_type, dep.pkg_identity.name, dep.version_req - ); + let dep_string = + format!("{}:{}@{}", dep.pkg_type, dep.name, dep.version_req); hasher.update(dep_string); } diff --git a/core/src/ten_rust/src/pkg_info/manifest/dependency.rs b/core/src/ten_rust/src/pkg_info/manifest/dependency.rs index e4f1ec186..325340c36 100644 --- a/core/src/ten_rust/src/pkg_info/manifest/dependency.rs +++ b/core/src/ten_rust/src/pkg_info/manifest/dependency.rs @@ -19,8 +19,8 @@ pub struct ManifestDependency { impl From for ManifestDependency { fn from(pkg_dependency: PkgDependency) -> Self { ManifestDependency { - pkg_type: pkg_dependency.pkg_identity.pkg_type.to_string(), - name: pkg_dependency.pkg_identity.name, + pkg_type: pkg_dependency.pkg_type.to_string(), + name: pkg_dependency.name, version: pkg_dependency.version_req.to_string(), } } diff --git a/core/src/ten_rust/src/pkg_info/mod.rs b/core/src/ten_rust/src/pkg_info/mod.rs index 8bd8d47de..8ee6a00e0 100644 --- a/core/src/ten_rust/src/pkg_info/mod.rs +++ b/core/src/ten_rust/src/pkg_info/mod.rs @@ -13,8 +13,9 @@ pub mod hash; pub mod language; pub mod manifest; pub mod message; -pub mod pkg_identity; +pub mod pkg_basic_info; pub mod pkg_type; +pub mod pkg_type_and_name; pub mod predefined_graphs; pub mod property; pub mod supports; @@ -23,13 +24,14 @@ pub mod value_type; use std::{ cmp::Ordering, - collections::{HashMap, HashSet}, + collections::HashMap, hash::{Hash, Hasher}, path::{Path, PathBuf}, }; use anyhow::Result; use graph::Graph; +use pkg_type_and_name::PkgTypeAndName; use semver::Version; use crate::schema::store::SchemaStore; @@ -40,7 +42,6 @@ use constants::{ }; use dependencies::{get_pkg_dependencies_from_manifest, PkgDependency}; use manifest::{parse_manifest_from_file, parse_manifest_in_folder, Manifest}; -use pkg_identity::PkgIdentity; use pkg_type::PkgType; use property::{ parse_property_from_file, parse_property_in_folder, @@ -54,10 +55,9 @@ pub fn localhost() -> String { #[derive(Clone, Debug)] pub struct PkgInfo { - pub pkg_identity: PkgIdentity, + pub pkg_type: PkgType, + pub name: String, pub version: Version, - pub dependencies: Vec, - pub api: Option, // Since the declaration 'does not support all environments' has no // practical meaning, not specifying the 'supports' field or specifying an @@ -66,6 +66,10 @@ pub struct PkgInfo { // 'supports' field represents support for all combinations of // environments. pub supports: Vec, + + pub dependencies: Vec, + pub api: Option, + pub compatible_score: i32, // Source information. @@ -83,7 +87,8 @@ pub struct PkgInfo { // supports are the same. impl Hash for PkgInfo { fn hash(&self, state: &mut H) { - self.pkg_identity.hash(state); + self.pkg_type.hash(state); + self.name.hash(state); self.version.hash(state); self.supports.hash(state); } @@ -91,7 +96,8 @@ impl Hash for PkgInfo { impl PartialEq for PkgInfo { fn eq(&self, other: &Self) -> bool { - self.pkg_identity == other.pkg_identity + self.pkg_type == other.pkg_type + && self.name == other.name && self.version == other.version && self.supports == other.supports } @@ -108,16 +114,13 @@ impl PartialOrd for PkgInfo { impl Ord for PkgInfo { fn cmp(&self, other: &Self) -> Ordering { // Compare pkg_type. - if self.pkg_identity.pkg_type != other.pkg_identity.pkg_type { - return self - .pkg_identity - .pkg_type - .cmp(&other.pkg_identity.pkg_type); + if self.pkg_type != other.pkg_type { + return self.pkg_type.cmp(&other.pkg_type); } // Compare name. - if self.pkg_identity.name != other.pkg_identity.name { - return self.pkg_identity.name.cmp(&other.pkg_identity.name); + if self.name != other.name { + return self.name.cmp(&other.name); } // Compare version. @@ -136,7 +139,8 @@ impl PkgInfo { property: &Option, ) -> Result { Ok(PkgInfo { - pkg_identity: PkgIdentity::from_manifest(manifest)?, + pkg_type: manifest.pkg_type.parse::()?, + name: manifest.name.clone(), version: Version::parse(&manifest.version)?, dependencies: get_pkg_dependencies_from_manifest(manifest)?, api: PkgApi::from_manifest(manifest)?, @@ -231,8 +235,7 @@ impl PkgInfo { pkg_name: &str, ) -> Option<&PkgDependency> { self.dependencies.iter().find(|dep| { - dep.pkg_identity.pkg_type.to_string() == pkg_type - && dep.pkg_identity.name == pkg_name + dep.pkg_type.to_string() == pkg_type && dep.name == pkg_name }) } } @@ -251,29 +254,30 @@ pub fn get_pkg_info_from_path(pkg_path: &Path) -> Result { fn collect_pkg_info_from_path( base_path: &Path, - pkgs_info: &mut HashSet, + pkgs_info: &mut HashMap, ) -> Result { let pkg_info = get_pkg_info_from_path(base_path)?; - if pkgs_info.contains(&pkg_info) { + let pkg_type_name = PkgTypeAndName::from(&pkg_info); + if pkgs_info.contains_key(&pkg_type_name) { return Err(anyhow::anyhow!( "Duplicated package, type: {}, name: {}", - pkg_info.pkg_identity.pkg_type, - pkg_info.pkg_identity.name + pkg_info.pkg_type, + pkg_info.name )); } let manifest = pkg_info.manifest.clone().unwrap().clone(); - pkgs_info.insert(pkg_info); + pkgs_info.insert(pkg_type_name, pkg_info); Ok(manifest) } -pub fn get_all_existed_pkgs_info_of_app_to_hashset( +pub fn get_all_existed_pkgs_info_of_app_to_hashmap( app_path: &Path, -) -> Result> { - let mut pkgs_info: HashSet = HashSet::new(); +) -> Result> { + let mut pkgs_info: HashMap = HashMap::new(); // Process the manifest.json file in the root path. let app_pkg_manifest = @@ -345,8 +349,8 @@ pub fn get_all_existed_pkgs_info_of_app_to_hashset( pub fn get_all_existed_pkgs_info_of_app( app_path: &Path, ) -> Result> { - let result = get_all_existed_pkgs_info_of_app_to_hashset(app_path)?; - Ok(result.into_iter().collect()) + let result = get_all_existed_pkgs_info_of_app_to_hashmap(app_path)?; + Ok(result.into_values().collect()) } pub fn find_untracked_local_packages<'a>( @@ -356,17 +360,15 @@ pub fn find_untracked_local_packages<'a>( let mut untracked_local_packages: Vec<&PkgInfo> = vec![]; for local_pkg in local_pkgs { - let pkg_identity = &local_pkg.pkg_identity; - - if pkg_identity.pkg_type == PkgType::App { + if local_pkg.pkg_type == PkgType::App { continue; } // Check if the package is in dependencies list. - if !dependencies - .iter() - .any(|dependency| dependency.pkg_identity == *pkg_identity) - { + if !dependencies.iter().any(|dependency| { + dependency.pkg_type == local_pkg.pkg_type + && dependency.name == local_pkg.name + }) { untracked_local_packages.push(local_pkg); } } @@ -389,11 +391,9 @@ pub fn find_to_be_replaced_local_pkgs<'a>( let mut result: Vec<(&PkgInfo, &PkgInfo)> = vec![]; for local_pkg in local_pkgs { - let pkg_identity = local_pkg.pkg_identity.clone(); - - let pkg_in_dependencies = dependencies - .iter() - .find(|pkg| pkg.pkg_identity == pkg_identity); + let pkg_in_dependencies = dependencies.iter().find(|pkg| { + pkg.pkg_type == local_pkg.pkg_type && pkg.name == local_pkg.name + }); if let Some(pkg_in_dependencies) = pkg_in_dependencies { // If the supports of a locally installed package are incompatible, diff --git a/core/src/ten_rust/src/pkg_info/pkg_basic_info.rs b/core/src/ten_rust/src/pkg_info/pkg_basic_info.rs new file mode 100644 index 000000000..db1533922 --- /dev/null +++ b/core/src/ten_rust/src/pkg_info/pkg_basic_info.rs @@ -0,0 +1,60 @@ +// +// Copyright © 2024 Agora +// This file is part of TEN Framework, an open source project. +// Licensed under the Apache License, Version 2.0, with certain conditions. +// Refer to the "LICENSE" file in the root directory for more information. +// +use std::hash::{Hash, Hasher}; + +use semver::Version; + +use super::{ + dependencies::PkgDependency, pkg_type_and_name::PkgTypeAndName, + supports::PkgSupport, PkgInfo, +}; + +#[derive(Clone, Debug)] +pub struct PkgBasicInfo { + pub type_and_name: PkgTypeAndName, + pub version: Version, + + // Since the declaration 'does not support all environments' has no + // practical meaning, not specifying the 'supports' field or specifying an + // empty 'supports' field both represent support for all environments. + // Therefore, the 'supports' field here is not an option. An empty + // 'supports' field represents support for all combinations of + // environments. + pub supports: Vec, + + pub dependencies: Vec, + + pub hash: String, +} + +impl Hash for PkgBasicInfo { + fn hash(&self, state: &mut H) { + self.type_and_name.pkg_type.hash(state); + self.type_and_name.name.hash(state); + } +} + +impl PartialEq for PkgBasicInfo { + fn eq(&self, other: &Self) -> bool { + self.type_and_name.pkg_type == other.type_and_name.pkg_type + && self.type_and_name.name == other.type_and_name.name + } +} + +impl Eq for PkgBasicInfo {} + +impl From<&PkgInfo> for PkgBasicInfo { + fn from(pkg_info: &PkgInfo) -> Self { + PkgBasicInfo { + type_and_name: pkg_info.into(), + version: pkg_info.version.clone(), + supports: pkg_info.supports.clone(), + dependencies: pkg_info.dependencies.clone(), + hash: pkg_info.hash.clone(), + } + } +} diff --git a/core/src/ten_rust/src/pkg_info/pkg_type.rs b/core/src/ten_rust/src/pkg_info/pkg_type.rs index f6f2251ff..6edc9c8da 100644 --- a/core/src/ten_rust/src/pkg_info/pkg_type.rs +++ b/core/src/ten_rust/src/pkg_info/pkg_type.rs @@ -10,7 +10,16 @@ use anyhow::{Error, Result}; use serde::{Deserialize, Serialize}; #[derive( - Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, + Copy, + Clone, + Debug, + PartialEq, + Eq, + PartialOrd, + Ord, + Hash, + Serialize, + Deserialize, )] pub enum PkgType { #[serde(rename = "system")] diff --git a/core/src/ten_rust/src/pkg_info/pkg_identity.rs b/core/src/ten_rust/src/pkg_info/pkg_type_and_name.rs similarity index 50% rename from core/src/ten_rust/src/pkg_info/pkg_identity.rs rename to core/src/ten_rust/src/pkg_info/pkg_type_and_name.rs index aa91fea90..1625a8d7a 100644 --- a/core/src/ten_rust/src/pkg_info/pkg_identity.rs +++ b/core/src/ten_rust/src/pkg_info/pkg_type_and_name.rs @@ -9,35 +9,55 @@ use std::hash::{Hash, Hasher}; use anyhow::Result; use serde::{Deserialize, Serialize}; -use super::pkg_type::PkgType; +use super::{pkg_basic_info::PkgBasicInfo, pkg_type::PkgType, PkgInfo}; use crate::pkg_info::manifest::Manifest; #[derive(Clone, Debug, Serialize, Deserialize, PartialOrd, Ord)] -pub struct PkgIdentity { +pub struct PkgTypeAndName { pub pkg_type: PkgType, pub name: String, } -impl Hash for PkgIdentity { +impl Hash for PkgTypeAndName { fn hash(&self, state: &mut H) { self.pkg_type.hash(state); self.name.hash(state); } } -impl PartialEq for PkgIdentity { +impl PartialEq for PkgTypeAndName { fn eq(&self, other: &Self) -> bool { self.pkg_type == other.pkg_type && self.name == other.name } } -impl Eq for PkgIdentity {} +impl Eq for PkgTypeAndName {} -impl PkgIdentity { - pub fn from_manifest(manifest: &Manifest) -> Result { - Ok(PkgIdentity { +impl TryFrom<&Manifest> for PkgTypeAndName { + type Error = anyhow::Error; + + fn try_from(manifest: &Manifest) -> Result { + Ok(PkgTypeAndName { pkg_type: manifest.pkg_type.parse::()?, name: manifest.name.clone(), }) } } + +impl From<&PkgInfo> for PkgTypeAndName { + fn from(pkg_info: &PkgInfo) -> Self { + PkgTypeAndName { + pkg_type: pkg_info.pkg_type, + name: pkg_info.name.clone(), + } + } +} + +impl From<&PkgBasicInfo> for PkgTypeAndName { + fn from(pkg_basic_info: &PkgBasicInfo) -> Self { + PkgTypeAndName { + pkg_type: pkg_basic_info.type_and_name.pkg_type, + name: pkg_basic_info.type_and_name.name.clone(), + } + } +} diff --git a/core/src/ten_rust/src/pkg_info/predefined_graphs/extension.rs b/core/src/ten_rust/src/pkg_info/predefined_graphs/extension.rs index d8bcd2901..ae07c6af9 100644 --- a/core/src/ten_rust/src/pkg_info/predefined_graphs/extension.rs +++ b/core/src/ten_rust/src/pkg_info/predefined_graphs/extension.rs @@ -26,9 +26,8 @@ pub fn get_extension_nodes_in_graph( graph_name: &String, all_pkgs: &[PkgInfo], ) -> Result> { - if let Some(app_pkg) = all_pkgs - .iter() - .find(|pkg| pkg.pkg_identity.pkg_type == PkgType::App) + if let Some(app_pkg) = + all_pkgs.iter().find(|pkg| pkg.pkg_type == PkgType::App) { if app_pkg.property.is_none() { return Err(anyhow::anyhow!("'property.json' file not found.")); @@ -67,8 +66,8 @@ pub fn get_pkg_info_for_extension<'a>( all_pkgs .iter() .find(|pkg| { - pkg.pkg_identity.pkg_type == PkgType::Extension - && pkg.pkg_identity.name == extension.addon + pkg.pkg_type == PkgType::Extension + && pkg.name == extension.addon }) .ok_or_else(|| { anyhow::anyhow!( diff --git a/core/src/ten_rust/tests/graph_check.rs b/core/src/ten_rust/tests/graph_check.rs index 1472db14b..1b1f48814 100644 --- a/core/src/ten_rust/tests/graph_check.rs +++ b/core/src/ten_rust/tests/graph_check.rs @@ -21,7 +21,7 @@ fn test_graph_check_extension_not_installed_1() { let app_pkg_info = pkg_infos .iter() - .filter(|pkg| pkg.pkg_identity.pkg_type == PkgType::App) + .filter(|pkg| pkg.pkg_type == PkgType::App) .last(); let app_pkg = app_pkg_info.unwrap(); let predefined_graphs = app_pkg.get_predefined_graphs().unwrap(); @@ -46,7 +46,7 @@ fn test_graph_check_extension_not_installed_2() { let app_pkg_info = pkg_infos .iter() - .filter(|pkg| pkg.pkg_identity.pkg_type == PkgType::App) + .filter(|pkg| pkg.pkg_type == PkgType::App) .last(); let app_pkg = app_pkg_info.unwrap(); let predefined_graphs = app_pkg.get_predefined_graphs().unwrap(); @@ -71,7 +71,7 @@ fn test_graph_check_predefined_graph_success() { let app_pkg_info = pkg_infos .iter() - .filter(|pkg| pkg.pkg_identity.pkg_type == PkgType::App) + .filter(|pkg| pkg.pkg_type == PkgType::App) .last(); let app_pkg = app_pkg_info.unwrap(); let predefined_graphs = app_pkg.get_predefined_graphs().unwrap(); @@ -95,7 +95,7 @@ fn test_graph_check_all_msgs_schema_incompatible() { let app_pkg_info = pkg_infos .iter() - .filter(|pkg| pkg.pkg_identity.pkg_type == PkgType::App) + .filter(|pkg| pkg.pkg_type == PkgType::App) .last(); let app_pkg = app_pkg_info.unwrap(); let predefined_graphs = app_pkg.get_predefined_graphs().unwrap();