Skip to content

Commit 07d7535

Browse files
committed
find all esp-idf instances and evaluate which one to process
IDF installed using eim or eclipse can be discovered parsing function for esp_idf.json file added POSIX discovery mvp updated activation script creation improved export paths in old version discovery added tool_set.json file parsing to the discovery returned the parse_tool_set_config back to working state updated according to changes in the scripts location Documentation update to add the discovery command reworked the vscode discovery according to new approach to isntallation removed unused code updated the discovery command help Fixed discovery tools paths improved windows debugging part of discovery and venv creation creating venv using proper python discovery disabled for vscode installed IDF on windows
1 parent 961940b commit 07d7535

File tree

8 files changed

+330
-57
lines changed

8 files changed

+330
-57
lines changed

docs/src/cli_commands.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ These options can be used with any command:
3030
| `remove` | Remove a specific ESP-IDF version |
3131
| `purge` | Purge all ESP-IDF installations |
3232
| `import` | Import existing ESP-IDF installation using tools_set_config.json |
33-
| `discover` | Discover available ESP-IDF versions (not implemented yet) |
33+
| `discover` | Discover available ESP-IDF versions |
34+
| `gui` | Run the ESP-IDF Installer GUI with arguments passed through command line |
3435

3536
## Command Details
3637

@@ -139,10 +140,10 @@ If `PATH` is not provided, the command will inform you that no config file was s
139140
Discover available ESP-IDF versions (not implemented yet).
140141
141142
```bash
142-
eim discover
143+
eim discover [PATH]
143144
```
144145
145-
This command is planned to discover ESP-IDF installations on your system but is not yet implemented.
146+
This command searches for previously installed ESP-IDF versions on your system. If PATH is not provided, the command will search from the root of the filesystem. For any found versions where automatic import is possible, they will be imported into EIM's management. For other found versions that cannot be automatically imported, the command will suggest the appropriate `eim install` command to allow the user to manually reinstall them.
146147
147148
## Examples
148149

src-tauri/src/cli/cli_args.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,11 @@ pub enum Commands {
6565
version: Option<String>,
6666
},
6767

68-
/// Discover available ESP-IDF versions (not implemented yet)
69-
Discover,
68+
/// Discover available ESP-IDF versions
69+
Discover {
70+
#[arg(help = "Discover available ESP-IDF versions and imports them")]
71+
path: Option<String>,
72+
},
7073

7174
/// Remove specific ESP-IDF version
7275
Remove {

src-tauri/src/cli/mod.rs

Lines changed: 104 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::path::Path;
12
use std::path::PathBuf;
23

34
use anyhow::Context;
@@ -9,7 +10,10 @@ use config::ConfigError;
910
use helpers::generic_input;
1011
use helpers::generic_select;
1112
use idf_im_lib::get_log_directory;
13+
use idf_im_lib::idf_config::IdfConfig;
1214
use idf_im_lib::settings::Settings;
15+
use idf_im_lib::utils::find_by_name_and_extension;
16+
use idf_im_lib::utils::parse_esp_idf_json;
1317
use idf_im_lib::version_manager::remove_single_idf_version;
1418
use idf_im_lib::version_manager::select_idf_version;
1519
use log::debug;
@@ -315,13 +319,107 @@ pub async fn run_cli(cli: Cli) -> anyhow::Result<()> {
315319
}
316320
}
317321
}
318-
Commands::Discover => {
319-
// TODO:Implement version discovery
320-
unimplemented!("Version discovery not implemented yet");
321-
println!("Discovering available versions... (This can take couple of minutes)");
322-
let idf_dirs = idf_im_lib::version_manager::find_esp_idf_folders("/");
322+
Commands::Discover {path } => {
323+
info!("Discovering available versions... (This can take couple of minutes)");
324+
let path = path.unwrap_or_else(|| {
325+
let default_path = match std::env::consts::OS {
326+
"windows" => {
327+
"C:\\".to_string()
328+
}
329+
_ => {
330+
"/".to_string()
331+
}
332+
};
333+
334+
335+
debug!("No path provided, using default: {}", default_path);
336+
default_path
337+
});
338+
// first parse existing esp_idf.json (using parse_esp_idf_json) || previous VSCode installations
339+
info!("Searching for esp_idf.json files...");
340+
let search_patch = Path::new(&path);
341+
let esp_idf_json_path = find_by_name_and_extension(
342+
search_patch,
343+
"esp_idf",
344+
"json",
345+
);
346+
if esp_idf_json_path.is_empty() {
347+
info!("No esp_idf.json found");
348+
} else {
349+
info!("Found {} esp_idf.json files:", esp_idf_json_path.len());
350+
}
351+
for path in esp_idf_json_path {
352+
info!("- {} ", &path);
353+
match parse_esp_idf_json(&path) {
354+
Ok(_) => {
355+
info!("Parsed config: {:?}", path);
356+
}
357+
Err(err) => {
358+
info!("Failed to parse esp_idf.json: {}", err);
359+
}
360+
}
361+
}
362+
// second try to find tool_set_config.json (using parse_tool_set_config) || previous Eclipse installations
363+
info!("Searching for tool_set_config.json files...");
364+
let tool_set_config_path = find_by_name_and_extension(
365+
search_patch,
366+
"tool_set_config",
367+
"json",
368+
);
369+
if tool_set_config_path.is_empty() {
370+
info!("No tool_set_config.json found");
371+
} else {
372+
info!("Found {} tool_set_config.json files:", tool_set_config_path.len());
373+
}
374+
for path in tool_set_config_path {
375+
info!("- {} ", &path);
376+
match idf_im_lib::utils::parse_tool_set_config(&path) {
377+
Ok(_) => {
378+
info!("Parsed config: {:?}", path);
379+
}
380+
Err(err) => {
381+
info!("Failed to parse tool_set_config.json: {}", err);
382+
}
383+
}
384+
}
385+
// third try to find IDF directories (using find_esp_idf_folders) || previous instalation from cli
386+
info!("Searching for any other IDF directories...");
387+
let idf_dirs = idf_im_lib::version_manager::find_esp_idf_folders(&path);
388+
if idf_dirs.is_empty() {
389+
info!("No IDF directories found");
390+
} else {
391+
info!("Found {} IDF directories:", idf_dirs.len());
392+
}
393+
let config = match idf_im_lib::version_manager::get_esp_ide_config() {
394+
Ok(config) => {
395+
if config.idf_installed.is_empty() {
396+
debug!(
397+
"No versions found. Every discovered version can be imported."
398+
);
399+
}
400+
config
401+
}
402+
Err(_err) => {
403+
debug!("No ide config found. New will be created.");
404+
IdfConfig::default()
405+
}
406+
};
407+
let mut paths_to_add = vec![];
323408
for dir in idf_dirs {
324-
println!("Found IDF directory: {}", dir);
409+
info!("- {} ", &dir);
410+
if config.clone().is_path_in_config(dir.clone()) {
411+
info!("Already present!");
412+
} else {
413+
info!("Can be added...");
414+
paths_to_add.push(dir);
415+
}
416+
}
417+
if paths_to_add.is_empty() {
418+
info!("No new IDF directories found to add.");
419+
return Ok(());
420+
} else {
421+
info!("Found {} new IDF directories available to add:", paths_to_add.len());
422+
info!("You can add them using `eim install` command with the `--path` option.");
325423
}
326424
Ok(())
327425
}

src-tauri/src/gui/mod.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -169,37 +169,6 @@ impl ToolSetup {
169169
}
170170
}
171171

172-
// async fn install_single_version(
173-
// app_handle: AppHandle,
174-
// settings: &Settings,
175-
// version: String,
176-
// ) -> Result<(), Box<dyn std::error::Error>> {
177-
// info!("Installing IDF version: {}", version);
178-
179-
// let version_path = prepare_installation_directories(app_handle.clone(), settings, &version)?;
180-
// let idf_path = version_path.clone().join("esp-idf");
181-
// download_idf(&app_handle, settings, &version, &idf_path).await?;
182-
// let export_vars = setup_tools(&app_handle, settings, &idf_path, &version).await?;
183-
// let tools_install_path = version_path.clone().join(
184-
// settings
185-
// .tool_install_folder_name
186-
// .clone()
187-
// .unwrap_or_default(),
188-
// );
189-
// let idf_python_env_path = tools_install_path.clone().join("python").join(&version).join("venv");
190-
// let activation_script_path = settings.esp_idf_json_path.clone().unwrap_or_default();
191-
// idf_im_lib::single_version_post_install(
192-
// &activation_script_path,
193-
// idf_path.to_str().unwrap(),
194-
// &version,
195-
// tools_install_path.to_str().unwrap(),
196-
// export_vars,
197-
// Some(idf_python_env_path.to_str().unwrap()),
198-
// );
199-
200-
// Ok(())
201-
// }
202-
203172
// Helper function to check if a process is running on Windows
204173
#[cfg(target_os = "windows")]
205174
fn is_process_running(pid: u32) -> bool {

src-tauri/src/lib/idf_config.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ pub struct IdfConfig {
3737
pub version: Option<String>,
3838
}
3939

40+
impl Default for IdfConfig {
41+
fn default() -> Self {
42+
IdfConfig {
43+
git_path: crate::utils::get_git_path().unwrap_or_default(),
44+
idf_installed: [].to_vec(),
45+
idf_selected_id: "".to_string(),
46+
eim_path: None,
47+
version: Some(IDF_CONFIG_FILE_VERSION.to_string()),
48+
}
49+
}
50+
}
51+
4052
impl IdfConfig {
4153
/// Saves the configuration to a file.
4254
///
@@ -226,6 +238,10 @@ impl IdfConfig {
226238
}
227239
}
228240

241+
pub fn is_path_in_config(self, path:String) -> bool {
242+
self.idf_installed.iter().find(|i| i.path == path).is_some()
243+
}
244+
229245
/// Removes an IDF installation from the configuration.
230246
///
231247
/// This function searches for an installation matching the given identifier
@@ -261,9 +277,6 @@ impl IdfConfig {
261277
}
262278
}
263279

264-
pub fn is_path_in_config(self, path:String) -> bool {
265-
self.idf_installed.iter().find(|i| i.path == path).is_some()
266-
}
267280
}
268281

269282
pub fn parse_idf_config<P: AsRef<Path>>(path: P) -> Result<IdfConfig> {

src-tauri/src/lib/python_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ async fn download_constraints_file(idf_tools_path: &Path, idf_version: &str) ->
201201
/// - Other system-level errors prevent the command from executing.
202202
/// - The `python -m venv` command itself encounters an error (e.g., invalid path).
203203
pub fn create_python_venv(venv_path: &str) -> Result<String, String> {
204-
info!("Creating Python virtual environment at: {}", venv_path);
204+
info!("Creating Python virtual environment at: {}", venv_path);
205205

206206
let output = match std::env::consts::OS {
207207
"windows" => command_executor::execute_command(

0 commit comments

Comments
 (0)