@@ -106,14 +106,18 @@ pub fn is_valid_idf_directory(path: &str) -> bool {
106106 let path = PathBuf :: from ( path) ;
107107 let tools_path = path. join ( "tools" ) ;
108108 let tools_json_path = tools_path. join ( "tools.json" ) ;
109+ debug ! ( "Checking for tools.json at: {}" , tools_json_path. display( ) ) ;
109110 if !tools_json_path. exists ( ) {
110111 return false ;
111112 }
113+ debug ! ( "Found tools.json at: {}" , tools_json_path. display( ) ) ;
112114 match read_and_parse_tools_file ( tools_json_path. to_str ( ) . unwrap ( ) ) {
113115 Ok ( _) => {
116+ debug ! ( "Valid IDF directory: {}" , path. display( ) ) ;
114117 true
115118 }
116119 Err ( _) => {
120+ debug ! ( "Invalid IDF directory: {}" , path. display( ) ) ;
117121 false
118122 }
119123 }
@@ -346,54 +350,71 @@ pub fn parse_tool_set_config(config_path: &str) -> Result<()> {
346350 let new_export_paths = vec ! [ tool_set. env_vars. get( "PATH" ) . unwrap( ) . to_string( ) ] ;
347351 let tmp = PathBuf :: from ( tool_set. idf_location . clone ( ) ) ;
348352 let version_path = tmp. parent ( ) . unwrap ( ) ;
349- single_version_post_install (
353+ match import_single_version (
350354 version_path. to_str ( ) . unwrap ( ) ,
351355 & tool_set. idf_location ,
352356 & tool_set. idf_version ,
353357 & new_idf_tools_path,
354358 new_export_paths,
355- ) ;
356-
357- let new_activation_script = match std:: env:: consts:: OS {
358- "windows" => format ! (
359- "{}\\ Microsoft.PowerShell_profile.ps1" ,
360- version_path. to_str( ) . unwrap( )
361- ) ,
362- _ => format ! (
363- "{}/activate_idf_{}.sh" ,
364- version_path. to_str( ) . unwrap( ) ,
365- tool_set. idf_version
366- ) ,
367- } ;
368- let installation = IdfInstallation {
369- id : tool_set. id . to_string ( ) ,
370- activation_script : new_activation_script,
371- path : tool_set. idf_location ,
372- name : tool_set. idf_version ,
373- python : tool_set. system_python_executable_path ,
374- idf_tools_path : new_idf_tools_path,
375- } ;
376- let config_path = get_default_config_path ( ) ;
377- let mut current_config = match IdfConfig :: from_file ( & config_path) {
378- Ok ( config) => config,
379- Err ( e) => {
380- return Err ( anyhow ! ( "Config file not found: {}" , e) ) ;
381- }
382- } ;
383- current_config. idf_installed . push ( installation) ;
384- match current_config. to_file ( config_path, true , false ) {
359+ Some ( tool_set. system_python_executable_path ) ,
360+ ) {
385361 Ok ( _) => {
386- debug ! ( "Updated config file with new tool set" ) ;
387- return Ok ( ( ) ) ;
362+ debug ! ( "Successfully imported tool set" ) ;
388363 }
389364 Err ( e) => {
390- return Err ( anyhow ! ( "Failed to update config file : {}" , e) ) ;
365+ return Err ( anyhow ! ( "Failed to import tool set : {}" , e) ) ;
391366 }
392367 }
393368 }
394369 Ok ( ( ) )
395370}
396371
372+ 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 < ( ) > {
373+ single_version_post_install (
374+ path_to_create_activation_script,
375+ idf_location,
376+ idf_version,
377+ & idf_tools_path,
378+ export_paths,
379+ ) ;
380+ let activation_script = match std:: env:: consts:: OS {
381+ "windows" => format ! (
382+ "{}\\ Microsoft.PowerShell_profile.ps1" ,
383+ path_to_create_activation_script,
384+ ) ,
385+ _ => format ! (
386+ "{}/activate_idf_{}.sh" ,
387+ path_to_create_activation_script,
388+ idf_version
389+ ) ,
390+ } ;
391+ let installation = IdfInstallation {
392+ id : idf_version. to_string ( ) ,
393+ activation_script,
394+ path : idf_location. to_string ( ) ,
395+ name : idf_version. to_string ( ) ,
396+ python : python. unwrap_or_else ( || "python" . to_string ( ) ) ,
397+ idf_tools_path : idf_tools_path. to_string ( ) ,
398+ } ;
399+ let config_path = get_default_config_path ( ) ;
400+ let mut current_config = match IdfConfig :: from_file ( & config_path) {
401+ Ok ( config) => config,
402+ Err ( e) => {
403+ return Err ( anyhow ! ( "Config file not found: {}" , e) ) ;
404+ }
405+ } ;
406+ current_config. idf_installed . push ( installation) ;
407+ match current_config. to_file ( config_path, true , false ) {
408+ Ok ( _) => {
409+ debug ! ( "Updated config file with new tool set" ) ;
410+ return Ok ( ( ) ) ;
411+ }
412+ Err ( e) => {
413+ return Err ( anyhow ! ( "Failed to update config file: {}" , e) ) ;
414+ }
415+ }
416+ }
417+
397418/// Converts a path to a long path compatible with Windows.
398419///
399420/// This function takes a string representing a path and returns a new string.
0 commit comments