diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index caece586..08c580ea 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -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 diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index e79c3db9..a0a1e6d2 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -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); diff --git a/src/SPC/builder/extension/opcache.php b/src/SPC/builder/extension/opcache.php index ec468cb8..865bf487 100644 --- a/src/SPC/builder/extension/opcache.php +++ b/src/SPC/builder/extension/opcache.php @@ -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; + } } diff --git a/src/SPC/builder/extension/pdo_sqlsrv.php b/src/SPC/builder/extension/pdo_sqlsrv.php index 195eaffe..75166903 100644 --- a/src/SPC/builder/extension/pdo_sqlsrv.php +++ b/src/SPC/builder/extension/pdo_sqlsrv.php @@ -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(); - } } } diff --git a/src/SPC/builder/extension/sqlsrv.php b/src/SPC/builder/extension/sqlsrv.php index f6cd21a0..55a2b6a0 100644 --- a/src/SPC/builder/extension/sqlsrv.php +++ b/src/SPC/builder/extension/sqlsrv.php @@ -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(); - } } } diff --git a/src/SPC/builder/extension/xdebug.php b/src/SPC/builder/extension/xdebug.php index 367eb420..90f225ae 100644 --- a/src/SPC/builder/extension/xdebug.php +++ b/src/SPC/builder/extension/xdebug.php @@ -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'); } } diff --git a/src/SPC/builder/extension/xhprof.php b/src/SPC/builder/extension/xhprof.php index 118a34cd..589ac583 100644 --- a/src/SPC/builder/extension/xhprof.php +++ b/src/SPC/builder/extension/xhprof.php @@ -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(); - } } } diff --git a/src/SPC/builder/freebsd/BSDBuilder.php b/src/SPC/builder/freebsd/BSDBuilder.php index b2e246b3..7c10881f 100644 --- a/src/SPC/builder/freebsd/BSDBuilder.php +++ b/src/SPC/builder/freebsd/BSDBuilder.php @@ -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); diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 0a827c85..0a814907 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -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); } diff --git a/src/SPC/builder/macos/MacOSBuilder.php b/src/SPC/builder/macos/MacOSBuilder.php index 9f9ad684..7d82f191 100644 --- a/src/SPC/builder/macos/MacOSBuilder.php +++ b/src/SPC/builder/macos/MacOSBuilder.php @@ -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 * diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index b92c2b7e..d645a68f 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -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)) { diff --git a/src/SPC/command/BuildPHPCommand.php b/src/SPC/command/BuildPHPCommand.php index 550fad3f..6c64995c 100644 --- a/src/SPC/command/BuildPHPCommand.php +++ b/src/SPC/command/BuildPHPCommand.php @@ -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('');