Skip to content

Commit 9fce473

Browse files
Rework update subcommand (esp-rs#285)
* 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] <[email protected]> * 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] <[email protected]> * 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] <[email protected]> * 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] <[email protected]> * Update readme (esp-rs#289) * docs: 📝 Update readme * docs: Udpate readme * build(deps): bump tokio from 1.28.2 to 1.29.1 (esp-rs#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] <[email protected]> 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 (esp-rs#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] <[email protected]> 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 (esp-rs#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] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump clap from 4.3.8 to 4.3.10 (esp-rs#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] <[email protected]> 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] <[email protected]> * 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] <[email protected]> * 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] <[email protected]> * 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] <[email protected]> * 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] <[email protected]> * 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] <[email protected]> * 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] <[email protected]> * 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] <[email protected]> * 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] <[email protected]> * 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] <[email protected]> * 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] <[email protected]> * 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] <[email protected]> * 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] <[email protected]> * 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] <[email protected]> * 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] <[email protected]> * 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] <[email protected]> * Ignore shebang of install.sh files (esp-rs#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] <[email protected]> * 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] <[email protected]> * 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] <[email protected]> * 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] <[email protected]> --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent c8c7876 commit 9fce473

File tree

4 files changed

+205
-224
lines changed

4 files changed

+205
-224
lines changed

src/cli.rs

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
use crate::{
2+
targets::{parse_targets, Target},
3+
toolchain::rust::XtensaRust,
4+
};
5+
use clap::Parser;
6+
use clap_complete::Shell;
7+
use std::{collections::HashSet, path::PathBuf};
8+
9+
#[derive(Debug, Parser)]
10+
pub struct CompletionsOpts {
11+
/// Verbosity level of the logs.
12+
#[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])]
13+
pub log_level: String,
14+
/// Shell to generate completions for.
15+
pub shell: Shell,
16+
}
17+
18+
#[derive(Debug, Parser)]
19+
pub struct InstallOpts {
20+
/// Target triple of the host.
21+
#[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"])]
22+
pub default_host: Option<String>,
23+
/// 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).
24+
#[arg(short = 'f', long)]
25+
pub export_file: Option<PathBuf>,
26+
/// Extends the LLVM installation.
27+
///
28+
/// This will install the whole LLVM instead of only installing the libs.
29+
#[arg(short = 'e', long)]
30+
pub extended_llvm: bool,
31+
/// Verbosity level of the logs.
32+
#[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])]
33+
pub log_level: String,
34+
/// Xtensa Rust toolchain name.
35+
#[arg(short = 'a', long, default_value = "esp")]
36+
pub name: String,
37+
/// Nightly Rust toolchain version.
38+
#[arg(short = 'n', long, default_value = "nightly")]
39+
pub nightly_version: String,
40+
/// Only install toolchains required for STD applications.
41+
///
42+
/// 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.
43+
#[arg(short = 's', long)]
44+
pub std: bool,
45+
/// Comma or space separated list of targets [esp32,esp32c2,esp32c3,esp32c6,esp32h2,esp32s2,esp32s3,all].
46+
#[arg(short = 't', long, default_value = "all", value_parser = parse_targets)]
47+
pub targets: HashSet<Target>,
48+
/// Xtensa Rust toolchain version.
49+
#[arg(short = 'v', long, value_parser = XtensaRust::parse_version)]
50+
pub toolchain_version: Option<String>,
51+
}
52+
53+
#[derive(Debug, Parser)]
54+
pub struct UninstallOpts {
55+
/// Verbosity level of the logs.
56+
#[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])]
57+
pub log_level: String,
58+
/// Xtensa Rust toolchain name.
59+
#[arg(short = 'a', long, default_value = "esp")]
60+
pub name: String,
61+
}

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub mod cli;
12
pub mod emoji;
23
pub mod env;
34
pub mod error;

src/main.rs

+10-223
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
use clap::{CommandFactory, Parser};
2-
use clap_complete::Shell;
32
#[cfg(windows)]
43
use espup::env::set_environment_variable;
54
use espup::{
5+
cli::{CompletionsOpts, InstallOpts, UninstallOpts},
66
emoji,
7-
env::{create_export_file, export_environment, get_export_file},
87
error::Error,
9-
host_triple::get_host_triple,
108
logging::initialize_logger,
11-
targets::{parse_targets, Target},
129
toolchain::{
13-
gcc::{uninstall_gcc_toolchains, Gcc},
14-
llvm::Llvm,
15-
rust::{check_rust_installation, get_rustup_home, RiscVTarget, XtensaRust},
16-
Installable,
10+
gcc::uninstall_gcc_toolchains, install as toolchain_install, llvm::Llvm,
11+
rust::get_rustup_home,
1712
},
1813
update::check_for_update,
1914
};
20-
use log::{debug, info, warn};
15+
use log::info;
2116
use miette::Result;
22-
use std::{collections::HashSet, env, fs::remove_dir_all, path::PathBuf};
23-
use tokio::sync::mpsc;
24-
use tokio_retry::{strategy::FixedInterval, Retry};
17+
use std::{env, fs::remove_dir_all};
2518

2619
#[derive(Parser)]
2720
#[command(about, version)]
@@ -40,77 +33,7 @@ pub enum SubCommand {
4033
/// Uninstalls Espressif Rust ecosystem.
4134
Uninstall(UninstallOpts),
4235
/// Updates Xtensa Rust toolchain.
43-
Update(UpdateOpts),
44-
}
45-
46-
#[derive(Debug, Parser)]
47-
pub struct CompletionsOpts {
48-
/// Verbosity level of the logs.
49-
#[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])]
50-
pub log_level: String,
51-
/// Shell to generate completions for.
52-
pub shell: Shell,
53-
}
54-
55-
#[derive(Debug, Parser)]
56-
pub struct InstallOpts {
57-
/// Target triple of the host.
58-
#[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"])]
59-
pub default_host: Option<String>,
60-
/// 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).
61-
#[arg(short = 'f', long)]
62-
pub export_file: Option<PathBuf>,
63-
/// Extends the LLVM installation.
64-
///
65-
/// This will install the whole LLVM instead of only installing the libs.
66-
#[arg(short = 'e', long)]
67-
pub extended_llvm: bool,
68-
/// Verbosity level of the logs.
69-
#[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])]
70-
pub log_level: String,
71-
/// Xtensa Rust toolchain name.
72-
#[arg(short = 'a', long, default_value = "esp")]
73-
pub name: String,
74-
/// Nightly Rust toolchain version.
75-
#[arg(short = 'n', long, default_value = "nightly")]
76-
pub nightly_version: String,
77-
/// Only install toolchains required for STD applications.
78-
///
79-
/// 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.
80-
#[arg(short = 's', long)]
81-
pub std: bool,
82-
/// Comma or space separated list of targets [esp32,esp32c2,esp32c3,esp32c6,esp32h2,esp32s2,esp32s3,all].
83-
#[arg(short = 't', long, default_value = "all", value_parser = parse_targets)]
84-
pub targets: HashSet<Target>,
85-
/// Xtensa Rust toolchain version.
86-
#[arg(short = 'v', long, value_parser = XtensaRust::parse_version)]
87-
pub toolchain_version: Option<String>,
88-
}
89-
90-
#[derive(Debug, Parser)]
91-
pub struct UpdateOpts {
92-
/// Target triple of the host.
93-
#[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"])]
94-
pub default_host: Option<String>,
95-
/// Verbosity level of the logs.
96-
#[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])]
97-
pub log_level: String,
98-
/// Xtensa Rust toolchain name.
99-
#[arg(short = 'a', long, default_value = "esp")]
100-
pub name: String,
101-
/// Xtensa Rust toolchain version.
102-
#[arg(short = 'v', long, value_parser = XtensaRust::parse_version)]
103-
pub toolchain_version: Option<String>,
104-
}
105-
106-
#[derive(Debug, Parser)]
107-
pub struct UninstallOpts {
108-
/// Verbosity level of the logs.
109-
#[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])]
110-
pub log_level: String,
111-
/// Xtensa Rust toolchain name.
112-
#[arg(short = 'a', long, default_value = "esp")]
113-
pub name: String,
36+
Update(Box<InstallOpts>),
11437
}
11538

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

14467
info!("{} Installing the Espressif Rust ecosystem", emoji::DISC);
145-
146-
let export_file = get_export_file(args.export_file)?;
147-
let mut exports: Vec<String> = Vec::new();
148-
let host_triple = get_host_triple(args.default_host)?;
149-
let xtensa_rust_version = if let Some(toolchain_version) = &args.toolchain_version {
150-
toolchain_version.clone()
151-
} else {
152-
XtensaRust::get_latest_version().await?
153-
};
154-
let install_path = get_rustup_home().join("toolchains").join(args.name);
155-
let llvm: Llvm = Llvm::new(
156-
&install_path,
157-
&host_triple,
158-
args.extended_llvm,
159-
&xtensa_rust_version,
160-
)?;
161-
let targets = args.targets;
162-
let xtensa_rust = if targets.contains(&Target::ESP32)
163-
|| targets.contains(&Target::ESP32S2)
164-
|| targets.contains(&Target::ESP32S3)
165-
{
166-
Some(XtensaRust::new(
167-
&xtensa_rust_version,
168-
&host_triple,
169-
&install_path,
170-
))
171-
} else {
172-
None
173-
};
174-
175-
debug!(
176-
"{} Arguments:
177-
- Export file: {:?}
178-
- Host triple: {}
179-
- LLVM Toolchain: {:?}
180-
- Nightly version: {:?}
181-
- Rust Toolchain: {:?}
182-
- Targets: {:?}
183-
- Toolchain path: {:?}
184-
- Toolchain version: {:?}",
185-
emoji::INFO,
186-
&export_file,
187-
host_triple,
188-
&llvm,
189-
&args.nightly_version,
190-
xtensa_rust,
191-
targets,
192-
&install_path,
193-
args.toolchain_version,
194-
);
195-
196-
check_rust_installation().await?;
197-
198-
// Build up a vector of installable applications, all of which implement the
199-
// `Installable` async trait.
200-
let mut to_install = Vec::<Box<dyn Installable + Send + Sync>>::new();
201-
202-
if let Some(ref xtensa_rust) = xtensa_rust {
203-
to_install.push(Box::new(xtensa_rust.to_owned()));
204-
}
205-
206-
to_install.push(Box::new(llvm));
207-
208-
if targets.iter().any(|t| t.is_riscv()) {
209-
let riscv_target = RiscVTarget::new(&args.nightly_version);
210-
to_install.push(Box::new(riscv_target));
211-
}
212-
213-
if !args.std {
214-
targets.iter().for_each(|target| {
215-
if target.is_xtensa() {
216-
let gcc = Gcc::new(target, &host_triple, &install_path);
217-
to_install.push(Box::new(gcc));
218-
}
219-
});
220-
// All RISC-V targets use the same GCC toolchain
221-
// ESP32S2 and ESP32S3 also install the RISC-V toolchain for their ULP coprocessor
222-
if targets.iter().any(|t| t != &Target::ESP32) {
223-
let riscv_gcc = Gcc::new_riscv(&host_triple, &install_path);
224-
to_install.push(Box::new(riscv_gcc));
225-
}
226-
}
227-
228-
// With a list of applications to install, install them all in parallel.
229-
let installable_items = to_install.len();
230-
let (tx, mut rx) = mpsc::channel::<Result<Vec<String>, Error>>(installable_items);
231-
for app in to_install {
232-
let tx = tx.clone();
233-
let retry_strategy = FixedInterval::from_millis(50).take(3);
234-
tokio::spawn(async move {
235-
let res = Retry::spawn(retry_strategy, || async {
236-
let res = app.install().await;
237-
if res.is_err() {
238-
warn!(
239-
"{} Installation for '{}' failed, retrying",
240-
emoji::WARN,
241-
app.name()
242-
);
243-
}
244-
res
245-
})
246-
.await;
247-
tx.send(res).await.unwrap();
248-
});
249-
}
250-
251-
// Read the results of the install tasks as they complete.
252-
for _ in 0..installable_items {
253-
let names = rx.recv().await.unwrap()?;
254-
exports.extend(names);
255-
}
256-
257-
create_export_file(&export_file, &exports)?;
258-
68+
toolchain_install(args).await?;
25969
info!("{} Installation successfully completed!", emoji::CHECK);
260-
export_environment(&export_file)?;
26170
Ok(())
26271
}
26372

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

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

297106
info!("{} Updating Espressif Rust ecosystem", emoji::DISC);
298-
299-
let host_triple = get_host_triple(args.default_host)?;
300-
let install_path = get_rustup_home().join("toolchains").join(args.name);
301-
let xtensa_rust: XtensaRust = if let Some(toolchain_version) = args.toolchain_version {
302-
XtensaRust::new(&toolchain_version, &host_triple, &install_path)
303-
} else {
304-
let latest_version = XtensaRust::get_latest_version().await?;
305-
XtensaRust::new(&latest_version, &host_triple, &install_path)
306-
};
307-
308-
debug!(
309-
"{} Arguments:
310-
- Host triple: {}
311-
- Install path: {:#?}
312-
- Toolchain version: {:#?}",
313-
emoji::INFO,
314-
host_triple,
315-
install_path,
316-
xtensa_rust,
317-
);
318-
319-
xtensa_rust.install().await?;
320-
107+
toolchain_install(args).await?;
321108
info!("{} Update successfully completed!", emoji::CHECK);
322109
Ok(())
323110
}
@@ -327,7 +114,7 @@ async fn main() -> Result<()> {
327114
match Cli::parse().subcommand {
328115
SubCommand::Completions(args) => completions(args).await,
329116
SubCommand::Install(args) => install(*args).await,
330-
SubCommand::Update(args) => update(args).await,
117+
SubCommand::Update(args) => update(*args).await,
331118
SubCommand::Uninstall(args) => uninstall(args).await,
332119
}
333120
}

0 commit comments

Comments
 (0)