findCommand('brew')) === null) { return CheckResult::fail('Homebrew is not installed', 'brew'); } if ($path !== '/opt/homebrew/bin/brew' && getenv('GNU_ARCH') === 'aarch64') { return CheckResult::fail('Current homebrew (/usr/local/bin/homebrew) is not installed for M1 Mac, please re-install homebrew in /opt/homebrew/ !'); } return CheckResult::ok(); } #[AsCheckItem('if necessary tools are installed', limit_os: 'Darwin')] public function checkCliTools(): ?CheckResult { $missing = []; foreach (self::REQUIRED_COMMANDS as $cmd) { if ($this->findCommand($cmd) === null) { $missing[] = $cmd; } } if (!empty($missing)) { return CheckResult::fail('missing system commands: ' . implode(', ', $missing), 'build-tools', [$missing]); } return CheckResult::ok(); } #[AsFixItem('brew')] public function fixBrew(): bool { try { shell(true)->exec('/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"'); } catch (RuntimeException) { return false; } return true; } #[AsFixItem('build-tools')] public function fixBuildTools(array $missing): bool { $replacement = [ 'glibtoolize' => 'libtool', ]; foreach ($missing as $cmd) { try { if (isset($replacement[$cmd])) { $cmd = $replacement[$cmd]; } shell(true)->exec('brew install --formula ' . escapeshellarg($cmd)); } catch (RuntimeException) { return false; } } return true; } }