Refactor Linux and macOS tool checks for improved error handling and command execution (#1025)

This commit is contained in:
Jerry Ma 2026-02-06 21:17:19 +08:00 committed by GitHub
parent 041b08f10f
commit 82bf317911
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 9 deletions

View File

@ -0,0 +1,2 @@
musl-wrapper:
source: 'https://musl.libc.org/releases/musl-1.2.5.tar.gz'

View File

@ -73,10 +73,14 @@ class LinuxMuslCheck
$prefix = 'sudo '; $prefix = 'sudo ';
logger()->warning('Current user is not root, using sudo for running command'); logger()->warning('Current user is not root, using sudo for running command');
} }
shell()->cd(SOURCE_PATH . '/musl-wrapper') $shell = shell()->cd(SOURCE_PATH . '/musl-wrapper')
->exec('CC=gcc CXX=g++ AR=ar LD=ld ./configure --disable-gcc-wrapper') ->exec('CC=gcc CXX=g++ AR=ar LD=ld ./configure --disable-gcc-wrapper')
->exec('CC=gcc CXX=g++ AR=ar LD=ld make -j') ->exec('CC=gcc CXX=g++ AR=ar LD=ld make -j');
->exec("CC=gcc CXX=g++ AR=ar LD=ld {$prefix}make install"); if ($prefix !== '') {
f_passthru('cd ' . SOURCE_PATH . "/musl-wrapper && CC=gcc CXX=g++ AR=ar LD=ld {$prefix}make install");
} else {
$shell->exec("CC=gcc CXX=g++ AR=ar LD=ld {$prefix}make install");
}
return true; return true;
} }
@ -97,7 +101,7 @@ class LinuxMuslCheck
$downloader->add('musl-toolchain')->download(false); $downloader->add('musl-toolchain')->download(false);
$extractor->extract('musl-toolchain'); $extractor->extract('musl-toolchain');
$pkg_root = PKG_ROOT_PATH . '/musl-toolchain'; $pkg_root = PKG_ROOT_PATH . '/musl-toolchain';
shell()->exec("{$prefix}cp -rf {$pkg_root}/* /usr/local/musl"); f_passthru("{$prefix}cp -rf {$pkg_root}/* /usr/local/musl");
FileSystem::removeDir($pkg_root); FileSystem::removeDir($pkg_root);
return true; return true;
} }

View File

@ -71,7 +71,7 @@ class LinuxToolCheck
} }
} }
if (!empty($missing)) { if (!empty($missing)) {
return CheckResult::fail(implode(', ', $missing) . ' not installed on your system', 'install-linux-tools', [$distro, $missing]); return CheckResult::fail(implode(', ', $missing) . ' not installed on your system', 'install-linux-tools', ['distro' => $distro, 'missing' => $missing]);
} }
return CheckResult::ok(); return CheckResult::ok();
} }
@ -96,7 +96,7 @@ class LinuxToolCheck
if (LinuxUtil::isMuslDist()) { if (LinuxUtil::isMuslDist()) {
// check linux-headers installation // check linux-headers installation
if (!file_exists('/usr/include/linux/mman.h')) { if (!file_exists('/usr/include/linux/mman.h')) {
return CheckResult::fail('linux-headers not installed on your system', 'install-linux-tools', [LinuxUtil::getOSRelease(), ['linux-headers']]); return CheckResult::fail('linux-headers not installed on your system', 'install-linux-tools', ['distro' => LinuxUtil::getOSRelease(), 'missing' => ['linux-headers']]);
} }
} }
return CheckResult::ok(); return CheckResult::ok();
@ -137,7 +137,7 @@ class LinuxToolCheck
$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);
shell()->exec($prefix . $install_cmd . ' ' . implode(' ', $to_install)); f_passthru($prefix . $install_cmd . ' ' . implode(' ', $to_install));
return true; return true;
} }

View File

@ -53,7 +53,7 @@ class MacOSToolCheck
} }
} }
if (!empty($missing)) { if (!empty($missing)) {
return CheckResult::fail('missing system commands: ' . implode(', ', $missing), 'build-tools', [$missing]); return CheckResult::fail('missing system commands: ' . implode(', ', $missing), 'build-tools', ['missing' => $missing]);
} }
return CheckResult::ok(); return CheckResult::ok();
} }
@ -63,7 +63,7 @@ class MacOSToolCheck
{ {
// if the bison command is /usr/bin/bison, it is the system bison that may be too old // if the bison command is /usr/bin/bison, it is the system bison that may be too old
if (($bison = MacOSUtil::findCommand('bison', $command_path)) === null) { if (($bison = MacOSUtil::findCommand('bison', $command_path)) === null) {
return CheckResult::fail('bison is not installed or too old', 'build-tools', [['bison']]); return CheckResult::fail('bison is not installed or too old', 'build-tools', ['missing' => ['bison']]);
} }
// check version: bison (GNU Bison) x.y(.z) // check version: bison (GNU Bison) x.y(.z)
$version = shell()->execWithResult("{$bison} --version", false); $version = shell()->execWithResult("{$bison} --version", false);