2023-03-18 17:32:21 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
|
|
namespace SPC\command;
|
|
|
|
|
|
|
2023-04-15 18:46:46 +08:00
|
|
|
|
use SPC\exception\FileSystemException;
|
|
|
|
|
|
use SPC\exception\RuntimeException;
|
|
|
|
|
|
use SPC\exception\WrongUsageException;
|
|
|
|
|
|
use SPC\util\DependencyUtil;
|
|
|
|
|
|
use SPC\util\LicenseDumper;
|
2023-04-22 17:45:43 +08:00
|
|
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
2023-04-15 18:46:46 +08:00
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
2023-03-18 17:32:21 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 修改 config 后对其 kv 进行排序的操作
|
|
|
|
|
|
*/
|
2023-04-22 17:45:43 +08:00
|
|
|
|
#[AsCommand('dump-license', 'Dump licenses for required libraries')]
|
2023-03-18 17:32:21 +08:00
|
|
|
|
class DumpLicenseCommand extends BaseCommand
|
|
|
|
|
|
{
|
2023-08-20 19:51:45 +08:00
|
|
|
|
public function configure(): void
|
2023-03-18 17:32:21 +08:00
|
|
|
|
{
|
2023-10-29 00:48:30 +02:00
|
|
|
|
$this->addOption('for-extensions', null, InputOption::VALUE_REQUIRED, 'Dump by extensions and related libraries', null);
|
2023-04-15 18:46:46 +08:00
|
|
|
|
$this->addOption('without-php', null, InputOption::VALUE_NONE, 'Dump without php-src');
|
2024-02-16 18:56:33 +08:00
|
|
|
|
$this->addOption('for-libs', null, InputOption::VALUE_REQUIRED, 'Dump by libraries', null);
|
|
|
|
|
|
$this->addOption('for-sources', null, InputOption::VALUE_REQUIRED, 'Dump by original sources (source.json)', null);
|
2023-04-15 18:46:46 +08:00
|
|
|
|
$this->addOption('dump-dir', null, InputOption::VALUE_REQUIRED, 'Change dump directory', BUILD_ROOT_PATH . '/license');
|
2023-03-18 17:32:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-15 18:46:46 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @throws WrongUsageException
|
|
|
|
|
|
* @throws FileSystemException
|
|
|
|
|
|
* @throws RuntimeException
|
|
|
|
|
|
*/
|
2023-04-22 17:45:43 +08:00
|
|
|
|
public function handle(): int
|
2023-03-18 17:32:21 +08:00
|
|
|
|
{
|
2023-04-15 18:46:46 +08:00
|
|
|
|
$dumper = new LicenseDumper();
|
2023-10-29 00:48:30 +02:00
|
|
|
|
if ($this->getOption('for-extensions') !== null) {
|
2023-04-15 18:46:46 +08:00
|
|
|
|
// 从参数中获取要编译的 extensions,并转换为数组
|
2023-10-29 00:48:30 +02:00
|
|
|
|
$extensions = array_map('trim', array_filter(explode(',', $this->getOption('for-extensions'))));
|
2023-04-15 18:46:46 +08:00
|
|
|
|
// 根据提供的扩展列表获取依赖库列表并编译
|
2024-02-16 18:56:33 +08:00
|
|
|
|
[$extensions, $libraries] = DependencyUtil::getExtsAndLibs($extensions);
|
2023-04-15 18:46:46 +08:00
|
|
|
|
$dumper->addExts($extensions);
|
|
|
|
|
|
$dumper->addLibs($libraries);
|
2023-04-22 17:45:43 +08:00
|
|
|
|
if (!$this->getOption('without-php')) {
|
2023-04-15 18:46:46 +08:00
|
|
|
|
$dumper->addSources(['php-src']);
|
|
|
|
|
|
}
|
2023-04-22 17:45:43 +08:00
|
|
|
|
$dumper->dump($this->getOption('dump-dir'));
|
|
|
|
|
|
$this->output->writeln('Dump license with extensions: ' . implode(', ', $extensions));
|
|
|
|
|
|
$this->output->writeln('Dump license with libraries: ' . implode(', ', $libraries));
|
|
|
|
|
|
$this->output->writeln('Dump license with' . ($this->getOption('without-php') ? 'out' : '') . ' php-src');
|
|
|
|
|
|
$this->output->writeln('Dump target dir: ' . $this->getOption('dump-dir'));
|
2023-08-06 10:43:20 +08:00
|
|
|
|
return static::SUCCESS;
|
2023-04-15 18:46:46 +08:00
|
|
|
|
}
|
2024-02-16 18:56:33 +08:00
|
|
|
|
if ($this->getOption('for-libs') !== null) {
|
|
|
|
|
|
$libraries = array_map('trim', array_filter(explode(',', $this->getOption('for-libs'))));
|
|
|
|
|
|
$libraries = DependencyUtil::getLibs($libraries);
|
2023-04-15 18:46:46 +08:00
|
|
|
|
$dumper->addLibs($libraries);
|
2023-04-22 17:45:43 +08:00
|
|
|
|
$dumper->dump($this->getOption('dump-dir'));
|
|
|
|
|
|
$this->output->writeln('Dump target dir: ' . $this->getOption('dump-dir'));
|
2023-08-06 10:43:20 +08:00
|
|
|
|
return static::SUCCESS;
|
2023-04-15 18:46:46 +08:00
|
|
|
|
}
|
2024-02-16 18:56:33 +08:00
|
|
|
|
if ($this->getOption('for-sources') !== null) {
|
|
|
|
|
|
$sources = array_map('trim', array_filter(explode(',', $this->getOption('for-sources'))));
|
2023-04-15 18:46:46 +08:00
|
|
|
|
$dumper->addSources($sources);
|
2023-04-22 17:45:43 +08:00
|
|
|
|
$dumper->dump($this->getOption('dump-dir'));
|
|
|
|
|
|
$this->output->writeln('Dump target dir: ' . $this->getOption('dump-dir'));
|
2023-08-06 10:43:20 +08:00
|
|
|
|
return static::SUCCESS;
|
2023-04-15 18:46:46 +08:00
|
|
|
|
}
|
2024-02-16 18:56:33 +08:00
|
|
|
|
$this->output->writeln('You must use one of "--for-extensions=", "--for-libs=", "--for-sources=" to dump');
|
2023-08-06 10:43:20 +08:00
|
|
|
|
return static::FAILURE;
|
2023-03-18 17:32:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|