Skip to content

Commit

Permalink
refactor: add more logic for local dependencies (#506)
Browse files Browse the repository at this point in the history
  • Loading branch information
halajohn authored Jan 5, 2025
1 parent 9d77264 commit d304517
Show file tree
Hide file tree
Showing 38 changed files with 619 additions and 470 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/out/linux/x64/ten_manager/bin/tman",
"cwd": "${workspaceFolder}/out/linux/x64/tests/ten_manager/install_all/install_all_in_local_file_system/test_app",
"cwd": "${workspaceFolder}/out/linux/x64/tests/ten_manager/install/mock_app/mock_app",
"args": [
"--config-file=${workspaceFolder}/out/linux/x64/tests/local_registry/config.json",
"install",
Expand Down
7 changes: 7 additions & 0 deletions core/src/ten_manager/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/src/ten_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ clap = { version = "4.5" }
clingo = { version = "0.8" }
console = { version = "0.15" }
dirs = { version = "5.0" }
fs_extra = "1.3.0"
futures-util = { version = "0.3" }
globset = { version = "0.4" }
handlebars = { version = "6.2" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use clap::{Arg, ArgMatches, Command};
use console::Emoji;
use ten_rust::json_schema::ten_validate_manifest_json_string;

use crate::{config::TmanConfig, utils::read_file_to_string};
use crate::{config::TmanConfig, fs::read_file_to_string};

#[derive(Debug)]
pub struct CheckManifestJsonCommand {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use clap::{Arg, ArgMatches, Command};
use console::Emoji;
use ten_rust::json_schema::ten_validate_property_json_string;

use crate::utils::read_file_to_string;
use crate::fs::read_file_to_string;

#[derive(Debug)]
pub struct CheckPropertyJsonCommand {
Expand Down
2 changes: 1 addition & 1 deletion core/src/ten_manager/src/cmd/cmd_designer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use console::Emoji;
use crate::{
config::TmanConfig,
designer::{configure_routes, DesignerState},
fs::{check_is_app_folder, get_cwd},
log::tman_verbose_println,
utils::{check_is_app_folder, get_cwd},
};

#[derive(Clone, Debug)]
Expand Down
13 changes: 8 additions & 5 deletions core/src/ten_manager/src/cmd/cmd_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use crate::{
constants::{APP_DIR_IN_DOT_TEN_DIR, DOT_TEN_DIR, MANIFEST_JSON_FILENAME},
dep_and_candidate::get_all_candidates_from_deps,
error::TmanError,
fs::{check_is_app_folder, check_is_package_folder},
install::PkgIdentityMapping,
log::tman_verbose_println,
manifest_lock::{
Expand All @@ -56,11 +57,11 @@ use crate::{
install_solver_results_in_standalone_mode,
},
},
utils::{check_is_app_folder, check_is_package_folder},
};

#[derive(Debug, Clone, Copy)]
pub enum LocalInstallMode {
Invalid,
Copy,
Link,
}
Expand Down Expand Up @@ -145,7 +146,7 @@ pub fn create_sub_cmd(args_cfg: &crate::cmd_line::ArgsCfg) -> Command {
.long("local-install-mode")
.help("Local install mode: copy or link")
.value_parser(["copy", "link"])
.default_value("copy")
.default_value("link")
.required(false),
)
}
Expand All @@ -166,7 +167,8 @@ pub fn parse_sub_cmd(sub_cmd_args: &ArgMatches) -> Result<InstallCommand> {
.get_one::<bool>("TEMPLATE_MODE")
.unwrap_or(&false),
template_data: HashMap::new(),
local_install_mode: LocalInstallMode::Copy,

local_install_mode: LocalInstallMode::Invalid,
};

let _ = cmd.support.set_defaults();
Expand Down Expand Up @@ -291,7 +293,7 @@ fn update_package_manifest(
break;
}
}
ManifestDependency::LocalDependency { path } => {
ManifestDependency::LocalDependency { path, .. } => {
let manifest_dependency_pkg_info =
match get_pkg_info_from_path(Path::new(&path), false) {
Ok(info) => info,
Expand Down Expand Up @@ -553,7 +555,7 @@ pub async fn execute_cmd(

let started = Instant::now();

let cwd = crate::utils::get_cwd()?;
let cwd = crate::fs::get_cwd()?;

// The package affected by tman install command, which is the root declared
// in the resolver.
Expand Down Expand Up @@ -692,6 +694,7 @@ pub async fn execute_cmd(
},
version_req: desired_pkg_src_version_.clone(),
path: None,
base_dir: None,
},
};
extra_dependency_relationships.push(extra_dependency_relationship);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use serde_json::Value;

use crate::{
cmd::cmd_modify::jq_util::jq_run, config::TmanConfig,
constants::PROPERTY_JSON_FILENAME, utils::read_file_to_string,
constants::PROPERTY_JSON_FILENAME, fs::read_file_to_string,
};

#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion core/src/ten_manager/src/cmd/cmd_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub async fn execute_cmd(

let started = Instant::now();

let cwd = crate::utils::get_cwd()?;
let cwd = crate::fs::get_cwd()?;

let pkg_info = get_pkg_info_from_path(&cwd, true)?;
let output_zip_file_name = get_package_zip_file_name(&pkg_info)?;
Expand Down
2 changes: 1 addition & 1 deletion core/src/ten_manager/src/cmd/cmd_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub async fn execute_cmd(

let started = Instant::now();

let cwd = crate::utils::get_cwd()?;
let cwd = crate::fs::get_cwd()?;

let pkg_info = get_pkg_info_from_path(&cwd, true)?;
let output_zip_file_name = get_package_zip_file_name(&pkg_info)?;
Expand Down
8 changes: 4 additions & 4 deletions core/src/ten_manager/src/cmd/cmd_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub async fn execute_cmd(
tman_verbose_println!(tman_config, "Executing run command: {:?}", cmd);

// Read `manifest.json` in the current working directory.
let cwd = crate::utils::get_cwd()?;
let cwd = crate::fs::get_cwd()?;
let manifest_path = cwd.join(MANIFEST_JSON_FILENAME);
if !manifest_path.exists() {
return Err(anyhow!(
Expand All @@ -78,10 +78,10 @@ pub async fn execute_cmd(
}

// Parse `manifest.json`.
let manifest_json_str = crate::utils::read_file_to_string(&manifest_path)
let manifest_json_str = crate::fs::read_file_to_string(&manifest_path)
.map_err(|e| {
anyhow!("Failed to read {}: {}", MANIFEST_JSON_FILENAME, e)
})?;
anyhow!("Failed to read {}: {}", MANIFEST_JSON_FILENAME, e)
})?;
let manifest_value: serde_json::Value =
serde_json::from_str(&manifest_json_str).map_err(|e| {
anyhow!("Failed to parse {}: {}", MANIFEST_JSON_FILENAME, e)
Expand Down
4 changes: 2 additions & 2 deletions core/src/ten_manager/src/cmd/cmd_uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ use crate::{
DOT_TEN_DIR, INSTALLED_PATHS_JSON_FILENAME, INSTALL_PATHS_APP_PREFIX,
PACKAGE_INFO_DIR_IN_DOT_TEN_DIR,
},
fs::check_is_app_folder,
install::installed_paths::InstalledPaths,
log::tman_verbose_println,
utils::check_is_app_folder,
};

#[derive(Debug)]
Expand Down Expand Up @@ -149,7 +149,7 @@ pub async fn execute_cmd(

let started = Instant::now();

let cwd = crate::utils::get_cwd()?;
let cwd = crate::fs::get_cwd()?;
check_is_app_folder(&cwd)?;

remove_installed_paths(&cwd, &command_data).await?;
Expand Down
Loading

0 comments on commit d304517

Please sign in to comment.