Skip to content

Commit 7cb1fce

Browse files
committed
fix: more robust version getting from gcc cmd
1 parent 4e9255b commit 7cb1fce

File tree

8 files changed

+22
-15
lines changed

8 files changed

+22
-15
lines changed

dist/actions/setup-cpp.js

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/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: 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.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: 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.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.

packages/setup-brew/src/install-pack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { join } from "path"
22
import { info } from "ci-log"
3-
/* eslint-disable require-atomic-updates */
43
import { execaSync } from "execa"
54
import which from "which"
65
import type { InstallationInfo } from "./InstallationInfo.js"
76
import { getBrewBinDir, setupBrew } from "./install.js"
87

8+
/* eslint-disable require-atomic-updates */
99
let hasBrew = false
1010

1111
export type BrewPackOptions = {

src/gcc/gcc.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { addEnv, addPath } from "envosman"
22

33
import { GITHUB_ACTIONS } from "ci-info"
4-
import { info, warning } from "ci-log"
4+
import { error, info, warning } from "ci-log"
55
import { type ExecaReturnValue, execa } from "execa"
66
import { pathExists } from "path-exists"
77
import { addExeExt, join } from "patha"
@@ -53,7 +53,6 @@ async function getGccPackageInfo(version: string, platform: NodeJS.Platform, arc
5353
}
5454
}
5555

56-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
5756
export async function setupGcc(version: string, setupDir: string, arch: string, priority: number = 40) {
5857
let installationInfo: InstallationInfo | undefined
5958
switch (process.platform) {
@@ -108,14 +107,14 @@ export async function setupGcc(version: string, setupDir: string, arch: string,
108107
} else {
109108
info(`Install g++-multilib because gcc for ${arch} was requested`)
110109
if (isArch()) {
111-
await setupPacmanPack("gcc-multilib", version)
110+
installationInfo = await setupPacmanPack("gcc-multilib", version)
112111
} else if (isUbuntu()) {
113112
if (version === "") {
114113
// the default version
115-
await installAptPack([{ name: "gcc-multilib" }])
114+
installationInfo = await installAptPack([{ name: "gcc-multilib" }])
116115
} else {
117116
// add the PPA for access to more versions
118-
await installAptPack([{
117+
installationInfo = await installAptPack([{
119118
name: "gcc-multilib",
120119
version,
121120
repository: "ppa:ubuntu-toolchain-r/test",
@@ -277,11 +276,19 @@ async function activateGcc(givenVersion: string, binDir: string, priority: numbe
277276
}
278277

279278
async function getGccCmdVersion(binDir: string, givenVersion: string) {
280-
const { stdout: versionStdout } = await execa(`${binDir}/gcc`, ["--version"], { stdio: "pipe" })
279+
// TODO get the version from the package manager
280+
try {
281+
const gccExe = await pathExists(`${binDir}/gcc`) ? `${binDir}/gcc` : "gcc"
282+
283+
const { stdout: versionStdout } = await execa(gccExe, ["--version"], { stdio: "pipe" })
281284

282-
const versionMatch = (versionStdout as string).match(/gcc \(.*\) ([\d.]+)/)
285+
const versionMatch = (versionStdout as string).match(/gcc \(.*\) ([\d.]+)/)
283286

284-
return versionMatch !== null ? versionMatch[1] : givenVersion
287+
return versionMatch !== null ? versionMatch[1] : givenVersion
288+
} catch (err) {
289+
error(`Failed to get gcc version: ${err}`)
290+
return givenVersion
291+
}
285292
}
286293

287294
async function addGccLoggingMatcher() {

0 commit comments

Comments
 (0)