2021-09-14 15:03:59 +08:00
|
|
|
import * as core from "@actions/core"
|
2021-09-16 16:26:53 +08:00
|
|
|
import { setupBrew } from "./brew/brew"
|
2021-09-16 16:41:47 +08:00
|
|
|
import { setupCcache } from "./ccache/ccache"
|
2021-09-15 05:01:08 +08:00
|
|
|
import { setupChocolatey } from "./chocolatey/chocolatey"
|
2021-09-14 15:33:49 +08:00
|
|
|
import { setupCmake } from "./cmake/cmake"
|
2021-09-15 01:06:20 +08:00
|
|
|
import { setupConan } from "./conan/conan"
|
2021-09-16 16:47:47 +08:00
|
|
|
import { setupCppcheck } from "./cppcheck/cppcheck"
|
|
|
|
import { setupDoxygen } from "./doxygen/doxygen"
|
2021-09-15 01:42:08 +08:00
|
|
|
import { setupGcovr } from "./gcovr/gcovr"
|
2021-09-14 20:02:34 +08:00
|
|
|
import { setupLLVM } from "./llvm/llvm"
|
2021-09-15 01:09:58 +08:00
|
|
|
import { setupMeson } from "./meson/meson"
|
2021-09-15 18:25:02 +08:00
|
|
|
import { setupMSVC } from "./msvc/msvc"
|
2021-09-14 15:42:17 +08:00
|
|
|
import { setupNinja } from "./ninja/ninja"
|
2021-09-16 16:49:25 +08:00
|
|
|
import { setupOpencppcoverage } from "./opencppcoverage/opencppcoverage"
|
2021-09-15 04:23:45 +08:00
|
|
|
import { setupPython } from "./python/python"
|
2021-09-16 19:07:52 +08:00
|
|
|
import semverValid from "semver/functions/valid"
|
2021-09-16 19:36:35 +08:00
|
|
|
import { getVersion } from "./default_versions"
|
2021-09-14 15:42:17 +08:00
|
|
|
|
|
|
|
function maybeGetInput(key: string) {
|
2021-09-16 16:51:09 +08:00
|
|
|
const value = core.getInput(key.toLowerCase())
|
2021-09-14 15:42:17 +08:00
|
|
|
if (value !== "false" && value !== "") {
|
|
|
|
return value
|
|
|
|
}
|
2021-09-16 19:14:06 +08:00
|
|
|
return undefined // skip installation
|
2021-09-14 15:42:17 +08:00
|
|
|
}
|
2021-09-14 15:03:59 +08:00
|
|
|
|
|
|
|
export async function main(): Promise<number> {
|
2021-09-15 04:23:45 +08:00
|
|
|
const arch = core.getInput("architecture") || process.arch
|
2021-09-14 20:02:34 +08:00
|
|
|
const setupCppDir = process.env.SETUP_CPP_DIR ?? "~/setup_cpp"
|
2021-09-14 15:03:59 +08:00
|
|
|
try {
|
2021-09-16 19:07:52 +08:00
|
|
|
const maybeCompiler = maybeGetInput("compiler")
|
|
|
|
if (maybeCompiler !== undefined) {
|
|
|
|
const compilerAndMaybeVersion = maybeCompiler.split("-")
|
|
|
|
const compiler = compilerAndMaybeVersion[0]
|
|
|
|
let version: string | undefined
|
|
|
|
if (1 in compilerAndMaybeVersion) {
|
|
|
|
const maybeVersion = compilerAndMaybeVersion[1]
|
|
|
|
if (semverValid(maybeVersion) !== null) {
|
|
|
|
version = maybeVersion
|
|
|
|
} else {
|
|
|
|
core.error(`Invalid version ${maybeVersion} used for the compiler. Using the default version...`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (compiler) {
|
|
|
|
case "llvm":
|
|
|
|
case "clang":
|
|
|
|
case "clang++": {
|
2021-09-16 19:36:35 +08:00
|
|
|
await setupLLVM(getVersion("llvm", version), setupCppDir)
|
2021-09-16 19:07:52 +08:00
|
|
|
break
|
|
|
|
}
|
|
|
|
case "cl":
|
|
|
|
case "msvc":
|
|
|
|
case "msbuild":
|
|
|
|
case "vs":
|
|
|
|
case "visualstudio":
|
|
|
|
case "visualcpp":
|
|
|
|
case "visualc++": {
|
2021-09-16 19:36:35 +08:00
|
|
|
await setupMSVC(getVersion("msvc", version), setupCppDir)
|
2021-09-16 19:07:52 +08:00
|
|
|
break
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
core.error(`Unsupported compiler ${compiler}`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-14 15:33:49 +08:00
|
|
|
// setup cmake
|
2021-09-14 15:42:17 +08:00
|
|
|
const cmakeVersion = maybeGetInput("cmake")
|
|
|
|
if (cmakeVersion !== undefined) {
|
2021-09-16 19:36:35 +08:00
|
|
|
await setupCmake(getVersion("cmake", cmakeVersion), setupCppDir)
|
2021-09-14 15:33:49 +08:00
|
|
|
}
|
2021-09-14 15:42:17 +08:00
|
|
|
|
|
|
|
// setup ninja
|
|
|
|
const ninjaVersion = maybeGetInput("ninja")
|
|
|
|
if (ninjaVersion !== undefined) {
|
2021-09-16 19:36:35 +08:00
|
|
|
await setupNinja(getVersion("ninja", ninjaVersion), setupCppDir)
|
2021-09-14 15:42:17 +08:00
|
|
|
}
|
2021-09-14 20:02:59 +08:00
|
|
|
|
2021-09-15 04:23:45 +08:00
|
|
|
// setup python (required for conan, meson, gcovr, etc.)
|
|
|
|
const pythonVersion = maybeGetInput("python")
|
|
|
|
if (pythonVersion !== undefined) {
|
2021-09-16 19:36:35 +08:00
|
|
|
await setupPython(getVersion("python", pythonVersion), arch)
|
2021-09-15 04:23:45 +08:00
|
|
|
}
|
|
|
|
|
2021-09-15 01:06:20 +08:00
|
|
|
// setup conan
|
|
|
|
const conanVersion = maybeGetInput("conan")
|
|
|
|
if (conanVersion !== undefined) {
|
2021-09-16 19:36:35 +08:00
|
|
|
await setupConan(getVersion("conan", conanVersion))
|
2021-09-15 01:06:20 +08:00
|
|
|
}
|
|
|
|
|
2021-09-15 01:09:58 +08:00
|
|
|
// setup meson
|
|
|
|
const mesonVersion = maybeGetInput("meson")
|
|
|
|
if (mesonVersion !== undefined) {
|
2021-09-16 19:36:35 +08:00
|
|
|
await setupMeson(getVersion("meson", mesonVersion))
|
2021-09-15 01:09:58 +08:00
|
|
|
}
|
|
|
|
|
2021-09-15 01:42:08 +08:00
|
|
|
// setup gcovr
|
|
|
|
const gcovrVersion = maybeGetInput("gcovr")
|
|
|
|
if (gcovrVersion !== undefined) {
|
2021-09-16 19:36:35 +08:00
|
|
|
await setupGcovr(getVersion("gcovr", gcovrVersion))
|
2021-09-15 01:42:08 +08:00
|
|
|
}
|
|
|
|
|
2021-09-16 16:49:25 +08:00
|
|
|
// setup opencppCoverage
|
|
|
|
const opencppCoverageVersion = maybeGetInput("opencppcoverage")
|
|
|
|
if (opencppCoverageVersion !== undefined) {
|
2021-09-16 19:36:35 +08:00
|
|
|
await setupOpencppcoverage(getVersion("opencppcoverage", opencppCoverageVersion))
|
2021-09-16 16:49:25 +08:00
|
|
|
}
|
|
|
|
|
2021-09-14 20:02:59 +08:00
|
|
|
// setup llvm
|
|
|
|
const llvmVersion = maybeGetInput("llvm")
|
|
|
|
if (llvmVersion !== undefined) {
|
2021-09-16 19:36:35 +08:00
|
|
|
await setupLLVM(getVersion("llvm", llvmVersion), setupCppDir)
|
2021-09-14 20:02:59 +08:00
|
|
|
}
|
2021-09-15 05:01:08 +08:00
|
|
|
|
|
|
|
// setup chocolatey (required for installing msvc)
|
|
|
|
const chocoVersion = maybeGetInput("choco")
|
|
|
|
if (chocoVersion !== undefined) {
|
|
|
|
await setupChocolatey()
|
|
|
|
}
|
2021-09-15 18:25:02 +08:00
|
|
|
|
2021-09-16 16:26:53 +08:00
|
|
|
// setup brew
|
|
|
|
const brewVersion = maybeGetInput("brew")
|
|
|
|
if (brewVersion !== undefined) {
|
2021-09-16 19:17:38 +08:00
|
|
|
setupBrew()
|
2021-09-16 16:26:53 +08:00
|
|
|
}
|
|
|
|
|
2021-09-16 16:41:47 +08:00
|
|
|
// setup ccache
|
|
|
|
const ccacheVersion = maybeGetInput("ccache")
|
|
|
|
if (ccacheVersion !== undefined) {
|
2021-09-16 19:36:35 +08:00
|
|
|
await setupCcache(getVersion("ccache", ccacheVersion))
|
2021-09-16 16:41:47 +08:00
|
|
|
}
|
|
|
|
|
2021-09-16 16:47:47 +08:00
|
|
|
// setup doxygen
|
|
|
|
const doxygenVersion = maybeGetInput("doxygen")
|
|
|
|
if (doxygenVersion !== undefined) {
|
2021-09-16 19:36:35 +08:00
|
|
|
await setupDoxygen(getVersion("doxygen", doxygenVersion))
|
2021-09-16 16:47:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// setup cppCheck
|
|
|
|
const cppCheckVersion = maybeGetInput("cppcheck")
|
|
|
|
if (cppCheckVersion !== undefined) {
|
2021-09-16 19:36:35 +08:00
|
|
|
await setupCppcheck(getVersion("cppcheck", cppCheckVersion))
|
2021-09-16 16:47:47 +08:00
|
|
|
}
|
|
|
|
|
2021-09-15 18:25:02 +08:00
|
|
|
// setup msvc
|
|
|
|
const msvcVersion = maybeGetInput("msvc")
|
|
|
|
if (msvcVersion !== undefined) {
|
2021-09-16 19:36:35 +08:00
|
|
|
await setupMSVC(getVersion("msvc", msvcVersion))
|
2021-09-15 18:25:02 +08:00
|
|
|
}
|
2021-09-14 15:03:59 +08:00
|
|
|
} catch (err) {
|
|
|
|
core.error(err as string | Error)
|
|
|
|
core.setFailed("install-cpp failed")
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
core.info("install-cpp succeeded")
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
main()
|
|
|
|
.then((ret) => {
|
|
|
|
process.exitCode = ret
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
2021-09-14 15:33:49 +08:00
|
|
|
core.error("main() failed!")
|
|
|
|
core.error(error as string | Error)
|
2021-09-14 15:03:59 +08:00
|
|
|
process.exitCode = 1
|
|
|
|
})
|