diff --git a/config/ext.json b/config/ext.json index f60637f4..85139f1f 100644 --- a/config/ext.json +++ b/config/ext.json @@ -169,14 +169,14 @@ "arg-type": "custom", "ext-depends": [ "mbstring" + ], + "lib-depends": [ + "onig" ] }, "mbstring": { "type": "builtin", - "arg-type": "custom", - "lib-depends": [ - "onig" - ] + "arg-type": "custom" }, "memcache": { "type": "external", diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 922d4f3d..21f0f574 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -163,6 +163,35 @@ class Extension return false; } + /** + * Run compile check if build target is cli + * If you need to run some check, overwrite this or add your assert in src/globals/tests/{extension_name}.php + * If check failed, throw RuntimeException + * + * @throws RuntimeException + */ + public function runCliCheck(): void + { + [$ret] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php --ri "' . $this->getDistName() . '"', false); + if ($ret !== 0) { + throw new RuntimeException('extension ' . $this->getName() . ' failed compile check: php-cli returned ' . $ret); + } + + if (file_exists(ROOT_DIR . '/src/globals/tests/' . $this->getName() . '.php')) { + // Trim additional content & escape special characters to allow inline usage + $test = str_replace( + ['getName() . '.php') + ); + + [$ret] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php -r "' . trim($test) . '"'); + if ($ret !== 0) { + throw new RuntimeException('extension ' . $this->getName() . ' failed sanity check'); + } + } + } + /** * @throws RuntimeException */ diff --git a/src/SPC/builder/extension/mbregex.php b/src/SPC/builder/extension/mbregex.php index 6a4d1457..0301557c 100644 --- a/src/SPC/builder/extension/mbregex.php +++ b/src/SPC/builder/extension/mbregex.php @@ -5,18 +5,25 @@ declare(strict_types=1); namespace SPC\builder\extension; use SPC\builder\Extension; +use SPC\exception\RuntimeException; use SPC\util\CustomExt; #[CustomExt('mbregex')] class mbregex extends Extension { - public function getDistName(): string - { - return 'mbstring'; - } - public function getConfigureArg(): string { return ''; } + + /** + * mbregex is not an extension, we need to overwrite the default check. + */ + public function runCliCheck(): void + { + [$ret] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php --ri "mbstring" | grep regex', false); + if ($ret !== 0) { + throw new RuntimeException('extension ' . $this->getName() . ' failed compile check: compiled php-cli mbstring extension does not contain regex !'); + } + } } diff --git a/src/SPC/builder/traits/UnixBuilderTrait.php b/src/SPC/builder/traits/UnixBuilderTrait.php index 2d0d43d2..3fead06f 100644 --- a/src/SPC/builder/traits/UnixBuilderTrait.php +++ b/src/SPC/builder/traits/UnixBuilderTrait.php @@ -66,24 +66,7 @@ trait UnixBuilderTrait foreach ($this->exts as $ext) { logger()->debug('testing ext: ' . $ext->getName()); - [$ret] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php --ri "' . $ext->getDistName() . '"', false); - if ($ret !== 0) { - throw new RuntimeException('extension ' . $ext->getName() . ' failed compile check'); - } - - if (file_exists(ROOT_DIR . '/src/globals/tests/' . $ext->getName() . '.php')) { - // Trim additional content & escape special characters to allow inline usage - $test = str_replace( - ['getName() . '.php') - ); - - [$ret] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php -r "' . trim($test) . '"'); - if ($ret !== 0) { - throw new RuntimeException('extension ' . $ext->getName() . ' failed sanity check'); - } - } + $ext->runCliCheck(); } }