Skip to content

Commit

Permalink
Rework update subcommand (#285)
Browse files Browse the repository at this point in the history
* feat: ✨ Refactor update and install subcomands

* feat: ✨ Refactor update and install subcomands

* Create issue_handler.yml

* build(deps): bump serde_json from 1.0.96 to 1.0.99

Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.96 to 1.0.99.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](serde-rs/json@v1.0.96...v1.0.99)

---
updated-dependencies:
- dependency-name: serde_json
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): bump clap from 4.3.3 to 4.3.8

Bumps [clap](https://github.com/clap-rs/clap) from 4.3.3 to 4.3.8.
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](clap-rs/clap@v4.3.3...v4.3.8)

---
updated-dependencies:
- dependency-name: clap
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): bump openssl from 0.10.54 to 0.10.55

Bumps [openssl](https://github.com/sfackler/rust-openssl) from 0.10.54 to 0.10.55.
- [Release notes](https://github.com/sfackler/rust-openssl/releases)
- [Commits](sfackler/rust-openssl@openssl-v0.10.54...openssl-v0.10.55)

---
updated-dependencies:
- dependency-name: openssl
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): bump strum from 0.24.1 to 0.25.0

Bumps [strum](https://github.com/Peternator7/strum) from 0.24.1 to 0.25.0.
- [Changelog](https://github.com/Peternator7/strum/blob/master/CHANGELOG.md)
- [Commits](https://github.com/Peternator7/strum/commits)

---
updated-dependencies:
- dependency-name: strum
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update readme (#289)

* docs: 📝 Update readme

* docs: Udpate readme

* build(deps): bump tokio from 1.28.2 to 1.29.1 (#290)

Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.28.2 to 1.29.1.
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](tokio-rs/tokio@tokio-1.28.2...tokio-1.29.1)

---
updated-dependencies:
- dependency-name: tokio
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump async-trait from 0.1.68 to 0.1.69 (#291)

Bumps [async-trait](https://github.com/dtolnay/async-trait) from 0.1.68 to 0.1.69.
- [Release notes](https://github.com/dtolnay/async-trait/releases)
- [Commits](dtolnay/async-trait@0.1.68...0.1.69)

---
updated-dependencies:
- dependency-name: async-trait
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump update-informer from 1.0.0 to 1.1.0 (#292)

Bumps [update-informer](https://github.com/mgrachev/update-informer) from 1.0.0 to 1.1.0.
- [Release notes](https://github.com/mgrachev/update-informer/releases)
- [Changelog](https://github.com/mgrachev/update-informer/blob/main/CHANGELOG.md)
- [Commits](mgrachev/update-informer@v1.0.0...v1.1.0)

---
updated-dependencies:
- dependency-name: update-informer
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump clap from 4.3.8 to 4.3.10 (#293)

Bumps [clap](https://github.com/clap-rs/clap) from 4.3.8 to 4.3.10.
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](clap-rs/clap@v4.3.8...v4.3.10)

---
updated-dependencies:
- dependency-name: clap
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump clap from 4.3.10 to 4.3.11

Bumps [clap](https://github.com/clap-rs/clap) from 4.3.10 to 4.3.11.
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](clap-rs/clap@v4.3.10...v4.3.11)

---
updated-dependencies:
- dependency-name: clap
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): bump serde_json from 1.0.99 to 1.0.100

Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.99 to 1.0.100.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](serde-rs/json@v1.0.99...v1.0.100)

---
updated-dependencies:
- dependency-name: serde_json
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): bump async-trait from 0.1.69 to 0.1.71

Bumps [async-trait](https://github.com/dtolnay/async-trait) from 0.1.69 to 0.1.71.
- [Release notes](https://github.com/dtolnay/async-trait/releases)
- [Commits](dtolnay/async-trait@0.1.69...0.1.71)

---
updated-dependencies:
- dependency-name: async-trait
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): bump clap_complete from 4.3.1 to 4.3.2

Bumps [clap_complete](https://github.com/clap-rs/clap) from 4.3.1 to 4.3.2.
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](clap-rs/clap@clap_complete-v4.3.1...clap_complete-v4.3.2)

---
updated-dependencies:
- dependency-name: clap_complete
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): bump regex from 1.8.4 to 1.9.1

Bumps [regex](https://github.com/rust-lang/regex) from 1.8.4 to 1.9.1.
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](rust-lang/regex@1.8.4...1.9.1)

---
updated-dependencies:
- dependency-name: regex
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): bump thiserror from 1.0.40 to 1.0.43

Bumps [thiserror](https://github.com/dtolnay/thiserror) from 1.0.40 to 1.0.43.
- [Release notes](https://github.com/dtolnay/thiserror/releases)
- [Commits](dtolnay/thiserror@1.0.40...1.0.43)

---
updated-dependencies:
- dependency-name: thiserror
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): bump tar from 0.4.38 to 0.4.39

Bumps [tar](https://github.com/alexcrichton/tar-rs) from 0.4.38 to 0.4.39.
- [Commits](alexcrichton/tar-rs@0.4.38...0.4.39)

---
updated-dependencies:
- dependency-name: tar
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): bump miette from 5.9.0 to 5.10.0

Bumps [miette](https://github.com/zkat/miette) from 5.9.0 to 5.10.0.
- [Release notes](https://github.com/zkat/miette/releases)
- [Changelog](https://github.com/zkat/miette/blob/main/CHANGELOG.md)
- [Commits](zkat/miette@miette-derive-v5.9.0...miette-derive-v5.10.0)

---
updated-dependencies:
- dependency-name: miette
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): bump serde_json from 1.0.100 to 1.0.103

Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.100 to 1.0.103.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](serde-rs/json@v1.0.100...v1.0.103)

---
updated-dependencies:
- dependency-name: serde_json
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): bump assert_cmd from 2.0.11 to 2.0.12

Bumps [assert_cmd](https://github.com/assert-rs/assert_cmd) from 2.0.11 to 2.0.12.
- [Changelog](https://github.com/assert-rs/assert_cmd/blob/master/CHANGELOG.md)
- [Commits](assert-rs/assert_cmd@v2.0.11...v2.0.12)

---
updated-dependencies:
- dependency-name: assert_cmd
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): bump clap from 4.3.11 to 4.3.14

Bumps [clap](https://github.com/clap-rs/clap) from 4.3.11 to 4.3.14.
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](clap-rs/clap@v4.3.11...v4.3.14)

---
updated-dependencies:
- dependency-name: clap
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): bump clap from 4.3.14 to 4.3.19

Bumps [clap](https://github.com/clap-rs/clap) from 4.3.14 to 4.3.19.
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](clap-rs/clap@v4.3.14...v4.3.19)

---
updated-dependencies:
- dependency-name: clap
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): bump thiserror from 1.0.43 to 1.0.44

Bumps [thiserror](https://github.com/dtolnay/thiserror) from 1.0.43 to 1.0.44.
- [Release notes](https://github.com/dtolnay/thiserror/releases)
- [Commits](dtolnay/thiserror@1.0.43...1.0.44)

---
updated-dependencies:
- dependency-name: thiserror
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): bump async-trait from 0.1.71 to 0.1.72

Bumps [async-trait](https://github.com/dtolnay/async-trait) from 0.1.71 to 0.1.72.
- [Release notes](https://github.com/dtolnay/async-trait/releases)
- [Commits](dtolnay/async-trait@0.1.71...0.1.72)

---
updated-dependencies:
- dependency-name: async-trait
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): bump tempfile from 3.6.0 to 3.7.0

Bumps [tempfile](https://github.com/Stebalien/tempfile) from 3.6.0 to 3.7.0.
- [Changelog](https://github.com/Stebalien/tempfile/blob/master/CHANGELOG.md)
- [Commits](Stebalien/tempfile@v3.6.0...v3.7.0)

---
updated-dependencies:
- dependency-name: tempfile
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): bump serde_json from 1.0.103 to 1.0.104

Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.103 to 1.0.104.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](serde-rs/json@v1.0.103...v1.0.104)

---
updated-dependencies:
- dependency-name: serde_json
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Ignore shebang of install.sh files (#312)

* fix: Remove -c argument

* feat: Split arguments and add checking result

* build(deps): bump tar from 0.4.39 to 0.4.40

Bumps [tar](https://github.com/alexcrichton/tar-rs) from 0.4.39 to 0.4.40.
- [Commits](alexcrichton/tar-rs@0.4.39...0.4.40)

---
updated-dependencies:
- dependency-name: tar
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): bump openssl from 0.10.55 to 0.10.56

Bumps [openssl](https://github.com/sfackler/rust-openssl) from 0.10.55 to 0.10.56.
- [Release notes](https://github.com/sfackler/rust-openssl/releases)
- [Commits](sfackler/rust-openssl@openssl-v0.10.55...openssl-v0.10.56)

---
updated-dependencies:
- dependency-name: openssl
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): bump regex from 1.9.1 to 1.9.3

Bumps [regex](https://github.com/rust-lang/regex) from 1.9.1 to 1.9.3.
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](rust-lang/regex@1.9.1...1.9.3)

---
updated-dependencies:
- dependency-name: regex
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): bump tempfile from 3.7.0 to 3.7.1

Bumps [tempfile](https://github.com/Stebalien/tempfile) from 3.7.0 to 3.7.1.
- [Changelog](https://github.com/Stebalien/tempfile/blob/master/CHANGELOG.md)
- [Commits](Stebalien/tempfile@v3.7.0...v3.7.1)

---
updated-dependencies:
- dependency-name: tempfile
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
SergioGasquez and dependabot[bot] committed Aug 11, 2023
1 parent a865da6 commit 0a64e78
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 224 deletions.
61 changes: 61 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use crate::{
targets::{parse_targets, Target},
toolchain::rust::XtensaRust,
};
use clap::Parser;
use clap_complete::Shell;
use std::{collections::HashSet, path::PathBuf};

#[derive(Debug, Parser)]
pub struct CompletionsOpts {
/// Verbosity level of the logs.
#[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])]
pub log_level: String,
/// Shell to generate completions for.
pub shell: Shell,
}

#[derive(Debug, Parser)]
pub struct InstallOpts {
/// Target triple of the host.
#[arg(short = 'd', long, value_parser = ["x86_64-unknown-linux-gnu", "aarch64-unknown-linux-gnu", "x86_64-pc-windows-msvc", "x86_64-pc-windows-gnu" , "x86_64-apple-darwin" , "aarch64-apple-darwin"])]
pub default_host: Option<String>,
/// Relative or full path for the export file that will be generated. If no path is provided, the file will be generated under home directory (https://docs.rs/dirs/latest/dirs/fn.home_dir.html).
#[arg(short = 'f', long)]
pub export_file: Option<PathBuf>,
/// Extends the LLVM installation.
///
/// This will install the whole LLVM instead of only installing the libs.
#[arg(short = 'e', long)]
pub extended_llvm: bool,
/// Verbosity level of the logs.
#[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])]
pub log_level: String,
/// Xtensa Rust toolchain name.
#[arg(short = 'a', long, default_value = "esp")]
pub name: String,
/// Nightly Rust toolchain version.
#[arg(short = 'n', long, default_value = "nightly")]
pub nightly_version: String,
/// Only install toolchains required for STD applications.
///
/// With this option, espup will skip GCC installation (it will be handled by esp-idf-sys), hence you won't be able to build no_std applications.
#[arg(short = 's', long)]
pub std: bool,
/// Comma or space separated list of targets [esp32,esp32c2,esp32c3,esp32c6,esp32h2,esp32s2,esp32s3,all].
#[arg(short = 't', long, default_value = "all", value_parser = parse_targets)]
pub targets: HashSet<Target>,
/// Xtensa Rust toolchain version.
#[arg(short = 'v', long, value_parser = XtensaRust::parse_version)]
pub toolchain_version: Option<String>,
}

#[derive(Debug, Parser)]
pub struct UninstallOpts {
/// Verbosity level of the logs.
#[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])]
pub log_level: String,
/// Xtensa Rust toolchain name.
#[arg(short = 'a', long, default_value = "esp")]
pub name: String,
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod cli;
pub mod emoji;
pub mod env;
pub mod error;
Expand Down
233 changes: 10 additions & 223 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
use clap::{CommandFactory, Parser};
use clap_complete::Shell;
#[cfg(windows)]
use espup::env::set_environment_variable;
use espup::{
cli::{CompletionsOpts, InstallOpts, UninstallOpts},
emoji,
env::{create_export_file, export_environment, get_export_file},
error::Error,
host_triple::get_host_triple,
logging::initialize_logger,
targets::{parse_targets, Target},
toolchain::{
gcc::{uninstall_gcc_toolchains, Gcc},
llvm::Llvm,
rust::{check_rust_installation, get_rustup_home, RiscVTarget, XtensaRust},
Installable,
gcc::uninstall_gcc_toolchains, install as toolchain_install, llvm::Llvm,
rust::get_rustup_home,
},
update::check_for_update,
};
use log::{debug, info, warn};
use log::info;
use miette::Result;
use std::{collections::HashSet, env, fs::remove_dir_all, path::PathBuf};
use tokio::sync::mpsc;
use tokio_retry::{strategy::FixedInterval, Retry};
use std::{env, fs::remove_dir_all};

#[derive(Parser)]
#[command(about, version)]
Expand All @@ -40,77 +33,7 @@ pub enum SubCommand {
/// Uninstalls Espressif Rust ecosystem.
Uninstall(UninstallOpts),
/// Updates Xtensa Rust toolchain.
Update(UpdateOpts),
}

#[derive(Debug, Parser)]
pub struct CompletionsOpts {
/// Verbosity level of the logs.
#[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])]
pub log_level: String,
/// Shell to generate completions for.
pub shell: Shell,
}

#[derive(Debug, Parser)]
pub struct InstallOpts {
/// Target triple of the host.
#[arg(short = 'd', long, value_parser = ["x86_64-unknown-linux-gnu", "aarch64-unknown-linux-gnu", "x86_64-pc-windows-msvc", "x86_64-pc-windows-gnu" , "x86_64-apple-darwin" , "aarch64-apple-darwin"])]
pub default_host: Option<String>,
/// Relative or full path for the export file that will be generated. If no path is provided, the file will be generated under home directory (https://docs.rs/dirs/latest/dirs/fn.home_dir.html).
#[arg(short = 'f', long)]
pub export_file: Option<PathBuf>,
/// Extends the LLVM installation.
///
/// This will install the whole LLVM instead of only installing the libs.
#[arg(short = 'e', long)]
pub extended_llvm: bool,
/// Verbosity level of the logs.
#[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])]
pub log_level: String,
/// Xtensa Rust toolchain name.
#[arg(short = 'a', long, default_value = "esp")]
pub name: String,
/// Nightly Rust toolchain version.
#[arg(short = 'n', long, default_value = "nightly")]
pub nightly_version: String,
/// Only install toolchains required for STD applications.
///
/// With this option, espup will skip GCC installation (it will be handled by esp-idf-sys), hence you won't be able to build no_std applications.
#[arg(short = 's', long)]
pub std: bool,
/// Comma or space separated list of targets [esp32,esp32c2,esp32c3,esp32c6,esp32h2,esp32s2,esp32s3,all].
#[arg(short = 't', long, default_value = "all", value_parser = parse_targets)]
pub targets: HashSet<Target>,
/// Xtensa Rust toolchain version.
#[arg(short = 'v', long, value_parser = XtensaRust::parse_version)]
pub toolchain_version: Option<String>,
}

#[derive(Debug, Parser)]
pub struct UpdateOpts {
/// Target triple of the host.
#[arg(short = 'd', long, value_parser = ["x86_64-unknown-linux-gnu", "aarch64-unknown-linux-gnu", "x86_64-pc-windows-msvc", "x86_64-pc-windows-gnu" , "x86_64-apple-darwin" , "aarch64-apple-darwin"])]
pub default_host: Option<String>,
/// Verbosity level of the logs.
#[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])]
pub log_level: String,
/// Xtensa Rust toolchain name.
#[arg(short = 'a', long, default_value = "esp")]
pub name: String,
/// Xtensa Rust toolchain version.
#[arg(short = 'v', long, value_parser = XtensaRust::parse_version)]
pub toolchain_version: Option<String>,
}

#[derive(Debug, Parser)]
pub struct UninstallOpts {
/// Verbosity level of the logs.
#[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])]
pub log_level: String,
/// Xtensa Rust toolchain name.
#[arg(short = 'a', long, default_value = "esp")]
pub name: String,
Update(Box<InstallOpts>),
}

/// Updates Xtensa Rust toolchain.
Expand Down Expand Up @@ -142,122 +65,8 @@ async fn install(args: InstallOpts) -> Result<()> {
check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));

info!("{} Installing the Espressif Rust ecosystem", emoji::DISC);

let export_file = get_export_file(args.export_file)?;
let mut exports: Vec<String> = Vec::new();
let host_triple = get_host_triple(args.default_host)?;
let xtensa_rust_version = if let Some(toolchain_version) = &args.toolchain_version {
toolchain_version.clone()
} else {
XtensaRust::get_latest_version().await?
};
let install_path = get_rustup_home().join("toolchains").join(args.name);
let llvm: Llvm = Llvm::new(
&install_path,
&host_triple,
args.extended_llvm,
&xtensa_rust_version,
)?;
let targets = args.targets;
let xtensa_rust = if targets.contains(&Target::ESP32)
|| targets.contains(&Target::ESP32S2)
|| targets.contains(&Target::ESP32S3)
{
Some(XtensaRust::new(
&xtensa_rust_version,
&host_triple,
&install_path,
))
} else {
None
};

debug!(
"{} Arguments:
- Export file: {:?}
- Host triple: {}
- LLVM Toolchain: {:?}
- Nightly version: {:?}
- Rust Toolchain: {:?}
- Targets: {:?}
- Toolchain path: {:?}
- Toolchain version: {:?}",
emoji::INFO,
&export_file,
host_triple,
&llvm,
&args.nightly_version,
xtensa_rust,
targets,
&install_path,
args.toolchain_version,
);

check_rust_installation().await?;

// Build up a vector of installable applications, all of which implement the
// `Installable` async trait.
let mut to_install = Vec::<Box<dyn Installable + Send + Sync>>::new();

if let Some(ref xtensa_rust) = xtensa_rust {
to_install.push(Box::new(xtensa_rust.to_owned()));
}

to_install.push(Box::new(llvm));

if targets.iter().any(|t| t.is_riscv()) {
let riscv_target = RiscVTarget::new(&args.nightly_version);
to_install.push(Box::new(riscv_target));
}

if !args.std {
targets.iter().for_each(|target| {
if target.is_xtensa() {
let gcc = Gcc::new(target, &host_triple, &install_path);
to_install.push(Box::new(gcc));
}
});
// All RISC-V targets use the same GCC toolchain
// ESP32S2 and ESP32S3 also install the RISC-V toolchain for their ULP coprocessor
if targets.iter().any(|t| t != &Target::ESP32) {
let riscv_gcc = Gcc::new_riscv(&host_triple, &install_path);
to_install.push(Box::new(riscv_gcc));
}
}

// With a list of applications to install, install them all in parallel.
let installable_items = to_install.len();
let (tx, mut rx) = mpsc::channel::<Result<Vec<String>, Error>>(installable_items);
for app in to_install {
let tx = tx.clone();
let retry_strategy = FixedInterval::from_millis(50).take(3);
tokio::spawn(async move {
let res = Retry::spawn(retry_strategy, || async {
let res = app.install().await;
if res.is_err() {
warn!(
"{} Installation for '{}' failed, retrying",
emoji::WARN,
app.name()
);
}
res
})
.await;
tx.send(res).await.unwrap();
});
}

// Read the results of the install tasks as they complete.
for _ in 0..installable_items {
let names = rx.recv().await.unwrap()?;
exports.extend(names);
}

create_export_file(&export_file, &exports)?;

toolchain_install(args).await?;
info!("{} Installation successfully completed!", emoji::CHECK);
export_environment(&export_file)?;
Ok(())
}

Expand Down Expand Up @@ -290,34 +99,12 @@ async fn uninstall(args: UninstallOpts) -> Result<()> {
}

/// Updates Xtensa Rust toolchain.
async fn update(args: UpdateOpts) -> Result<()> {
async fn update(args: InstallOpts) -> Result<()> {
initialize_logger(&args.log_level);
check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));

info!("{} Updating Espressif Rust ecosystem", emoji::DISC);

let host_triple = get_host_triple(args.default_host)?;
let install_path = get_rustup_home().join("toolchains").join(args.name);
let xtensa_rust: XtensaRust = if let Some(toolchain_version) = args.toolchain_version {
XtensaRust::new(&toolchain_version, &host_triple, &install_path)
} else {
let latest_version = XtensaRust::get_latest_version().await?;
XtensaRust::new(&latest_version, &host_triple, &install_path)
};

debug!(
"{} Arguments:
- Host triple: {}
- Install path: {:#?}
- Toolchain version: {:#?}",
emoji::INFO,
host_triple,
install_path,
xtensa_rust,
);

xtensa_rust.install().await?;

toolchain_install(args).await?;
info!("{} Update successfully completed!", emoji::CHECK);
Ok(())
}
Expand All @@ -327,7 +114,7 @@ async fn main() -> Result<()> {
match Cli::parse().subcommand {
SubCommand::Completions(args) => completions(args).await,
SubCommand::Install(args) => install(*args).await,
SubCommand::Update(args) => update(args).await,
SubCommand::Update(args) => update(*args).await,
SubCommand::Uninstall(args) => uninstall(args).await,
}
}
Loading

0 comments on commit 0a64e78

Please sign in to comment.