mirror of https://github.com/aminya/setup-cpp
fix: build or download kcov binary based on the ubuntu version
This commit is contained in:
parent
8fb789d7c1
commit
15070ee637
|
@ -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 */
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -115,3 +115,7 @@ export function semverCoerceIfInvalid(version: string) {
|
|||
}
|
||||
return version
|
||||
}
|
||||
|
||||
export function removeVPrefix(version: string) {
|
||||
return parseInt(version.replace(/^v/, ""), 10)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue