Skip to content

Commit

Permalink
feat: add conflict error information to tman
Browse files Browse the repository at this point in the history
  • Loading branch information
halajohn committed Nov 3, 2024
1 parent 19252a5 commit 15671be
Show file tree
Hide file tree
Showing 37 changed files with 651 additions and 148 deletions.
1 change: 1 addition & 0 deletions core/src/ten_manager/src/cmd/cmd_check/cmd_check_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{collections::HashMap, fs, path, str::FromStr};
use anyhow::{Context, Result};
use clap::{Arg, ArgMatches, Command};
use console::Emoji;

use ten_rust::pkg_info::{
get_all_existed_pkgs_info_of_app, graph::Graph, localhost,
property::parse_property_in_folder, PkgInfo,
Expand Down
5 changes: 3 additions & 2 deletions core/src/ten_manager/src/cmd/cmd_delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ use console::Emoji;
use indicatif::HumanDuration;
use semver::Version;

use crate::log::tman_verbose_println;
use crate::{config::TmanConfig, registry::delete_package};
use ten_rust::pkg_info::pkg_identity::PkgIdentity;
use ten_rust::pkg_info::pkg_type::PkgType;

use crate::log::tman_verbose_println;
use crate::{config::TmanConfig, registry::delete_package};

#[derive(Debug)]
pub struct DeleteCommand {
pub package_type: String,
Expand Down
56 changes: 43 additions & 13 deletions core/src/ten_manager/src/cmd/cmd_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,26 @@ use std::{
time::Instant,
};

use anyhow::{Ok, Result};
use anyhow::Result;
use clap::{Arg, ArgAction, ArgMatches, Command};
use console::Emoji;
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,
get_pkg_info_from_path,
pkg_identity::PkgIdentity,
pkg_type::PkgType,
supports::{is_pkg_supports_compatible_with, Arch, Os, PkgSupport},
PkgInfo,
};

use crate::{
config::TmanConfig,
constants::{APP_DIR_IN_DOT_TEN_DIR, DOT_TEN_DIR, MANIFEST_JSON_FILENAME},
Expand All @@ -32,7 +45,9 @@ use crate::{
},
package_info::tman_get_all_existed_pkgs_info_of_app,
solver::{
introducer::extract_introducer_relations_from_raw_solver_results,
solve::solve_all,
solver_error::{parse_error_statement, print_conflict_info},
solver_result::{
extract_solver_results_from_raw_solver_results,
filter_solver_results_by_type_and_name,
Expand All @@ -42,18 +57,6 @@ use crate::{
},
utils::{check_is_app_folder, check_is_package_folder},
};
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,
get_pkg_info_from_path,
pkg_identity::PkgIdentity,
pkg_type::PkgType,
supports::{is_pkg_supports_compatible_with, Arch, Os, PkgSupport},
PkgInfo,
};

#[derive(Debug)]
pub struct InstallCommand {
Expand Down Expand Up @@ -669,12 +672,39 @@ pub async fn execute_cmd(
)?;

// Print out the answer.
tman_verbose_println!(tman_config, "\n");
tman_verbose_println!(tman_config, "Result:");
for result in &results {
tman_verbose_println!(tman_config, " {:?}", result);
}
tman_verbose_println!(tman_config, "");

// Extract introducer relations.
let introducer_relations =
extract_introducer_relations_from_raw_solver_results(
&results,
&all_candidates,
)?;

// Parse the error message.
if let Ok(conflict_info) = parse_error_statement(&results) {
// Print the error message and dependency chains.
print_conflict_info(
tman_config,
&conflict_info,
&introducer_relations,
&all_candidates,
)?;

// Since there is an error, we need to exit.
return Err(TmanError::Custom(
"Dependency resolution failed.".to_string(),
)
.into());
}

// If there is no error message, proceed.

// Get the information of the resultant packages.
let solver_results = extract_solver_results_from_raw_solver_results(
&results,
Expand Down
3 changes: 2 additions & 1 deletion core/src/ten_manager/src/cmd/cmd_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ use clap::{ArgMatches, Command};
use console::Emoji;
use indicatif::HumanDuration;

use ten_rust::pkg_info::get_pkg_info_from_path;

use crate::{
config::TmanConfig,
log::tman_verbose_println,
package_file::{create_package_zip_file, get_package_zip_file_name},
};
use ten_rust::pkg_info::get_pkg_info_from_path;

#[derive(Debug)]
pub struct PackageCommand {}
Expand Down
3 changes: 2 additions & 1 deletion core/src/ten_manager/src/cmd/cmd_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ use clap::{ArgMatches, Command};
use console::Emoji;
use indicatif::HumanDuration;

use ten_rust::pkg_info::get_pkg_info_from_path;

use crate::config::TmanConfig;
use crate::log::tman_verbose_println;
use crate::package_file::create_package_zip_file;
use crate::package_file::get_package_zip_file_name;
use crate::registry::upload_package;
use ten_rust::pkg_info::get_pkg_info_from_path;

#[derive(Debug)]
pub struct PublishCommand {}
Expand Down
38 changes: 33 additions & 5 deletions core/src/ten_manager/src/dep_and_candidate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@
use std::collections::{HashMap, HashSet};
use std::hash::{Hash, Hasher};

use anyhow::Result;
use anyhow::{anyhow, Result};
use semver::{Version, VersionReq};

use super::config::TmanConfig;
use super::registry::{get_package_list, SearchCriteria};
use super::utils::pathbuf_to_string;
use crate::package_info::pkg_info_from_find_package_data;
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::supports::{
is_pkg_supports_compatible_with, PkgSupport,
};
use ten_rust::pkg_info::PkgInfo;

use super::config::TmanConfig;
use super::registry::{get_package_list, SearchCriteria};
use super::utils::pathbuf_to_string;
use crate::package_info::pkg_info_from_find_package_data;

// TODO(Wei): Should use the union of the semantic versioning rather than the
// union of all version requirements.
#[derive(Default)]
Expand Down Expand Up @@ -319,3 +321,29 @@ pub async fn get_all_candidates_from_deps(

Ok(all_candidates)
}

pub fn get_pkg_info_from_candidates(
pkg_type: &str,
pkg_name: &str,
version: &str,
all_candidates: &HashMap<PkgIdentity, HashSet<PkgInfo>>,
) -> Result<PkgInfo> {
let pkg_type_enum = pkg_type.parse::<PkgType>()?;
let pkg_identity = PkgIdentity {
pkg_type: pkg_type_enum,
name: pkg_name.to_string(),
};
let version_parsed = Version::parse(version)?;
let pkg_info = all_candidates
.get(&pkg_identity)
.and_then(|set| set.iter().find(|pkg| pkg.version == version_parsed))
.ok_or_else(|| {
anyhow!(
"PkgInfo not found for [{}]{}@{}",
pkg_type,
pkg_name,
version
)
})?;
Ok(pkg_info.clone())
}
4 changes: 3 additions & 1 deletion core/src/ten_manager/src/dev_server/addons/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use std::sync::{Arc, RwLock};
use actix_web::{web, HttpResponse, Responder};
use serde::{Deserialize, Serialize};

use ten_rust::pkg_info::pkg_type::PkgType;

use crate::dev_server::{
common::{
get_dev_server_api_cmd_likes_from_pkg,
Expand All @@ -20,7 +22,7 @@ use crate::dev_server::{
response::{ApiResponse, ErrorResponse, Status},
DevServerState,
};
use ten_rust::pkg_info::pkg_type::PkgType;


#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct DevServerExtensionAddon {
Expand Down
7 changes: 4 additions & 3 deletions core/src/ten_manager/src/dev_server/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ use std::collections::HashMap;

use serde::Deserialize;

use super::graphs::nodes::{
DevServerApiCmdLike, DevServerApiDataLike, DevServerPropertyAttributes,
};
use ten_rust::pkg_info::api::{
PkgApiCmdLike, PkgApiDataLike, PkgPropertyAttributes,
};

use super::graphs::nodes::{
DevServerApiCmdLike, DevServerApiDataLike, DevServerPropertyAttributes,
};

pub fn get_dev_server_property_hashmap_from_pkg(
items: HashMap<String, PkgPropertyAttributes>,
) -> HashMap<String, DevServerPropertyAttributes> {
Expand Down
5 changes: 3 additions & 2 deletions core/src/ten_manager/src/dev_server/graphs/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ use std::sync::{Arc, RwLock};

use actix_web::{web, HttpResponse, Responder};
use serde::{Deserialize, Serialize};

use ten_rust::pkg_info::graph::msg_conversion::MsgAndResultConversion;
use ten_rust::pkg_info::graph::{
GraphConnection, GraphDestination, GraphMessageFlow,
};
use ten_rust::pkg_info::pkg_type::PkgType;
use ten_rust::pkg_info::predefined_graphs::pkg_predefined_graphs_find;

use crate::dev_server::get_all_pkgs::get_all_pkgs;
use crate::dev_server::response::{ApiResponse, ErrorResponse, Status};
use crate::dev_server::DevServerState;
use ten_rust::pkg_info::pkg_type::PkgType;
use ten_rust::pkg_info::predefined_graphs::pkg_predefined_graphs_find;

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct DevServerConnection {
Expand Down
3 changes: 2 additions & 1 deletion core/src/ten_manager/src/dev_server/graphs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ use std::sync::{Arc, RwLock};
use actix_web::{web, HttpResponse, Responder};
use serde::{Deserialize, Serialize};

use ten_rust::pkg_info::pkg_type::PkgType;

use super::{
get_all_pkgs::get_all_pkgs,
response::{ApiResponse, ErrorResponse, Status},
DevServerState,
};
use ten_rust::pkg_info::pkg_type::PkgType;

#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct RespGraph {
Expand Down
15 changes: 8 additions & 7 deletions core/src/ten_manager/src/dev_server/graphs/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ use std::{
use actix_web::{web, HttpResponse, Responder};
use serde::{Deserialize, Serialize};

use ten_rust::pkg_info::api::{
PkgApiCmdLike, PkgApiDataLike, PkgPropertyAttributes, PkgPropertyItem,
};
use ten_rust::pkg_info::predefined_graphs::extension::get_extension_nodes_in_graph;
use ten_rust::pkg_info::{
api::PkgCmdResult, predefined_graphs::extension::get_pkg_info_for_extension,
};

use crate::dev_server::common::{
get_dev_server_api_cmd_likes_from_pkg,
get_dev_server_api_data_likes_from_pkg,
Expand All @@ -20,13 +28,6 @@ use crate::dev_server::common::{
use crate::dev_server::get_all_pkgs::get_all_pkgs;
use crate::dev_server::response::{ApiResponse, ErrorResponse, Status};
use crate::dev_server::DevServerState;
use ten_rust::pkg_info::api::{
PkgApiCmdLike, PkgApiDataLike, PkgPropertyAttributes, PkgPropertyItem,
};
use ten_rust::pkg_info::predefined_graphs::extension::get_extension_nodes_in_graph;
use ten_rust::pkg_info::{
api::PkgCmdResult, predefined_graphs::extension::get_pkg_info_for_extension,
};

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct DevServerExtension {
Expand Down
5 changes: 3 additions & 2 deletions core/src/ten_manager/src/dev_server/graphs/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ use std::sync::{Arc, RwLock};
use actix_web::{web, HttpResponse, Responder};
use serde::{Deserialize, Serialize};

use ten_rust::pkg_info::pkg_type::PkgType;
use ten_rust::pkg_info::predefined_graphs::get_pkg_predefined_graph_from_nodes_and_connections;

use super::{connections::DevServerConnection, nodes::DevServerExtension};
use crate::dev_server::response::{ApiResponse, ErrorResponse, Status};
use crate::dev_server::{get_all_pkgs::get_all_pkgs, DevServerState};
use ten_rust::pkg_info::pkg_type::PkgType;
use ten_rust::pkg_info::predefined_graphs::get_pkg_predefined_graph_from_nodes_and_connections;

#[derive(Deserialize, Serialize, Debug, PartialEq, Clone)]
pub struct GraphUpdateRequest {
Expand Down
3 changes: 2 additions & 1 deletion core/src/ten_manager/src/dev_server/manifest/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ use std::sync::{Arc, RwLock};
use actix_web::{web, HttpResponse, Responder};
use serde::Serialize;

use ten_rust::pkg_info::pkg_type::PkgType;

use crate::dev_server::{
common::CheckTypeQuery,
get_all_pkgs::get_all_pkgs,
response::{ApiResponse, ErrorResponse, Status},
DevServerState,
};
use ten_rust::pkg_info::pkg_type::PkgType;

#[derive(Serialize)]
struct CheckResponse {
Expand Down
5 changes: 3 additions & 2 deletions core/src/ten_manager/src/dev_server/manifest/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use std::{
use actix_web::{web, HttpResponse, Responder};
use serde::Serialize;

use ten_rust::pkg_info::manifest::dump_manifest_str_to_file;
use ten_rust::pkg_info::pkg_type::PkgType;

use crate::{
constants::MANIFEST_JSON_FILENAME,
dev_server::{
Expand All @@ -20,8 +23,6 @@ use crate::{
DevServerState,
},
};
use ten_rust::pkg_info::manifest::dump_manifest_str_to_file;
use ten_rust::pkg_info::pkg_type::PkgType;

#[derive(Serialize, Debug, PartialEq)]
struct DumpResponse {
Expand Down
14 changes: 8 additions & 6 deletions core/src/ten_manager/src/dev_server/messages/compatible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ use std::{
use actix_web::{web, HttpMessage, HttpRequest, HttpResponse, Responder};
use serde::{Deserialize, Serialize};

use crate::dev_server::{
get_all_pkgs::get_all_pkgs,
response::{ApiResponse, ErrorResponse, Status},
DevServerState,
};
use ten_rust::pkg_info::{
message::{MsgDirection, MsgType},
predefined_graphs::extension::{
Expand All @@ -26,6 +21,12 @@ use ten_rust::pkg_info::{
},
};

use crate::dev_server::{
get_all_pkgs::get_all_pkgs,
response::{ApiResponse, ErrorResponse, Status},
DevServerState,
};

#[derive(Debug, Deserialize, Serialize)]
pub struct InputData {
pub app: String,
Expand Down Expand Up @@ -304,11 +305,12 @@ mod tests {
use actix_web::{test, App};
use serde_json::json;

use ten_rust::pkg_info::localhost;

use super::*;
use crate::{
config::TmanConfig, dev_server::mock::tests::inject_all_pkgs_for_mock,
};
use ten_rust::pkg_info::localhost;

#[actix_web::test]
async fn test_get_compatible_messages_success() {
Expand Down
Loading

0 comments on commit 15671be

Please sign in to comment.