setup-cpp/src/main.ts

150 lines
3.9 KiB
TypeScript
Raw Normal View History

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"
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"
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"
import { setupNinja } from "./ninja/ninja"
2021-09-16 16:49:25 +08:00
import { setupOpencppcoverage } from "./opencppcoverage/opencppcoverage"
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"
import { InstallationInfo } from "./utils/setup/setupBin"
2021-09-16 22:03:54 +08:00
import { setupGcc } from "./gcc/gcc"
import { assert } from "console"
const tools = [
"cmake",
"ninja",
"python",
"conan",
"meson",
"gcovr",
"opencppcoverage",
"llvm",
"gcc",
"choco",
"brew",
"ccache",
"doxygen",
"cppcheck",
"msvc",
]
const setups = {
cmake: setupCmake,
ninja: setupNinja,
python: setupPython,
conan: setupConan,
meson: setupMeson,
gcovr: setupGcovr,
opencppcoverage: setupOpencppcoverage,
llvm: setupLLVM,
2021-09-16 22:03:54 +08:00
gcc: setupGcc,
choco: setupChocolatey,
brew: setupBrew,
ccache: setupCcache,
doxygen: setupDoxygen,
cppcheck: setupCppcheck,
msvc: setupMSVC,
} as Record<
string,
(
version: string | undefined,
setupCppDir: string,
...args: unknown[]
) => Promise<InstallationInfo> | Promise<void> | void
>
function maybeGetInput(key: string) {
const value = core.getInput(key.toLowerCase())
if (value !== "false" && value !== "") {
return value
}
return undefined // skip installation
}
2021-09-14 15:03:59 +08:00
export async function main(): Promise<number> {
const arch = core.getInput("architecture") || process.arch
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++": {
await setupLLVM(getVersion("llvm", version) as string, setupCppDir, arch)
2021-09-16 19:07:52 +08:00
break
}
2021-09-16 22:03:54 +08:00
case "gcc":
case "mingw":
case "cygwin":
case "msys": {
await setupGcc(getVersion("gcc", version) as string, setupCppDir, arch)
break
}
2021-09-16 19:07:52 +08:00
case "cl":
case "msvc":
case "msbuild":
case "vs":
case "visualstudio":
case "visualcpp":
case "visualc++": {
await setupMSVC(getVersion("msvc", version) as string, setupCppDir, arch)
2021-09-16 19:07:52 +08:00
break
}
default: {
core.error(`Unsupported compiler ${compiler}`)
}
}
}
2021-09-16 22:03:54 +08:00
for (const tool of tools) {
assert(tool in setups)
const version = maybeGetInput(tool)
if (version !== undefined) {
const setupFunction = setups[tool]
// eslint-disable-next-line no-await-in-loop
await setupFunction(getVersion(tool, version), setupCppDir, arch)
}
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) => {
core.error("main() failed!")
core.error(error as string | Error)
2021-09-14 15:03:59 +08:00
process.exitCode = 1
})