don't run extra logic in zig-cc script if there's no version string in SPC_TARGET

This commit is contained in:
DubbleClick
2025-07-03 14:46:07 +07:00
parent 3444e308fd
commit e5c5b77a9a
2 changed files with 16 additions and 12 deletions

View File

@@ -28,18 +28,20 @@ done
[[ -n "$SPC_TARGET" ]] && TARGET="-target $SPC_TARGET" || TARGET="" [[ -n "$SPC_TARGET" ]] && TARGET="-target $SPC_TARGET" || TARGET=""
output=$(zig cc $TARGET $COMPILER_EXTRA "${PARSED_ARGS[@]}" 2>&1) if [[ "$SPC_TARGET" =~ \.[0-9]+\.[0-9]+ ]]; then
status=$? output=$(zig cc $TARGET $COMPILER_EXTRA "${PARSED_ARGS[@]}" 2>&1)
status=$?
if [[ $status -eq 0 ]]; then if [[ $status -eq 0 ]]; then
echo "$output" echo "$output"
exit 0 exit 0
fi fi
if echo "$output" | grep -qE "version '.*' in target triple"; then if echo "$output" | grep -qE "version '.*' in target triple"; then
filtered_output=$(echo "$output" | grep -vE "version '.*' in target triple") filtered_output=$(echo "$output" | grep -vE "version '.*' in target triple")
echo "$filtered_output" echo "$filtered_output"
exit 0 exit 0
fi
fi fi
exec zig cc $TARGET $COMPILER_EXTRA "${PARSED_ARGS[@]}" exec zig cc $TARGET $COMPILER_EXTRA "${PARSED_ARGS[@]}"

View File

@@ -7,6 +7,7 @@ namespace SPC\store\source;
use JetBrains\PhpStorm\ArrayShape; use JetBrains\PhpStorm\ArrayShape;
use SPC\exception\DownloaderException; use SPC\exception\DownloaderException;
use SPC\exception\FileSystemException; use SPC\exception\FileSystemException;
use SPC\exception\WrongUsageException;
use SPC\store\Downloader; use SPC\store\Downloader;
class PhpSource extends CustomSourceBase class PhpSource extends CustomSourceBase
@@ -16,11 +17,12 @@ class PhpSource extends CustomSourceBase
/** /**
* @throws DownloaderException * @throws DownloaderException
* @throws FileSystemException * @throws FileSystemException
* @throws WrongUsageException
*/ */
public function fetch(bool $force = false, ?array $config = null, int $lock_as = SPC_DOWNLOAD_SOURCE): void public function fetch(bool $force = false, ?array $config = null, int $lock_as = SPC_DOWNLOAD_SOURCE): void
{ {
$major = defined('SPC_BUILD_PHP_VERSION') ? SPC_BUILD_PHP_VERSION : '8.3'; $major = defined('SPC_BUILD_PHP_VERSION') ? SPC_BUILD_PHP_VERSION : '8.3';
Downloader::downloadSource('php-src', self::getLatestPHPInfo($major), $force); Downloader::downloadSource('php-src', $this->getLatestPHPInfo($major), $force);
} }
/** /**
@@ -34,7 +36,7 @@ class PhpSource extends CustomSourceBase
// 查找最新的小版本号 // 查找最新的小版本号
$info = json_decode(Downloader::curlExec( $info = json_decode(Downloader::curlExec(
url: "https://www.php.net/releases/index.php?json&version={$major_version}", url: "https://www.php.net/releases/index.php?json&version={$major_version}",
retries: intval(getenv('SPC_DOWNLOAD_RETRIES') ?: 0) retries: (int) getenv('SPC_DOWNLOAD_RETRIES')
), true); ), true);
if (!isset($info['version'])) { if (!isset($info['version'])) {
throw new DownloaderException("Version {$major_version} not found."); throw new DownloaderException("Version {$major_version} not found.");