feat: support kcov

This commit is contained in:
Amin Yahyaabadi 2021-12-07 05:30:33 -06:00
parent cd6c820cf0
commit fa01e81c02
8 changed files with 105 additions and 4 deletions

View File

@ -28,6 +28,7 @@ The package can be used locally or from CI services like GitHub Actions.
- doxygen
- gcovr
- opencppcoverage
- kcov
- python
- choco
- brew

2
dist/setup_cpp.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -8,6 +8,7 @@ const DefaultVersions: Record<string, string> = {
conan: "1.42.1",
meson: "0.60.1",
python: "3.10.0",
kcov: "v39",
gcc: process.platform === "win32" ? "11.2.0.07112021" : "11",
}

View File

@ -0,0 +1,37 @@
import { setupKcov } from "../kcov"
import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers"
import { InstallationInfo } from "../../utils/setup/setupBin"
jest.setTimeout(300000)
async function testKcov(version: string, directory: string) {
const { binDir } = (await setupKcov(version, directory, "")) as InstallationInfo
await testBin("kcov", ["--version"], binDir)
return binDir
}
describe("setup-Kcov", () => {
if (process.platform !== "linux") {
it.todo("should setup kcov on non-linux")
return
}
it("should setup Kcov v39", async () => {
const directory = await setupTmpDir("kcov-v39")
await testKcov("v39", directory)
await cleanupTmpDir("kcov-v39")
})
// TODO
// it("should setup Kcov v38", async () => {
// const directory = await setupTmpDir("kcov-v38")
// await testKcov("v38", directory)
// await cleanupTmpDir("kcov-v39")
// })
// it("should find Kcov in the cache", async () => {
// const directory = await setupTmpDir("kcov-v39")
// const binDir = await testKcov("v39", directory)
// expect(binDir.includes("ToolCache")).toBeTruthy()
// await cleanupTmpDir("kcov-v39")
// })
})

58
src/kcov/kcov.ts Normal file
View File

@ -0,0 +1,58 @@
import execa from "execa"
// import { join } from "path"
// import untildify from "untildify"
// import { setupCmake } from "../cmake/cmake"
import { execaSudo } from "../utils/env/sudo"
import { addBinExtension } from "../utils/extension/extension"
import { extractTarByExe } from "../utils/setup/extract"
import { setupAptPack } from "../utils/setup/setupAptPack"
import { PackageInfo, setupBin } from "../utils/setup/setupBin"
function getKcovPackageInfo(version: string): PackageInfo {
const version_number = parseInt(version.replace(/^v/, ""), 10)
if (version_number === 38) {
// eslint-disable-next-line no-param-reassign
version = "v38"
}
if (version_number >= 39) {
return {
url: `https://github.com/SimonKagstrom/kcov/releases/download/${version}/kcov-amd64.tar.gz`,
extractedFolderName: "",
binRelativeDir: "usr/local/bin",
binFileName: addBinExtension("kcov"),
extractFunction: (file: string, dest: string) => {
return extractTarByExe(file, dest, ["--strip-components=0"])
},
}
} else {
return {
url: `https://github.com/SimonKagstrom/kcov/archive/refs/tags/${version}.tar.gz`,
extractedFolderName: `kcov-${version_number}`,
binRelativeDir: "build/",
binFileName: addBinExtension("kcov"),
extractFunction: async (file: string, dest: string): Promise<string> => {
const out = await extractTarByExe(file, dest)
// build after extraction using CMake
// await setupCmake("3.22.0", join(untildify("~/"), "cmake"), "")
await setupAptPack("libdw-dev")
await setupAptPack("libcurl4-openssl-dev")
await execa("cmake", ["-S", "./", "-B", "./build"], { cwd: out })
await execa("cmake", ["--build", "./build", "--config", "Release"], { cwd: out })
await execaSudo("cmake", ["--install", "./build"], out)
return out
},
}
}
}
export async function setupKcov(version: string, setupDir: string, arch: string) {
switch (process.platform) {
case "linux": {
const installationInfo = await setupBin("kcov", version, getKcovPackageInfo, setupDir)
return installationInfo
}
default: {
throw new Error(`Unsupported platform for ${arch}`)
}
}
}

View File

@ -26,6 +26,7 @@ import { setupVcpkg } from "./vcpkg/vcpkg"
import { join } from "path"
import { warning } from "@actions/core"
import { setupVCVarsall } from "./vcvarsall/vcvarsall"
import { setupKcov } from "./kcov/kcov"
/** The setup functions */
const setups = {
@ -46,6 +47,7 @@ const setups = {
cppcheck: setupCppcheck,
msvc: setupMSVC,
vcvarsall: setupVCVarsall,
kcov: setupKcov,
}
/** The tools that can be installed */
@ -67,6 +69,7 @@ const tools: Array<keyof typeof setups> = [
"gcc",
"msvc",
"vcvarsall",
"kcov",
]
/** The possible inputs to the program */
@ -267,6 +270,7 @@ All the available tools:
--doxygen
--gcovr
--opencppcoverage
--kcov
--python
--choco
--brew

View File

@ -19,9 +19,9 @@ export function mightSudo(command: string) {
return command
}
export function execaSudo(file: string, args: string[]) {
export function execaSudo(file: string, args: string[], cwd?: string) {
if (isRoot()) {
return execa.command(`sudo ${[file, ...args].join(" ")}`, { shell: true })
return execa.command(`sudo ${[file, ...args].join(" ")}`, { shell: true, cwd })
} else {
return execa(file, args)
}