Add esp-idf intallation

This commit is contained in:
Sergio Gasquez 2022-08-12 09:49:21 +00:00
parent d770db3df9
commit 0812175a2f
3 changed files with 32 additions and 10 deletions

View File

@ -9,15 +9,15 @@ type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>
// 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 <espressif>/tools/rust and <espressif>/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());

View File

@ -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<String> = [].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()) {

View File

@ -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,