Skip to content

Commit 6cf096c

Browse files
committed
fix: detect default gcc version via cmd
1 parent a45740c commit 6cf096c

File tree

7 files changed

+71
-56
lines changed

7 files changed

+71
-56
lines changed

dist/actions/setup-cpp.js

Lines changed: 17 additions & 17 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: 17 additions & 17 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: 17 additions & 17 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: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { addEnv, addPath } from "envosman"
22

33
import { GITHUB_ACTIONS } from "ci-info"
44
import { info, warning } from "ci-log"
5-
import type { ExecaReturnValue } from "execa"
5+
import { type ExecaReturnValue, execa } from "execa"
66
import { pathExists } from "path-exists"
77
import { addExeExt, join } from "patha"
88
import semverCoerce from "semver/functions/coerce"
@@ -207,7 +207,7 @@ async function setupChocoMingw(version: string, arch: string): Promise<Installat
207207
return undefined
208208
}
209209

210-
async function activateGcc(version: string, binDir: string, priority: number = 40) {
210+
async function activateGcc(givenVersion: string, binDir: string, priority: number = 40) {
211211
const promises: Promise<void | ExecaReturnValue<string>>[] = []
212212
// Setup gcc as the compiler
213213

@@ -228,6 +228,13 @@ async function activateGcc(version: string, binDir: string, priority: number = 4
228228
addEnv("CXX", addExeExt(`${binDir}/g++`), rcOptions),
229229
)
230230
} else {
231+
// if version is empty, get the version from the gcc command
232+
let version = givenVersion
233+
if (givenVersion === "") {
234+
version = await getGccCmdVersion(binDir, version)
235+
info(`Using gcc version ${version}`)
236+
}
237+
231238
const majorVersion = semverMajor(semverCoerce(version) ?? version)
232239
if (majorVersion >= 5) {
233240
promises.push(
@@ -269,6 +276,14 @@ async function activateGcc(version: string, binDir: string, priority: number = 4
269276
await Promise.all(promises)
270277
}
271278

279+
async function getGccCmdVersion(binDir: string, givenVersion: string) {
280+
const { stdout: versionStdout } = await execa(`${binDir}/gcc`, ["--version"], { stdio: "pipe" })
281+
282+
const versionMatch = (versionStdout as string).match(/gcc \(.*\) ([\d.]+)/)
283+
284+
return versionMatch !== null ? versionMatch[1] : givenVersion
285+
}
286+
272287
async function addGccLoggingMatcher() {
273288
const matcherPath = join(__dirname, "gcc_matcher.json")
274289
if (!(await pathExists(matcherPath))) {

0 commit comments

Comments
 (0)