add postgresql and custom downloader

This commit is contained in:
crazywhalecc 2023-04-09 12:11:14 +08:00
parent 9970986a52
commit 76e95b8c55
No known key found for this signature in database
GPG Key ID: 1F4BDD59391F2680
8 changed files with 122 additions and 5 deletions

View File

@ -66,6 +66,12 @@
"SystemConfiguration" "SystemConfiguration"
] ]
}, },
"postgresql": {
"source": "postgresql",
"static-libs-unix": [
"libpg.a"
]
},
"freetype": { "freetype": {
"source": "freetype", "source": "freetype",
"static-libs-unix": [ "static-libs-unix": [

View File

@ -44,6 +44,13 @@
"path": "LICENSE.TXT" "path": "LICENSE.TXT"
} }
}, },
"postgresql": {
"type": "custom",
"license": {
"type": "file",
"path": "COPYRIGHT"
}
},
"gmp": { "gmp": {
"type": "filelist", "type": "filelist",
"url": "https://gmplib.org/download/gmp/", "url": "https://gmplib.org/download/gmp/",
@ -224,6 +231,13 @@
"path": "LICENSE" "path": "LICENSE"
} }
}, },
"php-src": {
"type": "custom",
"license": {
"type": "file",
"path": "LICENSE"
}
},
"redis": { "redis": {
"type": "git", "type": "git",
"path": "php-src/ext/redis", "path": "php-src/ext/redis",

View File

@ -55,6 +55,7 @@ class FetchSourceCommand extends BaseCommand
try { try {
// 匹配版本 // 匹配版本
$ver = $this->php_major_ver = $input->getOption('with-php') ?? '8.1'; $ver = $this->php_major_ver = $input->getOption('with-php') ?? '8.1';
define('SPC_BUILD_PHP_VERSION', $ver);
preg_match('/^\d+\.\d+$/', $ver, $matches); preg_match('/^\d+\.\d+$/', $ver, $matches);
if (!$matches) { if (!$matches) {
logger()->error("bad version arg: {$ver}, x.y required!"); logger()->error("bad version arg: {$ver}, x.y required!");
@ -142,9 +143,7 @@ class FetchSourceCommand extends BaseCommand
f_mkdir(DOWNLOAD_PATH); f_mkdir(DOWNLOAD_PATH);
// 下载 PHP // 下载 PHP
logger()->info('Fetching PHP source'); array_unshift($chosen_sources, 'php-src');
Downloader::fetchSource('php-src', Downloader::getLatestPHPInfo($ver));
// 下载别的依赖资源 // 下载别的依赖资源
$cnt = count($chosen_sources); $cnt = count($chosen_sources);
$ni = 0; $ni = 0;

View File

@ -8,6 +8,7 @@ use JetBrains\PhpStorm\ArrayShape;
use SPC\exception\DownloaderException; use SPC\exception\DownloaderException;
use SPC\exception\FileSystemException; use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException; use SPC\exception\RuntimeException;
use SPC\store\source\CustomSourceBase;
/** /**
* 资源下载器 * 资源下载器
@ -144,7 +145,7 @@ class Downloader
} }
uksort($versions, 'version_compare'); uksort($versions, 'version_compare');
return [$source['url'] . end($versions), end($versions)]; return [$source['url'] . end($versions), end($versions), key($versions)];
} }
/** /**
@ -267,6 +268,14 @@ class Downloader
case 'git': // 通过拉回 Git 仓库的形式拉取 case 'git': // 通过拉回 Git 仓库的形式拉取
self::downloadGit($name, $source['url'], $source['rev'], $source['path'] ?? null); self::downloadGit($name, $source['url'], $source['rev'], $source['path'] ?? null);
break; break;
case 'custom':
$classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/source', 'SPC\\store\\source');
foreach ($classes as $class) {
if (is_a($class, CustomSourceBase::class, true) && $class::NAME === $name) {
(new $class())->fetch();
}
}
break;
default: default:
throw new DownloaderException('unknown source type: ' . $source['type']); throw new DownloaderException('unknown source type: ' . $source['type']);
} }

View File

@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace SPC\store\source;
abstract class CustomSourceBase
{
public const NAME = 'unknown';
abstract public function fetch();
}

View File

@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace SPC\store\source;
use JetBrains\PhpStorm\ArrayShape;
use SPC\exception\DownloaderException;
use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException;
use SPC\store\Downloader;
class PhpSource extends CustomSourceBase
{
public const NAME = 'php-src';
/**
* @throws DownloaderException
* @throws FileSystemException
* @throws RuntimeException
*/
public function fetch()
{
$major = defined('SPC_BUILD_PHP_VERSION') ? SPC_BUILD_PHP_VERSION : '8.1';
Downloader::fetchSource('php-src', self::getLatestPHPInfo($major));
}
/**
* 获取 PHP x.y 的具体版本号,例如通过 8.1 来获取 8.1.10
*
* @throws DownloaderException
*/
#[ArrayShape(['type' => 'string', 'path' => 'string', 'rev' => 'string', 'url' => 'string'])]
public function getLatestPHPInfo(string $major_version): array
{
// 查找最新的小版本号
$info = json_decode(Downloader::curlExec(url: "https://www.php.net/releases/index.php?json&version={$major_version}"), true);
$version = $info['version'];
// 从官网直接下载
return [
'type' => 'url',
'url' => "https://www.php.net/distributions/php-{$version}.tar.gz",
// 'url' => "https://mirrors.zhamao.xin/php/php-{$version}.tar.gz",
];
}
}

View File

@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace SPC\store\source;
use SPC\store\Downloader;
class PostgreSQLSource extends CustomSourceBase
{
public const NAME = 'postgresql';
public function fetch()
{
Downloader::fetchSource('postgresql', self::getLatestInfo());
}
public function getLatestInfo(): array
{
[$url, $filename, $version] = Downloader::getFromFileList('postgresql', [
'url' => 'https://www.postgresql.org/ftp/source/',
'regex' => '/href="(?<file>v(?<version>[^"]+)\/)"/',
]);
return [
'type' => 'url',
'url' => "https://ftp.postgresql.org/pub/source/{$filename}postgresql-{$version}.tar.gz",
];
}
}

View File

@ -3,6 +3,7 @@
declare(strict_types=1); declare(strict_types=1);
$info = gd_info(); $info = gd_info();
$true = $info['JPEG Support'] ?? false; // jpeg will be supported later
$true = true; // $info['JPEG Support'] ?? false;
$true = $true ? ($info['PNG Support'] ?? false) : false; $true = $true ? ($info['PNG Support'] ?? false) : false;
exit($true ? 0 : 1); exit($true ? 0 : 1);