mirror of https://github.com/aminya/setup-cpp
feat: support installing multiple dnf packages
This commit is contained in:
parent
dd9ff769c8
commit
41b2cf629a
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
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -23,9 +23,9 @@ export async function setupBazel(version: string, _setupDir: string, _arch: stri
|
|||
throw new Error("installing bazel on Arch linux is not supported yet")
|
||||
} else if (hasDnf()) {
|
||||
// https://bazel.build/install/redhat
|
||||
setupDnfPack("dnf-plugins-core", undefined)
|
||||
await setupDnfPack([{ name: "dnf-plugins-core" }])
|
||||
execRootSync("dnf", ["copr", "enable", "vbatts/bazel"])
|
||||
return setupDnfPack("bazel4", undefined)
|
||||
return setupDnfPack([{ name: "bazel4" }])
|
||||
} else if (isUbuntu()) {
|
||||
// https://bazel.build/install/ubuntu
|
||||
const keyFileName = await addAptKeyViaDownload(
|
||||
|
|
|
@ -20,7 +20,7 @@ export function setupCcache(version: string, _setupDir: string, _arch: string) {
|
|||
if (isArch()) {
|
||||
return setupPacmanPack("ccache", version)
|
||||
} else if (hasDnf()) {
|
||||
return setupDnfPack("ccache", version)
|
||||
return setupDnfPack([{ name: "ccache", version }])
|
||||
} else if (isUbuntu()) {
|
||||
return setupAptPack([{ name: "ccache", version }])
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ export async function setupCppcheck(version: string | undefined, _setupDir: stri
|
|||
if (isArch()) {
|
||||
return setupPacmanPack("cppcheck", version)
|
||||
} else if (hasDnf()) {
|
||||
return setupDnfPack("ccache", version)
|
||||
return setupDnfPack([{ name: "ccache", version }])
|
||||
} else if (isUbuntu()) {
|
||||
return setupAptPack([{ name: "cppcheck", version }])
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
|
|||
if (isArch()) {
|
||||
installationInfo = await setupPacmanPack("doxygen", version)
|
||||
} else if (hasDnf()) {
|
||||
return setupDnfPack("doxygen", version)
|
||||
return setupDnfPack([{ name: "doxygen", version }])
|
||||
} else if (isUbuntu()) {
|
||||
installationInfo = await setupAptPack([{ name: "doxygen", version }])
|
||||
} else {
|
||||
|
|
|
@ -98,9 +98,11 @@ export async function setupGcc(version: string, setupDir: string, arch: string)
|
|||
if (isArch()) {
|
||||
installationInfo = await setupPacmanPack("gcc", version)
|
||||
} else if (hasDnf()) {
|
||||
installationInfo = setupDnfPack("gcc", version)
|
||||
setupDnfPack("gcc-c++", version)
|
||||
setupDnfPack("libstdc++-devel", undefined)
|
||||
installationInfo = await setupDnfPack([
|
||||
{ name: "gcc", version },
|
||||
{ name: "gcc-c++", version },
|
||||
{ name: "libstdc++-devel" },
|
||||
])
|
||||
} else if (isUbuntu()) {
|
||||
installationInfo = await setupAptPack([
|
||||
{ name: "gcc", version, repositories: ["ppa:ubuntu-toolchain-r/test"] },
|
||||
|
|
|
@ -23,7 +23,7 @@ export async function setupGraphviz(version: string, _setupDir: string, _arch: s
|
|||
if (isArch()) {
|
||||
return setupPacmanPack("graphviz", version)
|
||||
} else if (hasDnf()) {
|
||||
return setupDnfPack("graphviz", version)
|
||||
return setupDnfPack([{ name: "graphviz", version }])
|
||||
} else if (isUbuntu()) {
|
||||
return setupAptPack([{ name: "graphviz", version }])
|
||||
}
|
||||
|
|
|
@ -47,8 +47,7 @@ async function buildKcov(file: string, dest: string) {
|
|||
if (isArch()) {
|
||||
await Promise.all([setupPacmanPack("libdwarf"), setupPacmanPack("libcurl-openssl")])
|
||||
} else if (hasDnf()) {
|
||||
setupDnfPack("libdwarf-devel")
|
||||
setupDnfPack("libcurl-devel")
|
||||
await setupDnfPack([{ name: "libdwarf-devel" }, { name: "libcurl-devel" }])
|
||||
} else if (isUbuntu()) {
|
||||
await setupAptPack([{ name: "libdw-dev" }, { name: "libcurl4-openssl-dev" }])
|
||||
}
|
||||
|
@ -116,7 +115,7 @@ export async function setupKcov(versionGiven: string, setupDir: string, arch: st
|
|||
if (isArch()) {
|
||||
await setupPacmanPack("binutils")
|
||||
} else if (hasDnf()) {
|
||||
setupDnfPack("binutils")
|
||||
await setupDnfPack([{ name: "binutils" }])
|
||||
} else if (isUbuntu()) {
|
||||
await setupAptPack([{ name: "libbinutils" }])
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ export async function setupMake(version: string, _setupDir: string, _arch: strin
|
|||
if (isArch()) {
|
||||
return setupPacmanPack("make", version)
|
||||
} else if (hasDnf()) {
|
||||
return setupDnfPack("make", version)
|
||||
return setupDnfPack([{ name: "make", version }])
|
||||
} else if (isUbuntu()) {
|
||||
return setupAptPack([{ name: "make", version }])
|
||||
}
|
||||
|
|
|
@ -26,12 +26,12 @@ export async function setupPowershell(version: string | undefined, _setupDir: st
|
|||
if (isArch()) {
|
||||
return setupPacmanPack("powershell-bin", version, "yay")
|
||||
} else if (hasDnf()) {
|
||||
setupDnfPack("curl")
|
||||
setupDnfPack([{ name: "curl" }])
|
||||
execRootSync("/bin/bash", [
|
||||
"-c",
|
||||
`curl https://packages.microsoft.com/config/rhel/8/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo`,
|
||||
])
|
||||
return setupDnfPack("powershell", version)
|
||||
return setupDnfPack([{ name: "powershell", version }])
|
||||
} else if (isUbuntu()) {
|
||||
await setupAptPack([{ name: "curl" }])
|
||||
const ubuntuVerSplitted = (await ubuntuVersion())!
|
||||
|
|
|
@ -112,7 +112,7 @@ async function setupPythonSystem(setupDir: string, version: string) {
|
|||
if (isArch()) {
|
||||
installInfo = await setupPacmanPack("python", version)
|
||||
} else if (hasDnf()) {
|
||||
installInfo = setupDnfPack("python3", version)
|
||||
installInfo = await setupDnfPack([{ name: "python3", version }])
|
||||
} else if (isUbuntu()) {
|
||||
installInfo = await setupAptPack([{ name: "python3", version }, { name: "python-is-python3" }])
|
||||
} else {
|
||||
|
@ -234,7 +234,7 @@ function setupPipSystem() {
|
|||
if (isArch()) {
|
||||
return setupPacmanPack("python-pip")
|
||||
} else if (hasDnf()) {
|
||||
return setupDnfPack("python3-pip")
|
||||
return setupDnfPack([{ name: "python3-pip" }])
|
||||
} else if (isUbuntu()) {
|
||||
return setupAptPack([{ name: "python3-pip" }])
|
||||
}
|
||||
|
|
|
@ -20,8 +20,10 @@ export function setupSevenZip(version: string, _setupDir: string, _arch: string)
|
|||
if (isArch()) {
|
||||
return setupPacmanPack("p7zip", version)
|
||||
} else if (hasDnf()) {
|
||||
setupDnfPack("p7zip", version)
|
||||
return setupDnfPack("p7zip-plugins", version)
|
||||
return setupDnfPack([
|
||||
{ name: "p7zip", version },
|
||||
{ name: "p7zip-plugins", version },
|
||||
])
|
||||
} else if (isUbuntu()) {
|
||||
return setupAptPack([{ name: "p7zip-full", version }])
|
||||
}
|
||||
|
|
|
@ -107,9 +107,7 @@ export async function setupBin(
|
|||
if (isArch()) {
|
||||
await Promise.all([setupPacmanPack("unzip"), setupPacmanPack("tar"), setupPacmanPack("xz")])
|
||||
} else if (hasDnf()) {
|
||||
setupDnfPack("unzip")
|
||||
setupDnfPack("tar")
|
||||
setupDnfPack("xz")
|
||||
await setupDnfPack([{ name: "unzip" }, { name: "tar" }, { name: "xz" }])
|
||||
} else if (isUbuntu()) {
|
||||
await setupAptPack([{ name: "unzip" }, { name: "tar" }, { name: "xz-utils" }])
|
||||
}
|
||||
|
|
|
@ -1,31 +1,35 @@
|
|||
/* eslint-disable require-atomic-updates */
|
||||
import { InstallationInfo } from "./setupBin"
|
||||
import { execRootSync } from "admina"
|
||||
import { info, warning } from "ci-log"
|
||||
import { execa } from "execa"
|
||||
|
||||
// let didUpdate: boolean = false
|
||||
export type DnfPackage = {
|
||||
name: string
|
||||
version?: string
|
||||
}
|
||||
|
||||
/** A function that installs a package using dnf */
|
||||
export function setupDnfPack(name: string, version?: string): InstallationInfo {
|
||||
info(`Installing ${name} ${version ?? ""} via dnf`)
|
||||
|
||||
const dnf = "dnf"
|
||||
|
||||
// if (!didUpdate) {
|
||||
// execRootSync(dnf, ["-y", "check-update"])
|
||||
// didUpdate = true
|
||||
// }
|
||||
|
||||
if (version !== undefined && version !== "") {
|
||||
try {
|
||||
execRootSync(dnf, ["-y", "install", `${name}-${version}`])
|
||||
} catch (err) {
|
||||
warning(`${(err as Error).toString()}\nInstalling the default version available via dnf`)
|
||||
execRootSync(dnf, ["-y", "install", name])
|
||||
}
|
||||
} else {
|
||||
execRootSync(dnf, ["-y", "install", name])
|
||||
export async function setupDnfPack(packages: DnfPackage[]): Promise<InstallationInfo> {
|
||||
for (const { name, version } of packages) {
|
||||
info(`Installing ${name} ${version ?? ""} via dnf`)
|
||||
}
|
||||
|
||||
const dnfArgs = await Promise.all(packages.map((pack) => getDnfArg(pack.name, pack.version)))
|
||||
execRootSync("dnf", ["-y", "install", ...dnfArgs])
|
||||
|
||||
return { binDir: "/usr/bin/" }
|
||||
}
|
||||
|
||||
async function getDnfArg(name: string, version: string | undefined) {
|
||||
if (version !== undefined && version !== "") {
|
||||
// check if name-version is available
|
||||
const { stdout } = await execa("dnf", ["search", `${name}-${version}`, "--exact", "--quiet"])
|
||||
|
||||
if (stdout.trim() !== "") {
|
||||
return `${name}-${version}`
|
||||
} else {
|
||||
warning(`Failed to install ${name} ${version} via dnf, trying without version`)
|
||||
}
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
|
|
@ -30,12 +30,14 @@ export async function setupVcpkg(_version: string, setupDir: string, _arch: stri
|
|||
setupPacmanPack("pkg-config"),
|
||||
])
|
||||
} else if (hasDnf()) {
|
||||
setupDnfPack("curl")
|
||||
setupDnfPack("zip")
|
||||
setupDnfPack("unzip")
|
||||
setupDnfPack("tar")
|
||||
setupDnfPack("git")
|
||||
setupDnfPack("pkg-config")
|
||||
await setupDnfPack([
|
||||
{ name: "curl" },
|
||||
{ name: "zip" },
|
||||
{ name: "unzip" },
|
||||
{ name: "tar" },
|
||||
{ name: "git" },
|
||||
{ name: "pkg-config" },
|
||||
])
|
||||
} else if (isUbuntu()) {
|
||||
await setupAptPack([
|
||||
{ name: "curl" },
|
||||
|
|
Loading…
Reference in New Issue