fix: detect default gcc version via cmd

This commit is contained in:
Amin Yahyaabadi 2024-09-03 04:23:02 -07:00
parent a45740c01f
commit 6cf096c7bf
No known key found for this signature in database
GPG Key ID: F52AF77F636088F0
7 changed files with 71 additions and 56 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

@ -2,7 +2,7 @@ import { addEnv, addPath } from "envosman"
import { GITHUB_ACTIONS } from "ci-info" import { GITHUB_ACTIONS } from "ci-info"
import { info, warning } from "ci-log" import { info, warning } from "ci-log"
import type { ExecaReturnValue } from "execa" import { type ExecaReturnValue, execa } from "execa"
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"
@ -207,7 +207,7 @@ async function setupChocoMingw(version: string, arch: string): Promise<Installat
return undefined 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>>[] = [] const promises: Promise<void | ExecaReturnValue<string>>[] = []
// Setup gcc as the compiler // Setup gcc as the compiler
@ -228,6 +228,13 @@ async function activateGcc(version: string, binDir: string, priority: number = 4
addEnv("CXX", addExeExt(`${binDir}/g++`), rcOptions), addEnv("CXX", addExeExt(`${binDir}/g++`), rcOptions),
) )
} else { } 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) const majorVersion = semverMajor(semverCoerce(version) ?? version)
if (majorVersion >= 5) { if (majorVersion >= 5) {
promises.push( promises.push(
@ -269,6 +276,14 @@ async function activateGcc(version: string, binDir: string, priority: number = 4
await Promise.all(promises) 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() { async function addGccLoggingMatcher() {
const matcherPath = join(__dirname, "gcc_matcher.json") const matcherPath = join(__dirname, "gcc_matcher.json")
if (!(await pathExists(matcherPath))) { if (!(await pathExists(matcherPath))) {