mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-08 01:06:09 +08:00
refactor: restructure tool target configs into tool package system
- Move tool configs from config/pkg/target/ to config/pkg/tool/ - Add ToolVersionRegistry for tracking installed tool versions - Delete old Target/pkgconfig.php, move to tool config - Rename: 7za-win, go-win, go-xcaddy, jom, nasm, protoc, strawberry-perl, upx, vswhere, zig, pkg-config
This commit is contained in:
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Package\Target;
|
||||
|
||||
use StaticPHP\Attribute\Package\BuildFor;
|
||||
use StaticPHP\Attribute\Package\InitPackage;
|
||||
use StaticPHP\Attribute\Package\Target;
|
||||
use StaticPHP\DI\ApplicationContext;
|
||||
use StaticPHP\Package\TargetPackage;
|
||||
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
|
||||
use StaticPHP\Toolchain\Interface\ToolchainInterface;
|
||||
|
||||
#[Target('pkg-config')]
|
||||
class pkgconfig
|
||||
{
|
||||
#[InitPackage]
|
||||
public function resolveBuild(): void
|
||||
{
|
||||
ApplicationContext::set('elephant', true);
|
||||
}
|
||||
|
||||
#[BuildFor('Linux')]
|
||||
#[BuildFor('Darwin')]
|
||||
public function build(TargetPackage $package, ToolchainInterface $toolchain): void
|
||||
{
|
||||
UnixAutoconfExecutor::create($package)
|
||||
->appendEnv([
|
||||
'CFLAGS' => '-Wimplicit-function-declaration -Wno-int-conversion',
|
||||
'LDFLAGS' => $toolchain->isStatic() ? '--static' : '',
|
||||
])
|
||||
->configure(
|
||||
'--with-internal-glib',
|
||||
'--disable-host-tool',
|
||||
'--without-sysroot',
|
||||
'--without-system-include-path',
|
||||
'--without-system-library-path',
|
||||
'--without-pc-path',
|
||||
)
|
||||
->make(with_install: 'install-exec');
|
||||
|
||||
shell()->exec("strip {$package->getBinDir()}/pkg-config");
|
||||
}
|
||||
}
|
||||
79
src/StaticPHP/Package/ToolVersionRegistry.php
Normal file
79
src/StaticPHP/Package/ToolVersionRegistry.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Package;
|
||||
|
||||
use StaticPHP\Runtime\SystemTarget;
|
||||
|
||||
/**
|
||||
* Tracks the version actually installed on disk for tool packages (PKG_ROOT_PATH), separate from
|
||||
* the download cache (ArtifactCache). Tools are installed once and reused across many builds, so
|
||||
* the download cache (which only reflects the last download) can drift from what's really on disk
|
||||
* (e.g. cache cleared, or installed a long time ago via `doctor`). This registry is the source of
|
||||
* truth for "what version is currently installed", used by ToolPackage::getInstalledVersion() and
|
||||
* the `check-update --installed` flag.
|
||||
*
|
||||
* Backed by a small JSON file at PKG_ROOT_PATH/.spc-tool-versions.json, mirroring the same
|
||||
* read-once/write-through pattern used by StaticPHP\Artifact\ArtifactCache.
|
||||
*/
|
||||
class ToolVersionRegistry
|
||||
{
|
||||
/** @var null|array<string, array{version: null|string, platform: string, installed_at: string}> */
|
||||
private static ?array $data = null;
|
||||
|
||||
/**
|
||||
* Get the recorded installed version for a tool, or null if never recorded (not a tool
|
||||
* package, not installed yet, or the artifact doesn't expose a version).
|
||||
*/
|
||||
public static function get(string $tool_name): ?string
|
||||
{
|
||||
self::load();
|
||||
return self::$data[$tool_name]['version'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Record the version currently installed for a tool. Called after a tool package's binary
|
||||
* has been (re-)installed, regardless of whether extraction actually ran (keeps the registry
|
||||
* self-healing if it was deleted separately from the installed files).
|
||||
*/
|
||||
public static function record(string $tool_name, ?string $version): void
|
||||
{
|
||||
self::load();
|
||||
self::$data[$tool_name] = [
|
||||
'version' => $version,
|
||||
'platform' => SystemTarget::getCurrentPlatformString(),
|
||||
'installed_at' => date('c'),
|
||||
];
|
||||
self::save();
|
||||
}
|
||||
|
||||
private static function getPath(): string
|
||||
{
|
||||
return PKG_ROOT_PATH . '/.spc-tool-versions.json';
|
||||
}
|
||||
|
||||
private static function load(): void
|
||||
{
|
||||
if (self::$data !== null) {
|
||||
return;
|
||||
}
|
||||
$path = self::getPath();
|
||||
if (!file_exists($path)) {
|
||||
self::$data = [];
|
||||
return;
|
||||
}
|
||||
$content = file_get_contents($path);
|
||||
self::$data = is_string($content) ? (json_decode($content, true) ?: []) : [];
|
||||
}
|
||||
|
||||
private static function save(): void
|
||||
{
|
||||
$path = self::getPath();
|
||||
$dir = dirname($path);
|
||||
if (!is_dir($dir)) {
|
||||
@mkdir($dir, 0755, true);
|
||||
}
|
||||
file_put_contents($path, json_encode(self::$data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user