Skip to content

Commit 9ad7147

Browse files
authored
Enhance musl-wrapper and musl-toolchain installation process (#988)
1 parent 106b55d commit 9ad7147

File tree

6 files changed

+31
-10
lines changed

6 files changed

+31
-10
lines changed

src/SPC/builder/linux/SystemUtil.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public static function getSupportedDistros(): array
141141
{
142142
return [
143143
// debian-like
144-
'debian', 'ubuntu', 'Deepin',
144+
'debian', 'ubuntu', 'Deepin', 'neon',
145145
// rhel-like
146146
'redhat',
147147
// centos

src/SPC/doctor/item/LinuxToolCheckList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function checkSystemOSPackages(): ?CheckResult
112112
public function fixBuildTools(array $distro, array $missing): bool
113113
{
114114
$install_cmd = match ($distro['dist']) {
115-
'ubuntu', 'debian', 'Deepin' => 'apt-get install -y',
115+
'ubuntu', 'debian', 'Deepin', 'neon' => 'apt-get install -y',
116116
'alpine' => 'apk add',
117117
'redhat' => 'dnf install -y',
118118
'centos' => 'yum install -y',
@@ -128,7 +128,7 @@ public function fixBuildTools(array $distro, array $missing): bool
128128
logger()->warning('Current user (' . $user . ') is not root, using sudo for running command (may require password input)');
129129
}
130130

131-
$is_debian = in_array($distro['dist'], ['debian', 'ubuntu', 'Deepin']);
131+
$is_debian = in_array($distro['dist'], ['debian', 'ubuntu', 'Deepin', 'neon']);
132132
$to_install = $is_debian ? str_replace('xz', 'xz-utils', $missing) : $missing;
133133
// debian, alpine libtool -> libtoolize
134134
$to_install = str_replace('libtoolize', 'libtool', $to_install);

src/StaticPHP/Artifact/ArtifactDownloader.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,12 @@ private function downloadWithType(Artifact $artifact, int $current, int $total,
397397
$instance = new $call();
398398
$lock = $instance->download($artifact->getName(), $item['config'], $this);
399399
} else {
400-
throw new ValidationException("Artifact has invalid download type '{$item['config']['type']}' for {$item['display']}.");
400+
if ($item['config']['type'] === 'custom') {
401+
$msg = "Artifact [{$artifact->getName()}] has no valid custom " . SystemTarget::getCurrentPlatformString() . ' download callback defined.';
402+
} else {
403+
$msg = "Artifact has invalid download type '{$item['config']['type']}' for {$item['display']}.";
404+
}
405+
throw new ValidationException($msg);
401406
}
402407
if (!$lock instanceof DownloadResult) {
403408
throw new ValidationException("Artifact {$artifact->getName()} has invalid custom return value. Must be instance of DownloadResult.");

src/StaticPHP/Doctor/Doctor.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function checkAll(bool $interactive = true): bool
3434
InteractiveTerm::notice('Starting doctor checks ...');
3535
}
3636
foreach ($this->getValidCheckList() as $check) {
37-
if (!$this->checkItem($check)) {
37+
if (!$this->checkItem($check, $interactive)) {
3838
return false;
3939
}
4040
}
@@ -47,7 +47,7 @@ public function checkAll(bool $interactive = true): bool
4747
* @param CheckItem|string $check The check item to be checked
4848
* @return bool True if the check passed or was fixed, false otherwise
4949
*/
50-
public function checkItem(CheckItem|string $check): bool
50+
public function checkItem(CheckItem|string $check, bool $interactive = true): bool
5151
{
5252
if (is_string($check)) {
5353
$found = null;
@@ -63,7 +63,8 @@ public function checkItem(CheckItem|string $check): bool
6363
}
6464
$check = $found;
6565
}
66-
$this->output?->write("Checking <comment>{$check->item_name}</comment> ... ");
66+
$prepend = $interactive ? ' - ' : '';
67+
$this->output?->write("{$prepend}Checking <comment>{$check->item_name}</comment> ... ");
6768

6869
// call check
6970
$result = call_user_func($check->callback);

src/StaticPHP/Doctor/Item/LinuxMuslCheck.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use StaticPHP\DI\ApplicationContext;
1414
use StaticPHP\Doctor\CheckResult;
1515
use StaticPHP\Runtime\Shell\Shell;
16+
use StaticPHP\Toolchain\Interface\ToolchainInterface;
1617
use StaticPHP\Toolchain\MuslToolchain;
1718
use StaticPHP\Toolchain\ZigToolchain;
1819
use StaticPHP\Util\FileSystem;
@@ -25,8 +26,8 @@ class LinuxMuslCheck
2526
{
2627
public static function optionalCheck(): bool
2728
{
28-
return getenv('SPC_TOOLCHAIN') === MuslToolchain::class ||
29-
(getenv('SPC_TOOLCHAIN') === ZigToolchain::class && !LinuxUtil::isMuslDist());
29+
$toolchain = ApplicationContext::get(ToolchainInterface::class);
30+
return $toolchain instanceof MuslToolchain || $toolchain instanceof ZigToolchain && !LinuxUtil::isMuslDist();
3031
}
3132

3233
/** @noinspection PhpUnused */

src/StaticPHP/Util/System/LinuxUtil.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ class LinuxUtil extends UnixUtil
1313
* Get current linux distro name and version.
1414
*
1515
* @noinspection PhpMissingBreakStatementInspection
16-
* @return array{dist: string, ver: string} Linux distro info (unknown if not found)
16+
* @return array{dist: string, ver: string, family: string} Linux distro info (unknown if not found)
1717
*/
1818
public static function getOSRelease(): array
1919
{
2020
$ret = [
2121
'dist' => 'unknown',
2222
'ver' => 'unknown',
23+
'family' => 'unknown',
2324
];
2425
switch (true) {
2526
case file_exists('/etc/centos-release'):
@@ -44,6 +45,9 @@ public static function getOSRelease(): array
4445
if (preg_match('/^ID=(.*)$/', $line, $matches)) {
4546
$ret['dist'] = $matches[1];
4647
}
48+
if (preg_match('/^ID_LIKE=(.*)$/', $line, $matches)) {
49+
$ret['family'] = $matches[1];
50+
}
4751
if (preg_match('/^VERSION_ID=(.*)$/', $line, $matches)) {
4852
$ret['ver'] = $matches[1];
4953
}
@@ -103,6 +107,16 @@ public static function getSupportedDistros(): array
103107
];
104108
}
105109

110+
/**
111+
* Check if current linux distro is debian-based.
112+
*/
113+
public static function isDebianDist(): bool
114+
{
115+
$dist = static::getOSRelease()['dist'];
116+
$family = explode(' ', static::getOSRelease()['family']);
117+
return in_array($dist, ['debian', 'ubuntu', 'Deepin', 'neon']) || in_array('debian', $family);
118+
}
119+
106120
/**
107121
* Get libc version string from ldd.
108122
*/

0 commit comments

Comments
 (0)