2025-11-30 15:35:04 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace StaticPHP\Command;
|
|
|
|
|
|
2026-02-03 20:23:32 +08:00
|
|
|
use StaticPHP\Artifact\DownloaderOptions;
|
2026-02-02 15:55:41 +08:00
|
|
|
use StaticPHP\Package\PackageInstaller;
|
2026-02-06 12:37:02 +08:00
|
|
|
use StaticPHP\Registry\PackageLoader;
|
2026-02-02 15:55:41 +08:00
|
|
|
use StaticPHP\Util\V2CompatLayer;
|
2025-11-30 15:35:04 +08:00
|
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
2026-02-06 12:37:02 +08:00
|
|
|
use Symfony\Component\Console\Completion\CompletionInput;
|
2025-11-30 15:35:04 +08:00
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
2026-02-02 15:55:41 +08:00
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
2025-11-30 15:35:04 +08:00
|
|
|
|
2026-02-02 15:35:59 +08:00
|
|
|
#[AsCommand('build:libs', 'Build specified library packages')]
|
2025-11-30 15:35:04 +08:00
|
|
|
class BuildLibsCommand extends BaseCommand
|
|
|
|
|
{
|
2026-02-02 15:35:59 +08:00
|
|
|
public function configure(): void
|
2025-11-30 15:35:04 +08:00
|
|
|
{
|
2026-02-06 12:37:02 +08:00
|
|
|
$this->addArgument(
|
|
|
|
|
'libraries',
|
|
|
|
|
InputArgument::REQUIRED,
|
|
|
|
|
'The library packages will be compiled, comma separated',
|
|
|
|
|
suggestedValues: function (CompletionInput $input) {
|
|
|
|
|
$packages = [];
|
|
|
|
|
foreach (PackageLoader::getPackages(['target', 'library']) as $name => $_) {
|
|
|
|
|
$packages[] = $name;
|
|
|
|
|
}
|
|
|
|
|
$val = $input->getCompletionValue();
|
|
|
|
|
return array_filter($packages, fn ($name) => str_starts_with($name, $val));
|
|
|
|
|
}
|
|
|
|
|
);
|
2026-02-02 15:55:41 +08:00
|
|
|
// Builder options
|
|
|
|
|
$this->getDefinition()->addOptions([
|
|
|
|
|
new InputOption('with-suggests', ['L', 'E'], null, 'Resolve and install suggested packages as well'),
|
|
|
|
|
new InputOption('with-packages', null, InputOption::VALUE_REQUIRED, 'add additional packages to install/build, comma separated', ''),
|
|
|
|
|
new InputOption('no-download', null, null, 'Skip downloading artifacts (use existing cached files)'),
|
|
|
|
|
...V2CompatLayer::getLegacyBuildOptions(),
|
|
|
|
|
]);
|
2026-02-03 20:23:32 +08:00
|
|
|
// Downloader options (with 'dl-' prefix to avoid conflicts)
|
|
|
|
|
$this->getDefinition()->addOptions(DownloaderOptions::getConsoleOptions('dl'));
|
2025-11-30 15:35:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function handle(): int
|
|
|
|
|
{
|
2026-02-28 10:32:50 +08:00
|
|
|
$this->checkDoctorCache();
|
|
|
|
|
|
2025-11-30 15:35:04 +08:00
|
|
|
$libs = parse_comma_list($this->input->getArgument('libraries'));
|
|
|
|
|
|
2026-02-02 15:55:41 +08:00
|
|
|
$installer = new PackageInstaller($this->input->getOptions());
|
2025-11-30 15:35:04 +08:00
|
|
|
foreach ($libs as $lib) {
|
|
|
|
|
$installer->addBuildPackage($lib);
|
|
|
|
|
}
|
|
|
|
|
$installer->run();
|
|
|
|
|
return static::SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
}
|