mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-07 16:55:38 +08:00
Refactor all (except command) modules using new exceptions
This commit is contained in:
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\windows;
|
||||
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\store\FileSystem;
|
||||
|
||||
class SystemUtil
|
||||
|
||||
@@ -5,8 +5,8 @@ declare(strict_types=1);
|
||||
namespace SPC\builder\windows;
|
||||
|
||||
use SPC\builder\BuilderBase;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\SPCInternalException;
|
||||
use SPC\exception\ValidationException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\store\Config;
|
||||
use SPC\store\FileSystem;
|
||||
@@ -267,7 +267,7 @@ class WindowsBuilder extends BuilderBase
|
||||
logger()->info('running cli sanity check');
|
||||
[$ret, $output] = cmd()->execWithResult(BUILD_ROOT_PATH . '\bin\php.exe -n -r "echo \"hello\";"');
|
||||
if ($ret !== 0 || trim(implode('', $output)) !== 'hello') {
|
||||
throw new RuntimeException('cli failed sanity check');
|
||||
throw new ValidationException('cli failed sanity check', validation_module: 'php-cli function check');
|
||||
}
|
||||
|
||||
foreach ($this->getExts(false) as $ext) {
|
||||
@@ -290,7 +290,10 @@ class WindowsBuilder extends BuilderBase
|
||||
foreach ($task['conditions'] as $condition => $closure) {
|
||||
if (!$closure($ret, $out)) {
|
||||
$raw_out = trim(implode('', $out));
|
||||
throw new RuntimeException("micro failed sanity check: {$task_name}, condition [{$condition}], ret[{$ret}], out[{$raw_out}]");
|
||||
throw new ValidationException(
|
||||
"failure info: {$condition}, code: {$ret}, output: {$raw_out}",
|
||||
validation_module: "phpmicro sanity check item [{$task_name}]"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -308,7 +311,7 @@ class WindowsBuilder extends BuilderBase
|
||||
$src = match ($type) {
|
||||
BUILD_TARGET_CLI => SOURCE_PATH . "\\php-src\\x64\\Release{$ts}\\php.exe",
|
||||
BUILD_TARGET_MICRO => SOURCE_PATH . "\\php-src\\x64\\Release{$ts}\\micro.sfx",
|
||||
default => throw new RuntimeException('Deployment does not accept type ' . $type),
|
||||
default => throw new SPCInternalException("Deployment does not accept type {$type}"),
|
||||
};
|
||||
|
||||
// with-upx-pack for cli and micro
|
||||
|
||||
@@ -5,24 +5,35 @@ declare(strict_types=1);
|
||||
namespace SPC\builder\windows\library;
|
||||
|
||||
use SPC\builder\windows\SystemUtil;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\BuildFailureException;
|
||||
use SPC\exception\EnvironmentException;
|
||||
use SPC\store\FileSystem;
|
||||
|
||||
class libsodium extends WindowsLibraryBase
|
||||
{
|
||||
public const NAME = 'libsodium';
|
||||
|
||||
protected function build()
|
||||
private string $vs_ver_dir;
|
||||
|
||||
public function validate(): void
|
||||
{
|
||||
FileSystem::replaceFileStr($this->source_dir . '\src\libsodium\include\sodium\export.h', '#ifdef SODIUM_STATIC', '#if 1');
|
||||
$vs_ver_dir = match (SystemUtil::findVisualStudio()['version']) {
|
||||
$this->vs_ver_dir = match ($ver = SystemUtil::findVisualStudio()['version']) {
|
||||
'vs17' => '\vs2022',
|
||||
'vs16' => '\vs2019',
|
||||
default => throw new RuntimeException('Current VS version is not supported yet!'),
|
||||
default => throw new EnvironmentException("Current VS version {$ver} is not supported yet!"),
|
||||
};
|
||||
}
|
||||
|
||||
public function patchBeforeBuild(): bool
|
||||
{
|
||||
FileSystem::replaceFileStr($this->source_dir . '\src\libsodium\include\sodium\export.h', '#ifdef SODIUM_STATIC', '#if 1');
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function build(): void
|
||||
{
|
||||
// start build
|
||||
cmd()->cd($this->source_dir . '\builds\msvc\\' . $vs_ver_dir)
|
||||
cmd()->cd($this->source_dir . '\builds\msvc' . $this->vs_ver_dir)
|
||||
->execWithWrapper(
|
||||
$this->builder->makeSimpleWrapper('msbuild'),
|
||||
'libsodium.sln /t:Rebuild /p:Configuration=StaticRelease /p:Platform=x64 /p:PreprocessorDefinitions="SODIUM_STATIC=1"'
|
||||
@@ -46,7 +57,7 @@ class libsodium extends WindowsLibraryBase
|
||||
}
|
||||
}
|
||||
if (!$find) {
|
||||
throw new RuntimeException('libsodium.lib not found');
|
||||
throw new BuildFailureException("Build libsodium success, but cannot find libsodium.lib in {$this->source_dir}\\bin .");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,23 +5,33 @@ declare(strict_types=1);
|
||||
namespace SPC\builder\windows\library;
|
||||
|
||||
use SPC\builder\windows\SystemUtil;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\EnvironmentException;
|
||||
use SPC\store\FileSystem;
|
||||
|
||||
class openssl extends WindowsLibraryBase
|
||||
{
|
||||
public const NAME = 'openssl';
|
||||
|
||||
private ?string $perl;
|
||||
|
||||
public function validate(): void
|
||||
{
|
||||
global $argv;
|
||||
$perl_path_native = PKG_ROOT_PATH . '\strawberry-perl-' . arch2gnu(php_uname('m')) . '-win\perl\bin\perl.exe';
|
||||
$this->perl = file_exists($perl_path_native) ? ($perl_path_native) : SystemUtil::findCommand('perl.exe');
|
||||
if ($this->perl === null) {
|
||||
throw new EnvironmentException(
|
||||
'You need to install perl first!',
|
||||
"Please run \"{$argv[0]} doctor\" to fix the environment.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function build(): void
|
||||
{
|
||||
$perl_path_native = PKG_ROOT_PATH . '\strawberry-perl-' . arch2gnu(php_uname('m')) . '-win\perl\bin\perl.exe';
|
||||
$perl = file_exists($perl_path_native) ? ($perl_path_native) : SystemUtil::findCommand('perl.exe');
|
||||
if ($perl === null) {
|
||||
throw new RuntimeException('You need to install perl first! (easiest way is using static-php-cli command "doctor")');
|
||||
}
|
||||
cmd()->cd($this->source_dir)
|
||||
->execWithWrapper(
|
||||
$this->builder->makeSimpleWrapper($perl),
|
||||
$this->builder->makeSimpleWrapper($this->perl),
|
||||
'Configure zlib VC-WIN64A ' .
|
||||
'no-shared ' .
|
||||
'--prefix=' . quote(BUILD_ROOT_PATH) . ' ' .
|
||||
|
||||
Reference in New Issue
Block a user