Skip to content

Commit bd9b386

Browse files
committed
fix: fix parsing of gcc version on macos + sort gcc exes
1 parent c2e0936 commit bd9b386

File tree

10 files changed

+47
-36
lines changed

10 files changed

+47
-36
lines changed

dist/actions/setup-cpp.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/actions/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/gcc/gcc.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { type InstallationInfo, type PackageInfo, setupBin } from "../utils/setu
2121
import { setupChocoPack } from "../utils/setup/setupChocoPack.js"
2222
import { setupDnfPack } from "../utils/setup/setupDnfPack.js"
2323
import { setupPacmanPack } from "../utils/setup/setupPacmanPack.js"
24+
import { compareVersion } from "../utils/setup/version.js"
2425

2526
async function getGccPackageInfo(version: string, platform: NodeJS.Platform, arch: string): Promise<PackageInfo> {
2627
switch (platform) {
@@ -284,7 +285,13 @@ async function getGccCmdVersion(binDir: string, givenVersion: string) {
284285
gccExe = `${binDir}/gcc`
285286
} else {
286287
// try to find the gcc exe in the bin dir
287-
const files = await readdir(binDir)
288+
const files = (await readdir(binDir)).sort(
289+
(exe1, exe2) => {
290+
const version1 = exe1.match(/^gcc-?(.*)(\.exe)?$/)?.[1] || ""
291+
const version2 = exe2.match(/^gcc-?(.*)(\.exe)?$/)?.[1] || ""
292+
return compareVersion(version1, version2)
293+
},
294+
)
288295
for (const file of files) {
289296
if (file.startsWith("gcc")) {
290297
gccExe = `${binDir}/${file}`
@@ -295,7 +302,11 @@ async function getGccCmdVersion(binDir: string, givenVersion: string) {
295302

296303
const { stdout: versionStdout } = await execa(gccExe, ["--version"], { stdio: "pipe" })
297304

298-
const versionMatch = (versionStdout as string).match(/gcc \(.*\) ([\d.]+)/)
305+
// gcc-11 (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
306+
// gcc-12 (Homebrew GCC 12.4.0) 12.4.0
307+
// gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0
308+
309+
const versionMatch = (versionStdout as string).match(/gcc.* \(.*\) ([\d.]+)/)
299310

300311
if (versionMatch !== null) {
301312
return versionMatch[1]

src/utils/github/fetch-assets.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Octokit } from "@octokit/rest"
22
import { writeFile } from "fs/promises"
33
import JsonStringify from "safe-stable-stringify"
4-
import { type Assets, compareTag } from "./load-assets.ts"
4+
import { compareVersion } from "../setup/version.ts"
5+
import type { Assets } from "./load-assets.ts"
56

67
/**
78
* Get the list of all releases of a GitHub repository
@@ -70,7 +71,7 @@ export async function saveGitHubAssetList(
7071
const assets = await fetchGitHubAssetList(owner, repo)
7172

7273
const jsonStringify = JsonStringify.configure({
73-
deterministic: compareTag,
74+
deterministic: compareVersion,
7475
})
7576
const data = jsonStringify(assets)
7677

src/utils/github/load-assets.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { readFile } from "fs/promises"
2-
import coerce from "semver/functions/coerce.js"
32

43
/**
54
* The list of assets of a GitHub release
@@ -8,18 +7,6 @@ import coerce from "semver/functions/coerce.js"
87
*/
98
export type Assets = Record<string, string[]>
109

11-
export function compareTag(tag1: string, tag2: string) {
12-
const v1 = coerce(tag1)
13-
const v2 = coerce(tag2)
14-
if (v1 !== null && v2 !== null) {
15-
// put the latest version first
16-
return v2.compare(v1)
17-
}
18-
19-
// if the tags are not semver, compare them as strings, putting the latest tag first
20-
return tag2.localeCompare(tag1)
21-
}
22-
2310
export async function loadGitHubAssetList(path: string): Promise<Assets> {
2411
const data = await readFile(path, "utf-8")
2512
return JSON.parse(data)

src/utils/setup/version.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,15 @@ export function addVPrefix(version: string) {
147147
}
148148
return version
149149
}
150+
151+
export function compareVersion(tag1: string, tag2: string) {
152+
const v1 = semverCoerce(tag1)
153+
const v2 = semverCoerce(tag2)
154+
if (v1 !== null && v2 !== null) {
155+
// put the latest version first
156+
return v2.compare(v1)
157+
}
158+
159+
// if the tags are not semver, compare them as strings, putting the latest tag first
160+
return tag2.localeCompare(tag1)
161+
}

0 commit comments

Comments
 (0)