Skip to content

Commit 542bafc

Browse files
authored
EIM-827 fix openocd script path (#835)
* EIM-827 fix openocd script path * get_tools_export_vars_from_list uses name and version sufixed paths
1 parent d966a87 commit 542bafc

4 files changed

Lines changed: 69 additions & 16 deletions

File tree

src-tauri/src/cli/wizard.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -828,8 +828,8 @@ pub async fn run_wizzard_run(mut config: Settings) -> Result<(), String> {
828828
.map_err(|err| t!("wizard.error.create_python_env", error = err.to_string()))?;
829829

830830
let export_paths = idf_im_lib::idf_tools::get_tools_export_paths_from_list(
831-
tools,
832-
installed_tools_list,
831+
tools.clone(),
832+
installed_tools_list.clone(),
833833
tool_install_directory.to_str().unwrap(),
834834
)
835835
.into_iter()
@@ -841,14 +841,19 @@ pub async fn run_wizzard_run(mut config: Settings) -> Result<(), String> {
841841
}
842842
})
843843
.collect();
844+
let export_vars = idf_im_lib::idf_tools::get_tools_export_vars_from_list(
845+
tools,
846+
installed_tools_list,
847+
tool_install_directory.to_str().unwrap(),
848+
);
844849
idf_im_lib::single_version_post_install(
845850
&paths.activation_script_path.to_str().unwrap(),
846851
paths.idf_path.to_str().unwrap(),
847852
&paths.actual_version,
848853
tool_install_directory.to_str().unwrap(),
849854
export_paths,
850855
paths.python_venv_path.to_str(),
851-
None, // env_vars
856+
Some(export_vars), // env_vars
852857
&paths.python_path.to_string_lossy(),
853858
config.create_bat_activation_script.unwrap_or(false),
854859
offline_mode,

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub async fn setup_tools(
9797
idf_path: &PathBuf,
9898
idf_version: &str,
9999
offline_archive_dir: Option<&Path>,
100-
) -> Result<Vec<String>> {
100+
) -> Result<(Vec<String>,Vec<(String,String)>)> {
101101
info!("Setting up tools...");
102102

103103
let is_simple_installation = crate::gui::app_state::is_simple_installation(&app_handle);
@@ -467,7 +467,7 @@ pub async fn setup_tools(
467467

468468
let paths = match settings.get_version_paths(&idf_version) {
469469
Ok(paths) => paths,
470-
Err(err) => {
470+
Err(_err) => {
471471
return Err(anyhow!("Failed to setup environment paths for idf versions"));
472472
}
473473
};
@@ -520,8 +520,8 @@ pub async fn setup_tools(
520520

521521
// Generate export paths
522522
let export_paths = idf_im_lib::idf_tools::get_tools_export_paths_from_list(
523-
tools,
524-
installed_tools_list,
523+
tools.clone(),
524+
installed_tools_list.clone(),
525525
tools_install_folder.to_str().unwrap(),
526526
)
527527
.into_iter()
@@ -534,6 +534,12 @@ pub async fn setup_tools(
534534
})
535535
.collect();
536536

537+
let export_vars = idf_im_lib::idf_tools::get_tools_export_vars_from_list(
538+
tools,
539+
installed_tools_list,
540+
tools_install_folder.to_str().unwrap(),
541+
);
542+
537543
// Configuration phase (95%)
538544
emit_installation_event(app_handle, InstallationProgress {
539545
stage: InstallationStage::Configure,
@@ -546,7 +552,7 @@ pub async fn setup_tools(
546552
emit_log_message(app_handle, MessageLevel::Success,
547553
t!("gui.setup_tools.setup_completed").to_string());
548554

549-
Ok(export_paths)
555+
Ok((export_paths,export_vars))
550556
}
551557

552558
#[tauri::command]

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,16 +219,16 @@ pub async fn install_single_version(
219219
}
220220

221221

222-
let export_vars = setup_tools(&app_handle, settings, &paths.idf_path, &paths.actual_version, None).await?;
222+
let (export_paths,export_vars) = setup_tools(&app_handle, settings, &paths.idf_path, &paths.actual_version, None).await?;
223223

224224
idf_im_lib::single_version_post_install(
225225
&paths.activation_script_path.to_string_lossy().to_string(),
226226
&paths.idf_path.to_string_lossy().to_string(),
227227
&paths.actual_version,
228228
&paths.tool_install_directory.to_string_lossy().to_string(),
229-
export_vars,
229+
export_paths,
230230
paths.python_venv_path.to_str(),
231-
None, // env_vars
231+
Some(export_vars), // env_vars
232232
&paths.python_path.to_string_lossy().to_string(),
233233
false, // create_cmd_bat
234234
false, // offline_installation
@@ -1826,11 +1826,11 @@ pub async fn start_offline_installation(app_handle: AppHandle, archives: Vec<Str
18261826
version: Some(idf_version.clone()),
18271827
});
18281828

1829-
let export_vars = match setup_tools(&app_handle, &settings, &paths.idf_path, &paths.actual_version, Some(offline_archive_dir.path())).await {
1830-
Ok(vars) => {
1829+
let (export_paths, export_vars ) = match setup_tools(&app_handle, &settings, &paths.idf_path, &paths.actual_version, Some(offline_archive_dir.path())).await {
1830+
Ok((paths, vars)) => {
18311831
emit_log_message(&app_handle, MessageLevel::Success,
18321832
rust_i18n::t!("gui.offline.tools_configured").to_string());
1833-
vars
1833+
(paths, vars)
18341834
}
18351835
Err(err) => {
18361836
let error_msg = rust_i18n::t!("gui.offline.tools_setup_failed", error = err.to_string()).to_string();
@@ -1861,9 +1861,9 @@ pub async fn start_offline_installation(app_handle: AppHandle, archives: Vec<Str
18611861
&paths.idf_path.to_string_lossy().to_string(),
18621862
&paths.actual_version,
18631863
&paths.tool_install_directory.to_string_lossy().to_string(),
1864-
export_vars,
1864+
export_paths,
18651865
paths.python_venv_path.to_str(),
1866-
None,
1866+
Some(export_vars),
18671867
&paths.python_path.to_string_lossy(),
18681868
false, // create_cmd_bat
18691869
true, // is_offline_install

src-tauri/src/lib/idf_tools.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,48 @@ pub fn get_tools_export_paths_from_list(
699699
paths
700700
}
701701

702+
/// Returns a `Vec<(String, String)>` of export variables for the installed tools.
703+
///
704+
/// This function iterates through a map of installed tools, finds their export variables
705+
/// from the `ToolsFile` definition, and replaces any `${TOOL_PATH}` placeholder in the
706+
/// values with the actual `tools_install_path`. All collected key-value pairs are returned
707+
/// as a vector of tuples.
708+
///
709+
/// # Arguments
710+
///
711+
/// * `tools_file` - A `ToolsFile` struct containing the definitions of tools,
712+
/// including their `export_vars`.
713+
/// * `installed_tools` - A `HashMap` where keys are tool names (`String`) and values
714+
/// are tuples containing the tool's installed version (`String`)
715+
/// and its `Download` information.
716+
/// * `tools_install_path` - A string slice representing the base directory where tools are installed.
717+
///
718+
/// # Returns
719+
///
720+
/// A `Vec<(String, String)>` containing the export variable names and their values
721+
/// for the specified installed tools.
722+
///
723+
pub fn get_tools_export_vars_from_list(
724+
_tools_file: ToolsFile,
725+
installed_tools: HashMap<String, (String, Download)>,
726+
tools_install_path: &str,
727+
) -> Vec<(String, String)> {
728+
let mut vars: Vec<(String, String)> = Vec::new();
729+
730+
for (tool_name, (_version, _download)) in installed_tools {
731+
if let Some(tool) = _tools_file.tools.iter().find(|t| t.name == tool_name) {
732+
for (var_name, var_value) in &tool.export_vars {
733+
let single_tool_install_path = PathBuf::from(tools_install_path).join(tool.name.clone()).join(tool.versions.first().unwrap().name.clone());
734+
let processed_value = var_value.replace("${TOOL_PATH}", &single_tool_install_path.to_string_lossy());
735+
vars.push((var_name.clone(), processed_value));
736+
}
737+
}
738+
}
739+
740+
log::debug!("Export vars from list: {:?}", vars);
741+
vars
742+
}
743+
702744
/// Recursively searches for directories named "bin" within the given path.
703745
///
704746
/// # Parameters

0 commit comments

Comments
 (0)