Skip to content

Commit

Permalink
fix: search under bindir for gcc exe
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Sep 3, 2024
1 parent 7cb1fce commit c2e0936
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 11 deletions.
4 changes: 2 additions & 2 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.

4 changes: 2 additions & 2 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.

4 changes: 2 additions & 2 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.

22 changes: 20 additions & 2 deletions src/gcc/gcc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { addEnv, addPath } from "envosman"
import { GITHUB_ACTIONS } from "ci-info"
import { error, info, warning } from "ci-log"
import { type ExecaReturnValue, execa } from "execa"
import { readdir } from "fs/promises"
import { pathExists } from "path-exists"
import { addExeExt, join } from "patha"
import semverCoerce from "semver/functions/coerce"
Expand Down Expand Up @@ -278,13 +279,30 @@ async function activateGcc(givenVersion: string, binDir: string, priority: numbe
async function getGccCmdVersion(binDir: string, givenVersion: string) {
// TODO get the version from the package manager
try {
const gccExe = await pathExists(`${binDir}/gcc`) ? `${binDir}/gcc` : "gcc"
let gccExe = "gcc"
if (await pathExists(`${binDir}/gcc`)) {
gccExe = `${binDir}/gcc`
} else {
// try to find the gcc exe in the bin dir
const files = await readdir(binDir)
for (const file of files) {
if (file.startsWith("gcc")) {
gccExe = `${binDir}/${file}`
break
}
}
}

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

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

return versionMatch !== null ? versionMatch[1] : givenVersion
if (versionMatch !== null) {
return versionMatch[1]
}

warning(`Failed to parse gcc version from: ${versionStdout}`)
return givenVersion
} catch (err) {
error(`Failed to get gcc version: ${err}`)
return givenVersion
Expand Down

0 comments on commit c2e0936

Please sign in to comment.