From db9645641f621d91c0e1a31da3e735bba3a98c95 Mon Sep 17 00:00:00 2001 From: Jerry Ma Date: Wed, 5 Jun 2024 23:20:21 +0800 Subject: [PATCH] Ignore passed internal extensions (#473) * Ignore passed internal extensions * Add tests * Add tests --- src/SPC/command/BaseCommand.php | 20 ++++++++++++++++++++ src/SPC/command/BuildCliCommand.php | 2 +- src/SPC/command/DownloadCommand.php | 2 +- src/SPC/command/DumpLicenseCommand.php | 2 +- src/globals/test-extensions.php | 2 +- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/SPC/command/BaseCommand.php b/src/SPC/command/BaseCommand.php index 041b53a5..cfb72e26 100644 --- a/src/SPC/command/BaseCommand.php +++ b/src/SPC/command/BaseCommand.php @@ -144,4 +144,24 @@ abstract class BaseCommand extends Command logger()->error($fail_msg); return static::FAILURE; } + + protected function parseExtensionList(string $ext_list): array + { + $a = array_map('trim', explode(',', $ext_list)); + return array_values(array_filter($a, function ($x) { + $filter_internals = [ + 'core', + 'hash', + 'json', + 'reflection', + 'spl', + 'standard', + ]; + if (in_array(strtolower($x), $filter_internals)) { + logger()->warning("Extension [{$x}] is an builtin extension, it will be ignored."); + return false; + } + return true; + })); + } } diff --git a/src/SPC/command/BuildCliCommand.php b/src/SPC/command/BuildCliCommand.php index d196b455..3c6fb59f 100644 --- a/src/SPC/command/BuildCliCommand.php +++ b/src/SPC/command/BuildCliCommand.php @@ -47,7 +47,7 @@ class BuildCliCommand extends BuildCommand // transform string to array $libraries = array_map('trim', array_filter(explode(',', $this->getOption('with-libs')))); // transform string to array - $extensions = array_map('trim', array_filter(explode(',', $this->getArgument('extensions')))); + $extensions = $this->parseExtensionList($this->getArgument('extensions')); // parse rule with options $rule = $this->parseRules(); diff --git a/src/SPC/command/DownloadCommand.php b/src/SPC/command/DownloadCommand.php index 36f5cea2..5ce1a06a 100644 --- a/src/SPC/command/DownloadCommand.php +++ b/src/SPC/command/DownloadCommand.php @@ -68,7 +68,7 @@ class DownloadCommand extends BaseCommand } // mode: --for-extensions if ($for_ext = $input->getOption('for-extensions')) { - $ext = array_map('trim', array_filter(explode(',', $for_ext))); + $ext = $this->parseExtensionList($for_ext); $sources = $this->calculateSourcesByExt($ext, !$input->getOption('without-suggestions')); if (PHP_OS_FAMILY !== 'Windows') { array_unshift($sources, 'pkg-config'); diff --git a/src/SPC/command/DumpLicenseCommand.php b/src/SPC/command/DumpLicenseCommand.php index 66047567..0e9147da 100644 --- a/src/SPC/command/DumpLicenseCommand.php +++ b/src/SPC/command/DumpLicenseCommand.php @@ -37,7 +37,7 @@ class DumpLicenseCommand extends BaseCommand $dumper = new LicenseDumper(); if ($this->getOption('for-extensions') !== null) { // 从参数中获取要编译的 extensions,并转换为数组 - $extensions = array_map('trim', array_filter(explode(',', $this->getOption('for-extensions')))); + $extensions = $this->parseExtensionList($this->getOption('for-extensions')); // 根据提供的扩展列表获取依赖库列表并编译 [$extensions, $libraries] = DependencyUtil::getExtsAndLibs($extensions); $dumper->addExts($extensions); diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index cfde3b3b..6a3cf7ba 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -19,7 +19,7 @@ $upx = true; // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). $extensions = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'libxml,xlswriter,openssl', + 'Linux', 'Darwin' => 'libxml,xlswriter,openssl,core,hash,json,standard,SPL,HASH,REFLECTION', 'Windows' => 'mbstring,pdo_sqlite,mbregex', };