Merge remote-tracking branch 'origin/v3-refactor/libs' into v3-refactor/libs

This commit is contained in:
crazywhalecc
2026-02-02 09:59:17 +08:00
11 changed files with 271 additions and 12 deletions

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace StaticPHP\DI;
use DI\Container;
use StaticPHP\Exception\SkipException;
use StaticPHP\Exception\SPCInternalException;
/**
@@ -92,7 +93,12 @@ readonly class CallbackInvoker
);
}
return $callback(...$args);
try {
return $callback(...$args);
} catch (SkipException $e) {
logger()->debug("Skipped invocation: {$e->getMessage()}");
return null;
}
}
/**

View File

@@ -0,0 +1,7 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Exception;
class SkipException extends SPCException {}

View File

@@ -7,6 +7,7 @@ namespace StaticPHP\Package;
use StaticPHP\Config\PackageConfig;
use StaticPHP\Exception\PatchException;
use StaticPHP\Util\FileSystem;
use StaticPHP\Util\SPCConfigUtil;
/**
* Represents a library package with platform-specific build functions.
@@ -159,6 +160,16 @@ class LibraryPackage extends Package
}
}
/**
* Get static library files for current package and its dependencies.
*/
public function getStaticLibFiles(): string
{
$config = new SPCConfigUtil(['libs_only_deps' => true, 'absolute_libs' => true]);
$res = $config->config([$this->getName()]);
return $res['libs'];
}
/**
* Get extra LIBS for current package.
* You need to define the environment variable in the format of {LIBRARY_NAME}_LIBS

View File

@@ -135,6 +135,22 @@ abstract class Package
return isset($this->build_functions[PHP_OS_FAMILY]);
}
/**
* Get the PackageBuilder instance for this package.
*/
public function getBuilder(): PackageBuilder
{
return ApplicationContext::get(PackageBuilder::class);
}
/**
* Get the PackageInstaller instance for this package.
*/
public function getInstaller(): PackageInstaller
{
return ApplicationContext::get(PackageInstaller::class);
}
/**
* Get the name of the package.
*/

View File

@@ -402,11 +402,64 @@ class PackageInstaller
return SPC_STATUS_INSTALLED;
}
/**
* @internal internally calling only, for users, please use specific getter, such as 'getLibraryPackage', 'getTaretPackage', etc
* @param string $package_name Package name
*/
public function getPackage(string $package_name): ?Package
{
return $this->packages[$package_name] ?? null;
}
/**
* Get a library package by name.
*
* @param string $package_name Package name
* @return null|LibraryPackage The library package instance or null if not found
*/
public function getLibraryPackage(string $package_name): ?LibraryPackage
{
$pkg = $this->getPackage($package_name);
if ($pkg instanceof LibraryPackage) {
return $pkg;
}
return null;
}
/**
* Get a target package by name.
*
* @param string $package_name Package name
* @return null|TargetPackage The target package instance or null if not found
*/
public function getTargetPackage(string $package_name): ?TargetPackage
{
$pkg = $this->getPackage($package_name);
if ($pkg instanceof TargetPackage) {
return $pkg;
}
return null;
}
/**
* Get a PHP extension by name.
*
* @param string $package_or_ext_name Extension name
* @return null|PhpExtensionPackage The target package instance or null if not found
*/
public function getPhpExtensionPackage(string $package_or_ext_name): ?PhpExtensionPackage
{
$pkg = $this->getPackage($package_or_ext_name);
if ($pkg instanceof PhpExtensionPackage) {
return $pkg;
}
$pkg = $this->getPackage("ext-{$package_or_ext_name}");
if ($pkg instanceof PhpExtensionPackage) {
return $pkg;
}
return null;
}
/**
* Validate that a package has required artifacts.
*/

View File

@@ -209,18 +209,21 @@ class SPCConfigUtil
$frameworks = [];
foreach ($packages as $package) {
// add pkg-configs libs
$pkg_configs = PackageConfig::get($package, 'pkg-configs', []);
foreach ($pkg_configs as $pkg_config) {
if (!file_exists(BUILD_LIB_PATH . "/pkgconfig/{$pkg_config}.pc")) {
throw new WrongUsageException("pkg-config file '{$pkg_config}.pc' for lib [{$package}] does not exist in '" . BUILD_LIB_PATH . "/pkgconfig'. Please build it first.");
// parse pkg-configs only for unix systems
if (SystemTarget::isUnix()) {
// add pkg-configs libs
$pkg_configs = PackageConfig::get($package, 'pkg-configs', []);
foreach ($pkg_configs as $pkg_config) {
if (!file_exists(BUILD_LIB_PATH . "/pkgconfig/{$pkg_config}.pc")) {
throw new WrongUsageException("pkg-config file '{$pkg_config}.pc' for lib [{$package}] does not exist in '" . BUILD_LIB_PATH . "/pkgconfig'. Please build it first.");
}
}
$pkg_configs = implode(' ', $pkg_configs);
if ($pkg_configs !== '') {
// static libs with dependencies come in reverse order, so reverse this too
$pc_libs = array_reverse(PkgConfigUtil::getLibsArray($pkg_configs));
$lib_names = [...$lib_names, ...$pc_libs];
}
}
$pkg_configs = implode(' ', $pkg_configs);
if ($pkg_configs !== '') {
// static libs with dependencies come in reverse order, so reverse this too
$pc_libs = array_reverse(PkgConfigUtil::getLibsArray($pkg_configs));
$lib_names = [...$lib_names, ...$pc_libs];
}
// convert all static-libs to short names
$libs = array_reverse(PackageConfig::get($package, 'static-libs', []));