Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let sanity check can be overwritten #253

Merged
merged 4 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions config/ext.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 29 additions & 0 deletions src/SPC/builder/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,35 @@ public function patchBeforeMake(): bool
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(
['<?php', 'declare(strict_types=1);', "\n", '"', '$'],
['', '', '', '\"', '\$'],
file_get_contents(ROOT_DIR . '/src/globals/tests/' . $this->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
*/
Expand Down
15 changes: 11 additions & 4 deletions src/SPC/builder/extension/mbregex.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,25 @@
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
public function getConfigureArg(): string
{
return 'mbstring';
return '';
}

public function getConfigureArg(): string
/**
* mbregex is not an extension, we need to overwrite the default check.
*/
public function runCliCheck(): void
{
return '';
[$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 !');
}
}
}
19 changes: 1 addition & 18 deletions src/SPC/builder/traits/UnixBuilderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,7 @@ public function sanityCheck(int $build_target): void

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(
['<?php', 'declare(strict_types=1);', "\n", '"', '$'],
['', '', '', '\"', '\$'],
file_get_contents(ROOT_DIR . '/src/globals/tests/' . $ext->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();
}
}

Expand Down