Skip to content

Commit

Permalink
fix: detect default gcc version via cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Sep 3, 2024
1 parent a45740c commit 6cf096c
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 56 deletions.
34 changes: 17 additions & 17 deletions dist/actions/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/actions/setup-cpp.js.map

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions dist/legacy/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js.map

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions dist/modern/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.js.map

Large diffs are not rendered by default.

19 changes: 17 additions & 2 deletions src/gcc/gcc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { addEnv, addPath } from "envosman"

import { GITHUB_ACTIONS } from "ci-info"
import { info, warning } from "ci-log"
import type { ExecaReturnValue } from "execa"
import { type ExecaReturnValue, execa } from "execa"
import { pathExists } from "path-exists"
import { addExeExt, join } from "patha"
import semverCoerce from "semver/functions/coerce"
Expand Down Expand Up @@ -207,7 +207,7 @@ async function setupChocoMingw(version: string, arch: string): Promise<Installat
return undefined
}

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

Expand All @@ -228,6 +228,13 @@ async function activateGcc(version: string, binDir: string, priority: number = 4
addEnv("CXX", addExeExt(`${binDir}/g++`), rcOptions),
)
} else {
// if version is empty, get the version from the gcc command
let version = givenVersion
if (givenVersion === "") {
version = await getGccCmdVersion(binDir, version)
info(`Using gcc version ${version}`)
}

const majorVersion = semverMajor(semverCoerce(version) ?? version)
if (majorVersion >= 5) {
promises.push(
Expand Down Expand Up @@ -269,6 +276,14 @@ async function activateGcc(version: string, binDir: string, priority: number = 4
await Promise.all(promises)
}

async function getGccCmdVersion(binDir: string, givenVersion: string) {
const { stdout: versionStdout } = await execa(`${binDir}/gcc`, ["--version"], { stdio: "pipe" })

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

return versionMatch !== null ? versionMatch[1] : givenVersion
}

async function addGccLoggingMatcher() {
const matcherPath = join(__dirname, "gcc_matcher.json")
if (!(await pathExists(matcherPath))) {
Expand Down

0 comments on commit 6cf096c

Please sign in to comment.