From b402b735d63a4de8bfa43c94314e2997ed10a5de Mon Sep 17 00:00:00 2001 From: henderkes Date: Thu, 15 May 2025 23:30:07 +0700 Subject: [PATCH] fix copy command with BUILD_MODULES_CONSTANT --- src/SPC/builder/Extension.php | 13 +++++++++++-- src/SPC/builder/extension/opcache.php | 11 +++++++++++ src/SPC/builder/extension/xdebug.php | 5 ++++- src/SPC/builder/unix/UnixBuilderBase.php | 4 ++-- src/globals/internal-env.php | 7 +++++++ 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 92894054..2ab50f98 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -194,7 +194,7 @@ class Extension */ public function runSharedExtensionCheckUnix(): void { - [$ret] = shell()->execWithResult(BUILD_BIN_PATH . '/php -n -d "extension=' . BUILD_LIB_PATH . '/' . $this->getName() . '.so" --ri ' . $this->getName()); + [$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'); } @@ -308,7 +308,16 @@ class Extension ->execWithEnv('make -j' . $this->builder->concurrency); // copy shared library - copy($this->source_dir . '/modules/' . $this->getDistName() . '.so', BUILD_LIB_PATH . '/' . $this->getDistName() . '.so'); + FileSystem::createDir(BUILD_MODULES_PATH); + $extensionDirFile = (getenv('EXTENSION_DIR') ?: $this->source_dir . '/modules') . '/' . $this->getName() . '.so'; + $sourceDirFile = $this->source_dir . '/modules/' . $this->getName() . '.so'; + if (file_exists($extensionDirFile)) { + copy($extensionDirFile, BUILD_MODULES_PATH . '/' . $this->getName() . '.so'); + } elseif (file_exists($sourceDirFile)) { + copy($sourceDirFile, BUILD_MODULES_PATH . '/' . $this->getName() . '.so'); + } else { + throw new RuntimeException('extension ' . $this->getName() . ' built successfully, but into an unexpected location.'); + } // check shared extension with php-cli if (file_exists(BUILD_BIN_PATH . '/php')) { $this->runSharedExtensionCheckUnix(); diff --git a/src/SPC/builder/extension/opcache.php b/src/SPC/builder/extension/opcache.php index 5d9dda0a..5f406e16 100644 --- a/src/SPC/builder/extension/opcache.php +++ b/src/SPC/builder/extension/opcache.php @@ -24,6 +24,17 @@ class opcache extends Extension } } + public function runSharedExtensionCheckUnix(): void + { + [$ret, $out] = shell()->execWithResult(BUILD_BIN_PATH . '/php -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')) { diff --git a/src/SPC/builder/extension/xdebug.php b/src/SPC/builder/extension/xdebug.php index ed592056..6b945f49 100644 --- a/src/SPC/builder/extension/xdebug.php +++ b/src/SPC/builder/extension/xdebug.php @@ -13,9 +13,12 @@ class xdebug extends Extension { public function runSharedExtensionCheckUnix(): void { - [$ret] = shell()->execWithResult(BUILD_BIN_PATH . '/php -n -d "zend_extension=' . BUILD_LIB_PATH . '/xdebug.so" --ri xdebug'); + [$ret, $out] = shell()->execWithResult(BUILD_BIN_PATH . '/php -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.'); + } } } diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 4c8df333..9ffca22a 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -223,8 +223,8 @@ abstract class UnixBuilderBase extends BuilderBase default => throw new RuntimeException('Deployment does not accept type ' . $type), }; logger()->info('Deploying ' . $this->getBuildTypeName($type) . ' file'); - FileSystem::createDir(BUILD_ROOT_PATH . '/bin'); - shell()->exec('cp ' . escapeshellarg($src) . ' ' . escapeshellarg(BUILD_ROOT_PATH . '/bin/')); + FileSystem::createDir(BUILD_BIN_PATH); + shell()->exec('cp ' . escapeshellarg($src) . ' ' . escapeshellarg(BUILD_BIN_PATH)); return true; } diff --git a/src/globals/internal-env.php b/src/globals/internal-env.php index 34b1ed99..1046848e 100644 --- a/src/globals/internal-env.php +++ b/src/globals/internal-env.php @@ -9,10 +9,17 @@ use SPC\builder\windows\SystemUtil as WindowsSystemUtil; use SPC\store\FileSystem; use SPC\util\GlobalEnvManager; +// output path for everything, other paths are defined relative to this by default define('BUILD_ROOT_PATH', FileSystem::convertPath(is_string($a = getenv('BUILD_ROOT_PATH')) ? $a : (WORKING_DIR . '/buildroot'))); +// output path for header files for development define('BUILD_INCLUDE_PATH', FileSystem::convertPath(is_string($a = getenv('BUILD_INCLUDE_PATH')) ? $a : (BUILD_ROOT_PATH . '/include'))); +// output path for libraries and for libphp.so, if building shared embed define('BUILD_LIB_PATH', FileSystem::convertPath(is_string($a = getenv('BUILD_LIB_PATH')) ? $a : (BUILD_ROOT_PATH . '/lib'))); +// output path for binaries define('BUILD_BIN_PATH', FileSystem::convertPath(is_string($a = getenv('BUILD_BIN_PATH')) ? $a : (BUILD_ROOT_PATH . '/bin'))); +// output path for shared extensions +define('BUILD_MODULES_PATH', FileSystem::convertPath(is_string($a = getenv('BUILD_MODULES_PATH')) ? $a : (BUILD_ROOT_PATH . '/modules'))); + define('PKG_ROOT_PATH', FileSystem::convertPath(is_string($a = getenv('PKG_ROOT_PATH')) ? $a : (WORKING_DIR . '/pkgroot'))); define('SOURCE_PATH', FileSystem::convertPath(is_string($a = getenv('SOURCE_PATH')) ? $a : (WORKING_DIR . '/source'))); define('DOWNLOAD_PATH', FileSystem::convertPath(is_string($a = getenv('DOWNLOAD_PATH')) ? $a : (WORKING_DIR . '/downloads')));