Enhance musl-wrapper and musl-toolchain installation process (#988)

This commit is contained in:
Jerry Ma
2025-12-06 16:50:36 +08:00
committed by GitHub
parent 106b55d4e7
commit 9ad7147155
6 changed files with 31 additions and 10 deletions

View File

@@ -141,7 +141,7 @@ class SystemUtil
{ {
return [ return [
// debian-like // debian-like
'debian', 'ubuntu', 'Deepin', 'debian', 'ubuntu', 'Deepin', 'neon',
// rhel-like // rhel-like
'redhat', 'redhat',
// centos // centos

View File

@@ -112,7 +112,7 @@ class LinuxToolCheckList
public function fixBuildTools(array $distro, array $missing): bool public function fixBuildTools(array $distro, array $missing): bool
{ {
$install_cmd = match ($distro['dist']) { $install_cmd = match ($distro['dist']) {
'ubuntu', 'debian', 'Deepin' => 'apt-get install -y', 'ubuntu', 'debian', 'Deepin', 'neon' => 'apt-get install -y',
'alpine' => 'apk add', 'alpine' => 'apk add',
'redhat' => 'dnf install -y', 'redhat' => 'dnf install -y',
'centos' => 'yum install -y', 'centos' => 'yum install -y',
@@ -128,7 +128,7 @@ class LinuxToolCheckList
logger()->warning('Current user (' . $user . ') is not root, using sudo for running command (may require password input)'); logger()->warning('Current user (' . $user . ') is not root, using sudo for running command (may require password input)');
} }
$is_debian = in_array($distro['dist'], ['debian', 'ubuntu', 'Deepin']); $is_debian = in_array($distro['dist'], ['debian', 'ubuntu', 'Deepin', 'neon']);
$to_install = $is_debian ? str_replace('xz', 'xz-utils', $missing) : $missing; $to_install = $is_debian ? str_replace('xz', 'xz-utils', $missing) : $missing;
// debian, alpine libtool -> libtoolize // debian, alpine libtool -> libtoolize
$to_install = str_replace('libtoolize', 'libtool', $to_install); $to_install = str_replace('libtoolize', 'libtool', $to_install);

View File

@@ -397,7 +397,12 @@ class ArtifactDownloader
$instance = new $call(); $instance = new $call();
$lock = $instance->download($artifact->getName(), $item['config'], $this); $lock = $instance->download($artifact->getName(), $item['config'], $this);
} else { } else {
throw new ValidationException("Artifact has invalid download type '{$item['config']['type']}' for {$item['display']}."); if ($item['config']['type'] === 'custom') {
$msg = "Artifact [{$artifact->getName()}] has no valid custom " . SystemTarget::getCurrentPlatformString() . ' download callback defined.';
} else {
$msg = "Artifact has invalid download type '{$item['config']['type']}' for {$item['display']}.";
}
throw new ValidationException($msg);
} }
if (!$lock instanceof DownloadResult) { if (!$lock instanceof DownloadResult) {
throw new ValidationException("Artifact {$artifact->getName()} has invalid custom return value. Must be instance of DownloadResult."); throw new ValidationException("Artifact {$artifact->getName()} has invalid custom return value. Must be instance of DownloadResult.");

View File

@@ -34,7 +34,7 @@ readonly class Doctor
InteractiveTerm::notice('Starting doctor checks ...'); InteractiveTerm::notice('Starting doctor checks ...');
} }
foreach ($this->getValidCheckList() as $check) { foreach ($this->getValidCheckList() as $check) {
if (!$this->checkItem($check)) { if (!$this->checkItem($check, $interactive)) {
return false; return false;
} }
} }
@@ -47,7 +47,7 @@ readonly class Doctor
* @param CheckItem|string $check The check item to be checked * @param CheckItem|string $check The check item to be checked
* @return bool True if the check passed or was fixed, false otherwise * @return bool True if the check passed or was fixed, false otherwise
*/ */
public function checkItem(CheckItem|string $check): bool public function checkItem(CheckItem|string $check, bool $interactive = true): bool
{ {
if (is_string($check)) { if (is_string($check)) {
$found = null; $found = null;
@@ -63,7 +63,8 @@ readonly class Doctor
} }
$check = $found; $check = $found;
} }
$this->output?->write("Checking <comment>{$check->item_name}</comment> ... "); $prepend = $interactive ? ' - ' : '';
$this->output?->write("{$prepend}Checking <comment>{$check->item_name}</comment> ... ");
// call check // call check
$result = call_user_func($check->callback); $result = call_user_func($check->callback);

View File

@@ -13,6 +13,7 @@ use StaticPHP\Attribute\Doctor\OptionalCheck;
use StaticPHP\DI\ApplicationContext; use StaticPHP\DI\ApplicationContext;
use StaticPHP\Doctor\CheckResult; use StaticPHP\Doctor\CheckResult;
use StaticPHP\Runtime\Shell\Shell; use StaticPHP\Runtime\Shell\Shell;
use StaticPHP\Toolchain\Interface\ToolchainInterface;
use StaticPHP\Toolchain\MuslToolchain; use StaticPHP\Toolchain\MuslToolchain;
use StaticPHP\Toolchain\ZigToolchain; use StaticPHP\Toolchain\ZigToolchain;
use StaticPHP\Util\FileSystem; use StaticPHP\Util\FileSystem;
@@ -25,8 +26,8 @@ class LinuxMuslCheck
{ {
public static function optionalCheck(): bool public static function optionalCheck(): bool
{ {
return getenv('SPC_TOOLCHAIN') === MuslToolchain::class || $toolchain = ApplicationContext::get(ToolchainInterface::class);
(getenv('SPC_TOOLCHAIN') === ZigToolchain::class && !LinuxUtil::isMuslDist()); return $toolchain instanceof MuslToolchain || $toolchain instanceof ZigToolchain && !LinuxUtil::isMuslDist();
} }
/** @noinspection PhpUnused */ /** @noinspection PhpUnused */

View File

@@ -13,13 +13,14 @@ class LinuxUtil extends UnixUtil
* Get current linux distro name and version. * Get current linux distro name and version.
* *
* @noinspection PhpMissingBreakStatementInspection * @noinspection PhpMissingBreakStatementInspection
* @return array{dist: string, ver: string} Linux distro info (unknown if not found) * @return array{dist: string, ver: string, family: string} Linux distro info (unknown if not found)
*/ */
public static function getOSRelease(): array public static function getOSRelease(): array
{ {
$ret = [ $ret = [
'dist' => 'unknown', 'dist' => 'unknown',
'ver' => 'unknown', 'ver' => 'unknown',
'family' => 'unknown',
]; ];
switch (true) { switch (true) {
case file_exists('/etc/centos-release'): case file_exists('/etc/centos-release'):
@@ -44,6 +45,9 @@ class LinuxUtil extends UnixUtil
if (preg_match('/^ID=(.*)$/', $line, $matches)) { if (preg_match('/^ID=(.*)$/', $line, $matches)) {
$ret['dist'] = $matches[1]; $ret['dist'] = $matches[1];
} }
if (preg_match('/^ID_LIKE=(.*)$/', $line, $matches)) {
$ret['family'] = $matches[1];
}
if (preg_match('/^VERSION_ID=(.*)$/', $line, $matches)) { if (preg_match('/^VERSION_ID=(.*)$/', $line, $matches)) {
$ret['ver'] = $matches[1]; $ret['ver'] = $matches[1];
} }
@@ -103,6 +107,16 @@ class LinuxUtil extends UnixUtil
]; ];
} }
/**
* Check if current linux distro is debian-based.
*/
public static function isDebianDist(): bool
{
$dist = static::getOSRelease()['dist'];
$family = explode(' ', static::getOSRelease()['family']);
return in_array($dist, ['debian', 'ubuntu', 'Deepin', 'neon']) || in_array('debian', $family);
}
/** /**
* Get libc version string from ldd. * Get libc version string from ldd.
*/ */