From 936413a6d91eb2f8fc9b10fab641397260295578 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 30 Mar 2025 14:01:31 +0800 Subject: [PATCH] Define HAVE_OMP_PAUSE_RESOURCE_ALL to 0, add additional file system func --- src/SPC/builder/extension/imagick.php | 10 +++++++--- src/SPC/store/FileSystem.php | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/SPC/builder/extension/imagick.php b/src/SPC/builder/extension/imagick.php index 4e1a2ff9..e452a98a 100644 --- a/src/SPC/builder/extension/imagick.php +++ b/src/SPC/builder/extension/imagick.php @@ -5,16 +5,20 @@ declare(strict_types=1); namespace SPC\builder\extension; use SPC\builder\Extension; +use SPC\exception\FileSystemException; use SPC\store\FileSystem; use SPC\util\CustomExt; #[CustomExt('imagick')] class imagick extends Extension { - public function patchBeforeBuildconf(): bool + /** + * @throws FileSystemException + */ + public function patchBeforeMake(): bool { - // destroy imagick build conf to avoid libgomp build error - FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/imagick/config.m4', '#include ', '#include '); + // replace php_config.h HAVE_OMP_PAUSE_RESOURCE_ALL line to #define HAVE_OMP_PAUSE_RESOURCE_ALL 0 + FileSystem::replaceFileLineContainsString(SOURCE_PATH . '/php-src/main/php_config.h', 'HAVE_OMP_PAUSE_RESOURCE_ALL', '#define HAVE_OMP_PAUSE_RESOURCE_ALL 0'); return true; } diff --git a/src/SPC/store/FileSystem.php b/src/SPC/store/FileSystem.php index 67b21ec4..16047427 100644 --- a/src/SPC/store/FileSystem.php +++ b/src/SPC/store/FileSystem.php @@ -461,6 +461,23 @@ class FileSystem } } + /** + * @throws FileSystemException + */ + public static function replaceFileLineContainsString(string $file, string $find, string $line): false|int + { + $lines = file($file); + if ($lines === false) { + throw new FileSystemException('Cannot read file: ' . $file); + } + foreach ($lines as $key => $value) { + if (str_contains($value, $find)) { + $lines[$key] = $line . PHP_EOL; + } + } + return file_put_contents($file, implode('', $lines)); + } + /** * @throws RuntimeException * @throws FileSystemException