Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi #16

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
added support for multiple targets
  • Loading branch information
Petr Gadorek committed Aug 6, 2024

Verified

This commit was signed with the committer’s verified signature.
mike182uk Michael Barrett
commit 446efcf19b37c2b8750163bc156b29dc684af4f6
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
@@ -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", branch="master" }
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"] }
2 changes: 1 addition & 1 deletion locales/app.yml
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ prerequisites.missing:
en: The following prerequisites are not satisfied:%{l}
cn: 以下依赖项不满足:%{l}
prerequisites.install.prompt:
en: Do you want to install these prerequisites?
en: Do you want to install prerequisites?
cn: 是否要安装这些依赖项?
prerequisites.install.success:
en: Prerequisites installed successfully
13 changes: 8 additions & 5 deletions src/cli_args/mod.rs
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -187,9 +191,8 @@ impl Settings {
.build();

let log_level = match cli.verbose {
0 => log::LevelFilter::Warn,
1 => log::LevelFilter::Info,
2 => log::LevelFilter::Debug,
0 => log::LevelFilter::Info,
1 => log::LevelFilter::Debug,
_ => log::LevelFilter::Trace,
};

41 changes: 23 additions & 18 deletions src/wizard/mod.rs
Original file line number Diff line number Diff line change
@@ -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) => {
@@ -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!(
"{} {:?}",
@@ -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 {
@@ -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> {
@@ -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,
@@ -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) => {
@@ -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),
)
@@ -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 {
@@ -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")),