From 0812175a2ffd46f667eb5a988cf07e5b88e07b7d Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Fri, 12 Aug 2022 09:49:21 +0000 Subject: [PATCH] Add esp-idf intallation --- src/main.rs | 24 +++++++++++++++++++----- src/toolchain.rs | 9 ++++----- src/utils.rs | 9 +++++++++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0c889f6..1516282 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,15 +9,15 @@ type Result = std::result::Result // General TODOs: // - Prettify prints (add emojis) -// - Reorder files: toolchain (esp, clang and gcc instalaltion), utils(?) +// - Avoid using shell commands +// - Maybe split toolchain into toolchain(espidf, gcc, llvm...) and rust(rust checks, instalaltion and crates) // - Add subcommand test that downloads a projects and builds it // - Esp-idf version should be contained in an enum with the possible values (see chips in espflash for reference) -// - Check if LdProxy is needed when no esp-idf is installed (if not needed only install it for esp-idf) // - Do a Tauri App so we can install it with gui. If no subcommand is passed, run gui installator // - Add tests // - Clean unused code // - Add progress bar -// - Shall we delete /tools/rust and /tools/rust-src? +// - For uninstall cmd: Run uninstall.sh scripts, delete rust and rust-src folders, delete llvm and gcc files #[derive(Parser)] struct Opts { @@ -232,6 +232,7 @@ fn install(args: InstallOpts) -> Result<()> { } // install_llvm_clang + // TODO: move to function if Path::new(idf_tool_xtensa_elf_clang.as_str()).exists() { println!( "Previous installation of LLVM exist in: {}", @@ -266,12 +267,25 @@ fn install(args: InstallOpts) -> Result<()> { } if args.espidf_version.is_some() { - install_espidf(&args.build_target, args.espidf_version.unwrap())?; + let espidf_version = args.espidf_version.unwrap(); + let mut espidf_targets: String = String::new(); + for target in targets { + if espidf_targets.is_empty() { + espidf_targets = espidf_targets + &target.to_string().to_lowercase().replace("-",""); + } else { + espidf_targets = espidf_targets + "," + &target.to_string().to_lowercase().replace("-",""); + } + + } + install_espidf(&espidf_targets, &espidf_version)?; exports.push(format!( "export IDF_TOOLS_PATH=\"{}\"", get_espressif_base_path() )); - exports.push(format!(". ./{}/export.sh\"", "TODO:UPDATE")); + exports.push(format!("source {}/export.sh", get_espidf_path(&espidf_version))); + + // TODO: Install ldproxy + } else { println!("No esp-idf version provided. Installing gcc for targets"); exports.extend(install_gcc_targets(targets)?.iter().cloned()); diff --git a/src/toolchain.rs b/src/toolchain.rs index 787cf1d..ba2cb2d 100644 --- a/src/toolchain.rs +++ b/src/toolchain.rs @@ -176,8 +176,9 @@ pub fn install_gcc(gcc_target: &str) { } } -pub fn install_espidf(targets: &str, version: String) -> Result<(), String> { - let espidf_path = format!("{}/frameworks/esp-idf", get_espressif_base_path()); +pub fn install_espidf(targets: &str, version: &str) -> Result<(), String> { + + let espidf_path = get_espidf_path(version); println!("ESP-IDF Path: {}", espidf_path); #[cfg(windows)] @@ -223,19 +224,17 @@ pub fn install_espidf(targets: &str, version: String) -> Result<(), String> { // let virtual_env_path = get_python_env_path("4.4", "3.8"); // TODO: Use any git crate? if !Path::new(&espidf_path).exists() { - // let clone_command = format!("git clone --shallow-since=2020-01-01 --jobs 8 --recursive git@github.com:espressif/esp-idf.git "); let mut arguments: Vec = [].to_vec(); arguments.push("clone".to_string()); arguments.push("--jobs".to_string()); arguments.push("8".to_string()); arguments.push("--branch".to_string()); - arguments.push(version); + arguments.push(version.to_string()); arguments.push("--depth".to_string()); arguments.push("1".to_string()); arguments.push("--shallow-submodules".to_string()); arguments.push("--recursive".to_string()); arguments.push("https://github.com/espressif/esp-idf.git".to_string()); - // arguments.push("git@github.com:espressif/esp-idf.git".to_string()); arguments.push(espidf_path.clone()); println!("Cloning: {} {:?}", git_path, arguments); match run_command(git_path, arguments, "".to_string()) { diff --git a/src/utils.rs b/src/utils.rs index f3a845a..cad5820 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -108,6 +108,15 @@ pub fn get_tool_path(tool_name: &str) -> String { format!("{}tools/{}", get_espressif_base_path(), tool_name) } +pub fn get_espidf_path(version: &str) -> String { + let parsed_version: String = version.chars() + .map(|x| match x { + '/' => '-', + _ => x + }).collect(); + format!("{}frameworks/esp-idf-{}", get_espressif_base_path(), parsed_version) +} + pub fn prepare_package_strip_prefix( package_url: &str, output_directory: String,