mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 04:44:53 +08:00
move hasCpp to SPCConfigUtil
This commit is contained in:
parent
8b2b658ced
commit
c2813d5736
@ -128,27 +128,6 @@ abstract class BuilderBase
|
||||
return array_filter($this->exts, fn ($ext) => $ext->isBuildStatic());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there is a cpp extensions or libraries.
|
||||
*/
|
||||
public function hasCpp(): bool
|
||||
{
|
||||
// judge cpp-extension
|
||||
$exts = array_keys($this->getExts(false));
|
||||
foreach ($exts as $ext) {
|
||||
if (Config::getExt($ext, 'cpp-extension', false) === true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
$libs = array_keys($this->getLibs());
|
||||
foreach ($libs as $lib) {
|
||||
if (Config::getLib($lib, 'cpp-library', false) === true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set libs only mode.
|
||||
*
|
||||
|
||||
@ -6,6 +6,8 @@ namespace SPC\util;
|
||||
|
||||
use SPC\builder\BuilderBase;
|
||||
use SPC\builder\BuilderProvider;
|
||||
use SPC\builder\Extension;
|
||||
use SPC\builder\LibraryBase;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\store\Config;
|
||||
use Symfony\Component\Console\Input\ArgvInput;
|
||||
@ -87,7 +89,7 @@ class SPCConfigUtil
|
||||
if (SPCTarget::getTargetOS() === 'Darwin') {
|
||||
$libs .= " {$this->getFrameworksString($extensions)}";
|
||||
}
|
||||
if ($this->builder->hasCpp() || collect($extensions)->contains(static fn (string $ext) => Config::getExt($ext)['cpp-extension'] ?? false)) {
|
||||
if ($this->hasCpp($extensions, $libraries)) {
|
||||
$libcpp = SPCTarget::getTargetOS() === 'Darwin' ? '-lc++' : '-lstdc++';
|
||||
$libs = str_replace($libcpp, '', $libs) . " {$libcpp}";
|
||||
}
|
||||
@ -123,6 +125,29 @@ class SPCConfigUtil
|
||||
];
|
||||
}
|
||||
|
||||
private function hasCpp(array $extensions, array $libraries): bool
|
||||
{
|
||||
// judge cpp-extension
|
||||
$builderExtNames = array_keys($this->builder->getExts(false));
|
||||
$extNames = array_map(fn (Extension $x) => $x->getName(), $extensions);
|
||||
$exts = array_unique([...$builderExtNames, ...$extNames]);
|
||||
|
||||
foreach ($exts as $ext) {
|
||||
if (Config::getExt($ext, 'cpp-extension', false) === true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
$builderLibNames = array_keys($this->builder->getLibs());
|
||||
$libNames = array_map(fn (LibraryBase $x) => $x->getName(), $libraries);
|
||||
$libs = array_unique([...$builderLibNames, ...$libNames]);
|
||||
foreach ($libs as $lib) {
|
||||
if (Config::getLib($lib, 'cpp-library', false) === true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function getIncludesString(array $libraries): string
|
||||
{
|
||||
$base = BUILD_INCLUDE_PATH;
|
||||
|
||||
@ -62,12 +62,6 @@ class BuilderTest extends TestCase
|
||||
$this->assertInstanceOf(Extension::class, $this->builder->getExt('mbregex'));
|
||||
}
|
||||
|
||||
public function testHasCpp()
|
||||
{
|
||||
// mbregex doesn't have cpp
|
||||
$this->assertFalse($this->builder->hasCpp());
|
||||
}
|
||||
|
||||
public function testMakeExtensionArgs()
|
||||
{
|
||||
$this->assertStringContainsString('--enable-mbstring', $this->builder->makeStaticExtensionArgs());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user