fix: search under bindir for gcc exe

This commit is contained in:
Amin Yahyaabadi 2024-09-03 14:16:56 -07:00
parent 7cb1fce6d7
commit c2e0936c40
No known key found for this signature in database
GPG Key ID: F52AF77F636088F0
7 changed files with 29 additions and 11 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -3,6 +3,7 @@ import { addEnv, addPath } from "envosman"
import { GITHUB_ACTIONS } from "ci-info" import { GITHUB_ACTIONS } from "ci-info"
import { error, info, warning } from "ci-log" import { error, info, warning } from "ci-log"
import { type ExecaReturnValue, execa } from "execa" import { type ExecaReturnValue, execa } from "execa"
import { readdir } from "fs/promises"
import { pathExists } from "path-exists" import { pathExists } from "path-exists"
import { addExeExt, join } from "patha" import { addExeExt, join } from "patha"
import semverCoerce from "semver/functions/coerce" import semverCoerce from "semver/functions/coerce"
@ -278,13 +279,30 @@ async function activateGcc(givenVersion: string, binDir: string, priority: numbe
async function getGccCmdVersion(binDir: string, givenVersion: string) { async function getGccCmdVersion(binDir: string, givenVersion: string) {
// TODO get the version from the package manager // TODO get the version from the package manager
try { 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 { stdout: versionStdout } = await execa(gccExe, ["--version"], { stdio: "pipe" })
const versionMatch = (versionStdout as string).match(/gcc \(.*\) ([\d.]+)/) 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) { } catch (err) {
error(`Failed to get gcc version: ${err}`) error(`Failed to get gcc version: ${err}`)
return givenVersion return givenVersion