diff --git a/src/toolbox/setup/homebrew.ts b/src/toolbox/setup/homebrew.ts index eefddf4..72ee5bb 100644 --- a/src/toolbox/setup/homebrew.ts +++ b/src/toolbox/setup/homebrew.ts @@ -42,3 +42,16 @@ export async function ensureHomebrew(): Promise { 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 = { + stdout: null | string; + status: number; + error: null | Error; +} + +export async function formulaeExists(formulae: string): Promise { + if (system.which('brew') === null) return false + + const result: SpawnResult = await system.spawn(`brew list ${formulae}`, { shell: process.env.SHELL }) + return result.status === 0; +} diff --git a/src/toolbox/setup/pico/mac.ts b/src/toolbox/setup/pico/mac.ts index 9514969..5855d9b 100644 --- a/src/toolbox/setup/pico/mac.ts +++ b/src/toolbox/setup/pico/mac.ts @@ -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 @@ -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')