From 302cf8345de443b0e3a095251ca9e4dd2dfbff64 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 13 Jun 2025 13:01:02 +0700 Subject: [PATCH] properly handle different php versions, clean up only required files --- src/SPC/command/BuildPHPCommand.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/SPC/command/BuildPHPCommand.php b/src/SPC/command/BuildPHPCommand.php index 61781d2c..353605b1 100644 --- a/src/SPC/command/BuildPHPCommand.php +++ b/src/SPC/command/BuildPHPCommand.php @@ -6,6 +6,7 @@ namespace SPC\command; use SPC\builder\BuilderProvider; use SPC\exception\ExceptionHandler; +use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; use SPC\store\Config; use SPC\store\FileSystem; @@ -158,14 +159,24 @@ class BuildPHPCommand extends BuildCommand if ($this->input->getOption('with-upx-pack') && in_array(PHP_OS_FAMILY, ['Linux', 'Windows'])) { $indent_texts['UPX Pack'] = 'enabled'; } + try { - $ver = $builder->getPHPVersion(); - $indent_texts['PHP Version'] = $ver; - } catch (\Throwable) { - if (($ver = $builder->getPHPVersionFromArchive()) !== false) { - $indent_texts['PHP Version'] = $ver; + $cleanPhpSrc = $builder->getPHPVersion() !== $builder->getPHPVersionFromArchive(); + } catch (RuntimeException|WrongUsageException) { + $cleanPhpSrc = true; + } + if ($cleanPhpSrc) { + logger()->info('Cleaning previous php build due to mismatching versions...'); + FileSystem::removeDir(SOURCE_PATH . '/php-src'); + FileSystem::removeDir(BUILD_MODULES_PATH); + $binFiles = glob(BUILD_BIN_PATH . '/php*'); + $libFiles = glob(BUILD_LIB_PATH . '/libphp*'); + foreach ([...$binFiles, ...$libFiles] as $file) { + unlink($file); } } + $ver = $builder->getPHPVersionFromArchive() ?: $builder->getPHPVersion(); + $indent_texts['PHP Version'] = $ver; if (!empty($not_included)) { $indent_texts['Extra Exts (' . count($not_included) . ')'] = implode(', ', $not_included);