2024-08-07 14:44:32 +08:00
|
|
|
import { join } from "path"
|
2024-09-18 05:32:10 +08:00
|
|
|
import { endGroup, startGroup } from "@actions/core"
|
2023-05-25 14:48:26 +08:00
|
|
|
import { error, info } from "ci-log"
|
|
|
|
import semverValid from "semver/functions/valid"
|
2024-09-18 05:32:10 +08:00
|
|
|
import { getSuccessMessage } from "./cli-options.js"
|
2024-08-16 06:22:07 +08:00
|
|
|
import { setupGcc, setupMingw } from "./gcc/gcc.js"
|
|
|
|
import { activateGcovGCC, activateGcovLLVM } from "./gcovr/gcovr.js"
|
2024-09-18 05:32:10 +08:00
|
|
|
import { setupAppleClang } from "./llvm/apple-clang.js"
|
2024-08-16 06:22:07 +08:00
|
|
|
import { setupLLVM } from "./llvm/llvm.js"
|
|
|
|
import { setupMSVC } from "./msvc/msvc.js"
|
2024-09-18 05:32:10 +08:00
|
|
|
import { appleClangSetups, gccSetups, llvmSetups, mingwSetups, msvcSetups } from "./tool.js"
|
|
|
|
import type { InstallationInfo } from "./utils/setup/setupBin.js"
|
2024-08-16 06:22:07 +08:00
|
|
|
import { getVersion } from "./versions/versions.js"
|
2023-05-25 14:48:26 +08:00
|
|
|
|
2024-09-18 05:32:10 +08:00
|
|
|
/**
|
|
|
|
* Detecting the compiler version. Divide the given string by `-` and use the second element as the version
|
|
|
|
*
|
|
|
|
* @param compilerAndVersion - The compiler and version string
|
|
|
|
* @returns The compiler and version
|
|
|
|
*
|
|
|
|
* @nothrow It doesn't throw any error, but it logs the error if it fails to parse the compiler info
|
|
|
|
*/
|
2023-05-25 14:48:26 +08:00
|
|
|
export function getCompilerInfo(compilerAndVersion: string) {
|
2024-09-18 05:32:10 +08:00
|
|
|
try {
|
|
|
|
const compilerAndMaybeVersion = compilerAndVersion.split("-")
|
|
|
|
const compiler = compilerAndMaybeVersion[0]
|
|
|
|
if (1 in compilerAndMaybeVersion) {
|
|
|
|
const maybeVersion = compilerAndMaybeVersion[1]
|
|
|
|
if (semverValid(maybeVersion) === null) {
|
|
|
|
info(`Invalid semver version ${maybeVersion} used for the compiler.`)
|
|
|
|
}
|
2023-05-25 14:48:26 +08:00
|
|
|
return { compiler, version: maybeVersion }
|
|
|
|
}
|
2024-09-18 05:32:10 +08:00
|
|
|
return { compiler, version: undefined }
|
|
|
|
} catch (err) {
|
|
|
|
error(`Failed to parse the compiler info ${compilerAndVersion}: ${err}`)
|
|
|
|
return { compiler: compilerAndVersion, version: undefined }
|
2023-05-25 14:48:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Installing the specified compiler */
|
|
|
|
export async function installCompiler(
|
|
|
|
compilerAndVersion: string,
|
|
|
|
osVersion: number[] | null,
|
|
|
|
setupCppDir: string,
|
|
|
|
arch: string,
|
|
|
|
successMessages: string[],
|
2023-07-25 04:20:04 +08:00
|
|
|
errorMessages: string[],
|
2023-05-25 14:48:26 +08:00
|
|
|
) {
|
2024-09-18 05:32:10 +08:00
|
|
|
const { compiler, version } = getCompilerInfo(compilerAndVersion)
|
2023-05-25 14:48:26 +08:00
|
|
|
|
2024-09-18 05:32:10 +08:00
|
|
|
let installationInfo: InstallationInfo | undefined | void | null // null means the compiler is not supported
|
|
|
|
try {
|
2023-05-25 14:48:26 +08:00
|
|
|
// install the compiler. We allow some aliases for the compiler name
|
|
|
|
startGroup(`Installing ${compiler} ${version ?? ""}`)
|
2024-09-18 05:32:10 +08:00
|
|
|
if (compiler in llvmSetups) {
|
|
|
|
installationInfo = await setupLLVM(
|
|
|
|
getVersion("llvm", version, osVersion),
|
|
|
|
join(setupCppDir, "llvm"),
|
|
|
|
arch,
|
|
|
|
)
|
|
|
|
await activateGcovLLVM()
|
|
|
|
} else if (compiler in gccSetups) {
|
|
|
|
const gccVersion = getVersion("gcc", version, osVersion)
|
|
|
|
installationInfo = await setupGcc(gccVersion, join(setupCppDir, "gcc"), arch)
|
|
|
|
await activateGcovGCC(gccVersion)
|
|
|
|
} else if (compiler in mingwSetups) {
|
|
|
|
const gccVersion = getVersion("mingw", version, osVersion)
|
|
|
|
installationInfo = await setupMingw(gccVersion, join(setupCppDir, "gcc"), arch)
|
|
|
|
await activateGcovGCC(gccVersion)
|
|
|
|
} else if (compiler in msvcSetups) {
|
|
|
|
installationInfo = await setupMSVC(
|
|
|
|
getVersion("msvc", version, osVersion),
|
|
|
|
join(setupCppDir, "msvc"),
|
|
|
|
arch,
|
|
|
|
)
|
|
|
|
} else if (compiler in appleClangSetups) {
|
|
|
|
await setupAppleClang()
|
|
|
|
} else {
|
|
|
|
installationInfo = null
|
|
|
|
errorMessages.push(`Unsupported compiler ${compiler}`)
|
2023-05-25 14:48:26 +08:00
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
error(err as string | Error)
|
|
|
|
errorMessages.push(`Failed to install the ${compilerAndVersion}`)
|
|
|
|
}
|
|
|
|
|
2024-09-18 05:32:10 +08:00
|
|
|
if (installationInfo !== null) {
|
|
|
|
successMessages.push(getSuccessMessage(compiler, installationInfo))
|
|
|
|
}
|
|
|
|
|
2023-05-25 14:48:26 +08:00
|
|
|
endGroup()
|
|
|
|
}
|