feat: support update PlatformIO Core (#759)

This commit is contained in:
SteveLauC
2024-04-07 11:03:33 +08:00
committed by GitHub
parent ab21600ca6
commit d90ce30452
3 changed files with 24 additions and 0 deletions

View File

@@ -121,6 +121,7 @@ pub enum Step {
Pipx,
Pkg,
Pkgin,
PlatformioCore,
Pnpm,
Powershell,
Protonup,

View File

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

View File

@@ -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()
}