From d90ce30452ccd80c55f90305fc3608090f259a9c Mon Sep 17 00:00:00 2001 From: SteveLauC Date: Sun, 7 Apr 2024 11:03:33 +0800 Subject: [PATCH] feat: support update PlatformIO Core (#759) --- src/config.rs | 1 + src/main.rs | 3 +++ src/steps/generic.rs | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/src/config.rs b/src/config.rs index ac6a0886..6ce001be 100644 --- a/src/config.rs +++ b/src/config.rs @@ -121,6 +121,7 @@ pub enum Step { Pipx, Pkg, Pkgin, + PlatformioCore, Pnpm, Powershell, Protonup, diff --git a/src/main.rs b/src/main.rs index b421ffc2..bbee9980 100644 --- a/src/main.rs +++ b/src/main.rs @@ -407,6 +407,9 @@ fn run() -> Result<()> { runner.execute(Step::Certbot, "Certbot", || generic::run_certbot(&ctx))?; runner.execute(Step::GitRepos, "Git Repositories", || git::run_git_pull(&ctx))?; runner.execute(Step::ClamAvDb, "ClamAV Databases", || generic::run_freshclam(&ctx))?; + runner.execute(Step::PlatformioCore, "PlatformIO Core", || { + generic::run_platform_io(&ctx) + })?; if should_run_powershell { runner.execute(Step::Powershell, "Powershell Modules Update", || { diff --git a/src/steps/generic.rs b/src/steps/generic.rs index d7b44e59..7ed37519 100644 --- a/src/steps/generic.rs +++ b/src/steps/generic.rs @@ -940,3 +940,23 @@ pub fn run_freshclam(ctx: &ExecutionContext) -> Result<()> { print_separator("Update ClamAV Database(FreshClam)"); ctx.run_type().execute(freshclam).status_checked() } + +/// Involve `pio upgrade` to update PlatformIO core. +pub fn run_platform_io(ctx: &ExecutionContext) -> Result<()> { + // We use the full path because by default the binary is not in `PATH`: + // https://github.com/topgrade-rs/topgrade/issues/754#issuecomment-2020537559 + #[cfg(unix)] + fn bin_path() -> PathBuf { + HOME_DIR.join(".platformio/penv/bin/pio") + } + #[cfg(windows)] + fn bin_path() -> PathBuf { + HOME_DIR.join(".platformio/penv/Scripts/pio.exe") + } + + let bin_path = require(bin_path())?; + + print_separator("PlatformIO Core"); + + ctx.run_type().execute(bin_path).arg("upgrade").status_checked() +}