Skip to content

Commit 01c32b3

Browse files
committed
POSIX discovery mvp
1 parent 178bcb2 commit 01c32b3

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
lines changed

src-tauri/src/cli/wizard.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ pub async fn run_wizzard_run(mut config: Settings) -> Result<(), String> {
622622
&idf_version,
623623
tool_install_directory.to_str().unwrap(),
624624
export_paths,
625+
None,
625626
)
626627
}
627628
save_config_if_desired(&config)?;

src-tauri/src/gui/commands/installation.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ async fn install_single_version(
163163
&version,
164164
tools_install_path.to_str().unwrap(),
165165
export_vars,
166+
None,
166167
);
167168

168169
Ok(())

src-tauri/src/gui/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ async fn install_single_version(
224224
&version,
225225
tools_install_path.to_str().unwrap(),
226226
export_vars,
227+
None,
227228
);
228229

229230
Ok(())

src-tauri/src/lib/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,7 @@ pub fn single_version_post_install(
14531453
idf_version: &str,
14541454
tool_install_directory: &str,
14551455
export_paths: Vec<String>,
1456+
idf_python_env_path: Option<&str>
14561457
) {
14571458
let env_vars = setup_environment_variables(
14581459
&PathBuf::from(tool_install_directory),

src-tauri/src/lib/utils.rs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{
22
command_executor::execute_command, idf_config::{IdfConfig, IdfInstallation}, idf_tools::{self, read_and_parse_tools_file}, replace_unescaped_spaces_win, settings::Settings, single_version_post_install, version_manager::get_default_config_path
33
};
44
use anyhow::{anyhow, Result};
5-
use log::{debug, warn};
5+
use log::{debug, info, warn};
66
use rust_search::SearchBuilder;
77
use serde::{Deserialize, Serialize};
88
use uuid::Uuid;
@@ -414,9 +414,11 @@ pub fn parse_esp_idf_json(idf_json_path: &str) -> Result<()> {
414414
let idf_path = value.path;
415415
let python = value.python;
416416
let tools_path = config.idf_tools_path.clone();
417+
println!("IDF tools path: {}", tools_path);
418+
println!("IDF version: {}", idf_version);
417419
let export_paths = vec![config.git_path.clone()];
418420
match import_single_version(
419-
idf_json_path.to_str().unwrap(),
421+
idf_json_path.parent().unwrap().to_str().unwrap(),
420422
&idf_path,
421423
&idf_version,
422424
&tools_path,
@@ -483,10 +485,12 @@ pub fn try_import_existing_idf(idf_path:&str) -> Result<()> {
483485
}
484486
}
485487
// was not installed by eim
488+
debug!("Path {} was not installed by EIM", idf_path);
486489
let path_to_create_activation_script = match path.parent() {
487490
Some(parent) => parent,
488491
None => path,
489492
};
493+
info!("Path to create activation script: {}", path_to_create_activation_script.display());
490494
let idf_version = path_to_create_activation_script.file_name().unwrap().to_str().unwrap();
491495
let tools_file = match idf_tools::read_and_parse_tools_file(&Path::new(idf_path).join("tools").join("tools.json").to_str().unwrap()){
492496
Ok(tools_file) => tools_file,
@@ -520,22 +524,39 @@ pub fn try_import_existing_idf(idf_path:&str) -> Result<()> {
520524
debug!("Successfully imported tool set");
521525
}
522526
Err(e) => {
523-
warn!("Failed to import tool set: {}", e);
527+
warn!("Failed to import tool set:{} {}", idf_path, e);
524528
}
525529
}
526530
// TODO: add more approaches for different legacy installations
527531
Ok(())
528532
}
529533

530534
pub fn import_single_version(path_to_create_activation_script: &str,idf_location: &str, idf_version: &str, idf_tools_path: &str, export_paths: Vec<String>, python: Option<String>) -> Result<()> {
531-
// TODO: skip is path does not exist
532-
// TODO: check if not alreasdy in the config
535+
let config_path = get_default_config_path();
536+
let mut current_config = match IdfConfig::from_file(&config_path) {
537+
Ok(config) => config,
538+
Err(e) => IdfConfig::default(),
539+
};
540+
let idf_path = PathBuf::from(idf_location);
541+
if !idf_path.exists() {
542+
warn!("Path {} does not exists, skipping", idf_location);
543+
return Err(anyhow!("Path {} does not exists", idf_location));
544+
};
545+
if current_config.clone().is_path_in_config(idf_location.to_string()) {
546+
info!("Path {} already in config, skipping", idf_location);
547+
return Ok(());
548+
};
549+
let python_env = python.clone().and_then(|s| {
550+
s.find("python_env").map(|index| s[..=index+9].to_string())
551+
});
552+
println!("Python env: {:?}", python_env);
533553
single_version_post_install(
534554
path_to_create_activation_script,
535555
idf_location,
536556
idf_version,
537557
&idf_tools_path,
538558
export_paths,
559+
python_env.as_deref(),
539560
);
540561
let activation_script = match std::env::consts::OS {
541562
"windows" => format!(
@@ -556,13 +577,7 @@ pub fn import_single_version(path_to_create_activation_script: &str,idf_location
556577
python: python.unwrap_or_else(|| "python".to_string()),
557578
idf_tools_path: idf_tools_path.to_string(),
558579
};
559-
let config_path = get_default_config_path();
560-
let mut current_config = match IdfConfig::from_file(&config_path) {
561-
Ok(config) => config,
562-
Err(e) => {
563-
return Err(anyhow!("Config file not found: {}", e));
564-
}
565-
};
580+
566581
current_config.idf_installed.push(installation);
567582
match current_config.to_file(config_path, true, false) {
568583
Ok(_) => {

0 commit comments

Comments
 (0)