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 which from "which"
|
|
|
|
import { setupCmake } from "../cmake/cmake"
|
|
|
|
import { getVersion } from "../default_versions"
|
2022-08-08 09:36:04 +08:00
|
|
|
import { addBinExtension } from "extension-tools"
|
2021-12-07 19:30:33 +08:00
|
|
|
import { extractTarByExe } from "../utils/setup/extract"
|
|
|
|
import { setupAptPack } from "../utils/setup/setupAptPack"
|
2022-06-30 00:06:35 +08:00
|
|
|
import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
|
2022-07-22 16:06:43 +08:00
|
|
|
import { InstallationInfo, PackageInfo, setupBin } from "../utils/setup/setupBin"
|
2022-06-30 10:06:33 +08:00
|
|
|
import { isArch } from "../utils/env/isArch"
|
2022-07-11 07:34:56 +08:00
|
|
|
import { hasDnf } from "../utils/env/hasDnf"
|
|
|
|
import { setupDnfPack } from "../utils/setup/setupDnfPack"
|
2022-07-11 08:39:21 +08:00
|
|
|
import { isUbuntu } from "../utils/env/isUbuntu"
|
2022-07-23 04:57:11 +08:00
|
|
|
import { addVPrefix, removeVPrefix } from "../utils/setup/version"
|
2022-08-08 16:22:28 +08:00
|
|
|
import { info } from "ci-log"
|
2022-08-08 11:04:59 +08:00
|
|
|
import { untildifyUser } from "untildify-user"
|
2022-07-28 09:45:26 +08:00
|
|
|
import { setupNinja } from "../ninja/ninja"
|
2021-12-07 19:30:33 +08:00
|
|
|
|
2022-07-28 04:35:11 +08:00
|
|
|
function getDownloadKcovPackageInfo(version: string): PackageInfo {
|
2022-07-22 16:06:43 +08:00
|
|
|
return {
|
2022-07-28 04:35:11 +08:00
|
|
|
url: `https://github.com/SimonKagstrom/kcov/releases/download/${version}/kcov-amd64.tar.gz`,
|
2022-07-22 16:06:43 +08:00
|
|
|
extractedFolderName: "",
|
|
|
|
binRelativeDir: "usr/local/bin",
|
|
|
|
binFileName: addBinExtension("kcov"),
|
|
|
|
extractFunction: extractTarByExe,
|
2021-12-07 19:30:33 +08:00
|
|
|
}
|
2022-07-22 16:06:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function getBuildKcovPackageInfo(version: string): PackageInfo {
|
|
|
|
return {
|
|
|
|
url: `https://github.com/SimonKagstrom/kcov/archive/refs/tags/${version}.tar.gz`,
|
2022-07-28 09:45:26 +08:00
|
|
|
extractedFolderName: "",
|
|
|
|
binRelativeDir: "build/src",
|
2022-07-22 16:06:43 +08:00
|
|
|
binFileName: addBinExtension("kcov"),
|
|
|
|
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"])
|
2022-07-28 09:45:26 +08:00
|
|
|
|
2022-04-16 15:42:53 +08:00
|
|
|
// build after extraction using CMake
|
2022-07-28 10:07:30 +08:00
|
|
|
const cmake = await getCmake()
|
2022-07-28 09:45:26 +08:00
|
|
|
|
2022-04-16 15:42:53 +08:00
|
|
|
if (process.platform === "linux") {
|
2022-06-30 10:06:33 +08:00
|
|
|
if (isArch()) {
|
2022-06-30 00:06:35 +08:00
|
|
|
setupPacmanPack("libdwarf")
|
|
|
|
setupPacmanPack("libcurl-openssl")
|
2022-07-11 07:34:56 +08:00
|
|
|
} else if (hasDnf()) {
|
|
|
|
setupDnfPack("libdwarf-devel")
|
|
|
|
setupDnfPack("libcurl-devel")
|
2022-07-11 08:39:21 +08:00
|
|
|
} else if (isUbuntu()) {
|
2022-07-28 10:07:30 +08:00
|
|
|
await setupAptPack("libdw-dev")
|
|
|
|
await setupAptPack("libcurl4-openssl-dev")
|
2022-06-30 00:06:35 +08:00
|
|
|
}
|
2022-04-16 15:42:53 +08:00
|
|
|
}
|
2022-07-28 09:45:26 +08:00
|
|
|
const buildDir = join(out, "build")
|
|
|
|
await execa(cmake, ["-S", out, "-B", buildDir, "-DCMAKE_BUILD_TYPE=Release", "-G", "Ninja"], {
|
|
|
|
cwd: out,
|
|
|
|
stdio: "inherit",
|
|
|
|
})
|
|
|
|
await execa(cmake, ["--build", buildDir, "--config", "Release"], { cwd: out, stdio: "inherit" })
|
2022-08-08 08:33:11 +08:00
|
|
|
// execRootSync(cmake, ["--install", buildDir], out)
|
2022-07-28 04:51:05 +08:00
|
|
|
// return "user/local/bin" // the cmake install prefix
|
2022-07-28 09:45:26 +08:00
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getCmake() {
|
|
|
|
let cmake = which.sync("cmake", { nothrow: true })
|
|
|
|
if (cmake === null) {
|
2022-08-08 11:04:59 +08:00
|
|
|
const { binDir } = await setupCmake(getVersion("cmake", undefined), join(untildifyUser(""), "cmake"), "")
|
2022-07-28 09:45:26 +08:00
|
|
|
cmake = join(binDir, "cmake")
|
|
|
|
}
|
2022-07-28 10:07:30 +08:00
|
|
|
const ninja = which.sync("ninja", { nothrow: true })
|
2022-07-28 09:45:26 +08:00
|
|
|
if (ninja === null) {
|
2022-08-08 11:04:59 +08:00
|
|
|
await setupNinja(getVersion("ninja", undefined), join(untildifyUser(""), "ninja"), "")
|
2022-07-28 09:45:26 +08:00
|
|
|
}
|
|
|
|
return cmake
|
2022-04-16 15:42:53 +08:00
|
|
|
}
|
|
|
|
|
2022-07-22 16:06:43 +08:00
|
|
|
export async function setupKcov(versionGiven: string, setupDir: string, arch: string) {
|
2022-07-28 03:30:56 +08:00
|
|
|
if (process.platform !== "linux") {
|
2022-07-25 14:08:28 +08:00
|
|
|
info("Kcov is not supported on non-linux")
|
2022-07-23 04:57:11 +08:00
|
|
|
return
|
|
|
|
}
|
2022-07-22 16:06:43 +08:00
|
|
|
|
2022-07-23 04:57:11 +08:00
|
|
|
// parse version
|
|
|
|
const versionSplit = versionGiven.split("-")
|
|
|
|
let version = addVPrefix(versionSplit[0])
|
|
|
|
const installMethod = versionSplit[1] as "binary" | undefined
|
|
|
|
const version_number = removeVPrefix(version)
|
|
|
|
// fix inconsistency in tagging
|
|
|
|
if (version_number === 38) {
|
|
|
|
version = "v38"
|
|
|
|
}
|
|
|
|
|
|
|
|
let installationInfo: InstallationInfo
|
|
|
|
if (installMethod === "binary" && version_number >= 39) {
|
|
|
|
installationInfo = await setupBin("kcov", version, getDownloadKcovPackageInfo, setupDir, arch)
|
|
|
|
if (isArch()) {
|
|
|
|
setupPacmanPack("binutils")
|
|
|
|
} else if (hasDnf()) {
|
|
|
|
setupDnfPack("binutils")
|
|
|
|
} else if (isUbuntu()) {
|
2022-07-28 10:07:30 +08:00
|
|
|
await setupAptPack("libbinutils")
|
2021-12-07 19:30:33 +08:00
|
|
|
}
|
2022-07-23 04:57:11 +08:00
|
|
|
return installationInfo
|
|
|
|
} else {
|
|
|
|
installationInfo = await setupBin("kcov", version, getBuildKcovPackageInfo, setupDir, arch)
|
2021-12-07 19:30:33 +08:00
|
|
|
}
|
2022-07-23 04:57:11 +08:00
|
|
|
return installationInfo
|
2021-12-07 19:30:33 +08:00
|
|
|
}
|