From fe31e43a579dcc2c2e1f8ea0799104cfe8bee6b5 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Thu, 3 Nov 2022 22:02:29 +0000 Subject: [PATCH 01/22] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Use=20absolute=20pa?= =?UTF-8?q?th=20to=20export=20file=20in=20config=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 91b8954..65085be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,7 @@ use espup::{ use log::{debug, info, warn}; use std::{ collections::HashSet, - fs::{remove_dir_all, remove_file, File}, + fs::{canonicalize, remove_dir_all, remove_file, File}, io::Write, path::{Path, PathBuf}, }; @@ -214,7 +214,7 @@ fn install(args: InstallOpts) -> Result<()> { info!("{} Saving configuration file", emoji::WRENCH); let config = Config { espidf_version: args.espidf_version, - export_file, + export_file: canonicalize(&export_file)?, extra_crates: extra_crates .iter() .map(|x| x.name.clone()) From 03780132d2c464b88dc5bf0e5ad404ecc8e48463 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Thu, 3 Nov 2022 23:17:15 +0100 Subject: [PATCH 02/22] =?UTF-8?q?ci:=20=F0=9F=91=B7=20Update=20CI=20to=20r?= =?UTF-8?q?un=20in=20parallel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yaml | 45 +++++++++++++++------------------------ 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6b55c6d..c0d3d31 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -16,7 +16,7 @@ env: jobs: continuous-integration: - name: Checks + name: cargo ${{ matrix.action.command }} - ${{ matrix.job.os }} runs-on: ${{ matrix.job.os }} strategy: fail-fast: false @@ -29,6 +29,19 @@ jobs: - os: windows-latest os-name: windows binary-postfix: ".exe" + action: + - command: build + args: --release + - command: test + args: --all-features --workspace + - command: fmt + args: --all -- --check + - command: clippy + args: --all-targets --all-features --workspace -- -D warnings + - command: doc + args: --no-deps --document-private-items --all-features --workspace --examples + - command: publish + args: --dry-run steps: - name: Install dependencies if: ${{ matrix.job.os == 'ubuntu-latest' }} @@ -45,34 +58,10 @@ jobs: - name: Build uses: actions-rs/cargo@v1 with: - command: build - args: --release - - name: Test suite - uses: actions-rs/cargo@v1 - with: - command: test - args: --all-features --workspace - - name: Format check - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check - - name: Clippy check - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --all-targets --all-features --workspace -- -D warnings - - name: Docs - uses: actions-rs/cargo@v1 - with: - command: doc - args: --no-deps --document-private-items --all-features --workspace --examples - - name: Publish dry run - uses: actions-rs/cargo@v1 - with: - command: publish - args: --dry-run + command: ${{ matrix.action.command }} + args: ${{ matrix.action.args }} - name: Archive artifact + if: ${{ matrix.action.command == 'build' }} uses: actions/upload-artifact@v3 with: name: espup-${{ matrix.job.os-name }}${{ matrix.job.binary-postfix }} From 94376da073df14719bd542e5af5a3a138a7f0a78 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Thu, 3 Nov 2022 23:26:41 +0100 Subject: [PATCH 03/22] =?UTF-8?q?ci:=20=E2=9A=A1=EF=B8=8F=20Only=20run=20C?= =?UTF-8?q?I=20when=20pushing=20to=20main?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c0d3d31..797ea22 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -3,6 +3,8 @@ name: Continuous Integration on: push: + branches: + - main paths-ignore: - "**/README.md" - "**/cd.yml" From 4d3eadbe70e83916da12c0787907219dc121c63b Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Sat, 5 Nov 2022 09:42:27 +0100 Subject: [PATCH 04/22] =?UTF-8?q?chore:=20=E2=AC=86=EF=B8=8F=20Update=20ve?= =?UTF-8?q?rsion=20to=20`0.2.2-dev`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 45a9778..3dd2559 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -144,9 +144,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.0.18" +version = "4.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "335867764ed2de42325fafe6d18b8af74ba97ee0c590fa016f157535b42ab04b" +checksum = "8e67816e006b17427c9b4386915109b494fec2d929c63e3bd3561234cbf1bf1e" dependencies = [ "atty", "bitflags", @@ -416,7 +416,7 @@ dependencies = [ [[package]] name = "espup" -version = "0.2.1" +version = "0.2.2-dev" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index ad93cec..4230897 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "espup" -version = "0.2.1" +version = "0.2.2-dev" authors = ["Sergio Gasquez Arcos "] edition = "2021" license = "MIT OR Apache-2.0" From a59cf1b9119b793ba9bf1d2175e2e406a5c9aea7 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Sat, 5 Nov 2022 09:03:06 +0000 Subject: [PATCH 05/22] =?UTF-8?q?chore:=20=E2=9A=A1=EF=B8=8F=20Update=20de?= =?UTF-8?q?fault=20extra=5Fcrates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2cd1d15..b86caf5 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,7 @@ Options: -c, --extra-crates Comma or space list of extra crates to install - [default: cargo-espflash] + [default: ] -x, --llvm-version LLVM version diff --git a/src/main.rs b/src/main.rs index 02107d5..1d645b1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -80,7 +80,7 @@ pub struct InstallOpts { #[arg(short = 'f', long, default_value = DEFAULT_EXPORT_FILE)] pub export_file: PathBuf, /// Comma or space list of extra crates to install. - #[arg(short = 'c', long, default_value = "cargo-espflash")] + #[arg(short = 'c', long, default_value = "")] pub extra_crates: String, /// LLVM version. #[arg(short = 'x', long, default_value = "15", value_parser = ["15"])] From 945ec4588f45509b8c98d77d47ce795c35963a3c Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Sat, 5 Nov 2022 09:43:41 +0000 Subject: [PATCH 06/22] =?UTF-8?q?fix:=20=E2=9A=A1=EF=B8=8F=20Use=20absolut?= =?UTF-8?q?e=20path=20of=20export-file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 65085be..dff3990 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,7 @@ use espup::{ use log::{debug, info, warn}; use std::{ collections::HashSet, - fs::{canonicalize, remove_dir_all, remove_file, File}, + fs::{remove_dir_all, remove_file, File}, io::Write, path::{Path, PathBuf}, }; @@ -131,7 +131,12 @@ fn install(args: InstallOpts) -> Result<()> { let host_triple = get_host_triple(args.default_host)?; let mut extra_crates: HashSet = args.extra_crates.split(',').map(Crate::new).collect(); let mut exports: Vec = Vec::new(); - let export_file = args.export_file.clone(); + let export_file = if args.export_file.is_absolute() { + args.export_file + } else { + let current_dir = std::env::current_dir()?; + current_dir.join(args.export_file) + }; let xtensa_rust = if targets.contains(&Target::ESP32) || targets.contains(&Target::ESP32S2) || targets.contains(&Target::ESP32S3) @@ -164,7 +169,7 @@ fn install(args: InstallOpts) -> Result<()> { host_triple, targets, &args.espidf_version, - export_file, + &export_file, &extra_crates, llvm, &args.nightly_version, @@ -214,7 +219,7 @@ fn install(args: InstallOpts) -> Result<()> { info!("{} Saving configuration file", emoji::WRENCH); let config = Config { espidf_version: args.espidf_version, - export_file: canonicalize(&export_file)?, + export_file, extra_crates: extra_crates .iter() .map(|x| x.name.clone()) @@ -371,7 +376,7 @@ pub fn export_environment(export_file: &PathBuf, exports: &[String]) -> Result<( ); #[cfg(unix)] warn!( - "{} PLEASE set up the environment variables running: '. ./{}'", + "{} PLEASE set up the environment variables running: '. {}'", emoji::INFO, export_file.display() ); From ba34a8ce5bd3cd228d2e30d8e756ebed8b150045 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Sat, 5 Nov 2022 11:17:11 +0000 Subject: [PATCH 07/22] =?UTF-8?q?refactor:=20=E2=99=BB=EF=B8=8F=20Update?= =?UTF-8?q?=20default=20path=20of=20export=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index dff3990..292ea37 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use anyhow::{bail, Result}; use clap::Parser; use directories_next::ProjectDirs; +use dirs::home_dir; use embuild::{ cmd, espidf::{parse_esp_idf_git_ref, EspIdfRemote}, @@ -77,8 +78,8 @@ pub struct InstallOpts { #[arg(short = 'e', long, required = false)] pub espidf_version: Option, /// Destination of the generated export file. - #[arg(short = 'f', long, default_value = DEFAULT_EXPORT_FILE)] - pub export_file: PathBuf, + #[arg(short = 'f', long)] + pub export_file: Option, /// Comma or space list of extra crates to install. #[arg(short = 'c', long, default_value = "cargo-espflash")] pub extra_crates: String, @@ -131,12 +132,6 @@ fn install(args: InstallOpts) -> Result<()> { let host_triple = get_host_triple(args.default_host)?; let mut extra_crates: HashSet = args.extra_crates.split(',').map(Crate::new).collect(); let mut exports: Vec = Vec::new(); - let export_file = if args.export_file.is_absolute() { - args.export_file - } else { - let current_dir = std::env::current_dir()?; - current_dir.join(args.export_file) - }; let xtensa_rust = if targets.contains(&Target::ESP32) || targets.contains(&Target::ESP32S2) || targets.contains(&Target::ESP32S3) @@ -151,6 +146,17 @@ fn install(args: InstallOpts) -> Result<()> { } else { None }; + let export_file = if let Some(export_file) = args.export_file { + if export_file.is_absolute() { + export_file + } else { + let current_dir = std::env::current_dir()?; + current_dir.join(export_file) + } + } else { + let home_dir = home_dir().unwrap(); + home_dir.join(DEFAULT_EXPORT_FILE) + }; let llvm = Llvm::new(args.llvm_version, args.profile_minimal, &host_triple); debug!( From 835231336d28a22a7a87750547776a57976fc2b4 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Sat, 5 Nov 2022 11:19:46 +0000 Subject: [PATCH 08/22] =?UTF-8?q?docs:=20=F0=9F=93=9D=20Update=20install?= =?UTF-8?q?=20subcommand=20usage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9dfed20..eb2e59a 100644 --- a/README.md +++ b/README.md @@ -136,13 +136,17 @@ Options: -f, --export-file Destination of the generated export file - [default: export-esp.sh] - -c, --extra-crates Comma or space list of extra crates to install [default: cargo-espflash] + -x, --llvm-version + LLVM version + + [default: 15] + [possible values: 15] + -l, --log-level Verbosity level of the logs @@ -165,8 +169,6 @@ Options: -v, --toolchain-version Xtensa Rust toolchain version - [default: 1.64.0.0] - -h, --help Print help information (use `-h` for a summary) ``` From 8261e6f0d4f05c507cd76edf74ea2f8e41ec316f Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Sat, 5 Nov 2022 11:41:17 +0000 Subject: [PATCH 09/22] =?UTF-8?q?test:=20=F0=9F=A7=AA=20Extract=20get=5Fex?= =?UTF-8?q?port=5Ffile=20to=20a=20fn=20and=20add=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 60 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index 292ea37..ac81649 100644 --- a/src/main.rs +++ b/src/main.rs @@ -146,17 +146,7 @@ fn install(args: InstallOpts) -> Result<()> { } else { None }; - let export_file = if let Some(export_file) = args.export_file { - if export_file.is_absolute() { - export_file - } else { - let current_dir = std::env::current_dir()?; - current_dir.join(export_file) - } - } else { - let home_dir = home_dir().unwrap(); - home_dir.join(DEFAULT_EXPORT_FILE) - }; + let export_file = get_export_file(args.export_file)?; let llvm = Llvm::new(args.llvm_version, args.profile_minimal, &host_triple); debug!( @@ -366,8 +356,23 @@ fn clear_dist_folder() -> Result<()> { Ok(()) } +/// Returns the absolute path to the export file, uses the DEFAULT_EXPORT_FILE if no arg is provided. +fn get_export_file(export_file: Option) -> Result { + if let Some(export_file) = export_file { + if export_file.is_absolute() { + Ok(export_file) + } else { + let current_dir = std::env::current_dir()?; + Ok(current_dir.join(export_file)) + } + } else { + let home_dir = home_dir().unwrap(); + Ok(home_dir.join(DEFAULT_EXPORT_FILE)) + } +} + /// Creates the export file with the necessary environment variables. -pub fn export_environment(export_file: &PathBuf, exports: &[String]) -> Result<()> { +fn export_environment(export_file: &PathBuf, exports: &[String]) -> Result<()> { info!("{} Creating export file", emoji::WRENCH); let mut file = File::create(export_file)?; for e in exports.iter() { @@ -410,3 +415,34 @@ pub fn check_arguments(targets: &HashSet, espidf_version: &Option Date: Sat, 5 Nov 2022 11:54:10 +0000 Subject: [PATCH 10/22] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Allow=20unused=20va?= =?UTF-8?q?riables=20in=20test=5Fget=5Fexport=5Ffile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index ac81649..2a9243d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -420,12 +420,10 @@ pub fn check_arguments(targets: &HashSet, espidf_version: &Option Date: Sat, 5 Nov 2022 19:37:19 +0100 Subject: [PATCH 11/22] =?UTF-8?q?chore:=20=E2=9A=A1=EF=B8=8F=20Use=20clap?= =?UTF-8?q?=20value=5Fparser=20to=20parse=20targets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1d645b1..770c3aa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -95,8 +95,8 @@ pub struct InstallOpts { #[arg(short = 'm', long)] pub profile_minimal: bool, /// Comma or space separated list of targets [esp32,esp32s2,esp32s3,esp32c2,esp32c3,all]. - #[arg(short = 't', long, default_value = "all")] - pub targets: String, + #[arg(short = 't', long, default_value = "all", value_parser = parse_targets)] + pub targets: HashSet, /// Xtensa Rust toolchain version. #[arg(short = 'v', long, value_parser = XtensaRust::parse_version)] pub toolchain_version: Option, @@ -127,7 +127,7 @@ fn install(args: InstallOpts) -> Result<()> { initialize_logger(&args.log_level); info!("{} Installing esp-rs", emoji::DISC); - let targets: HashSet = parse_targets(&args.targets).unwrap(); + let targets = args.targets; let host_triple = get_host_triple(args.default_host)?; let mut extra_crates: HashSet = args.extra_crates.split(',').map(Crate::new).collect(); let mut exports: Vec = Vec::new(); From 1e46c9047bbcc213ef1ceb794db29c07b6c82282 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Sun, 6 Nov 2022 01:15:11 +0100 Subject: [PATCH 12/22] =?UTF-8?q?test:=20=F0=9F=A7=AA=20Add=20tests=20for?= =?UTF-8?q?=20get=5Fhost=5Ftriple?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/host_triple.rs | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/src/host_triple.rs b/src/host_triple.rs index 5f16ccd..d5e3cdd 100644 --- a/src/host_triple.rs +++ b/src/host_triple.rs @@ -42,3 +42,70 @@ pub fn get_host_triple(host_triple_arg: Option) -> Result { .context(format!("{} Unable to guess host triple.", emoji::ERROR,)) } } + +#[cfg(test)] +mod tests { + use crate::host_triple::{get_host_triple, HostTriple}; + + #[test] + fn test_get_host_triple() { + assert!(matches!( + get_host_triple(Some("x86_64-unknown-linux-gnu".to_string())), + Ok(HostTriple::X86_64UnknownLinuxGnu) + )); + assert!(matches!( + get_host_triple(Some("aarch64-unknown-linux-gnu".to_string())), + Ok(HostTriple::Aarch64UnknownLinuxGnu) + )); + assert!(matches!( + get_host_triple(Some("x86_64-pc-windows-msvc".to_string())), + Ok(HostTriple::X86_64PcWindowsMsvc) + )); + assert!(matches!( + get_host_triple(Some("x86_64-pc-windows-gnu".to_string())), + Ok(HostTriple::X86_64PcWindowsGnu) + )); + assert!(matches!( + get_host_triple(Some("x86_64-apple-darwin".to_string())), + Ok(HostTriple::X86_64AppleDarwin) + )); + assert!(matches!( + get_host_triple(Some("aarch64-apple-darwin".to_string())), + Ok(HostTriple::Aarch64AppleDarwin) + )); + + assert!(get_host_triple(Some("some-fake-triple".to_string())).is_err()); + + // Guessed Host Triples + #[cfg(all(target_os = "linux", target_arch = "aarch64"))] + assert!(matches!( + get_host_triple(None), + Ok(HostTriple::Aarch64UnknownLinuxGnu) + )); + #[cfg(all(target_os = "linux", target_arch = "x86_64"))] + assert!(matches!( + get_host_triple(None), + Ok(HostTriple::X86_64UnknownLinuxGnu) + )); + #[cfg(all(target_os = "windows", target_arch = "x86_64", target_env = "msvc"))] + assert!(matches!( + get_host_triple(None), + Ok(HostTriple::X86_64PcWindowsMsvc) + )); + #[cfg(all(target_os = "windows", target_arch = "x86_64", target_env = "gnu"))] + assert!(matches!( + get_host_triple(None), + Ok(HostTriple::X86_64PcWindowsGnu) + )); + #[cfg(all(target_os = "macos", target_arch = "x86_64"))] + assert!(matches!( + get_host_triple(None), + Ok(HostTriple::X86_64AppleDarwin) + )); + #[cfg(all(target_os = "macos", target_arch = "aarch64"))] + assert!(matches!( + get_host_triple(None), + Ok(HostTriple::Aarch64AppleDarwin) + )); + } +} From d95c275af9020c8fdfa2b6e36b97313186cec18f Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Mon, 7 Nov 2022 09:58:18 +0100 Subject: [PATCH 13/22] =?UTF-8?q?refactor:=20=E2=9A=A1=EF=B8=8F=20Make=20e?= =?UTF-8?q?xtra-crates=20arg=20optional?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 10 +++++++--- src/toolchain/rust.rs | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 770c3aa..0558e38 100644 --- a/src/main.rs +++ b/src/main.rs @@ -80,8 +80,8 @@ pub struct InstallOpts { #[arg(short = 'f', long, default_value = DEFAULT_EXPORT_FILE)] pub export_file: PathBuf, /// Comma or space list of extra crates to install. - #[arg(short = 'c', long, default_value = "")] - pub extra_crates: String, + #[arg(short = 'c', long, required = false, value_parser = Crate::parse_crates)] + pub extra_crates: Option>, /// LLVM version. #[arg(short = 'x', long, default_value = "15", value_parser = ["15"])] pub llvm_version: String, @@ -129,7 +129,11 @@ fn install(args: InstallOpts) -> Result<()> { info!("{} Installing esp-rs", emoji::DISC); let targets = args.targets; let host_triple = get_host_triple(args.default_host)?; - let mut extra_crates: HashSet = args.extra_crates.split(',').map(Crate::new).collect(); + let mut extra_crates = if let Some(arg_crates) = args.extra_crates { + arg_crates + } else { + HashSet::new() + }; let mut exports: Vec = Vec::new(); let export_file = args.export_file.clone(); let xtensa_rust = if targets.contains(&Target::ESP32) diff --git a/src/toolchain/rust.rs b/src/toolchain/rust.rs index 0cc9fb0..79c6004 100644 --- a/src/toolchain/rust.rs +++ b/src/toolchain/rust.rs @@ -11,7 +11,7 @@ use log::{debug, info, warn}; use regex::Regex; use reqwest::header; use serde::{Deserialize, Serialize}; -use std::fmt::Debug; +use std::{collections::HashSet, fmt::Debug}; use std::{env, fs::remove_dir_all, path::PathBuf, process::Stdio}; /// Xtensa Rust Toolchain repository @@ -226,6 +226,11 @@ impl Crate { name: name.to_string(), } } + + /// Parses the extra crates to be installed. + pub fn parse_crates(arg: &str) -> Result> { + Ok(arg.split(',').map(Crate::new).collect()) + } } /// Gets the artifact extension based on the host architecture. @@ -383,7 +388,8 @@ fn install_rust_nightly(version: &str) -> Result<()> { #[cfg(test)] mod tests { - use crate::toolchain::rust::XtensaRust; + use crate::toolchain::rust::{Crate, XtensaRust}; + use std::collections::HashSet; #[test] fn test_xtensa_rust_parse_version() { @@ -395,4 +401,33 @@ mod tests { assert!(XtensaRust::parse_version("1..1.1").is_err()); assert!(XtensaRust::parse_version("1._.*.1").is_err()); } + + #[test] + #[allow(unused_variables)] + fn test_parse_crates() { + let mut crates: HashSet = HashSet::new(); + crates.insert(Crate::new("ldproxy")); + assert!(matches!(Crate::parse_crates("ldproxy"), Ok(crates))); + let mut crates: HashSet = HashSet::new(); + crates.insert(Crate::new("ldproxy")); + crates.insert(Crate::new("espflash")); + assert!(matches!( + Crate::parse_crates("ldproxy, espflash"), + Ok(crates) + )); + let mut crates: HashSet = HashSet::new(); + crates.insert(Crate::new("cargo-generate")); + crates.insert(Crate::new("sccache")); + assert!(matches!( + Crate::parse_crates("cargo-generate sccache"), + Ok(crates) + )); + let mut crates: HashSet = HashSet::new(); + crates.insert(Crate::new("cargo-binstall")); + crates.insert(Crate::new("espmonitor")); + assert!(matches!( + Crate::parse_crates("cargo-binstall,espmonitor"), + Ok(crates) + )); + } } From b9c77cfe8c220cd0dc3ad65462a2e4aca623943a Mon Sep 17 00:00:00 2001 From: Juraj Sadel Date: Mon, 7 Nov 2022 10:23:09 +0100 Subject: [PATCH 14/22] bugfix: update error log when Xtensa toolchain is already installed --- src/toolchain/rust.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/toolchain/rust.rs b/src/toolchain/rust.rs index 0cc9fb0..b584936 100644 --- a/src/toolchain/rust.rs +++ b/src/toolchain/rust.rs @@ -79,9 +79,9 @@ impl XtensaRust { let toolchain_path = self.toolchain_destination.clone().join("esp"); if toolchain_path.exists() { bail!( - "{} Previous installation of Rust Toolchain exist in: '{}'. Please, remove the directory before new installation.", + "{} The previous installation of Rust Toolchain exists in: '{}'. Please, remove the directory before the new installation.", emoji::WARN, - self.toolchain_destination.display() + toolchain_path.display() ); } info!( From f370c567f9076789b68002dfaf93735fa301b977 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Mon, 7 Nov 2022 11:00:39 +0100 Subject: [PATCH 15/22] =?UTF-8?q?refactor:=20=E2=99=BB=EF=B8=8F=20Refactor?= =?UTF-8?q?=20extra-crates=20arg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config.rs | 2 +- src/main.rs | 47 +++++++++++++++++++++++++------------------ src/toolchain/rust.rs | 11 ++++++++++ 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/config.rs b/src/config.rs index e01306d..8d20885 100644 --- a/src/config.rs +++ b/src/config.rs @@ -16,7 +16,7 @@ pub struct Config { /// Destination of the generated export file. pub export_file: PathBuf, /// Extra crates to installed. - pub extra_crates: HashSet, + pub extra_crates: Option>, /// Host triple pub host_triple: HostTriple, /// LLVM toolchain path. diff --git a/src/main.rs b/src/main.rs index 0558e38..06d8923 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,9 @@ use espup::{ }, gcc::{get_toolchain_name, install_gcc_targets}, llvm::Llvm, - rust::{check_rust_installation, install_riscv_target, Crate, XtensaRust}, + rust::{ + check_rust_installation, install_extra_crates, install_riscv_target, Crate, XtensaRust, + }, }, }; use log::{debug, info, warn}; @@ -129,11 +131,7 @@ fn install(args: InstallOpts) -> Result<()> { info!("{} Installing esp-rs", emoji::DISC); let targets = args.targets; let host_triple = get_host_triple(args.default_host)?; - let mut extra_crates = if let Some(arg_crates) = args.extra_crates { - arg_crates - } else { - HashSet::new() - }; + let mut extra_crates = args.extra_crates; let mut exports: Vec = Vec::new(); let export_file = args.export_file.clone(); let xtensa_rust = if targets.contains(&Target::ESP32) @@ -195,18 +193,19 @@ fn install(args: InstallOpts) -> Result<()> { if let Some(espidf_version) = &args.espidf_version { let repo = EspIdfRepo::new(espidf_version, args.profile_minimal, &targets); exports.extend(repo.install()?); - extra_crates.insert(Crate::new("ldproxy")); + if let Some(ref mut extra_crates) = extra_crates { + extra_crates.insert(Crate::new("ldproxy")); + } else { + let mut crates = HashSet::new(); + crates.insert(Crate::new("ldproxy")); + extra_crates = Some(crates); + }; } else { exports.extend(install_gcc_targets(&targets, &host_triple)?); } - debug!( - "{} Installing the following crates: {:#?}", - emoji::DEBUG, - extra_crates - ); - for extra_crate in &extra_crates { - extra_crate.install()?; + if let Some(ref extra_crates) = &extra_crates { + install_extra_crates(&extra_crates)?; } if args.profile_minimal { @@ -219,10 +218,16 @@ fn install(args: InstallOpts) -> Result<()> { let config = Config { espidf_version: args.espidf_version, export_file, - extra_crates: extra_crates - .iter() - .map(|x| x.name.clone()) - .collect::>(), + extra_crates: if let Some(extra_crates) = &extra_crates { + Some( + extra_crates + .iter() + .map(|x| x.name.clone()) + .collect::>(), + ) + } else { + None + }, host_triple, llvm_path: llvm.path, nightly_version: args.nightly_version, @@ -277,8 +282,10 @@ fn uninstall(args: UninstallOpts) -> Result<()> { } info!("{} Uninstalling extra crates", emoji::WRENCH); - for extra_crate in &config.extra_crates { - cmd!("cargo", "uninstall", extra_crate).run()?; + if let Some(extra_crates) = &config.extra_crates { + for extra_crate in extra_crates { + cmd!("cargo", "uninstall", extra_crate).run()?; + } } clear_dist_folder()?; diff --git a/src/toolchain/rust.rs b/src/toolchain/rust.rs index 79c6004..b230508 100644 --- a/src/toolchain/rust.rs +++ b/src/toolchain/rust.rs @@ -233,6 +233,17 @@ impl Crate { } } +pub fn install_extra_crates(crates: &HashSet) -> Result<()> { + debug!( + "{} Installing the following crates: {:#?}", + emoji::DEBUG, + crates + ); + for c in crates { + c.install()?; + } + Ok(()) +} /// Gets the artifact extension based on the host architecture. fn get_artifact_extension(host_triple: &HostTriple) -> &str { match host_triple { From da88ca81e19450214925da27a338505a8b1e2669 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Mon, 7 Nov 2022 11:28:47 +0100 Subject: [PATCH 16/22] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Fix=20clippy=20warn?= =?UTF-8?q?ings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 06d8923..d952e03 100644 --- a/src/main.rs +++ b/src/main.rs @@ -205,7 +205,7 @@ fn install(args: InstallOpts) -> Result<()> { } if let Some(ref extra_crates) = &extra_crates { - install_extra_crates(&extra_crates)?; + install_extra_crates(extra_crates)?; } if args.profile_minimal { @@ -218,16 +218,12 @@ fn install(args: InstallOpts) -> Result<()> { let config = Config { espidf_version: args.espidf_version, export_file, - extra_crates: if let Some(extra_crates) = &extra_crates { - Some( - extra_crates - .iter() - .map(|x| x.name.clone()) - .collect::>(), - ) - } else { - None - }, + extra_crates: extra_crates.as_ref().map(|extra_crates| { + extra_crates + .iter() + .map(|x| x.name.clone()) + .collect::>() + }), host_triple, llvm_path: llvm.path, nightly_version: args.nightly_version, From 829c3858e7cbe54f2076c86cbe9f9ba66673fc26 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Mon, 7 Nov 2022 13:33:42 +0100 Subject: [PATCH 17/22] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Use=20Box=20for=20I?= =?UTF-8?q?nstallOpts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index d952e03..36f6550 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,7 +51,7 @@ struct Cli { #[derive(Parser)] pub enum SubCommand { /// Installs esp-rs environment - Install(InstallOpts), + Install(Box), /// Uninstalls esp-rs environment Uninstall(UninstallOpts), /// Updates Xtensa Rust toolchain @@ -346,7 +346,7 @@ fn update(args: UpdateOpts) -> Result<()> { fn main() -> Result<()> { match Cli::parse().subcommand { - SubCommand::Install(args) => install(args), + SubCommand::Install(args) => install(*args), SubCommand::Update(args) => update(args), SubCommand::Uninstall(args) => uninstall(args), } From bb62b15e2c943851d514f7bb568a7424e33bedfa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Nov 2022 21:26:07 +0000 Subject: [PATCH 18/22] build(deps): bump regex from 1.6.0 to 1.7.0 Bumps [regex](https://github.com/rust-lang/regex) from 1.6.0 to 1.7.0. - [Release notes](https://github.com/rust-lang/regex/releases) - [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/regex/compare/1.6.0...1.7.0) --- updated-dependencies: - dependency-name: regex dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3dd2559..dfe3561 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1118,9 +1118,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" +checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" dependencies = [ "aho-corasick", "memchr", diff --git a/Cargo.toml b/Cargo.toml index 4230897..c8dbf23 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ toml = "0.5.9" directories-next = "2.0.0" serde = { version = "1.0.146", features = ["derive"] } miette = "5.4.1" -regex = "1.6.0" +regex = "1.7.0" serde_json = "1.0.87" [target.aarch64-unknown-linux-gnu.dependencies] From cef4fbeb071370941a187fa348089ca00273eee5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Nov 2022 21:26:14 +0000 Subject: [PATCH 19/22] build(deps): bump clap from 4.0.19 to 4.0.22 Bumps [clap](https://github.com/clap-rs/clap) from 4.0.19 to 4.0.22. - [Release notes](https://github.com/clap-rs/clap/releases) - [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md) - [Commits](https://github.com/clap-rs/clap/compare/v4.0.19...v4.0.22) --- updated-dependencies: - dependency-name: clap dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3dd2559..58a37ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -144,9 +144,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.0.19" +version = "4.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e67816e006b17427c9b4386915109b494fec2d929c63e3bd3561234cbf1bf1e" +checksum = "91b9970d7505127a162fdaa9b96428d28a479ba78c9ec7550a63a5d9863db682" dependencies = [ "atty", "bitflags", @@ -159,9 +159,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.0.18" +version = "4.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16a1b0f6422af32d5da0c58e2703320f379216ee70198241c84173a8c5ac28f3" +checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014" dependencies = [ "heck", "proc-macro-error", diff --git a/Cargo.toml b/Cargo.toml index 4230897..ce21b6d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ rust-version = "1.62" [dependencies] anyhow = "1.0.66" -clap = { version = "4.0.18", features = ["derive"] } +clap = { version = "4.0.22", features = ["derive"] } dirs = "4.0.0" flate2 = "1.0.22" guess_host_triple = "0.1.3" From 81f0642db2165f2c603bcba7bdc5f23f547d05c1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Nov 2022 21:26:20 +0000 Subject: [PATCH 20/22] build(deps): bump env_logger from 0.9.1 to 0.9.3 Bumps [env_logger](https://github.com/env-logger-rs/env_logger) from 0.9.1 to 0.9.3. - [Release notes](https://github.com/env-logger-rs/env_logger/releases) - [Changelog](https://github.com/env-logger-rs/env_logger/blob/main/CHANGELOG.md) - [Commits](https://github.com/env-logger-rs/env_logger/compare/v0.9.1...v0.9.3) --- updated-dependencies: - dependency-name: env_logger dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3dd2559..1d4ac03 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -382,9 +382,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.9.1" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c90bf5f19754d10198ccb95b70664fc925bd1fc090a0fd9a6ebc54acc8cd6272" +checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" dependencies = [ "atty", "humantime", diff --git a/Cargo.toml b/Cargo.toml index 4230897..1e44309 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ xz2 = "0.1.6" console = "0.15.1" tempfile = "3.3.0" log = "0.4.17" -env_logger = "0.9.0" +env_logger = "0.9.3" embuild = { version = "0.30.4", features = ["espidf", "git"] } strum = { version = "0.24", features = ["derive"] } strum_macros = "0.24.3" From 7c499f6434467182f87f20b7da24eb7f0190a0b6 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Tue, 8 Nov 2022 09:01:39 +0000 Subject: [PATCH 21/22] =?UTF-8?q?docs:=20=F0=9F=90=9B=20Remove=20duplicate?= =?UTF-8?q?d=20argument?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/README.md b/README.md index 9e00c9e..f60725f 100644 --- a/README.md +++ b/README.md @@ -179,12 +179,6 @@ Options: [default: 15] [possible values: 15] - -x, --llvm-version - LLVM version - - [default: 15] - [possible values: 15] - -l, --log-level Verbosity level of the logs From 3f8ced82d9d8e9bc99cf9f8a773a79c68cd2f4ab Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Tue, 8 Nov 2022 09:13:27 +0000 Subject: [PATCH 22/22] =?UTF-8?q?refactor:=20=F0=9F=8E=A8=20Rename=20esp-i?= =?UTF-8?q?df-version=20argument?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- src/config.rs | 2 +- src/main.rs | 22 +++++++++++----------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f60725f..2b7ad50 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ See [Usage](#usage) section for more details. - [`std`](https://esp-rs.github.io/book/overview/using-the-standard-library.html): Installing `esp-idf` via `espup` is not mandatory, as [`esp-idf-sys`](https://github.com/esp-rs/esp-idf-sys) already takes care of it, but has some benefits. ```sh - espup install --espidf-version + espup install --esp-idf-version # Unix . ./export-esp.sh # Windows @@ -150,7 +150,7 @@ Options: -d, --default-host Target triple of the host - -e, --espidf-version + -e, --esp-idf-version ESP-IDF version to install. If empty, no esp-idf is installed. Version format: - `commit:`: Uses the commit `` of the `esp-idf` repository. diff --git a/src/config.rs b/src/config.rs index 8d20885..2306e60 100644 --- a/src/config.rs +++ b/src/config.rs @@ -12,7 +12,7 @@ use std::{ #[derive(Debug, Deserialize, Serialize, Default, Clone)] pub struct Config { /// ESP-IDF version - pub espidf_version: Option, + pub esp_idf_version: Option, /// Destination of the generated export file. pub export_file: PathBuf, /// Extra crates to installed. diff --git a/src/main.rs b/src/main.rs index a42dc9b..15e62c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,7 +78,7 @@ pub struct InstallOpts { /// /// When using this option, `ldproxy` crate will also be installed. #[arg(short = 'e', long, required = false)] - pub espidf_version: Option, + pub esp_idf_version: Option, /// Destination of the generated export file. #[arg(short = 'f', long)] pub export_file: Option, @@ -166,7 +166,7 @@ fn install(args: InstallOpts) -> Result<()> { emoji::INFO, host_triple, targets, - &args.espidf_version, + &args.esp_idf_version, &export_file, &extra_crates, llvm, @@ -177,7 +177,7 @@ fn install(args: InstallOpts) -> Result<()> { ); #[cfg(windows)] - check_arguments(&targets, &args.espidf_version)?; + check_arguments(&targets, &args.esp_idf_version)?; check_rust_installation(&args.nightly_version)?; @@ -191,8 +191,8 @@ fn install(args: InstallOpts) -> Result<()> { install_riscv_target(&args.nightly_version)?; } - if let Some(espidf_version) = &args.espidf_version { - let repo = EspIdfRepo::new(espidf_version, args.profile_minimal, &targets); + if let Some(esp_idf_version) = &args.esp_idf_version { + let repo = EspIdfRepo::new(esp_idf_version, args.profile_minimal, &targets); exports.extend(repo.install()?); if let Some(ref mut extra_crates) = extra_crates { extra_crates.insert(Crate::new("ldproxy")); @@ -217,7 +217,7 @@ fn install(args: InstallOpts) -> Result<()> { info!("{} Saving configuration file", emoji::WRENCH); let config = Config { - espidf_version: args.espidf_version, + esp_idf_version: args.esp_idf_version, export_file, extra_crates: extra_crates.as_ref().map(|extra_crates| { extra_crates @@ -263,10 +263,10 @@ fn uninstall(args: UninstallOpts) -> Result<()> { info!("{} Deleting Xtensa LLVM", emoji::WRENCH); remove_dir_all(config.llvm_path)?; - if let Some(espidf_version) = config.espidf_version { - info!("{} Deleting ESP-IDF {}", emoji::WRENCH, espidf_version); + if let Some(esp_idf_version) = config.esp_idf_version { + info!("{} Deleting ESP-IDF {}", emoji::WRENCH, esp_idf_version); let repo = EspIdfRemote { - git_ref: parse_esp_idf_git_ref(&espidf_version), + git_ref: parse_esp_idf_git_ref(&esp_idf_version), repo_url: Some(DEFAULT_GIT_REPOSITORY.to_string()), }; remove_dir_all(get_install_path(repo).parent().unwrap())?; @@ -407,8 +407,8 @@ fn export_environment(export_file: &PathBuf, exports: &[String]) -> Result<()> { #[cfg(windows)] /// For Windows, we need to check that we are installing all the targets if we are installing esp-idf. -pub fn check_arguments(targets: &HashSet, espidf_version: &Option) -> Result<()> { - if espidf_version.is_some() +pub fn check_arguments(targets: &HashSet, esp_idf_version: &Option) -> Result<()> { + if esp_idf_version.is_some() && (!targets.contains(&Target::ESP32) || !targets.contains(&Target::ESP32C3) || !targets.contains(&Target::ESP32S2)