Merge pull request #107 from aminya/kcov [skip ci]

This commit is contained in:
Amin Yahyaabadi 2022-07-27 18:58:10 -07:00 committed by GitHub
commit a9e484f19f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 123 additions and 57 deletions

View File

@ -22,6 +22,7 @@ words:
- CPPFLAGS
- cpprc
- Cpython
- DCMAKE
- deps
- devel
- dyld

2
dist/setup_cpp.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/setup_cpp.mjs vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

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

@ -2,22 +2,35 @@ import { setupKcov } from "../kcov"
import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers"
import { InstallationInfo } from "../../utils/setup/setupBin"
import which from "which"
import { info } from "@actions/core"
jest.setTimeout(300000)
describe("setup-Kcov", () => {
if (process.platform !== "linux") {
it.todo("should setup kcov on non-linux")
it.todo("should setup kcov on non-Windows")
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 { binDir } = (await setupKcov("40", directory, "")) as InstallationInfo
await testBin("kcov", ["--version"], binDir)
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 { binDir } = (await setupKcov("39", directory, "")) as InstallationInfo
await testBin("kcov", ["--version"], binDir)
@ -32,7 +45,7 @@ describe("setup-Kcov", () => {
// await cleanupTmpDir("kcov-v39")
// })
it("should setup Kcov v38", async () => {
it("should build and setup Kcov v38", async () => {
try {
const directory2 = await setupTmpDir("kcov-v38")

View File

@ -1,51 +1,48 @@
import execa from "execa"
import { join } from "path"
import untildify from "untildify"
import which from "which"
import { setupCmake } from "../cmake/cmake"
import { getVersion } from "../default_versions"
import { execSudo } from "../utils/exec/sudo"
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 { 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 {
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: string): PackageInfo {
return {
url: `https://github.com/SimonKagstrom/kcov/releases/download/v${version_number}/kcov-amd64.tar.gz`,
url: `https://github.com/SimonKagstrom/kcov/releases/download/${version}/kcov-amd64.tar.gz`,
extractedFolderName: "",
binRelativeDir: "usr/local/bin",
binFileName: addBinExtension("kcov"),
extractFunction: extractTarByExe,
}
} else {
}
function getBuildKcovPackageInfo(version: string): PackageInfo {
return {
url: `https://github.com/SimonKagstrom/kcov/archive/refs/tags/${version}.tar.gz`,
extractedFolderName: `kcov-${version_number}`,
binRelativeDir: "build/",
extractedFolderName: "",
binRelativeDir: "build/src",
binFileName: addBinExtension("kcov"),
extractFunction: buildKcov,
}
}
}
async function buildKcov(file: string, dest: string) {
const out = await extractTarByExe(file, dest, ["--strip-components=1"])
// build after extraction using CMake
if (which.sync("cmake", { nothrow: true }) === null) {
await setupCmake(getVersion("cmake", undefined), join(untildify(""), "cmake"), "")
}
let cmake = await getCmake()
if (process.platform === "linux") {
if (isArch()) {
setupPacmanPack("libdwarf")
@ -58,16 +55,49 @@ async function buildKcov(file: string, dest: string) {
setupAptPack("libcurl4-openssl-dev")
}
}
await execa("cmake", ["-S", "./", "-B", "./build"], { cwd: out, stdio: "inherit" })
await execa("cmake", ["--build", "./build", "--config", "Release"], { cwd: out, stdio: "inherit" })
execSudo("cmake", ["--install", "./build"], out)
const buildDir = join(out, "build")
await execa(cmake, ["-S", out, "-B", buildDir, "-DCMAKE_BUILD_TYPE=Release", "-G", "Ninja"], {
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
}
export async function setupKcov(version: string, setupDir: string, arch: string) {
switch (process.platform) {
case "linux": {
const installationInfo = await setupBin("kcov", version, getKcovPackageInfo, setupDir, arch)
async function getCmake() {
let cmake = which.sync("cmake", { nothrow: true })
if (cmake === null) {
const { binDir } = await setupCmake(getVersion("cmake", undefined), join(untildify_user(""), "cmake"), "")
cmake = join(binDir, "cmake")
}
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()) {
@ -76,9 +106,8 @@ export async function setupKcov(version: string, setupDir: string, arch: string)
setupAptPack("libbinutils")
}
return installationInfo
} else {
installationInfo = await setupBin("kcov", version, getBuildKcovPackageInfo, setupDir, arch)
}
default: {
throw new Error(`Unsupported platform for ${arch}`)
}
}
return installationInfo
}

View File

@ -82,8 +82,8 @@ export async function setupBin(
}
}
const installDir = join(setupDir, extractedFolderName)
const binDir = join(installDir, binRelativeDir)
let installDir = join(setupDir, extractedFolderName)
let binDir = join(installDir, binRelativeDir)
const binFile = join(binDir, binFileName)
// download ane extract the package into the installation directory.
@ -114,8 +114,12 @@ export async function setupBin(
try {
const downloaded = await downloadTool(url)
await extractFunction?.(downloaded, setupDir)
// if (typeof extractedBinDir === "string") {
// binDir = extractedBinDir
// installDir = extractedBinDir
// }
} catch (err) {
throw new Error(`Failed to download ${name} ${version} ${arch}: ${err}`)
throw new Error(`Failed to download ${name} ${version} ${arch} from ${url}: ${err}`)
}
}

View File

@ -115,3 +115,14 @@ export function semverCoerceIfInvalid(version: string) {
}
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
}

View File

@ -37,6 +37,7 @@ export async function testBin(
) {
let bin = name
if (typeof binDir === "string") {
console.log(`Testing the existence of ${binDir}`)
expect(binDir).toBeDefined()
expect(binDir).not.toHaveLength(0)
expect(existsSync(binDir)).toBeTruthy()