From 3831b30d85d88e592901e27009fc53abd5579055 Mon Sep 17 00:00:00 2001 From: Hu Yueh-Wei Date: Thu, 19 Dec 2024 12:07:08 +0800 Subject: [PATCH 1/2] refactor: abstract pkg_basic_info concept --- .../ten_manager/src/dep_and_candidate/mod.rs | 7 ++++--- core/src/ten_manager/src/solver/solve.rs | 10 +++++----- .../graph/check/nodes_are_installed.rs | 4 ++-- .../ten_rust/src/pkg_info/pkg_basic_info.rs | 19 ++++++------------- .../src/pkg_info/pkg_type_and_name.rs | 4 +--- 5 files changed, 18 insertions(+), 26 deletions(-) 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 b49519b00a..541d86032d 100644 --- a/core/src/ten_manager/src/dep_and_candidate/mod.rs +++ b/core/src/ten_manager/src/dep_and_candidate/mod.rs @@ -11,6 +11,7 @@ use anyhow::{anyhow, Result}; use semver::{Version, VersionReq}; use ten_rust::pkg_info::dependencies::PkgDependency; +use ten_rust::pkg_info::pkg_basic_info::PkgBasicInfo; use ten_rust::pkg_info::pkg_type::PkgType; use ten_rust::pkg_info::pkg_type_and_name::PkgTypeAndName; use ten_rust::pkg_info::supports::{ @@ -299,7 +300,7 @@ pub async fn get_all_candidates_from_deps( locked_pkgs: Option<&HashMap>, ) -> Result>> { let mut merged_dependencies = HashSet::::new(); - let mut processed_pkgs = HashSet::::new(); + let mut processed_pkgs = HashSet::::new(); // If there is extra dependencies (ex: specified in the command line), // handle those dependencies, too. @@ -324,7 +325,7 @@ pub async fn get_all_candidates_from_deps( // Process all packages to be searched. while let Some(pkg_to_be_search) = pkgs_to_be_searched.pop() { - if processed_pkgs.contains(&pkg_to_be_search) { + if processed_pkgs.contains(&(&pkg_to_be_search).into()) { // If this package info has already been processed, do not // process it again. continue; @@ -341,7 +342,7 @@ pub async fn get_all_candidates_from_deps( .await?; // Remember that this package has already been processed. - processed_pkgs.insert(pkg_to_be_search); + processed_pkgs.insert((&pkg_to_be_search).into()); } if new_pkgs_to_be_searched.is_empty() { diff --git a/core/src/ten_manager/src/solver/solve.rs b/core/src/ten_manager/src/solver/solve.rs index f53e710bad..bf50c07ec1 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_type::PkgType, - pkg_type_and_name::PkgTypeAndName, PkgInfo, + dependencies::DependencyRelationship, pkg_basic_info::PkgBasicInfo, + pkg_type::PkgType, pkg_type_and_name::PkgTypeAndName, PkgInfo, }; use crate::{ @@ -338,14 +338,14 @@ fn create_input_str_for_dependency_relationship( fn create_input_str_for_pkg_info_dependencies( input_str: &mut String, pkg_info: &PkgInfo, - dumped_pkgs_info: &mut HashSet, + dumped_pkgs_info: &mut HashSet, all_candidates: &HashMap>, ) -> Result<()> { // If this package has already been dumped, skip it. - if dumped_pkgs_info.contains(pkg_info) { + if dumped_pkgs_info.contains(&pkg_info.into()) { return Ok(()); } - dumped_pkgs_info.insert(pkg_info.clone()); + dumped_pkgs_info.insert(pkg_info.into()); for dependency in &pkg_info.dependencies { let candidates = all_candidates.get(&(dependency).into()); 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 765ca9b0e4..8b743dc2cf 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 @@ -28,7 +28,7 @@ impl Graph { if !skip_if_app_not_exist { not_installed_pkgs.push(( node_app_uri.to_string(), - node.node_type.clone(), + node.node_type, node.addon.clone(), )); } @@ -48,7 +48,7 @@ impl Graph { if found.is_none() { not_installed_pkgs.push(( node_app_uri.to_string(), - node.node_type.clone(), + node.node_type, node.addon.clone(), )); } 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 index db15339222..7cda31842b 100644 --- a/core/src/ten_rust/src/pkg_info/pkg_basic_info.rs +++ b/core/src/ten_rust/src/pkg_info/pkg_basic_info.rs @@ -8,12 +8,9 @@ use std::hash::{Hash, Hasher}; use semver::Version; -use super::{ - dependencies::PkgDependency, pkg_type_and_name::PkgTypeAndName, - supports::PkgSupport, PkgInfo, -}; +use super::{pkg_type_and_name::PkgTypeAndName, supports::PkgSupport, PkgInfo}; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Eq)] pub struct PkgBasicInfo { pub type_and_name: PkgTypeAndName, pub version: Version, @@ -25,16 +22,14 @@ pub struct PkgBasicInfo { // '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); + self.version.hash(state); + self.supports.hash(state); } } @@ -42,19 +37,17 @@ 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 + && self.version == other.version + && self.supports == other.supports } } -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_and_name.rs b/core/src/ten_rust/src/pkg_info/pkg_type_and_name.rs index 1625a8d7a4..fc31548491 100644 --- a/core/src/ten_rust/src/pkg_info/pkg_type_and_name.rs +++ b/core/src/ten_rust/src/pkg_info/pkg_type_and_name.rs @@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize}; use super::{pkg_basic_info::PkgBasicInfo, pkg_type::PkgType, PkgInfo}; use crate::pkg_info::manifest::Manifest; -#[derive(Clone, Debug, Serialize, Deserialize, PartialOrd, Ord)] +#[derive(Clone, Debug, Serialize, Deserialize, PartialOrd, Eq)] pub struct PkgTypeAndName { pub pkg_type: PkgType, pub name: String, @@ -31,8 +31,6 @@ impl PartialEq for PkgTypeAndName { } } -impl Eq for PkgTypeAndName {} - impl TryFrom<&Manifest> for PkgTypeAndName { type Error = anyhow::Error; From 2a6a2c699d8a57b26ca4be1ee9ce5808cf3acd17 Mon Sep 17 00:00:00 2001 From: Hu Yueh-Wei Date: Thu, 19 Dec 2024 12:47:30 +0800 Subject: [PATCH 2/2] refactor: abstract pkg_basic_info concept --- core/src/ten_manager/src/cmd/cmd_install.rs | 22 ++++--- .../ten_manager/src/dep_and_candidate/mod.rs | 57 +++++++++++-------- .../ten_manager/src/designer/graphs/update.rs | 23 ++++---- core/src/ten_manager/src/manifest_lock/mod.rs | 2 +- core/src/ten_manager/src/registry/local.rs | 2 +- core/src/ten_manager/src/solver/introducer.rs | 6 +- core/src/ten_manager/src/solver/solve.rs | 37 ++++++------ .../ten_manager/src/solver/solver_error.rs | 8 ++- .../ten_manager/src/solver/solver_result.rs | 17 +++--- .../src/pkg_info/predefined_graphs/mod.rs | 4 +- 10 files changed, 100 insertions(+), 78 deletions(-) diff --git a/core/src/ten_manager/src/cmd/cmd_install.rs b/core/src/ten_manager/src/cmd/cmd_install.rs index 0e317d8be2..c32b0b8021 100644 --- a/core/src/ten_manager/src/cmd/cmd_install.rs +++ b/core/src/ten_manager/src/cmd/cmd_install.rs @@ -5,7 +5,7 @@ // Refer to the "LICENSE" file in the root directory for more information. // use std::{ - collections::{HashMap, HashSet}, + collections::HashMap, env, fs::{self, OpenOptions}, path::{Path, PathBuf}, @@ -20,9 +20,6 @@ use indicatif::HumanDuration; use inquire::Confirm; use semver::VersionReq; -use ten_rust::pkg_info::manifest::{ - dependency::ManifestDependency, parse_manifest_in_folder, -}; use ten_rust::pkg_info::{ dependencies::{DependencyRelationship, PkgDependency}, find_to_be_replaced_local_pkgs, find_untracked_local_packages, @@ -32,6 +29,10 @@ use ten_rust::pkg_info::{ supports::{is_pkg_supports_compatible_with, Arch, Os, PkgSupport}, PkgInfo, }; +use ten_rust::pkg_info::{ + manifest::{dependency::ManifestDependency, parse_manifest_in_folder}, + pkg_basic_info::PkgBasicInfo, +}; use crate::{ config::TmanConfig, @@ -298,7 +299,10 @@ 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< + PkgTypeAndName, + HashMap, + >, support: &PkgSupport, ) { for existed_pkg in all_existing_local_pkgs.to_owned().iter_mut() { @@ -324,7 +328,7 @@ fn filter_compatible_pkgs_to_candidates( all_candidates .entry((&*existed_pkg).into()) .or_default() - .insert(existed_pkg.clone()); + .insert((&*existed_pkg).into(), existed_pkg.clone()); } else { // The existed package is not compatible with the current system, so // it should not be considered as a candidate. @@ -455,8 +459,10 @@ 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> = - HashMap::new(); + let mut all_candidates: HashMap< + PkgTypeAndName, + HashMap, + > = HashMap::new(); // 'all_existing_local_pkgs' contains all the packages which are already // located in the app directory. 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 541d86032d..80c1c6c833 100644 --- a/core/src/ten_manager/src/dep_and_candidate/mod.rs +++ b/core/src/ten_manager/src/dep_and_candidate/mod.rs @@ -119,9 +119,8 @@ fn merge_dependency_to_dependencies( /// # Parameters /// /// - `all_candidates`: A mutable reference to a map where the keys are package -/// identities (`PkgIdentity`) and the values are sets of candidate package -/// information (`HashSet`). This map will be updated with potential -/// candidate packages for each dependency. +/// type & name and the values are sets of candidate package information. This +/// map will be updated with potential candidate packages for each dependency. /// /// # Returns /// @@ -136,7 +135,10 @@ async fn process_dependencies_to_get_candidates( support: &PkgSupport, input_dependencies: &Vec, merged_dependencies: &mut HashSet, - all_candidates: &mut HashMap>, + all_candidates: &mut HashMap< + PkgTypeAndName, + HashMap, + >, new_pkgs_to_be_searched: &mut Vec, ) -> Result<()> { for dependency in input_dependencies { @@ -197,14 +199,14 @@ async fn process_dependencies_to_get_candidates( // dependencies within those packages are processed. if let Some(candidates) = all_candidates.get(&dependency.into()) { for candidate in candidates { - if dependency.version_req.matches(&candidate.version) { + if dependency.version_req.matches(&candidate.0.version) { tman_verbose_println!( tman_config, "Collect candidate: {:?}", candidate ); - candidate_pkg_infos.push(candidate.clone()); + candidate_pkg_infos.push(candidate.1.clone()); } } } @@ -234,10 +236,10 @@ async fn process_dependencies_to_get_candidates( candidate_pkg_info ); - all_candidates - .entry(dependency.into()) - .or_default() - .insert(candidate_pkg_info.clone()); + all_candidates.entry(dependency.into()).or_default().insert( + (&candidate_pkg_info).into(), + candidate_pkg_info.clone(), + ); new_pkgs_to_be_searched.push(candidate_pkg_info); } @@ -251,7 +253,10 @@ 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>, + all_candidates: &mut HashMap< + PkgTypeAndName, + HashMap, + >, locked_pkgs: Option<&HashMap>, ) { for (pkg_type_name, pkg_infos) in all_candidates.iter_mut() { @@ -264,30 +269,34 @@ fn clean_up_all_candidates( for pkg_info in pkg_infos.iter() { // Check if the candidate is a locked one. if let Some(locked_pkg) = locked_pkg { - if locked_pkg.version == pkg_info.version - && locked_pkg.hash == pkg_info.hash + if locked_pkg.version == pkg_info.1.version + && locked_pkg.hash == pkg_info.1.hash { - locked_pkgs_map.insert(pkg_info.version.clone(), pkg_info); + locked_pkgs_map + .insert(pkg_info.1.version.clone(), pkg_info.1); } } version_map - .entry(pkg_info.version.clone()) + .entry(pkg_info.1.version.clone()) .and_modify(|existing_pkg_info| { - if pkg_info.compatible_score + if pkg_info.1.compatible_score > existing_pkg_info.compatible_score { - *existing_pkg_info = pkg_info; + *existing_pkg_info = pkg_info.1; } }) - .or_insert(pkg_info); + .or_insert(pkg_info.1); } // If there is a locked one, replace the candidate with the highest // score with the locked one. version_map.extend(locked_pkgs_map); - *pkg_infos = version_map.into_values().cloned().collect(); + *pkg_infos = version_map + .into_values() + .map(|pkg_info| (pkg_info.into(), pkg_info.clone())) + .collect(); } } @@ -295,10 +304,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>> { +) -> Result>> { let mut merged_dependencies = HashSet::::new(); let mut processed_pkgs = HashSet::::new(); @@ -360,7 +369,7 @@ 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_name = PkgTypeAndName { pkg_type: pkg_type.parse::()?, @@ -369,7 +378,7 @@ pub fn get_pkg_info_from_candidates( let version_parsed = Version::parse(version)?; let pkg_info = all_candidates .get(&pkg_type_name) - .and_then(|set| set.iter().find(|pkg| pkg.version == version_parsed)) + .and_then(|set| set.iter().find(|pkg| pkg.1.version == version_parsed)) .ok_or_else(|| { anyhow!( "PkgInfo not found for [{}]{}@{}", @@ -378,5 +387,5 @@ pub fn get_pkg_info_from_candidates( version ) })?; - Ok(pkg_info.clone()) + Ok(pkg_info.1.clone()) } diff --git a/core/src/ten_manager/src/designer/graphs/update.rs b/core/src/ten_manager/src/designer/graphs/update.rs index 5a2c09541a..d853f04523 100644 --- a/core/src/ten_manager/src/designer/graphs/update.rs +++ b/core/src/ten_manager/src/designer/graphs/update.rs @@ -9,6 +9,7 @@ use std::sync::{Arc, RwLock}; use actix_web::{web, HttpResponse, Responder}; use serde::{Deserialize, Serialize}; +use ten_rust::pkg_info::graph::{GraphConnection, GraphNode}; use ten_rust::pkg_info::pkg_type::PkgType; use ten_rust::pkg_info::predefined_graphs::get_pkg_predefined_graph_from_nodes_and_connections; @@ -44,21 +45,23 @@ 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_type == PkgType::App) + if let Some(app_pkg) = + pkgs.iter_mut().find(|pkg| pkg.pkg_type == PkgType::App) { + // Collect nodes into a Vec. + let nodes: Vec = + body.nodes.iter().cloned().map(|v| v.into()).collect(); + + // Collect connections into a Vec. + let connections: Vec = + body.connections.iter().cloned().map(|v| v.into()).collect(); + let new_graph = match get_pkg_predefined_graph_from_nodes_and_connections( &graph_name, body.auto_start, - &body.nodes.clone().into_iter().map(|v| v.into()).collect(), - &body - .connections - .clone() - .into_iter() - .map(|v| v.into()) - .collect(), + &nodes, + &connections, ) { Ok(graph) => graph, Err(err) => { diff --git a/core/src/ten_manager/src/manifest_lock/mod.rs b/core/src/ten_manager/src/manifest_lock/mod.rs index e57515b0ea..c5f8f819d1 100644 --- a/core/src/ten_manager/src/manifest_lock/mod.rs +++ b/core/src/ten_manager/src/manifest_lock/mod.rs @@ -35,7 +35,7 @@ pub struct ManifestLock { type LockedPkgsInfo<'a> = &'a Vec<&'a PkgInfo>; -impl<'a> From> for ManifestLock { +impl From> for ManifestLock { // Convert a complete `Resolve` to a ManifestLock which can be serialized to // a `manifest-lock.json` file. fn from(resolve: LockedPkgsInfo) -> Self { diff --git a/core/src/ten_manager/src/registry/local.rs b/core/src/ten_manager/src/registry/local.rs index ff9e9135b3..07f11210c6 100644 --- a/core/src/ten_manager/src/registry/local.rs +++ b/core/src/ten_manager/src/registry/local.rs @@ -117,7 +117,7 @@ fn find_file_with_criteria( name: &String, criteria: &SearchCriteria, ) -> Result> { - let target_path = base_url.join(pkg_type.to_string()).join(&name); + let target_path = base_url.join(pkg_type.to_string()).join(name); let mut results = Vec::::new(); diff --git a/core/src/ten_manager/src/solver/introducer.rs b/core/src/ten_manager/src/solver/introducer.rs index a7c9d0a159..977c803362 100644 --- a/core/src/ten_manager/src/solver/introducer.rs +++ b/core/src/ten_manager/src/solver/introducer.rs @@ -9,14 +9,16 @@ use std::collections::{HashMap, HashSet}; use anyhow::Result; use regex::Regex; -use ten_rust::pkg_info::{pkg_type_and_name::PkgTypeAndName, PkgInfo}; +use ten_rust::pkg_info::{ + pkg_basic_info::PkgBasicInfo, 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\("([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]*)","([^"]*)"\)"#, diff --git a/core/src/ten_manager/src/solver/solve.rs b/core/src/ten_manager/src/solver/solve.rs index bf50c07ec1..759a39795d 100644 --- a/core/src/ten_manager/src/solver/solve.rs +++ b/core/src/ten_manager/src/solver/solve.rs @@ -294,7 +294,7 @@ fn solve(tman_config: &TmanConfig, input: &str) -> SolveResult { 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 = @@ -305,16 +305,16 @@ fn create_input_str_for_dependency_relationship( if dependency_relationship .dependency .version_req - .matches(&candidate.version) + .matches(&candidate.1.version) { input_str.push_str(&format!( "depends_on_declared(\"{}\", \"{}\", \"{}\", \"{}\", \"{}\", \"{}\").\n", dependency_relationship.pkg_type, dependency_relationship.name, dependency_relationship.version, - candidate.pkg_type, - candidate.name, - candidate.version, + candidate.1.pkg_type, + candidate.1.name, + candidate.1.version, )); } } @@ -339,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.into()) { @@ -354,20 +354,20 @@ fn create_input_str_for_pkg_info_dependencies( let mut found_matched = false; for candidate in candidates { - if dependency.version_req.matches(&candidate.version) { + if dependency.version_req.matches(&candidate.1.version) { input_str.push_str(&format!( "depends_on_declared(\"{}\", \"{}\", \"{}\", \"{}\", \"{}\", \"{}\").\n", pkg_info.pkg_type, pkg_info.name, pkg_info.version, - candidate.pkg_type, - candidate.name, - candidate.version, + candidate.1.pkg_type, + candidate.1.name, + candidate.1.version, )); create_input_str_for_pkg_info_dependencies( input_str, - candidate, + candidate.1, dumped_pkgs_info, all_candidates, )?; @@ -420,11 +420,12 @@ 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>, + all_candidates: &HashMap>, locked_pkgs: Option<&HashMap>, ) -> Result<()> { for candidates in all_candidates { - let mut candidates_vec: Vec<_> = candidates.1.iter().collect(); + let mut candidates_vec: Vec = + candidates.1.values().cloned().collect(); // The sorting below places the larger versions at the front, thus // having smaller indexes. This is correct because, in the Clingo @@ -447,13 +448,13 @@ fn create_input_str_for_all_possible_pkgs_info( if let Some(idx) = idx { candidates_vec.remove(idx); - candidates_vec.insert(0, locked_pkg); + candidates_vec.insert(0, locked_pkg.clone()); } } for (idx, candidate) in candidates_vec.into_iter().enumerate() { create_input_str_for_pkg_info_without_dependencies( - input_str, candidate, &idx, + input_str, &candidate, &idx, )?; } } @@ -466,7 +467,7 @@ fn create_input_str( pkg_name: &String, pkg_type: &PkgType, extra_dependency_relationships: &Vec, - all_candidates: &HashMap>, + all_candidates: &HashMap>, locked_pkgs: Option<&HashMap>, ) -> Result { let mut input_str = String::new(); @@ -494,7 +495,7 @@ fn create_input_str( for candidate in candidates.1 { create_input_str_for_pkg_info_dependencies( &mut input_str, - candidate, + candidate.1, &mut dumped_pkgs_info, all_candidates, )?; @@ -519,7 +520,7 @@ pub fn solve_all( pkg_name: &String, pkg_type: &PkgType, extra_dependency_relationships: &Vec, - all_candidates: &HashMap>, + all_candidates: &HashMap>, locked_pkgs: Option<&HashMap>, ) -> SolveResult { let input_str = create_input_str( diff --git a/core/src/ten_manager/src/solver/solver_error.rs b/core/src/ten_manager/src/solver/solver_error.rs index 4b52be2d82..255402ee89 100644 --- a/core/src/ten_manager/src/solver/solver_error.rs +++ b/core/src/ten_manager/src/solver/solver_error.rs @@ -4,13 +4,15 @@ // 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::collections::{HashMap, HashSet}; +use std::collections::HashMap; use anyhow::{anyhow, Result}; use console::Emoji; use regex::Regex; -use ten_rust::pkg_info::{pkg_type_and_name::PkgTypeAndName, PkgInfo}; +use ten_rust::pkg_info::{ + pkg_basic_info::PkgBasicInfo, pkg_type_and_name::PkgTypeAndName, PkgInfo, +}; use crate::{ dep_and_candidate::get_pkg_info_from_candidates, @@ -145,7 +147,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: {}", diff --git a/core/src/ten_manager/src/solver/solver_result.rs b/core/src/ten_manager/src/solver/solver_result.rs index 1e1f5dba79..e6724d2dda 100644 --- a/core/src/ten_manager/src/solver/solver_result.rs +++ b/core/src/ten_manager/src/solver/solver_result.rs @@ -4,10 +4,7 @@ // 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::{ - collections::{HashMap, HashSet}, - path::Path, -}; +use std::{collections::HashMap, path::Path}; use anyhow::Result; use console::Emoji; @@ -16,7 +13,8 @@ use regex::Regex; use semver::Version; use ten_rust::pkg_info::{ - pkg_type::PkgType, pkg_type_and_name::PkgTypeAndName, PkgInfo, + pkg_basic_info::PkgBasicInfo, pkg_type::PkgType, + pkg_type_and_name::PkgTypeAndName, PkgInfo, }; use crate::{ @@ -30,7 +28,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\("([^"]+)","([^"]+)","([^"]+)"\)"#) @@ -54,12 +52,13 @@ pub fn extract_solver_results_from_raw_solver_results( }) .unwrap() { - if candidate.pkg_type != pkg_type || candidate.name != name { + if candidate.1.pkg_type != pkg_type || candidate.1.name != name + { panic!("Should not happen."); } - if candidate.version == semver { - results_info.push(candidate.clone()); + if candidate.1.version == semver { + results_info.push(candidate.1.clone()); continue 'outer; } } diff --git a/core/src/ten_rust/src/pkg_info/predefined_graphs/mod.rs b/core/src/ten_rust/src/pkg_info/predefined_graphs/mod.rs index 047c097ef3..8453696f9f 100644 --- a/core/src/ten_rust/src/pkg_info/predefined_graphs/mod.rs +++ b/core/src/ten_rust/src/pkg_info/predefined_graphs/mod.rs @@ -32,8 +32,8 @@ where pub fn get_pkg_predefined_graph_from_nodes_and_connections( graph_name: &str, auto_start: bool, - nodes: &Vec, - connections: &Vec, + nodes: &[GraphNode], + connections: &[GraphConnection], ) -> Result { Ok(PropertyPredefinedGraph { name: graph_name.to_string(),