Skip to content

Commit 302cf83

Browse files
committed
properly handle different php versions, clean up only required files
1 parent d249391 commit 302cf83

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

src/SPC/command/BuildPHPCommand.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use SPC\builder\BuilderProvider;
88
use SPC\exception\ExceptionHandler;
9+
use SPC\exception\RuntimeException;
910
use SPC\exception\WrongUsageException;
1011
use SPC\store\Config;
1112
use SPC\store\FileSystem;
@@ -158,14 +159,24 @@ public function handle(): int
158159
if ($this->input->getOption('with-upx-pack') && in_array(PHP_OS_FAMILY, ['Linux', 'Windows'])) {
159160
$indent_texts['UPX Pack'] = 'enabled';
160161
}
162+
161163
try {
162-
$ver = $builder->getPHPVersion();
163-
$indent_texts['PHP Version'] = $ver;
164-
} catch (\Throwable) {
165-
if (($ver = $builder->getPHPVersionFromArchive()) !== false) {
166-
$indent_texts['PHP Version'] = $ver;
164+
$cleanPhpSrc = $builder->getPHPVersion() !== $builder->getPHPVersionFromArchive();
165+
} catch (RuntimeException|WrongUsageException) {
166+
$cleanPhpSrc = true;
167+
}
168+
if ($cleanPhpSrc) {
169+
logger()->info('Cleaning previous php build due to mismatching versions...');
170+
FileSystem::removeDir(SOURCE_PATH . '/php-src');
171+
FileSystem::removeDir(BUILD_MODULES_PATH);
172+
$binFiles = glob(BUILD_BIN_PATH . '/php*');
173+
$libFiles = glob(BUILD_LIB_PATH . '/libphp*');
174+
foreach ([...$binFiles, ...$libFiles] as $file) {
175+
unlink($file);
167176
}
168177
}
178+
$ver = $builder->getPHPVersionFromArchive() ?: $builder->getPHPVersion();
179+
$indent_texts['PHP Version'] = $ver;
169180

170181
if (!empty($not_included)) {
171182
$indent_texts['Extra Exts (' . count($not_included) . ')'] = implode(', ', $not_included);

0 commit comments

Comments
 (0)