Add check for Bison version in MacOS tool checklist, trigger extension test

This commit is contained in:
crazywhalecc 2025-07-28 16:47:04 +08:00
parent b9bec5b526
commit 4efb3dfc9a
No known key found for this signature in database
GPG Key ID: 1F4BDD59391F2680

View File

@ -62,6 +62,30 @@ class MacOSToolCheckList
return CheckResult::ok();
}
#[AsCheckItem('if bison version is 3.0 or later', limit_os: 'Darwin')]
public function checkBisonVersion(array $command_path = []): ?CheckResult
{
// if the bison command is /usr/bin/bison, it is the system bison that may be too old
if (($bison = $this->findCommand('bison', $command_path)) === null) {
return CheckResult::fail('bison is not installed or too old', 'build-tools', [['bison']]);
}
// check version: bison (GNU Bison) x.y(.z)
$version = shell()->execWithResult("{$bison} --version", false);
if (preg_match('/bison \(GNU Bison\) (\d+)\.(\d+)(?:\.(\d+))?/', $version[1][0], $matches)) {
$major = (int) $matches[1];
// major should be 3 or later
if ($major < 3) {
// find homebrew keg-only bison
if ($command_path !== []) {
return CheckResult::fail("Current {$bison} version is too old: " . $matches[0]);
}
return $this->checkBisonVersion(['/opt/homebrew/opt/bison/bin', '/usr/local/homebrew/opt/bison/bin']);
}
return CheckResult::ok($matches[0]);
}
return CheckResult::fail('bison version cannot be determined');
}
#[AsFixItem('brew')]
public function fixBrew(): bool
{