Skip to content

Commit

Permalink
fix(setup/pico): verify source of arm-gcc before removing
Browse files Browse the repository at this point in the history
  • Loading branch information
HipsterBrown committed Mar 23, 2024
1 parent 217acf1 commit 24002bc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/toolbox/setup/homebrew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,16 @@ export async function ensureHomebrew(): Promise<void> {
throw new Error(`Visit https://brew.sh/ to learn more about installing Homebrew. If you don't want to use Homebrew, please install the following packages manually before trying this command again: `)
}
}

type SpawnResult = {

Check failure on line 46 in src/toolbox/setup/homebrew.ts

View workflow job for this annotation

GitHub Actions / lint

Use an `interface` instead of a `type`
stdout: null | string;
status: number;
error: null | Error;
}

export async function formulaeExists(formulae: string): Promise<boolean> {
if (system.which('brew') === null) return false

const result: SpawnResult = await system.spawn(`brew list ${formulae}`, { shell: process.env.SHELL })
return result.status === 0;
}
4 changes: 2 additions & 2 deletions src/toolbox/setup/pico/mac.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GluegunPrint, print, system } from 'gluegun'
import { ensureHomebrew } from '../homebrew';
import { ensureHomebrew, formulaeExists } from '../homebrew';

export async function installDeps(
spinner: ReturnType<GluegunPrint['spin']>
Expand All @@ -13,7 +13,7 @@ export async function installDeps(
}
}

if (system.which('arm-none-eabi-gcc') !== null) {
if (system.which('arm-none-eabi-gcc') !== null && (await formulaeExists('arm-none-eabi-gcc'))) {
spinner.start('Removing outdated arm gcc dependency')
await system.exec('brew untap ArmMbed/homebrew-formulae')
await system.exec('brew uninstall arm-none-eabi-gcc')
Expand Down

0 comments on commit 24002bc

Please sign in to comment.