From 15070ee63704b67beec45ef6b84704917d7bb6a3 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 22 Jul 2022 01:06:43 -0700 Subject: [PATCH] fix: build or download kcov binary based on the ubuntu version --- src/default_versions.ts | 7 ++++ src/kcov/kcov.ts | 73 ++++++++++++++++++++++---------------- src/utils/setup/version.ts | 4 +++ 3 files changed, 54 insertions(+), 30 deletions(-) diff --git a/src/default_versions.ts b/src/default_versions.ts index ee6c1502..2145c859 100644 --- a/src/default_versions.ts +++ b/src/default_versions.ts @@ -63,6 +63,13 @@ const DefaultUbuntuVersion: Record> = { 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 */ diff --git a/src/kcov/kcov.ts b/src/kcov/kcov.ts index aaab3b40..849a5baf 100644 --- a/src/kcov/kcov.ts +++ b/src/kcov/kcov.ts @@ -9,34 +9,31 @@ 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" +function getDownloadKcovPackageInfo(version_number: string): PackageInfo { + return { + url: `https://github.com/SimonKagstrom/kcov/releases/download/v${version_number}/kcov-amd64.tar.gz`, + extractedFolderName: "", + binRelativeDir: "usr/local/bin", + binFileName: addBinExtension("kcov"), + extractFunction: extractTarByExe, } - if (version_number >= 39) { - return { - url: `https://github.com/SimonKagstrom/kcov/releases/download/v${version_number}/kcov-amd64.tar.gz`, - extractedFolderName: "", - binRelativeDir: "usr/local/bin", - binFileName: addBinExtension("kcov"), - extractFunction: extractTarByExe, - } - } else { - return { - url: `https://github.com/SimonKagstrom/kcov/archive/refs/tags/${version}.tar.gz`, - extractedFolderName: `kcov-${version_number}`, - binRelativeDir: "build/", - binFileName: addBinExtension("kcov"), - extractFunction: buildKcov, - } +} + +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}`, + binRelativeDir: "build/", + binFileName: addBinExtension("kcov"), + extractFunction: buildKcov, } } @@ -64,16 +61,32 @@ 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) - if (isArch()) { - setupPacmanPack("binutils") - } else if (hasDnf()) { - setupDnfPack("binutils") - } else if (isUbuntu()) { - setupAptPack("libbinutils") + // 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()) { + setupDnfPack("binutils") + } else if (isUbuntu()) { + setupAptPack("libbinutils") + } + return installationInfo + } else { + installationInfo = await setupBin("kcov", version, getBuildKcovPackageInfo, setupDir, arch) } return installationInfo } diff --git a/src/utils/setup/version.ts b/src/utils/setup/version.ts index 95eaa7a7..ae56403a 100644 --- a/src/utils/setup/version.ts +++ b/src/utils/setup/version.ts @@ -115,3 +115,7 @@ export function semverCoerceIfInvalid(version: string) { } return version } + +export function removeVPrefix(version: string) { + return parseInt(version.replace(/^v/, ""), 10) +}