mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 04:44:53 +08:00
Add getLibVersion and getExtVersion method for extensions and libs
This commit is contained in:
parent
f645c8869a
commit
eb00e0012f
5
config/pre-built.json
Normal file
5
config/pre-built.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"repo": "static-php/static-php-cli-hosted",
|
||||
"match-pattern": "{name}-{arch}-{os}.tgz",
|
||||
"pack-config": {}
|
||||
}
|
||||
@ -8,7 +8,9 @@ use SPC\command\BuildCliCommand;
|
||||
use SPC\command\BuildLibsCommand;
|
||||
use SPC\command\DeleteDownloadCommand;
|
||||
use SPC\command\dev\AllExtCommand;
|
||||
use SPC\command\dev\ExtVerCommand;
|
||||
use SPC\command\dev\GenerateExtDocCommand;
|
||||
use SPC\command\dev\LibVerCommand;
|
||||
use SPC\command\dev\PhpVerCommand;
|
||||
use SPC\command\dev\SortConfigCommand;
|
||||
use SPC\command\DoctorCommand;
|
||||
@ -48,6 +50,8 @@ final class ConsoleApplication extends Application
|
||||
// Dev commands
|
||||
new AllExtCommand(),
|
||||
new PhpVerCommand(),
|
||||
new LibVerCommand(),
|
||||
new ExtVerCommand(),
|
||||
new SortConfigCommand(),
|
||||
new GenerateExtDocCommand(),
|
||||
]
|
||||
|
||||
@ -161,7 +161,7 @@ abstract class BuilderBase
|
||||
* @throws WrongUsageException
|
||||
* @internal
|
||||
*/
|
||||
public function proveExts(array $extensions): void
|
||||
public function proveExts(array $extensions, bool $skip_check_deps = false): void
|
||||
{
|
||||
CustomExt::loadCustomExt();
|
||||
$this->emitPatchPoint('before-php-extract');
|
||||
@ -181,6 +181,10 @@ abstract class BuilderBase
|
||||
$this->addExt($ext);
|
||||
}
|
||||
|
||||
if ($skip_check_deps) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->exts as $ext) {
|
||||
$ext->checkDependency();
|
||||
}
|
||||
|
||||
@ -228,6 +228,16 @@ class Extension
|
||||
// do nothing, just throw wrong usage exception if not valid
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current extension version
|
||||
*
|
||||
* @return null|string Version string or null
|
||||
*/
|
||||
public function getExtVersion(): ?string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
|
||||
@ -182,6 +182,16 @@ abstract class LibraryBase
|
||||
// do nothing, just throw wrong usage exception if not valid
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current lib version
|
||||
*
|
||||
* @return null|string Version string or null
|
||||
*/
|
||||
public function getLibVersion(): ?string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current builder object.
|
||||
*/
|
||||
|
||||
@ -10,6 +10,18 @@ use SPC\util\CustomExt;
|
||||
#[CustomExt('swoole')]
|
||||
class swoole extends Extension
|
||||
{
|
||||
public function getExtVersion(): ?string
|
||||
{
|
||||
// Get version from source directory
|
||||
$file = SOURCE_PATH . '/php-src/ext/swoole/include/swoole_version.h';
|
||||
// Match #define SWOOLE_VERSION "5.1.3"
|
||||
$pattern = '/#define SWOOLE_VERSION "(.+)"/';
|
||||
if (preg_match($pattern, file_get_contents($file), $matches)) {
|
||||
return $matches[1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getUnixConfigureArg(): string
|
||||
{
|
||||
// enable swoole
|
||||
|
||||
51
src/SPC/command/dev/ExtVerCommand.php
Normal file
51
src/SPC/command/dev/ExtVerCommand.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\command\dev;
|
||||
|
||||
use SPC\builder\BuilderProvider;
|
||||
use SPC\command\BaseCommand;
|
||||
use SPC\store\Config;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
#[AsCommand('dev:ext-version', 'Returns version of extension from source directory', ['dev:ext-ver'])]
|
||||
class ExtVerCommand extends BaseCommand
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
$this->addArgument('extension', InputArgument::REQUIRED, 'The library name');
|
||||
}
|
||||
|
||||
public function initialize(InputInterface $input, OutputInterface $output): void
|
||||
{
|
||||
$this->no_motd = true;
|
||||
parent::initialize($input, $output);
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
// Get lib object
|
||||
$builder = BuilderProvider::makeBuilderByInput($this->input);
|
||||
|
||||
$ext_conf = Config::getExt($this->getArgument('extension'));
|
||||
$builder->proveExts([$this->getArgument('extension')], true);
|
||||
|
||||
// Check whether lib is extracted
|
||||
// if (!is_dir(SOURCE_PATH . '/' . $this->getArgument('library'))) {
|
||||
// $this->output->writeln("<error>Library {$this->getArgument('library')} is not extracted</error>");
|
||||
// return static::FAILURE;
|
||||
// }
|
||||
|
||||
$version = $builder->getExt($this->getArgument('extension'))->getExtVersion();
|
||||
if ($version === null) {
|
||||
$this->output->writeln("<error>Failed to get version of extension {$this->getArgument('extension')}</error>");
|
||||
return static::FAILURE;
|
||||
}
|
||||
$this->output->writeln("<info>{$version}</info>");
|
||||
return static::SUCCESS;
|
||||
}
|
||||
}
|
||||
60
src/SPC/command/dev/LibVerCommand.php
Normal file
60
src/SPC/command/dev/LibVerCommand.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\command\dev;
|
||||
|
||||
use SPC\builder\BuilderProvider;
|
||||
use SPC\command\BaseCommand;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\store\Config;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
#[AsCommand('dev:lib-version', 'Returns version of library from source directory', ['dev:lib-ver'])]
|
||||
class LibVerCommand extends BaseCommand
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
$this->addArgument('library', InputArgument::REQUIRED, 'The library name');
|
||||
}
|
||||
|
||||
public function initialize(InputInterface $input, OutputInterface $output): void
|
||||
{
|
||||
$this->no_motd = true;
|
||||
parent::initialize($input, $output);
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
// Get lib object
|
||||
$builder = BuilderProvider::makeBuilderByInput($this->input);
|
||||
$builder->setLibsOnly();
|
||||
|
||||
// check lib name exist in lib.json
|
||||
try {
|
||||
Config::getLib($this->getArgument('library'));
|
||||
} catch (WrongUsageException $e) {
|
||||
$this->output->writeln("<error>Library {$this->getArgument('library')} is not supported yet</error>");
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
$builder->proveLibs([$this->getArgument('library')]);
|
||||
|
||||
// Check whether lib is extracted
|
||||
if (!is_dir(SOURCE_PATH . '/' . $this->getArgument('library'))) {
|
||||
$this->output->writeln("<error>Library {$this->getArgument('library')} is not extracted</error>");
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
$version = $builder->getLib($this->getArgument('library'))->getLibVersion();
|
||||
if ($version === null) {
|
||||
$this->output->writeln("<error>Failed to get version of library {$this->getArgument('library')}</error>");
|
||||
return static::FAILURE;
|
||||
}
|
||||
$this->output->writeln("<info>{$version}</info>");
|
||||
return static::SUCCESS;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user