Refactor package resolution to filter only available build artifacts

This commit is contained in:
crazywhalecc
2026-04-06 13:13:45 +08:00
parent 991da260ba
commit f8d24e2b3a
7 changed files with 1410 additions and 1385 deletions

View File

@@ -301,6 +301,32 @@ class PackageInstaller
return isset($this->packages[$package_name]);
}
/**
* Get resolved package names filtered to only packages whose build artifacts are available.
* This excludes library packages that haven't been built/installed yet, which naturally
* prevents SPCConfigUtil from checking static-lib files of libraries that come after
* the current target in the build order (e.g. 'watcher' for frankenphp isn't built
* when 'php' is being compiled).
*
* @return string[] Available resolved package names
*/
public function getAvailableResolvedPackageNames(): array
{
return array_values(array_filter(
array_keys($this->packages),
function (string $name): bool {
$pkg = $this->packages[$name] ?? null;
// Exclude library packages whose build artifacts don't exist yet.
// Extensions and targets are not filtered — extensions are compiled into PHP
// and don't have standalone build artifacts.
if ($pkg instanceof LibraryPackage && $pkg->getType() === 'library' && !$pkg->isInstalled()) {
return false;
}
return true;
}
));
}
public function isPackageInstalled(Package|string $package_name): bool
{
if (empty($this->packages)) {

View File

@@ -1,64 +1,64 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Runtime\Shell;
use StaticPHP\Exception\SPCInternalException;
use ZM\Logger\ConsoleColor;
class WindowsCmd extends Shell
{
public function __construct(?bool $debug = null)
{
if (PHP_OS_FAMILY !== 'Windows') {
throw new SPCInternalException('Only windows can use WindowsCmd');
}
parent::__construct($debug);
}
public function exec(string $cmd): static
{
/* @phpstan-ignore-next-line */
logger()->info(ConsoleColor::yellow('[EXEC] ') . ConsoleColor::green($cmd));
$original_command = $cmd;
$this->logCommandInfo($original_command);
$this->last_cmd = $cmd = $this->getExecString($cmd);
// echo $cmd . PHP_EOL;
$this->passthru($cmd, $this->console_putput, $original_command, cwd: $this->cd);
return $this;
}
public function execWithWrapper(string $wrapper, string $args): WindowsCmd
{
return $this->exec($wrapper . ' "' . str_replace('"', '^"', $args) . '"');
}
public function execWithResult(string $cmd, bool $with_log = true): array
{
if ($with_log) {
/* @phpstan-ignore-next-line */
logger()->info(ConsoleColor::blue('[EXEC] ') . ConsoleColor::green($cmd));
} else {
logger()->debug('Running command with result: ' . $cmd);
}
$original_command = $cmd;
$this->logCommandInfo($original_command);
$cmd = $this->getExecString($cmd);
$result = $this->passthru($cmd, $this->console_putput, $original_command, capture_output: true, throw_on_error: false, cwd: $this->cd, env: $this->env);
$out = explode("\n", $result['output']);
return [$result['code'], $out];
}
public function getLastCommand(): string
{
return $this->last_cmd;
}
private function getExecString(string $cmd): string
{
return $cmd;
}
}
<?php
declare(strict_types=1);
namespace StaticPHP\Runtime\Shell;
use StaticPHP\Exception\SPCInternalException;
use ZM\Logger\ConsoleColor;
class WindowsCmd extends Shell
{
public function __construct(?bool $debug = null)
{
if (PHP_OS_FAMILY !== 'Windows') {
throw new SPCInternalException('Only windows can use WindowsCmd');
}
parent::__construct($debug);
}
public function exec(string $cmd): static
{
/* @phpstan-ignore-next-line */
logger()->info(ConsoleColor::yellow('[EXEC] ') . ConsoleColor::green($cmd));
$original_command = $cmd;
$this->logCommandInfo($original_command);
$this->last_cmd = $cmd = $this->getExecString($cmd);
// echo $cmd . PHP_EOL;
$this->passthru($cmd, $this->console_putput, $original_command, cwd: $this->cd);
return $this;
}
public function execWithWrapper(string $wrapper, string $args): WindowsCmd
{
return $this->exec($wrapper . ' "' . str_replace('"', '^"', $args) . '"');
}
public function execWithResult(string $cmd, bool $with_log = true): array
{
if ($with_log) {
/* @phpstan-ignore-next-line */
logger()->info(ConsoleColor::blue('[EXEC] ') . ConsoleColor::green($cmd));
} else {
logger()->debug('Running command with result: ' . $cmd);
}
$original_command = $cmd;
$this->logCommandInfo($original_command);
$cmd = $this->getExecString($cmd);
$result = $this->passthru($cmd, $this->console_putput, $original_command, capture_output: true, throw_on_error: false, cwd: $this->cd, env: $this->env);
$out = explode("\n", $result['output']);
return [$result['code'], $out];
}
public function getLastCommand(): string
{
return $this->last_cmd;
}
private function getExecString(string $cmd): string
{
return $cmd;
}
}

File diff suppressed because it is too large Load Diff