@@ -368,7 +368,11 @@ fn extract_tools_path_from_python_env_path(path: &str) -> Option<PathBuf> {
368368/// It also logs errors if the IDF installation configuration cannot be updated.
369369pub fn parse_tool_set_config ( config_path : & str ) -> Result < ( ) > {
370370 let config_path = Path :: new ( config_path) ;
371- let json_str = std:: fs:: read_to_string ( config_path) . unwrap ( ) ;
371+ let json_str = match std:: fs:: read_to_string ( config_path) {
372+ Ok ( content) => content,
373+ Err ( e) => return Err ( anyhow ! ( "Failed to read config file: {}" , e) ) ,
374+ } ;
375+ debug ! ( "Parsing tool set config from: {}" , config_path. display( ) ) ;
372376 let config: Vec < IdfToolsConfig > = match serde_json:: from_str ( & json_str) {
373377 Ok ( config) => config,
374378 Err ( e) => return Err ( anyhow ! ( "Failed to parse config file: {}" , e) ) ,
@@ -384,19 +388,50 @@ pub fn parse_tool_set_config(config_path: &str) -> Result<()> {
384388 let new_export_paths = vec ! [ tool_set. env_vars. get( "PATH" ) . unwrap( ) . to_string( ) ] ;
385389 let tmp = PathBuf :: from ( tool_set. idf_location . clone ( ) ) ;
386390 let version_path = tmp. parent ( ) . unwrap ( ) ;
387- match import_single_version (
391+ single_version_post_install (
388392 version_path. to_str ( ) . unwrap ( ) ,
389393 & tool_set. idf_location ,
390394 & tool_set. idf_version ,
391395 & new_idf_tools_path,
392396 new_export_paths,
393- Some ( tool_set. system_python_executable_path ) ,
394- ) {
397+ None ,
398+ ) ;
399+
400+ let new_activation_script = match std:: env:: consts:: OS {
401+ "windows" => format ! (
402+ "{}\\ Microsoft.PowerShell_profile.ps1" ,
403+ version_path. to_str( ) . unwrap( )
404+ ) ,
405+ _ => format ! (
406+ "{}/activate_idf_{}.sh" ,
407+ version_path. to_str( ) . unwrap( ) ,
408+ tool_set. idf_version
409+ ) ,
410+ } ;
411+ let installation = IdfInstallation {
412+ id : tool_set. id . to_string ( ) ,
413+ activation_script : new_activation_script,
414+ path : tool_set. idf_location ,
415+ name : tool_set. idf_version ,
416+ python : tool_set. system_python_executable_path ,
417+ idf_tools_path : new_idf_tools_path,
418+ } ;
419+ let config_path = get_default_config_path ( ) ;
420+ let mut current_config = match IdfConfig :: from_file ( & config_path) {
421+ Ok ( config) => config,
422+ Err ( e) => {
423+ debug ! ( "Config file not found, creating a new one: {}" , e) ;
424+ IdfConfig :: default ( )
425+ }
426+ } ;
427+ current_config. idf_installed . push ( installation) ;
428+ match current_config. to_file ( config_path, true , false ) {
395429 Ok ( _) => {
396- debug ! ( "Successfully imported tool set" ) ;
430+ debug ! ( "Updated config file with new tool set" ) ;
431+ return Ok ( ( ) ) ;
397432 }
398433 Err ( e) => {
399- return Err ( anyhow ! ( "Failed to import tool set : {}" , e) ) ;
434+ return Err ( anyhow ! ( "Failed to update config file : {}" , e) ) ;
400435 }
401436 }
402437 }
0 commit comments