Skip to content

Commit

Permalink
added support for multiple targets
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Gadorek committed Aug 6, 2024
1 parent 4b3e1d2 commit cd57bc3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[dependencies]
tokio = {version = "1.37.0", features=["full"]}
idf-im-lib = { path = "/Users/petrgadorek/work/idf-im/idf-im-lib" }
idf-im-lib = { git = "https://github.com/espressif/idf-im-lib.git", rev="ecff9449464ba03c51a42e910fa9d7778a8e3eb0" }
clap = {version = "4.5", features = ["cargo", "derive", "color"]}
crossterm = "0.27.0"
dialoguer = { git = "https://github.com/Hahihula/dialoguer.git", branch = "folder-select", features = ["folder-select"] }
Expand Down
8 changes: 6 additions & 2 deletions src/cli_args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct Settings {
pub idf_path: Option<PathBuf>,
pub tool_download_folder_name: Option<String>,
pub tool_install_folder_name: Option<String>,
pub target: Option<String>,
pub target: Option<Vec<String>>,
pub idf_versions: Option<Vec<String>>,
pub tools_json_file: Option<String>,
pub idf_tools_path: Option<String>, // relative to idf path
Expand Down Expand Up @@ -133,7 +133,11 @@ impl IntoIterator for Cli {
"non_interactive".to_string(),
self.non_interactive.map(|b| b.into()),
),
("target".to_string(), self.target.map(|p| p.into())),
(
"target".to_string(),
self.target
.map(|s| s.split(",").collect::<Vec<&str>>().into()),
),
(
"idf_version".to_string(),
self.idf_versions
Expand Down
41 changes: 23 additions & 18 deletions src/wizard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn check_prerequisites() -> Result<Vec<String>, String> {
}
}

async fn select_target(theme: &ColorfulTheme) -> Result<String, String> {
async fn select_target(theme: &ColorfulTheme) -> Result<Vec<String>, String> {
let avalible_targets_result = idf_im_lib::idf_versions::get_avalible_targets().await;
match avalible_targets_result {
Ok(mut avalible_targets) => {
Expand All @@ -79,7 +79,14 @@ async fn select_target(theme: &ColorfulTheme) -> Result<String, String> {
.interact()
.unwrap();

Ok(avalible_targets[selection[0]].clone()) //todo return all selected
if selection.is_empty() {
return Err("You must select target".to_string());
}
let result = selection
.into_iter()
.map(|i| avalible_targets[i].clone())
.collect();
Ok(result)
}
Err(err) => Err(format!(
"{} {:?}",
Expand Down Expand Up @@ -171,13 +178,10 @@ fn download_idf(

fn get_tools_export_paths(
tools_file: ToolsFile,
selected_chip: &str,
selected_chip: Vec<String>,
tools_install_path: &str,
) -> Vec<String> {
let list = idf_im_lib::idf_tools::filter_tools_by_target(
tools_file.tools,
&selected_chip.to_lowercase(),
);
let list = idf_im_lib::idf_tools::filter_tools_by_target(tools_file.tools, &selected_chip);
debug!("Creating export paths for: {:?}", list);
let mut paths = vec![];
for tool in &list {
Expand All @@ -195,7 +199,7 @@ fn get_tools_export_paths(
}
async fn download_tools(
tools_file: ToolsFile,
selected_chip: &str,
selected_chip: Vec<String>,
destination_path: &str,
mirror: Option<&str>,
) -> Vec<String> {
Expand All @@ -209,10 +213,7 @@ async fn download_tools(
t!("wizard.tools_download.progress"),
tool_name_list
);
let list = idf_im_lib::idf_tools::filter_tools_by_target(
tools_file.tools,
&selected_chip.to_lowercase(),
);
let list = idf_im_lib::idf_tools::filter_tools_by_target(tools_file.tools, &selected_chip);

let platform = match idf_im_lib::idf_tools::get_platform_identification() {
Ok(platform) => platform,
Expand Down Expand Up @@ -454,11 +455,11 @@ pub async fn run_wizzard_run(mut config: Settings) -> Result<(), String> {
};
config.target = Some(chip_id);
}
let target = config.target.clone().unwrap().to_string();
debug!("Selected target: {}", target);
let target = config.target.clone().unwrap();
debug!("Selected target: {:?}", target);
// select version
if config.idf_versions.is_none() {
let selected_idf_version = select_idf_version(&target, &theme).await;
let selected_idf_version = select_idf_version(&target.clone()[0], &theme).await; // TODO: handle multiple targets
match selected_idf_version {
Ok(selected_idf_version) => config.idf_versions = Some(selected_idf_version),
Err(err) => {
Expand Down Expand Up @@ -691,7 +692,7 @@ pub async fn run_wizzard_run(mut config: Settings) -> Result<(), String> {

let downloaded_tools_list = download_tools(
tools.clone(),
&target,
target.clone(),
tool_download_directory.to_str().unwrap(),
Some(&dl_mirror),
)
Expand Down Expand Up @@ -796,8 +797,11 @@ pub async fn run_wizzard_run(mut config: Settings) -> Result<(), String> {
t!("wizard.idf_tools.failed_to_run", e = err.to_string())
),
}
let export_paths =
get_tools_export_paths(tools, &target, tool_install_directory.to_str().unwrap());
let export_paths = get_tools_export_paths(
tools,
target.clone(),
tool_install_directory.to_str().unwrap(),
);

if std::env::consts::OS == "windows" {
// for p in export_paths {
Expand All @@ -808,6 +812,7 @@ pub async fn run_wizzard_run(mut config: Settings) -> Result<(), String> {
match idf_im_lib::create_desktop_shortcut(
version_instalation_path.to_str().unwrap(),
idf_path.to_str().unwrap(),
&idf_version,
tool_install_directory.to_str().unwrap(),
) {
Ok(_) => info!("{}", t!("wizard.after_install.desktop_shortcut.created")),
Expand Down

0 comments on commit cd57bc3

Please sign in to comment.