2021-12-07 19:30:33 +08:00
|
|
|
import execa from "execa"
|
2022-04-16 15:42:53 +08:00
|
|
|
import { join } from "path"
|
|
|
|
import untildify from "untildify"
|
|
|
|
import which from "which"
|
|
|
|
import { setupCmake } from "../cmake/cmake"
|
|
|
|
import { getVersion } from "../default_versions"
|
2022-01-31 09:23:09 +08:00
|
|
|
import { execSudo } from "../utils/exec/sudo"
|
2021-12-07 19:30:33 +08:00
|
|
|
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 {
|
2022-04-16 15:42:53 +08:00
|
|
|
url: `https://github.com/SimonKagstrom/kcov/releases/download/v${version_number}/kcov-amd64.tar.gz`,
|
2021-12-07 19:30:33 +08:00
|
|
|
extractedFolderName: "",
|
|
|
|
binRelativeDir: "usr/local/bin",
|
|
|
|
binFileName: addBinExtension("kcov"),
|
2022-01-31 10:36:25 +08:00
|
|
|
extractFunction: extractTarByExe,
|
2021-12-07 19:30:33 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
url: `https://github.com/SimonKagstrom/kcov/archive/refs/tags/${version}.tar.gz`,
|
|
|
|
extractedFolderName: `kcov-${version_number}`,
|
|
|
|
binRelativeDir: "build/",
|
|
|
|
binFileName: addBinExtension("kcov"),
|
2022-04-16 15:42:53 +08:00
|
|
|
extractFunction: buildKcov,
|
2021-12-07 19:30:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-16 15:42:53 +08:00
|
|
|
async function buildKcov(file: string, dest: string) {
|
|
|
|
const out = await extractTarByExe(file, dest, ["--strip-components=1"])
|
|
|
|
// build after extraction using CMake
|
|
|
|
if (which.sync("cmake", { nothrow: true }) === null) {
|
|
|
|
await setupCmake(getVersion("cmake", undefined), join(untildify(""), "cmake"), "")
|
|
|
|
}
|
|
|
|
if (process.platform === "linux") {
|
2022-04-27 15:02:35 +08:00
|
|
|
setupAptPack("libdw-dev")
|
|
|
|
setupAptPack("libcurl4-openssl-dev")
|
2022-04-16 15:42:53 +08:00
|
|
|
}
|
|
|
|
await execa("cmake", ["-S", "./", "-B", "./build"], { cwd: out, stdio: "inherit" })
|
|
|
|
await execa("cmake", ["--build", "./build", "--config", "Release"], { cwd: out, stdio: "inherit" })
|
2022-04-27 15:02:35 +08:00
|
|
|
execSudo("cmake", ["--install", "./build"], out)
|
2022-04-16 15:42:53 +08:00
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
2021-12-07 19:30:33 +08:00
|
|
|
export async function setupKcov(version: string, setupDir: string, arch: string) {
|
|
|
|
switch (process.platform) {
|
|
|
|
case "linux": {
|
2022-01-31 07:33:22 +08:00
|
|
|
const installationInfo = await setupBin("kcov", version, getKcovPackageInfo, setupDir, arch)
|
2022-04-27 15:02:35 +08:00
|
|
|
setupAptPack("libbinutils")
|
2021-12-07 19:30:33 +08:00
|
|
|
return installationInfo
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
throw new Error(`Unsupported platform for ${arch}`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|