remove runSharedExtensionCheckUnix

This commit is contained in:
DubbleClick 2025-05-21 18:35:48 +07:00
parent af51469b62
commit b376d1682f
12 changed files with 45 additions and 61 deletions

View File

@ -234,6 +234,11 @@ abstract class BuilderBase
*/
abstract public function buildPHP(int $build_target = BUILD_TARGET_NONE);
/**
* Test PHP
*/
abstract public function testPHP(int $build_target = BUILD_TARGET_NONE);
/**
* @throws WrongUsageException
* @throws RuntimeException

View File

@ -206,21 +206,6 @@ class Extension
return false;
}
/**
* Run shared extension check when cli is enabled
* @throws RuntimeException
*/
public function runSharedExtensionCheckUnix(): void
{
[$ret] = shell()->execWithResult(BUILD_BIN_PATH . '/php -n -d "extension=' . BUILD_MODULES_PATH . '/' . $this->getName() . '.so" --ri ' . $this->getName());
if ($ret !== 0) {
throw new RuntimeException($this->getName() . '.so failed to load');
}
if ($this->isBuildStatic()) {
logger()->warning($this->getName() . '.so test succeeded, but has little significance since it is also compiled in statically.');
}
}
public function getRequiredSharedExtensions(): string
{
$loaded = [];
@ -244,7 +229,11 @@ class Extension
$ret = '';
foreach ($order as $ext) {
if ($ext instanceof Extension && $ext->isBuildShared()) {
$ret .= ' -d "extension=' . BUILD_MODULES_PATH . '/' . $ext->getName() . '.so"';
if ($ext->isZendExtension()) {
$ret .= ' -d "zend_extension=' . BUILD_MODULES_PATH . '/' . $ext->getName() . '.so"';
} else {
$ret .= ' -d "extension=' . BUILD_MODULES_PATH . '/' . $ext->getName() . '.so"';
}
}
}
@ -260,7 +249,7 @@ class Extension
// If you need to run some check, overwrite this or add your assert in src/globals/ext-tests/{extension_name}.php
// If check failed, throw RuntimeException
$sharedExtensions = $this->getRequiredSharedExtensions();
[$ret] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php -n' . $sharedExtensions . ' --ri "' . $this->getDistName() . '"', false);
[$ret] = shell()->execWithResult(BUILD_BIN_PATH . '/php -n' . $sharedExtensions . ' --ri "' . $this->getDistName() . '"', false);
if ($ret !== 0) {
throw new RuntimeException('extension ' . $this->getName() . ' failed compile check: php-cli returned ' . $ret);
}
@ -273,7 +262,7 @@ class Extension
file_get_contents(ROOT_DIR . '/src/globals/ext-tests/' . $this->getName() . '.php')
);
[$ret, $out] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php -n' . $sharedExtensions . ' -r "' . trim($test) . '"');
[$ret, $out] = shell()->execWithResult(BUILD_BIN_PATH . '/php -n' . $sharedExtensions . ' -r "' . trim($test) . '"');
if ($ret !== 0) {
if ($this->builder->getOption('debug')) {
var_dump($out);
@ -374,11 +363,6 @@ class Extension
->execWithEnv('make clean')
->execWithEnv('make -j' . $this->builder->concurrency)
->execWithEnv('make install');
// check shared extension with php-cli
if (file_exists(BUILD_BIN_PATH . '/php')) {
$this->runSharedExtensionCheckUnix();
}
}
/**
@ -449,6 +433,11 @@ class Extension
}
}
protected function isZendExtension(): bool
{
return false;
}
private function getLibraryDependencies(bool $recursive = false): array
{
$ret = array_filter($this->dependencies, fn ($x) => $x instanceof LibraryBase);

View File

@ -24,17 +24,6 @@ class opcache extends Extension
}
}
public function runSharedExtensionCheckUnix(): void
{
[$ret, $out] = shell()->execWithResult(BUILD_BIN_PATH . '/php -n -d "zend_extension=' . BUILD_MODULES_PATH . '/opcache.so" -v');
if ($ret !== 0) {
throw new RuntimeException('opcache.so failed to load.');
}
if (!str_contains(join($out), 'with Zend OPcache')) {
throw new RuntimeException('opcache.so failed to load.');
}
}
public function patchBeforeBuildconf(): bool
{
if (file_exists(SOURCE_PATH . '/php-src/.opcache_patched')) {
@ -62,4 +51,9 @@ class opcache extends Extension
{
return 'Zend Opcache';
}
protected function isZendExtension(): bool
{
return true;
}
}

View File

@ -29,10 +29,5 @@ class pdo_sqlsrv extends Extension
->execWithEnv('make clean')
->execWithEnv('make -j' . $this->builder->concurrency)
->execWithEnv('make install');
// check shared extension with php-cli
if (file_exists(BUILD_BIN_PATH . '/php')) {
$this->runSharedExtensionCheckUnix();
}
}
}

View File

@ -60,10 +60,5 @@ class sqlsrv extends Extension
->execWithEnv('make clean')
->execWithEnv('make -j' . $this->builder->concurrency)
->execWithEnv('make install');
// check shared extension with php-cli
if (file_exists(BUILD_BIN_PATH . '/php')) {
$this->runSharedExtensionCheckUnix();
}
}
}

View File

@ -5,20 +5,13 @@ declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\exception\RuntimeException;
use SPC\util\CustomExt;
#[CustomExt('xdebug')]
class xdebug extends Extension
{
public function runSharedExtensionCheckUnix(): void
protected function isZendExtension(): bool
{
[$ret, $out] = shell()->execWithResult(BUILD_BIN_PATH . '/php -n -d "zend_extension=' . BUILD_MODULES_PATH . '/xdebug.so" -v');
if ($ret !== 0) {
throw new RuntimeException('xdebug.so failed to load.');
}
if (!str_contains(join($out), 'with Xdebug')) {
throw new RuntimeException('xdebug.so failed to load.');
}
return str_contains($this->builder->getExt('zend')->getName(), 'xdebug');
}
}

View File

@ -56,10 +56,5 @@ class xhprof extends Extension
->execWithEnv('make clean')
->execWithEnv('make -j' . $this->builder->concurrency)
->execWithEnv('make install');
// check shared extension with php-cli
if (file_exists(BUILD_BIN_PATH . '/php')) {
$this->runSharedExtensionCheckUnix();
}
}
}

View File

@ -145,7 +145,10 @@ class BSDBuilder extends UnixBuilderBase
}
$this->buildEmbed();
}
}
public function testPHP(int $build_target = BUILD_TARGET_NONE)
{
if (php_uname('m') === $this->getOption('arch')) {
$this->emitPatchPoint('before-sanity-check');
$this->sanityCheck($build_target);

View File

@ -222,7 +222,10 @@ class LinuxBuilder extends UnixBuilderBase
}
$this->buildEmbed();
}
}
public function testPHP(int $build_target = BUILD_TARGET_NONE)
{
$this->emitPatchPoint('before-sanity-check');
$this->sanityCheck($build_target);
}

View File

@ -209,6 +209,12 @@ class MacOSBuilder extends UnixBuilderBase
$this->sanityCheck($build_target);
}
public function testPHP(int $build_target = BUILD_TARGET_NONE)
{
$this->emitPatchPoint('before-sanity-check');
$this->sanityCheck($build_target);
}
/**
* Build cli sapi
*

View File

@ -138,9 +138,9 @@ abstract class UnixBuilderBase extends BuilderBase
protected function sanityCheck(int $build_target): void
{
// sanity check for php-cli
if (($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI) {
if (($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI || file_exists(BUILD_BIN_PATH . '/php')) {
logger()->info('running cli sanity check');
[$ret, $output] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php -n -r "echo \"hello\";"');
[$ret, $output] = shell()->execWithResult(BUILD_BIN_PATH . '/php -n -r "echo \"hello\";"');
$raw_output = implode('', $output);
if ($ret !== 0 || trim($raw_output) !== 'hello') {
throw new RuntimeException("cli failed sanity check: ret[{$ret}]. out[{$raw_output}]");
@ -173,7 +173,11 @@ abstract class UnixBuilderBase extends BuilderBase
}
// sanity check for embed
if (($build_target & BUILD_TARGET_EMBED) === BUILD_TARGET_EMBED) {
if (($build_target & BUILD_TARGET_EMBED) === BUILD_TARGET_EMBED ||
file_exists(BUILD_BIN_PATH . '/php-config') &&
file_exists(BUILD_BIN_PATH . '/phpize') &&
(file_exists(BUILD_LIB_PATH . '/libphp.a') || file_exists(BUILD_LIB_PATH . '/libphp.so'))
) {
logger()->info('running embed sanity check');
$sample_file_path = SOURCE_PATH . '/embed-test';
if (!is_dir($sample_file_path)) {

View File

@ -218,6 +218,8 @@ class BuildPHPCommand extends BuildCommand
$builder->buildSharedExts();
}
$builder->testPHP($rule);
// compile stopwatch :P
$time = round(microtime(true) - START_TIME, 3);
logger()->info('');