Add re2c build for spc-gnu-docker

This commit is contained in:
crazywhalecc
2025-07-31 01:44:44 +08:00
parent 3c972ac905
commit 601444d0a5
4 changed files with 68 additions and 7 deletions

View File

@@ -4,7 +4,7 @@ declare(strict_types=1);
namespace SPC\doctor;
#[\Attribute(\Attribute::TARGET_METHOD)]
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class AsCheckItem
{
public mixed $callback = null;

View File

@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace SPC\doctor\item;
use SPC\builder\BuilderProvider;
use SPC\builder\traits\UnixSystemUtilTrait;
use SPC\doctor\AsCheckItem;
use SPC\doctor\AsFixItem;
use SPC\doctor\CheckResult;
use SPC\store\Downloader;
use Symfony\Component\Console\Input\ArgvInput;
class Re2cVersionCheck
{
use UnixSystemUtilTrait;
#[AsCheckItem('if re2c version >= 1.0.3', limit_os: 'Linux', level: 20)]
#[AsCheckItem('if re2c version >= 1.0.3', limit_os: 'Darwin', level: 20)]
public function checkRe2cVersion(): ?CheckResult
{
$ver = shell()->execWithResult('re2c --version', false);
// match version: re2c X.X(.X)
if ($ver[0] !== 0 || !preg_match('/re2c\s+(\d+\.\d+(\.\d+)?)/', $ver[1][0], $matches)) {
return CheckResult::fail('Failed to get re2c version', 'build-re2c');
}
$version_string = $matches[1];
if (version_compare($version_string, '1.0.3') < 0) {
return CheckResult::fail('re2c version is too low (' . $version_string . ')', 'build-re2c');
}
return CheckResult::ok($version_string);
}
#[AsFixItem('build-re2c')]
public function buildRe2c(): bool
{
Downloader::downloadSource('re2c');
$builder = BuilderProvider::makeBuilderByInput(new ArgvInput([]));
$builder->proveLibs(['re2c']);
$builder->setupLibs();
return true;
}
}