fix: fix parsing of gcc version on macos + sort gcc exes

This commit is contained in:
Amin Yahyaabadi 2024-09-03 14:34:00 -07:00
parent c2e0936c40
commit bd9b386672
No known key found for this signature in database
GPG Key ID: F52AF77F636088F0
10 changed files with 47 additions and 36 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -21,6 +21,7 @@ import { type InstallationInfo, type PackageInfo, setupBin } from "../utils/setu
import { setupChocoPack } from "../utils/setup/setupChocoPack.js" import { setupChocoPack } from "../utils/setup/setupChocoPack.js"
import { setupDnfPack } from "../utils/setup/setupDnfPack.js" import { setupDnfPack } from "../utils/setup/setupDnfPack.js"
import { setupPacmanPack } from "../utils/setup/setupPacmanPack.js" import { setupPacmanPack } from "../utils/setup/setupPacmanPack.js"
import { compareVersion } from "../utils/setup/version.js"
async function getGccPackageInfo(version: string, platform: NodeJS.Platform, arch: string): Promise<PackageInfo> { async function getGccPackageInfo(version: string, platform: NodeJS.Platform, arch: string): Promise<PackageInfo> {
switch (platform) { switch (platform) {
@ -284,7 +285,13 @@ async function getGccCmdVersion(binDir: string, givenVersion: string) {
gccExe = `${binDir}/gcc` gccExe = `${binDir}/gcc`
} else { } else {
// try to find the gcc exe in the bin dir // try to find the gcc exe in the bin dir
const files = await readdir(binDir) const files = (await readdir(binDir)).sort(
(exe1, exe2) => {
const version1 = exe1.match(/^gcc-?(.*)(\.exe)?$/)?.[1] || ""
const version2 = exe2.match(/^gcc-?(.*)(\.exe)?$/)?.[1] || ""
return compareVersion(version1, version2)
},
)
for (const file of files) { for (const file of files) {
if (file.startsWith("gcc")) { if (file.startsWith("gcc")) {
gccExe = `${binDir}/${file}` gccExe = `${binDir}/${file}`
@ -295,7 +302,11 @@ async function getGccCmdVersion(binDir: string, givenVersion: string) {
const { stdout: versionStdout } = await execa(gccExe, ["--version"], { stdio: "pipe" }) const { stdout: versionStdout } = await execa(gccExe, ["--version"], { stdio: "pipe" })
const versionMatch = (versionStdout as string).match(/gcc \(.*\) ([\d.]+)/) // gcc-11 (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
// gcc-12 (Homebrew GCC 12.4.0) 12.4.0
// gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0
const versionMatch = (versionStdout as string).match(/gcc.* \(.*\) ([\d.]+)/)
if (versionMatch !== null) { if (versionMatch !== null) {
return versionMatch[1] return versionMatch[1]

View File

@ -1,7 +1,8 @@
import { Octokit } from "@octokit/rest" import { Octokit } from "@octokit/rest"
import { writeFile } from "fs/promises" import { writeFile } from "fs/promises"
import JsonStringify from "safe-stable-stringify" import JsonStringify from "safe-stable-stringify"
import { type Assets, compareTag } from "./load-assets.ts" import { compareVersion } from "../setup/version.ts"
import type { Assets } from "./load-assets.ts"
/** /**
* Get the list of all releases of a GitHub repository * Get the list of all releases of a GitHub repository
@ -70,7 +71,7 @@ export async function saveGitHubAssetList(
const assets = await fetchGitHubAssetList(owner, repo) const assets = await fetchGitHubAssetList(owner, repo)
const jsonStringify = JsonStringify.configure({ const jsonStringify = JsonStringify.configure({
deterministic: compareTag, deterministic: compareVersion,
}) })
const data = jsonStringify(assets) const data = jsonStringify(assets)

View File

@ -1,5 +1,4 @@
import { readFile } from "fs/promises" import { readFile } from "fs/promises"
import coerce from "semver/functions/coerce.js"
/** /**
* The list of assets of a GitHub release * The list of assets of a GitHub release
@ -8,18 +7,6 @@ import coerce from "semver/functions/coerce.js"
*/ */
export type Assets = Record<string, string[]> export type Assets = Record<string, string[]>
export function compareTag(tag1: string, tag2: string) {
const v1 = coerce(tag1)
const v2 = coerce(tag2)
if (v1 !== null && v2 !== null) {
// put the latest version first
return v2.compare(v1)
}
// if the tags are not semver, compare them as strings, putting the latest tag first
return tag2.localeCompare(tag1)
}
export async function loadGitHubAssetList(path: string): Promise<Assets> { export async function loadGitHubAssetList(path: string): Promise<Assets> {
const data = await readFile(path, "utf-8") const data = await readFile(path, "utf-8")
return JSON.parse(data) return JSON.parse(data)

View File

@ -147,3 +147,15 @@ export function addVPrefix(version: string) {
} }
return version return version
} }
export function compareVersion(tag1: string, tag2: string) {
const v1 = semverCoerce(tag1)
const v2 = semverCoerce(tag2)
if (v1 !== null && v2 !== null) {
// put the latest version first
return v2.compare(v1)
}
// if the tags are not semver, compare them as strings, putting the latest tag first
return tag2.localeCompare(tag1)
}