From b1ae48a20920d13925a3062bd3c96418173422c4 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Wed, 1 Nov 2023 01:46:21 +0800 Subject: [PATCH 1/4] let sanity check can be overwritten --- src/SPC/builder/Extension.php | 28 +++++++++++++++++++++ src/SPC/builder/traits/UnixBuilderTrait.php | 19 +------------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 922d4f3d..5d9f2e6b 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -163,6 +163,34 @@ 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 + * + * @throws RuntimeException + */ + public function runCheck(): 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/traits/UnixBuilderTrait.php b/src/SPC/builder/traits/UnixBuilderTrait.php index 2d0d43d2..d698c730 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->runCheck(); } } From 5db23e1db705b75ce88ae88b53bbbf1a0d5259d0 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Wed, 1 Nov 2023 01:49:48 +0800 Subject: [PATCH 2/4] let sanity check can be overwritten --- src/SPC/builder/Extension.php | 3 ++- src/SPC/builder/traits/UnixBuilderTrait.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 5d9f2e6b..21f0f574 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -166,10 +166,11 @@ class Extension /** * 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 runCheck(): void + public function runCliCheck(): void { [$ret] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php --ri "' . $this->getDistName() . '"', false); if ($ret !== 0) { diff --git a/src/SPC/builder/traits/UnixBuilderTrait.php b/src/SPC/builder/traits/UnixBuilderTrait.php index d698c730..3fead06f 100644 --- a/src/SPC/builder/traits/UnixBuilderTrait.php +++ b/src/SPC/builder/traits/UnixBuilderTrait.php @@ -66,7 +66,7 @@ trait UnixBuilderTrait foreach ($this->exts as $ext) { logger()->debug('testing ext: ' . $ext->getName()); - $ext->runCheck(); + $ext->runCliCheck(); } } From dccfde9f39d43480d3f6936147a55b39e493b602 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 5 Nov 2023 17:47:57 +0800 Subject: [PATCH 3/4] Adjust mbstring and mbregex dependencies --- config/ext.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/ext.json b/config/ext.json index b18c8eb9..778afe0e 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", From ff74f0cdaf9057eac343568f7b0c01f64bde22fe Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 5 Nov 2023 17:48:20 +0800 Subject: [PATCH 4/4] overwrite mbregex cli check --- src/SPC/builder/extension/mbregex.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) 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 !'); + } + } }