mirror of https://github.com/aminya/setup-cpp
feat: use a similar interface for installing all the packages
This commit is contained in:
parent
a970eb0e44
commit
511a2fbbce
|
@ -1,7 +1,8 @@
|
|||
import { execFileSync } from "child_process"
|
||||
import which from "which"
|
||||
|
||||
export function setupBrew() {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function setupBrew(_version: string, _setupCppDir: string, _arch: string) {
|
||||
if (!["darwin", "linux"].includes(process.platform)) {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -2,7 +2,8 @@ import { setupAptPack } from "../utils/setup/setupAptPack"
|
|||
import { setupBrewPack } from "../utils/setup/setupBrewPack"
|
||||
import { setupChocoPack } from "../utils/setup/setupChocoPack"
|
||||
|
||||
export function setupCcache(version?: string) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function setupCcache(version: string, _setupCppDir: string, _arch: string) {
|
||||
switch (process.platform) {
|
||||
case "win32": {
|
||||
return setupChocoPack("ccache", version)
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { exec } from "@actions/exec"
|
||||
import which from "which"
|
||||
|
||||
export async function setupChocolatey() {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export async function setupChocolatey(_version: string, _setupCppDir: string, _arch: string) {
|
||||
if (process.platform !== "win32") {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ function getCmakePackageInfo(version: string, platform?: NodeJS.Platform): Packa
|
|||
}
|
||||
|
||||
/** Setup cmake */
|
||||
export function setupCmake(version: string, setupCppDir: string): Promise<InstallationInfo> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function setupCmake(version: string, setupCppDir: string, _arch: string): Promise<InstallationInfo> {
|
||||
return setupBin("cmake", version, getCmakePackageInfo, setupCppDir)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { setupPipPack } from "../utils/setup/setupPipPack"
|
||||
|
||||
export async function setupConan(version?: string) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export async function setupConan(version: string | undefined, _setupCppDir: string, _arch: string) {
|
||||
await setupPipPack("conan", version)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,8 @@ import { setupAptPack } from "../utils/setup/setupAptPack"
|
|||
import { setupBrewPack } from "../utils/setup/setupBrewPack"
|
||||
import { setupChocoPack } from "../utils/setup/setupChocoPack"
|
||||
|
||||
export function setupCppcheck(version?: string) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function setupCppcheck(version: string | undefined, _setupCppDir: string, _arch: string) {
|
||||
switch (process.platform) {
|
||||
case "win32": {
|
||||
return setupChocoPack("cppcheck", version)
|
||||
|
|
|
@ -7,7 +7,7 @@ const DefaultVersions: Record<string, string> = {
|
|||
|
||||
/** Get the default version if passed true or undefined, otherwise return the version itself */
|
||||
export function getVersion(name: string, version: string | undefined) {
|
||||
if (version === "true" || version === undefined) {
|
||||
if (version === "true" || (version === undefined && name in DefaultVersions)) {
|
||||
return DefaultVersions[name]
|
||||
} else {
|
||||
return version
|
||||
|
|
|
@ -2,7 +2,8 @@ import { setupAptPack } from "../utils/setup/setupAptPack"
|
|||
import { setupBrewPack } from "../utils/setup/setupBrewPack"
|
||||
import { setupChocoPack } from "../utils/setup/setupChocoPack"
|
||||
|
||||
export async function setupDoxygen(version?: string) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export async function setupDoxygen(version: string | undefined, _setupCppDir: string, _arch: string) {
|
||||
switch (process.platform) {
|
||||
case "win32": {
|
||||
await setupChocoPack("graphviz", version)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { setupPipPack } from "../utils/setup/setupPipPack"
|
||||
|
||||
export async function setupGcovr(version?: string) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export async function setupGcovr(version: string | undefined, _setupCppDir: string, _arch: string) {
|
||||
await setupPipPack("gcovr", version)
|
||||
}
|
||||
|
|
|
@ -233,8 +233,13 @@ async function getLLVMPackageInfo(version: string, platform: NodeJS.Platform): P
|
|||
}
|
||||
}
|
||||
|
||||
export async function setupLLVM(version: string, directoryGiven?: string): Promise<InstallationInfo> {
|
||||
let directory = directoryGiven
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export async function setupLLVM(
|
||||
version: string,
|
||||
_setupCppDir: string | undefined,
|
||||
_arch: string
|
||||
): Promise<InstallationInfo> {
|
||||
let directory = _setupCppDir
|
||||
if (directory === "" || directory === undefined) {
|
||||
directory = process.platform === "win32" ? DEFAULT_WIN32_DIRECTORY : DEFAULT_NIX_DIRECTORY
|
||||
}
|
||||
|
|
134
src/main.ts
134
src/main.ts
|
@ -13,8 +13,34 @@ import { setupMSVC } from "./msvc/msvc"
|
|||
import { setupNinja } from "./ninja/ninja"
|
||||
import { setupOpencppcoverage } from "./opencppcoverage/opencppcoverage"
|
||||
import { setupPython } from "./python/python"
|
||||
|
||||
import semverValid from "semver/functions/valid"
|
||||
import { getVersion } from "./default_versions"
|
||||
import { InstallationInfo } from "./utils/setup/setupBin"
|
||||
|
||||
const setups = {
|
||||
cmake: setupCmake,
|
||||
ninja: setupNinja,
|
||||
python: setupPython,
|
||||
conan: setupConan,
|
||||
meson: setupMeson,
|
||||
gcovr: setupGcovr,
|
||||
opencppcoverage: setupOpencppcoverage,
|
||||
llvm: setupLLVM,
|
||||
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())
|
||||
|
@ -46,7 +72,7 @@ export async function main(): Promise<number> {
|
|||
case "llvm":
|
||||
case "clang":
|
||||
case "clang++": {
|
||||
await setupLLVM(getVersion("llvm", version), setupCppDir)
|
||||
await setupLLVM(getVersion("llvm", version) as string, setupCppDir, arch)
|
||||
break
|
||||
}
|
||||
case "cl":
|
||||
|
@ -56,7 +82,7 @@ export async function main(): Promise<number> {
|
|||
case "visualstudio":
|
||||
case "visualcpp":
|
||||
case "visualc++": {
|
||||
await setupMSVC(getVersion("msvc", version), setupCppDir)
|
||||
await setupMSVC(getVersion("msvc", version) as string, setupCppDir, arch)
|
||||
break
|
||||
}
|
||||
default: {
|
||||
|
@ -65,88 +91,28 @@ export async function main(): Promise<number> {
|
|||
}
|
||||
}
|
||||
|
||||
// setup cmake
|
||||
const cmakeVersion = maybeGetInput("cmake")
|
||||
if (cmakeVersion !== undefined) {
|
||||
await setupCmake(getVersion("cmake", cmakeVersion), setupCppDir)
|
||||
}
|
||||
|
||||
// setup ninja
|
||||
const ninjaVersion = maybeGetInput("ninja")
|
||||
if (ninjaVersion !== undefined) {
|
||||
await setupNinja(getVersion("ninja", ninjaVersion), setupCppDir)
|
||||
}
|
||||
|
||||
// setup python (required for conan, meson, gcovr, etc.)
|
||||
const pythonVersion = maybeGetInput("python")
|
||||
if (pythonVersion !== undefined) {
|
||||
await setupPython(getVersion("python", pythonVersion), arch)
|
||||
}
|
||||
|
||||
// setup conan
|
||||
const conanVersion = maybeGetInput("conan")
|
||||
if (conanVersion !== undefined) {
|
||||
await setupConan(getVersion("conan", conanVersion))
|
||||
}
|
||||
|
||||
// setup meson
|
||||
const mesonVersion = maybeGetInput("meson")
|
||||
if (mesonVersion !== undefined) {
|
||||
await setupMeson(getVersion("meson", mesonVersion))
|
||||
}
|
||||
|
||||
// setup gcovr
|
||||
const gcovrVersion = maybeGetInput("gcovr")
|
||||
if (gcovrVersion !== undefined) {
|
||||
await setupGcovr(getVersion("gcovr", gcovrVersion))
|
||||
}
|
||||
|
||||
// setup opencppCoverage
|
||||
const opencppCoverageVersion = maybeGetInput("opencppcoverage")
|
||||
if (opencppCoverageVersion !== undefined) {
|
||||
await setupOpencppcoverage(getVersion("opencppcoverage", opencppCoverageVersion))
|
||||
}
|
||||
|
||||
// setup llvm
|
||||
const llvmVersion = maybeGetInput("llvm")
|
||||
if (llvmVersion !== undefined) {
|
||||
await setupLLVM(getVersion("llvm", llvmVersion), setupCppDir)
|
||||
}
|
||||
|
||||
// setup chocolatey (required for installing msvc)
|
||||
const chocoVersion = maybeGetInput("choco")
|
||||
if (chocoVersion !== undefined) {
|
||||
await setupChocolatey()
|
||||
}
|
||||
|
||||
// setup brew
|
||||
const brewVersion = maybeGetInput("brew")
|
||||
if (brewVersion !== undefined) {
|
||||
setupBrew()
|
||||
}
|
||||
|
||||
// setup ccache
|
||||
const ccacheVersion = maybeGetInput("ccache")
|
||||
if (ccacheVersion !== undefined) {
|
||||
await setupCcache(getVersion("ccache", ccacheVersion))
|
||||
}
|
||||
|
||||
// setup doxygen
|
||||
const doxygenVersion = maybeGetInput("doxygen")
|
||||
if (doxygenVersion !== undefined) {
|
||||
await setupDoxygen(getVersion("doxygen", doxygenVersion))
|
||||
}
|
||||
|
||||
// setup cppCheck
|
||||
const cppCheckVersion = maybeGetInput("cppcheck")
|
||||
if (cppCheckVersion !== undefined) {
|
||||
await setupCppcheck(getVersion("cppcheck", cppCheckVersion))
|
||||
}
|
||||
|
||||
// setup msvc
|
||||
const msvcVersion = maybeGetInput("msvc")
|
||||
if (msvcVersion !== undefined) {
|
||||
await setupMSVC(getVersion("msvc", msvcVersion))
|
||||
for (const tool of [
|
||||
"cmake",
|
||||
"ninja",
|
||||
"python",
|
||||
"conan",
|
||||
"meson",
|
||||
"gcovr",
|
||||
"opencppcoverage",
|
||||
"llvm",
|
||||
"choco",
|
||||
"brew",
|
||||
"ccache",
|
||||
"doxygen",
|
||||
"cppcheck",
|
||||
"msvc",
|
||||
]) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
core.error(err as string | Error)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { setupPipPack } from "../utils/setup/setupPipPack"
|
||||
|
||||
export async function setupMeson(version?: string) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export async function setupMeson(version: string | undefined, _setupCppDir: string, _arch: string) {
|
||||
await setupPipPack("meson", version)
|
||||
}
|
||||
|
|
|
@ -24,10 +24,11 @@ function getArch(arch: string): string {
|
|||
|
||||
export async function setupMSVC(
|
||||
version: MSVCVersion,
|
||||
_setupCppDir: string,
|
||||
arch: string,
|
||||
sdk?: string,
|
||||
uwp?: boolean,
|
||||
spectre?: boolean,
|
||||
arch = osArch()
|
||||
spectre?: boolean
|
||||
): Promise<void> {
|
||||
if (process.platform !== "win32") {
|
||||
return
|
||||
|
|
|
@ -26,6 +26,7 @@ function getNinjaPackageInfo(version: string, platform: NodeJS.Platform): Packag
|
|||
}
|
||||
}
|
||||
|
||||
export function setupNinja(version: string, setupCppDir: string): Promise<InstallationInfo> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function setupNinja(version: string, setupCppDir: string, _arch: string): Promise<InstallationInfo> {
|
||||
return setupBin("ninja", version, getNinjaPackageInfo, setupCppDir)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { addPath } from "@actions/core"
|
||||
import { setupChocoPack } from "../utils/setup/setupChocoPack"
|
||||
|
||||
export async function setupOpencppcoverage(version?: string) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export async function setupOpencppcoverage(version: string | undefined, _setupCppDir: string, _arch: string) {
|
||||
if (process.platform !== "win32") {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -2,24 +2,21 @@ import * as core from "@actions/core"
|
|||
import * as finder from "./setup-python/src/find-python"
|
||||
import * as finderPyPy from "./setup-python/src/find-pypy"
|
||||
import * as path from "path"
|
||||
import * as os from "os"
|
||||
|
||||
function isPyPyVersion(versionSpec: string) {
|
||||
return versionSpec.startsWith("pypy-")
|
||||
}
|
||||
|
||||
export async function setupPython(version?: string, arch: string = os.arch()) {
|
||||
export async function setupPython(version: string, _setupCppDir: string, arch: string) {
|
||||
try {
|
||||
if (version !== undefined && version !== "") {
|
||||
if (isPyPyVersion(version)) {
|
||||
const installed = await finderPyPy.findPyPyVersion(version, arch)
|
||||
core.info(
|
||||
`Successfully setup PyPy ${installed.resolvedPyPyVersion} with Python (${installed.resolvedPythonVersion})`
|
||||
)
|
||||
} else {
|
||||
const installed = await finder.findPythonVersion(version, arch)
|
||||
core.info(`Successfully setup ${installed.impl} (${installed.version})`)
|
||||
}
|
||||
if (isPyPyVersion(version)) {
|
||||
const installed = await finderPyPy.findPyPyVersion(version, arch)
|
||||
core.info(
|
||||
`Successfully setup PyPy ${installed.resolvedPyPyVersion} with Python (${installed.resolvedPythonVersion})`
|
||||
)
|
||||
} else {
|
||||
const installed = await finder.findPythonVersion(version, arch)
|
||||
core.info(`Successfully setup ${installed.impl} (${installed.version})`)
|
||||
}
|
||||
const matchersPath = path.join(__dirname, "..", ".github")
|
||||
core.info(`##[add-matcher]${path.join(matchersPath, "python.json")}`)
|
||||
|
|
Loading…
Reference in New Issue