Combine the macos tool checks into a single checkBrewOrPorts method

This commit is contained in:
Kevin Boyd
2026-06-04 21:40:01 -07:00
parent 6057394641
commit 0761267eb3

View File

@@ -33,24 +33,20 @@ class MacOSToolCheck
'glibtoolize',
];
#[CheckItem('if homebrew has installed', limit_os: 'Darwin', level: 998)]
public function checkBrew(): ?CheckResult
#[CheckItem('if homebrew or macports has installed', limit_os: 'Darwin', level: 998)]
public function checkBrewOrPorts(): ?CheckResult
{
if (($path = MacOSUtil::findCommand('brew')) === null) {
return CheckResult::fail('Homebrew is not installed', 'brew');
}
if ($path !== '/opt/homebrew/bin/brew' && getenv('GNU_ARCH') === 'aarch64') {
$brewPath = MacOSUtil::findCommand('brew');
$portPath = MacOSUtil::findCommand('port');
if ($brewPath && $brewPath !== '/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();
}
#[CheckItem('if macports has installed', limit_os: 'Darwin', level: 998)]
public function checkPorts(): ?CheckResult
{
if (MacOSUtil::findCommand('port') === null) {
return CheckResult::fail('MacPorts is not installed', 'port');
if ($brewPath === null && $portPath === null) {
return CheckResult::fail('Homebrew is not installed', 'brew');
}
return CheckResult::ok();
}
@@ -69,8 +65,8 @@ class MacOSToolCheck
return CheckResult::ok();
}
#[CheckItem('if homebrew llvm are installed', limit_os: 'Darwin')]
public function checkBrewLLVM(): ?CheckResult
#[CheckItem('if homebrew or macports llvm are installed', limit_os: 'Darwin')]
public function checkBrewOrPortsLLVM(): ?CheckResult
{
if (getenv('SPC_USE_LLVM') === 'brew') {
$homebrew_prefix = getenv('HOMEBREW_PREFIX') ?: (SystemTarget::getTargetArch() === 'aarch64' ? '/opt/homebrew' : '/usr/local/homebrew');
@@ -80,20 +76,16 @@ class MacOSToolCheck
}
return CheckResult::ok($path);
}
return null;
}
#[CheckItem('if macports llvm are installed', limit_os: 'Darwin')]
public function checkPortsLLVM(): ?CheckResult
{
if (getenv('SPC_USE_LLVM') === 'port') {
$macports_prefix = getenv('MACPORTS_PREFIX') ?: '/opt/local';
$macportsPrefix = '/opt/local';
if (($path = MacOSUtil::findCommand('clang', ["{$macports_prefix}/bin"])) === null) {
if (($path = MacOSUtil::findCommand('clang', ["{$macportsPrefix}/bin"])) === null) {
return CheckResult::fail('MacPorts llvm is not installed', 'build-tools', ['missing' => ['llvm']]);
}
return CheckResult::ok($path);
}
return null;
}
@@ -124,11 +116,6 @@ class MacOSToolCheck
#[FixItem('brew')]
public function fixBrew(): bool
{
$hasMacports = $this->checkPorts();
if ($hasMacports->isOK()) {
return true; // Nothing to fix - will use macports instead
}
shell(true)->exec('/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"');
return true;
}
@@ -136,8 +123,8 @@ class MacOSToolCheck
#[FixItem('build-tools')]
public function fixBuildTools(array $missing): bool
{
$hasBrew = $this->checkBrew()?->isOK();
$hasMacports = $this->checkPorts()?->isOK();
$brewPath = MacOSUtil::findCommand('brew');
$portPath = MacOSUtil::findCommand('port');
$replacement = [
'glibtoolize' => 'libtool',
@@ -147,12 +134,12 @@ class MacOSToolCheck
$cmd = $replacement[$cmd];
}
if ($hasBrew) {
if ($brewPath !== null) {
shell()->exec('brew install --formula ' . escapeshellarg($cmd));
continue;
}
if ($hasMacports) {
if ($portPath !== null) {
shell()->exec('port install ' . escapeshellarg($cmd));
continue;
}