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", 16: "legacy",
14: "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 */ /** Get the default version if passed true or undefined, otherwise return the version itself */

View File

@ -9,34 +9,31 @@ import { addBinExtension } from "../utils/extension/extension"
import { extractTarByExe } from "../utils/setup/extract" import { extractTarByExe } from "../utils/setup/extract"
import { setupAptPack } from "../utils/setup/setupAptPack" import { setupAptPack } from "../utils/setup/setupAptPack"
import { setupPacmanPack } from "../utils/setup/setupPacmanPack" 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 { isArch } from "../utils/env/isArch"
import { hasDnf } from "../utils/env/hasDnf" import { hasDnf } from "../utils/env/hasDnf"
import { setupDnfPack } from "../utils/setup/setupDnfPack" import { setupDnfPack } from "../utils/setup/setupDnfPack"
import { isUbuntu } from "../utils/env/isUbuntu" import { isUbuntu } from "../utils/env/isUbuntu"
import { removeVPrefix } from "../utils/setup/version"
function getKcovPackageInfo(version: string): PackageInfo { function getDownloadKcovPackageInfo(version_number: string): PackageInfo {
const version_number = parseInt(version.replace(/^v/, ""), 10) return {
if (version_number === 38) { url: `https://github.com/SimonKagstrom/kcov/releases/download/v${version_number}/kcov-amd64.tar.gz`,
// eslint-disable-next-line no-param-reassign extractedFolderName: "",
version = "v38" 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`, function getBuildKcovPackageInfo(version: string): PackageInfo {
extractedFolderName: "", const version_number = removeVPrefix(version)
binRelativeDir: "usr/local/bin", return {
binFileName: addBinExtension("kcov"), url: `https://github.com/SimonKagstrom/kcov/archive/refs/tags/${version}.tar.gz`,
extractFunction: extractTarByExe, extractedFolderName: `kcov-${version_number}`,
} binRelativeDir: "build/",
} else { binFileName: addBinExtension("kcov"),
return { extractFunction: buildKcov,
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 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) { switch (process.platform) {
case "linux": { case "linux": {
const installationInfo = await setupBin("kcov", version, getKcovPackageInfo, setupDir, arch) // parse version
if (isArch()) { const versionSplit = versionGiven.split("-")
setupPacmanPack("binutils") let version = versionSplit[0]
} else if (hasDnf()) { const installMethod = versionSplit[1] as "binary" | undefined
setupDnfPack("binutils") const version_number = removeVPrefix(version)
} else if (isUbuntu()) { // fix inconsistency in tagging
setupAptPack("libbinutils") 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 return installationInfo
} }

View File

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