mirror of https://github.com/aminya/setup-cpp
fix: more robust version getting from gcc cmd
This commit is contained in:
parent
4e9255bbdf
commit
7cb1fce6d7
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
|
@ -1,11 +1,11 @@
|
||||||
import { join } from "path"
|
import { join } from "path"
|
||||||
import { info } from "ci-log"
|
import { info } from "ci-log"
|
||||||
/* eslint-disable require-atomic-updates */
|
|
||||||
import { execaSync } from "execa"
|
import { execaSync } from "execa"
|
||||||
import which from "which"
|
import which from "which"
|
||||||
import type { InstallationInfo } from "./InstallationInfo.js"
|
import type { InstallationInfo } from "./InstallationInfo.js"
|
||||||
import { getBrewBinDir, setupBrew } from "./install.js"
|
import { getBrewBinDir, setupBrew } from "./install.js"
|
||||||
|
|
||||||
|
/* eslint-disable require-atomic-updates */
|
||||||
let hasBrew = false
|
let hasBrew = false
|
||||||
|
|
||||||
export type BrewPackOptions = {
|
export type BrewPackOptions = {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { addEnv, addPath } from "envosman"
|
import { addEnv, addPath } from "envosman"
|
||||||
|
|
||||||
import { GITHUB_ACTIONS } from "ci-info"
|
import { GITHUB_ACTIONS } from "ci-info"
|
||||||
import { 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 { pathExists } from "path-exists"
|
import { pathExists } from "path-exists"
|
||||||
import { addExeExt, join } from "patha"
|
import { addExeExt, join } from "patha"
|
||||||
|
@ -53,7 +53,6 @@ async function getGccPackageInfo(version: string, platform: NodeJS.Platform, arc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
export async function setupGcc(version: string, setupDir: string, arch: string, priority: number = 40) {
|
export async function setupGcc(version: string, setupDir: string, arch: string, priority: number = 40) {
|
||||||
let installationInfo: InstallationInfo | undefined
|
let installationInfo: InstallationInfo | undefined
|
||||||
switch (process.platform) {
|
switch (process.platform) {
|
||||||
|
@ -108,14 +107,14 @@ export async function setupGcc(version: string, setupDir: string, arch: string,
|
||||||
} else {
|
} else {
|
||||||
info(`Install g++-multilib because gcc for ${arch} was requested`)
|
info(`Install g++-multilib because gcc for ${arch} was requested`)
|
||||||
if (isArch()) {
|
if (isArch()) {
|
||||||
await setupPacmanPack("gcc-multilib", version)
|
installationInfo = await setupPacmanPack("gcc-multilib", version)
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
if (version === "") {
|
if (version === "") {
|
||||||
// the default version
|
// the default version
|
||||||
await installAptPack([{ name: "gcc-multilib" }])
|
installationInfo = await installAptPack([{ name: "gcc-multilib" }])
|
||||||
} else {
|
} else {
|
||||||
// add the PPA for access to more versions
|
// add the PPA for access to more versions
|
||||||
await installAptPack([{
|
installationInfo = await installAptPack([{
|
||||||
name: "gcc-multilib",
|
name: "gcc-multilib",
|
||||||
version,
|
version,
|
||||||
repository: "ppa:ubuntu-toolchain-r/test",
|
repository: "ppa:ubuntu-toolchain-r/test",
|
||||||
|
@ -277,11 +276,19 @@ async function activateGcc(givenVersion: string, binDir: string, priority: numbe
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getGccCmdVersion(binDir: string, givenVersion: string) {
|
async function getGccCmdVersion(binDir: string, givenVersion: string) {
|
||||||
const { stdout: versionStdout } = await execa(`${binDir}/gcc`, ["--version"], { stdio: "pipe" })
|
// TODO get the version from the package manager
|
||||||
|
try {
|
||||||
|
const gccExe = await pathExists(`${binDir}/gcc`) ? `${binDir}/gcc` : "gcc"
|
||||||
|
|
||||||
|
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
|
return versionMatch !== null ? versionMatch[1] : givenVersion
|
||||||
|
} catch (err) {
|
||||||
|
error(`Failed to get gcc version: ${err}`)
|
||||||
|
return givenVersion
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addGccLoggingMatcher() {
|
async function addGccLoggingMatcher() {
|
||||||
|
|
Loading…
Reference in New Issue