@@ -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} ;
44use anyhow:: { anyhow, Result } ;
5- use log:: { debug, warn} ;
5+ use log:: { debug, info , warn} ;
66use rust_search:: SearchBuilder ;
77use serde:: { Deserialize , Serialize } ;
88use 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
530534pub 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