mirror of https://github.com/aminya/setup-cpp
Merge pull request #107 from aminya/kcov [skip ci]
This commit is contained in:
commit
a9e484f19f
|
@ -22,6 +22,7 @@ words:
|
||||||
- CPPFLAGS
|
- CPPFLAGS
|
||||||
- cpprc
|
- cpprc
|
||||||
- Cpython
|
- Cpython
|
||||||
|
- DCMAKE
|
||||||
- deps
|
- deps
|
||||||
- devel
|
- devel
|
||||||
- dyld
|
- dyld
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -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 */
|
||||||
|
|
|
@ -2,22 +2,35 @@ import { setupKcov } from "../kcov"
|
||||||
import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers"
|
import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers"
|
||||||
import { InstallationInfo } from "../../utils/setup/setupBin"
|
import { InstallationInfo } from "../../utils/setup/setupBin"
|
||||||
import which from "which"
|
import which from "which"
|
||||||
|
import { info } from "@actions/core"
|
||||||
|
|
||||||
jest.setTimeout(300000)
|
jest.setTimeout(300000)
|
||||||
describe("setup-Kcov", () => {
|
describe("setup-Kcov", () => {
|
||||||
if (process.platform !== "linux") {
|
if (process.platform !== "linux") {
|
||||||
it.todo("should setup kcov on non-linux")
|
it.todo("should setup kcov on non-Windows")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
it("should setup Kcov v40", async () => {
|
it("should setup Kcov v40 via downloading the binaries", async () => {
|
||||||
|
const directory = await setupTmpDir("kcov-v40")
|
||||||
|
const { binDir } = (await setupKcov("40-binary", directory, "")) as InstallationInfo
|
||||||
|
// the prebuild binary only works on ubuntu 20.04
|
||||||
|
try {
|
||||||
|
await testBin("kcov", ["--version"], binDir)
|
||||||
|
} catch (err) {
|
||||||
|
info((err as Error).message)
|
||||||
|
}
|
||||||
|
await cleanupTmpDir("kcov-v40")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should build and setup Kcov v40", async () => {
|
||||||
const directory = await setupTmpDir("kcov-v40")
|
const directory = await setupTmpDir("kcov-v40")
|
||||||
const { binDir } = (await setupKcov("40", directory, "")) as InstallationInfo
|
const { binDir } = (await setupKcov("40", directory, "")) as InstallationInfo
|
||||||
await testBin("kcov", ["--version"], binDir)
|
await testBin("kcov", ["--version"], binDir)
|
||||||
await cleanupTmpDir("kcov-v40")
|
await cleanupTmpDir("kcov-v40")
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should setup Kcov v39", async () => {
|
it("should build and setup Kcov v39", async () => {
|
||||||
const directory = await setupTmpDir("kcov-v39")
|
const directory = await setupTmpDir("kcov-v39")
|
||||||
const { binDir } = (await setupKcov("39", directory, "")) as InstallationInfo
|
const { binDir } = (await setupKcov("39", directory, "")) as InstallationInfo
|
||||||
await testBin("kcov", ["--version"], binDir)
|
await testBin("kcov", ["--version"], binDir)
|
||||||
|
@ -32,7 +45,7 @@ describe("setup-Kcov", () => {
|
||||||
// await cleanupTmpDir("kcov-v39")
|
// await cleanupTmpDir("kcov-v39")
|
||||||
// })
|
// })
|
||||||
|
|
||||||
it("should setup Kcov v38", async () => {
|
it("should build and setup Kcov v38", async () => {
|
||||||
try {
|
try {
|
||||||
const directory2 = await setupTmpDir("kcov-v38")
|
const directory2 = await setupTmpDir("kcov-v38")
|
||||||
|
|
||||||
|
|
121
src/kcov/kcov.ts
121
src/kcov/kcov.ts
|
@ -1,51 +1,48 @@
|
||||||
import execa from "execa"
|
import execa from "execa"
|
||||||
import { join } from "path"
|
import { join } from "path"
|
||||||
import untildify from "untildify"
|
|
||||||
import which from "which"
|
import which from "which"
|
||||||
import { setupCmake } from "../cmake/cmake"
|
import { setupCmake } from "../cmake/cmake"
|
||||||
import { getVersion } from "../default_versions"
|
import { getVersion } from "../default_versions"
|
||||||
import { execSudo } from "../utils/exec/sudo"
|
|
||||||
import { addBinExtension } from "../utils/extension/extension"
|
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 { addVPrefix, removeVPrefix } from "../utils/setup/version"
|
||||||
|
import { info } from "../utils/io/io"
|
||||||
|
import { untildify_user } from "../utils/path/untildify"
|
||||||
|
import { setupNinja } from "../ninja/ninja"
|
||||||
|
|
||||||
function getKcovPackageInfo(version: string): PackageInfo {
|
function getDownloadKcovPackageInfo(version: string): PackageInfo {
|
||||||
const version_number = parseInt(version.replace(/^v/, ""), 10)
|
return {
|
||||||
if (version_number === 38) {
|
url: `https://github.com/SimonKagstrom/kcov/releases/download/${version}/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: "",
|
return {
|
||||||
binRelativeDir: "usr/local/bin",
|
url: `https://github.com/SimonKagstrom/kcov/archive/refs/tags/${version}.tar.gz`,
|
||||||
binFileName: addBinExtension("kcov"),
|
extractedFolderName: "",
|
||||||
extractFunction: extractTarByExe,
|
binRelativeDir: "build/src",
|
||||||
}
|
binFileName: addBinExtension("kcov"),
|
||||||
} else {
|
extractFunction: buildKcov,
|
||||||
return {
|
|
||||||
url: `https://github.com/SimonKagstrom/kcov/archive/refs/tags/${version}.tar.gz`,
|
|
||||||
extractedFolderName: `kcov-${version_number}`,
|
|
||||||
binRelativeDir: "build/",
|
|
||||||
binFileName: addBinExtension("kcov"),
|
|
||||||
extractFunction: buildKcov,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function buildKcov(file: string, dest: string) {
|
async function buildKcov(file: string, dest: string) {
|
||||||
const out = await extractTarByExe(file, dest, ["--strip-components=1"])
|
const out = await extractTarByExe(file, dest, ["--strip-components=1"])
|
||||||
|
|
||||||
// build after extraction using CMake
|
// build after extraction using CMake
|
||||||
if (which.sync("cmake", { nothrow: true }) === null) {
|
let cmake = await getCmake()
|
||||||
await setupCmake(getVersion("cmake", undefined), join(untildify(""), "cmake"), "")
|
|
||||||
}
|
|
||||||
if (process.platform === "linux") {
|
if (process.platform === "linux") {
|
||||||
if (isArch()) {
|
if (isArch()) {
|
||||||
setupPacmanPack("libdwarf")
|
setupPacmanPack("libdwarf")
|
||||||
|
@ -58,27 +55,59 @@ async function buildKcov(file: string, dest: string) {
|
||||||
setupAptPack("libcurl4-openssl-dev")
|
setupAptPack("libcurl4-openssl-dev")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await execa("cmake", ["-S", "./", "-B", "./build"], { cwd: out, stdio: "inherit" })
|
const buildDir = join(out, "build")
|
||||||
await execa("cmake", ["--build", "./build", "--config", "Release"], { cwd: out, stdio: "inherit" })
|
await execa(cmake, ["-S", out, "-B", buildDir, "-DCMAKE_BUILD_TYPE=Release", "-G", "Ninja"], {
|
||||||
execSudo("cmake", ["--install", "./build"], out)
|
cwd: out,
|
||||||
|
stdio: "inherit",
|
||||||
|
})
|
||||||
|
await execa(cmake, ["--build", buildDir, "--config", "Release"], { cwd: out, stdio: "inherit" })
|
||||||
|
// execSudo(cmake, ["--install", buildDir], out)
|
||||||
|
// return "user/local/bin" // the cmake install prefix
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setupKcov(version: string, setupDir: string, arch: string) {
|
async function getCmake() {
|
||||||
switch (process.platform) {
|
let cmake = which.sync("cmake", { nothrow: true })
|
||||||
case "linux": {
|
if (cmake === null) {
|
||||||
const installationInfo = await setupBin("kcov", version, getKcovPackageInfo, setupDir, arch)
|
const { binDir } = await setupCmake(getVersion("cmake", undefined), join(untildify_user(""), "cmake"), "")
|
||||||
if (isArch()) {
|
cmake = join(binDir, "cmake")
|
||||||
setupPacmanPack("binutils")
|
|
||||||
} else if (hasDnf()) {
|
|
||||||
setupDnfPack("binutils")
|
|
||||||
} else if (isUbuntu()) {
|
|
||||||
setupAptPack("libbinutils")
|
|
||||||
}
|
|
||||||
return installationInfo
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
throw new Error(`Unsupported platform for ${arch}`)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
let ninja = which.sync("ninja", { nothrow: true })
|
||||||
|
if (ninja === null) {
|
||||||
|
await setupNinja(getVersion("ninja", undefined), join(untildify_user(""), "ninja"), "")
|
||||||
|
}
|
||||||
|
return cmake
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function setupKcov(versionGiven: string, setupDir: string, arch: string) {
|
||||||
|
if (process.platform !== "linux") {
|
||||||
|
info("Kcov is not supported on non-linux")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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()) {
|
||||||
|
setupAptPack("libbinutils")
|
||||||
|
}
|
||||||
|
return installationInfo
|
||||||
|
} else {
|
||||||
|
installationInfo = await setupBin("kcov", version, getBuildKcovPackageInfo, setupDir, arch)
|
||||||
|
}
|
||||||
|
return installationInfo
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,8 +82,8 @@ export async function setupBin(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const installDir = join(setupDir, extractedFolderName)
|
let installDir = join(setupDir, extractedFolderName)
|
||||||
const binDir = join(installDir, binRelativeDir)
|
let binDir = join(installDir, binRelativeDir)
|
||||||
const binFile = join(binDir, binFileName)
|
const binFile = join(binDir, binFileName)
|
||||||
|
|
||||||
// download ane extract the package into the installation directory.
|
// download ane extract the package into the installation directory.
|
||||||
|
@ -114,8 +114,12 @@ export async function setupBin(
|
||||||
try {
|
try {
|
||||||
const downloaded = await downloadTool(url)
|
const downloaded = await downloadTool(url)
|
||||||
await extractFunction?.(downloaded, setupDir)
|
await extractFunction?.(downloaded, setupDir)
|
||||||
|
// if (typeof extractedBinDir === "string") {
|
||||||
|
// binDir = extractedBinDir
|
||||||
|
// installDir = extractedBinDir
|
||||||
|
// }
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error(`Failed to download ${name} ${version} ${arch}: ${err}`)
|
throw new Error(`Failed to download ${name} ${version} ${arch} from ${url}: ${err}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,3 +115,14 @@ export function semverCoerceIfInvalid(version: string) {
|
||||||
}
|
}
|
||||||
return version
|
return version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function removeVPrefix(version: string) {
|
||||||
|
return parseInt(version.replace(/^v/, ""), 10)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function addVPrefix(version: string) {
|
||||||
|
if (!version.match(/^v/)) {
|
||||||
|
return `v${version}`
|
||||||
|
}
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ export async function testBin(
|
||||||
) {
|
) {
|
||||||
let bin = name
|
let bin = name
|
||||||
if (typeof binDir === "string") {
|
if (typeof binDir === "string") {
|
||||||
|
console.log(`Testing the existence of ${binDir}`)
|
||||||
expect(binDir).toBeDefined()
|
expect(binDir).toBeDefined()
|
||||||
expect(binDir).not.toHaveLength(0)
|
expect(binDir).not.toHaveLength(0)
|
||||||
expect(existsSync(binDir)).toBeTruthy()
|
expect(existsSync(binDir)).toBeTruthy()
|
||||||
|
|
Loading…
Reference in New Issue