From 6af40cd92d85767d366499fafd634799cdedaee5 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 26 Mar 2023 23:59:34 +0800 Subject: [PATCH] fix micro build and change deploy command args --- src/SPC/builder/BuilderBase.php | 9 ++++---- src/SPC/builder/linux/LinuxBuilder.php | 8 +++---- src/SPC/command/DeployCommand.php | 30 ++++++++++++++++++++------ 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index 22bbc8d8..54f23ec6 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -30,6 +30,9 @@ abstract class BuilderBase /** @var array 要编译的扩展列表 */ protected array $exts = []; + /** @var array 要编译的扩展列表(仅名字列表,用于最后生成编译的扩展列表给 micro) */ + protected array $plain_extensions = []; + /** @var bool 本次编译是否只编译 libs,不编译 PHP */ protected bool $libs_only = false; @@ -149,10 +152,6 @@ abstract class BuilderBase */ public function proveExts(array $extensions): void { - if (defined('BUILD_ALL_STATIC') && BUILD_ALL_STATIC) { - $k = array_search('ffi', $extensions, true); - $k !== false && array_splice($extensions, $k, 1); - } foreach ($extensions as $extension) { $ext = new Extension($extension, $this); $this->addExt($ext); @@ -162,6 +161,8 @@ abstract class BuilderBase // 检查下依赖就行了,作用是导入依赖给 Extension 对象,今后可以对库依赖进行选择性处理 $ext->checkDependency(); } + + $this->plain_extensions = $extensions; } /** diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 147da22a..94cb824a 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -215,6 +215,8 @@ class LinuxBuilder extends BuilderBase if ($this->phar_patched) { shell()->cd(SOURCE_PATH . '/php-src')->exec('patch -p1 -R < sapi/micro/patches/phar.patch'); } + + file_put_contents(SOURCE_PATH . '/php-src/.extensions.json', json_encode($this->plain_extensions, JSON_PRETTY_PRINT)); } /** @@ -265,11 +267,7 @@ class LinuxBuilder extends BuilderBase 'micro' ); - shell()->cd(SOURCE_PATH . '/php-src/sapi/micro') - ->exec("{$this->cross_compile_prefix}objcopy --only-keep-debug micro.sfx micro.sfx.debug") - ->exec('elfedit --output-osabi linux micro.sfx') - ->exec("{$this->cross_compile_prefix}strip --strip-all micro.sfx") - ->exec("{$this->cross_compile_prefix}objcopy --update-section .comment=/tmp/comment --add-gnu-debuglink=micro.sfx.debug --remove-section=.note micro.sfx'"); + shell()->cd(SOURCE_PATH . '/php-src/sapi/micro')->exec("{$this->cross_compile_prefix}strip --strip-all micro.sfx"); $this->deployBinary(BUILD_TYPE_MICRO); } diff --git a/src/SPC/command/DeployCommand.php b/src/SPC/command/DeployCommand.php index 6fa990a2..2cddf89a 100644 --- a/src/SPC/command/DeployCommand.php +++ b/src/SPC/command/DeployCommand.php @@ -16,7 +16,7 @@ use Symfony\Component\Console\Output\OutputInterface; /** @noinspection PhpUnused */ class DeployCommand extends BaseCommand { - protected static $defaultName = 'deploy-self'; + protected static $defaultName = 'deploy'; public function configure() { @@ -24,7 +24,7 @@ class DeployCommand extends BaseCommand $this->addArgument('target', InputArgument::OPTIONAL, 'The file or directory to pack.'); $this->addOption('auto-phar-fix', null, InputOption::VALUE_NONE, 'Automatically fix ini option.'); $this->addOption('overwrite', 'W', InputOption::VALUE_NONE, 'Overwrite existing files.'); - $this->addOption('disable-gzip', 'z', InputOption::VALUE_NONE, 'disable gzip archive mode'); + // $this->addOption('disable-gzip', 'z', InputOption::VALUE_NONE, 'disable gzip archive mode'); } public function execute(InputInterface $input, OutputInterface $output): int @@ -67,7 +67,7 @@ class DeployCommand extends BaseCommand $all = DataProvider::scanDirFiles($path, true, true); $all = array_filter($all, function ($x) { - $dirs = preg_match('/(^(bin|config|src|vendor)\\/|^(composer\\.json|README\\.md|source\\.json|LICENSE|README-en\\.md)$)/', $x); + $dirs = preg_match('/(^(config|src|vendor)\\/|^(composer\\.json|README\\.md|source\\.json|LICENSE|README-en\\.md)$)/', $x); return !($dirs !== 1); }); sort($all); @@ -78,7 +78,10 @@ class DeployCommand extends BaseCommand $output->writeln('Start packing files...'); try { - $phar->buildFromIterator(new SeekableArrayIterator($map, new ProgressBar($output))); + foreach ($this->progress($output)->iterate($map) as $file => $origin_file) { + $phar->addFromString($file, php_strip_whitespace($origin_file)); + } + // $phar->buildFromIterator(new SeekableArrayIterator($map, new ProgressBar($output))); $phar->addFromString( '.phar-entry.php', str_replace( @@ -94,9 +97,10 @@ class DeployCommand extends BaseCommand return 1; } $phar->addFromString('.prod', 'true'); - if (!$input->getOption('disable-gzip')) { - $phar->compressFiles(\Phar::GZ); - } + // disable gzip compression due to phpmicro bug + // if (!$input->getOption('disable-gzip')) { + // $phar->compressFiles(\Phar::GZ); + // } $phar->stopBuffering(); $output->writeln(PHP_EOL . 'Done! Phar file is generated at "' . $phar_path . '".'); if (file_exists(SOURCE_PATH . '/php-src/sapi/micro/micro.sfx')) { @@ -113,4 +117,16 @@ class DeployCommand extends BaseCommand $output->writeln('Phar: ' . $phar_path . ''); return 0; } + + private function progress(OutputInterface $output, int $max = 0): ProgressBar + { + $progress = new ProgressBar($output, $max); + $progress->setBarCharacter('⚬'); + $progress->setEmptyBarCharacter('⚬'); + $progress->setProgressCharacter('➤'); + $progress->setFormat( + "%current%/%max% [%bar%] %percent:3s%%\n🪅 %estimated:-20s% %memory:20s%" . PHP_EOL + ); + return $progress; + } }