fix: build or download kcov binary based on the ubuntu version

This commit is contained in:
Amin Yahyaabadi 2022-07-22 01:06:43 -07:00
parent 8fb789d7c1
commit 15070ee637
3 changed files with 54 additions and 30 deletions

View File

@ -63,6 +63,13 @@ const DefaultUbuntuVersion: Record<string, Record<number, string>> = {
16: "legacy",
14: "legacy",
},
kcov: {
22: "40",
20: "40-binary", // https://github.com/SimonKagstrom/kcov/releases
18: "40",
16: "40",
14: "40",
},
}
/** Get the default version if passed true or undefined, otherwise return the version itself */

View File

@ -9,19 +9,14 @@ import { addBinExtension } from "../utils/extension/extension"
import { extractTarByExe } from "../utils/setup/extract"
import { setupAptPack } from "../utils/setup/setupAptPack"
import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
import { PackageInfo, setupBin } from "../utils/setup/setupBin"
import { InstallationInfo, PackageInfo, setupBin } from "../utils/setup/setupBin"
import { isArch } from "../utils/env/isArch"
import { hasDnf } from "../utils/env/hasDnf"
import { setupDnfPack } from "../utils/setup/setupDnfPack"
import { isUbuntu } from "../utils/env/isUbuntu"
import { removeVPrefix } from "../utils/setup/version"
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) {
function getDownloadKcovPackageInfo(version_number: string): PackageInfo {
return {
url: `https://github.com/SimonKagstrom/kcov/releases/download/v${version_number}/kcov-amd64.tar.gz`,
extractedFolderName: "",
@ -29,7 +24,10 @@ function getKcovPackageInfo(version: string): PackageInfo {
binFileName: addBinExtension("kcov"),
extractFunction: extractTarByExe,
}
} else {
}
function getBuildKcovPackageInfo(version: string): PackageInfo {
const version_number = removeVPrefix(version)
return {
url: `https://github.com/SimonKagstrom/kcov/archive/refs/tags/${version}.tar.gz`,
extractedFolderName: `kcov-${version_number}`,
@ -38,7 +36,6 @@ function getKcovPackageInfo(version: string): PackageInfo {
extractFunction: buildKcov,
}
}
}
async function buildKcov(file: string, dest: string) {
const out = await extractTarByExe(file, dest, ["--strip-components=1"])
@ -64,10 +61,22 @@ async function buildKcov(file: string, dest: string) {
return out
}
export async function setupKcov(version: string, setupDir: string, arch: string) {
export async function setupKcov(versionGiven: string, setupDir: string, arch: string) {
switch (process.platform) {
case "linux": {
const installationInfo = await setupBin("kcov", version, getKcovPackageInfo, setupDir, arch)
// parse version
const versionSplit = versionGiven.split("-")
let version = 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()) {
@ -76,6 +85,10 @@ export async function setupKcov(version: string, setupDir: string, arch: string)
setupAptPack("libbinutils")
}
return installationInfo
} else {
installationInfo = await setupBin("kcov", version, getBuildKcovPackageInfo, setupDir, arch)
}
return installationInfo
}
default: {
throw new Error(`Unsupported platform for ${arch}`)

View File

@ -115,3 +115,7 @@ export function semverCoerceIfInvalid(version: string) {
}
return version
}
export function removeVPrefix(version: string) {
return parseInt(version.replace(/^v/, ""), 10)
}