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")
|
throw new Error("installing bazel on Arch linux is not supported yet")
|
||||||
} else if (hasDnf()) {
|
} else if (hasDnf()) {
|
||||||
// https://bazel.build/install/redhat
|
// https://bazel.build/install/redhat
|
||||||
setupDnfPack("dnf-plugins-core", undefined)
|
await setupDnfPack([{ name: "dnf-plugins-core" }])
|
||||||
execRootSync("dnf", ["copr", "enable", "vbatts/bazel"])
|
execRootSync("dnf", ["copr", "enable", "vbatts/bazel"])
|
||||||
return setupDnfPack("bazel4", undefined)
|
return setupDnfPack([{ name: "bazel4" }])
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
// https://bazel.build/install/ubuntu
|
// https://bazel.build/install/ubuntu
|
||||||
const keyFileName = await addAptKeyViaDownload(
|
const keyFileName = await addAptKeyViaDownload(
|
||||||
|
|
|
@ -20,7 +20,7 @@ export function setupCcache(version: string, _setupDir: string, _arch: string) {
|
||||||
if (isArch()) {
|
if (isArch()) {
|
||||||
return setupPacmanPack("ccache", version)
|
return setupPacmanPack("ccache", version)
|
||||||
} else if (hasDnf()) {
|
} else if (hasDnf()) {
|
||||||
return setupDnfPack("ccache", version)
|
return setupDnfPack([{ name: "ccache", version }])
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
return setupAptPack([{ name: "ccache", version }])
|
return setupAptPack([{ name: "ccache", version }])
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ export async function setupCppcheck(version: string | undefined, _setupDir: stri
|
||||||
if (isArch()) {
|
if (isArch()) {
|
||||||
return setupPacmanPack("cppcheck", version)
|
return setupPacmanPack("cppcheck", version)
|
||||||
} else if (hasDnf()) {
|
} else if (hasDnf()) {
|
||||||
return setupDnfPack("ccache", version)
|
return setupDnfPack([{ name: "ccache", version }])
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
return setupAptPack([{ name: "cppcheck", version }])
|
return setupAptPack([{ name: "cppcheck", version }])
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
|
||||||
if (isArch()) {
|
if (isArch()) {
|
||||||
installationInfo = await setupPacmanPack("doxygen", version)
|
installationInfo = await setupPacmanPack("doxygen", version)
|
||||||
} else if (hasDnf()) {
|
} else if (hasDnf()) {
|
||||||
return setupDnfPack("doxygen", version)
|
return setupDnfPack([{ name: "doxygen", version }])
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
installationInfo = await setupAptPack([{ name: "doxygen", version }])
|
installationInfo = await setupAptPack([{ name: "doxygen", version }])
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -98,9 +98,11 @@ export async function setupGcc(version: string, setupDir: string, arch: string)
|
||||||
if (isArch()) {
|
if (isArch()) {
|
||||||
installationInfo = await setupPacmanPack("gcc", version)
|
installationInfo = await setupPacmanPack("gcc", version)
|
||||||
} else if (hasDnf()) {
|
} else if (hasDnf()) {
|
||||||
installationInfo = setupDnfPack("gcc", version)
|
installationInfo = await setupDnfPack([
|
||||||
setupDnfPack("gcc-c++", version)
|
{ name: "gcc", version },
|
||||||
setupDnfPack("libstdc++-devel", undefined)
|
{ name: "gcc-c++", version },
|
||||||
|
{ name: "libstdc++-devel" },
|
||||||
|
])
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
installationInfo = await setupAptPack([
|
installationInfo = await setupAptPack([
|
||||||
{ name: "gcc", version, repositories: ["ppa:ubuntu-toolchain-r/test"] },
|
{ 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()) {
|
if (isArch()) {
|
||||||
return setupPacmanPack("graphviz", version)
|
return setupPacmanPack("graphviz", version)
|
||||||
} else if (hasDnf()) {
|
} else if (hasDnf()) {
|
||||||
return setupDnfPack("graphviz", version)
|
return setupDnfPack([{ name: "graphviz", version }])
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
return setupAptPack([{ name: "graphviz", version }])
|
return setupAptPack([{ name: "graphviz", version }])
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,8 +47,7 @@ async function buildKcov(file: string, dest: string) {
|
||||||
if (isArch()) {
|
if (isArch()) {
|
||||||
await Promise.all([setupPacmanPack("libdwarf"), setupPacmanPack("libcurl-openssl")])
|
await Promise.all([setupPacmanPack("libdwarf"), setupPacmanPack("libcurl-openssl")])
|
||||||
} else if (hasDnf()) {
|
} else if (hasDnf()) {
|
||||||
setupDnfPack("libdwarf-devel")
|
await setupDnfPack([{ name: "libdwarf-devel" }, { name: "libcurl-devel" }])
|
||||||
setupDnfPack("libcurl-devel")
|
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
await setupAptPack([{ name: "libdw-dev" }, { name: "libcurl4-openssl-dev" }])
|
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()) {
|
if (isArch()) {
|
||||||
await setupPacmanPack("binutils")
|
await setupPacmanPack("binutils")
|
||||||
} else if (hasDnf()) {
|
} else if (hasDnf()) {
|
||||||
setupDnfPack("binutils")
|
await setupDnfPack([{ name: "binutils" }])
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
await setupAptPack([{ name: "libbinutils" }])
|
await setupAptPack([{ name: "libbinutils" }])
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ export async function setupMake(version: string, _setupDir: string, _arch: strin
|
||||||
if (isArch()) {
|
if (isArch()) {
|
||||||
return setupPacmanPack("make", version)
|
return setupPacmanPack("make", version)
|
||||||
} else if (hasDnf()) {
|
} else if (hasDnf()) {
|
||||||
return setupDnfPack("make", version)
|
return setupDnfPack([{ name: "make", version }])
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
return setupAptPack([{ name: "make", version }])
|
return setupAptPack([{ name: "make", version }])
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,12 +26,12 @@ export async function setupPowershell(version: string | undefined, _setupDir: st
|
||||||
if (isArch()) {
|
if (isArch()) {
|
||||||
return setupPacmanPack("powershell-bin", version, "yay")
|
return setupPacmanPack("powershell-bin", version, "yay")
|
||||||
} else if (hasDnf()) {
|
} else if (hasDnf()) {
|
||||||
setupDnfPack("curl")
|
setupDnfPack([{ name: "curl" }])
|
||||||
execRootSync("/bin/bash", [
|
execRootSync("/bin/bash", [
|
||||||
"-c",
|
"-c",
|
||||||
`curl https://packages.microsoft.com/config/rhel/8/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo`,
|
`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()) {
|
} else if (isUbuntu()) {
|
||||||
await setupAptPack([{ name: "curl" }])
|
await setupAptPack([{ name: "curl" }])
|
||||||
const ubuntuVerSplitted = (await ubuntuVersion())!
|
const ubuntuVerSplitted = (await ubuntuVersion())!
|
||||||
|
|
|
@ -112,7 +112,7 @@ async function setupPythonSystem(setupDir: string, version: string) {
|
||||||
if (isArch()) {
|
if (isArch()) {
|
||||||
installInfo = await setupPacmanPack("python", version)
|
installInfo = await setupPacmanPack("python", version)
|
||||||
} else if (hasDnf()) {
|
} else if (hasDnf()) {
|
||||||
installInfo = setupDnfPack("python3", version)
|
installInfo = await setupDnfPack([{ name: "python3", version }])
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
installInfo = await setupAptPack([{ name: "python3", version }, { name: "python-is-python3" }])
|
installInfo = await setupAptPack([{ name: "python3", version }, { name: "python-is-python3" }])
|
||||||
} else {
|
} else {
|
||||||
|
@ -234,7 +234,7 @@ function setupPipSystem() {
|
||||||
if (isArch()) {
|
if (isArch()) {
|
||||||
return setupPacmanPack("python-pip")
|
return setupPacmanPack("python-pip")
|
||||||
} else if (hasDnf()) {
|
} else if (hasDnf()) {
|
||||||
return setupDnfPack("python3-pip")
|
return setupDnfPack([{ name: "python3-pip" }])
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
return setupAptPack([{ name: "python3-pip" }])
|
return setupAptPack([{ name: "python3-pip" }])
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,10 @@ export function setupSevenZip(version: string, _setupDir: string, _arch: string)
|
||||||
if (isArch()) {
|
if (isArch()) {
|
||||||
return setupPacmanPack("p7zip", version)
|
return setupPacmanPack("p7zip", version)
|
||||||
} else if (hasDnf()) {
|
} else if (hasDnf()) {
|
||||||
setupDnfPack("p7zip", version)
|
return setupDnfPack([
|
||||||
return setupDnfPack("p7zip-plugins", version)
|
{ name: "p7zip", version },
|
||||||
|
{ name: "p7zip-plugins", version },
|
||||||
|
])
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
return setupAptPack([{ name: "p7zip-full", version }])
|
return setupAptPack([{ name: "p7zip-full", version }])
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,9 +107,7 @@ export async function setupBin(
|
||||||
if (isArch()) {
|
if (isArch()) {
|
||||||
await Promise.all([setupPacmanPack("unzip"), setupPacmanPack("tar"), setupPacmanPack("xz")])
|
await Promise.all([setupPacmanPack("unzip"), setupPacmanPack("tar"), setupPacmanPack("xz")])
|
||||||
} else if (hasDnf()) {
|
} else if (hasDnf()) {
|
||||||
setupDnfPack("unzip")
|
await setupDnfPack([{ name: "unzip" }, { name: "tar" }, { name: "xz" }])
|
||||||
setupDnfPack("tar")
|
|
||||||
setupDnfPack("xz")
|
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
await setupAptPack([{ name: "unzip" }, { name: "tar" }, { name: "xz-utils" }])
|
await setupAptPack([{ name: "unzip" }, { name: "tar" }, { name: "xz-utils" }])
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,31 +1,35 @@
|
||||||
/* eslint-disable require-atomic-updates */
|
|
||||||
import { InstallationInfo } from "./setupBin"
|
import { InstallationInfo } from "./setupBin"
|
||||||
import { execRootSync } from "admina"
|
import { execRootSync } from "admina"
|
||||||
import { info, warning } from "ci-log"
|
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 */
|
/** A function that installs a package using dnf */
|
||||||
export function setupDnfPack(name: string, version?: string): InstallationInfo {
|
export async function setupDnfPack(packages: DnfPackage[]): Promise<InstallationInfo> {
|
||||||
|
for (const { name, version } of packages) {
|
||||||
info(`Installing ${name} ${version ?? ""} via dnf`)
|
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])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const dnfArgs = await Promise.all(packages.map((pack) => getDnfArg(pack.name, pack.version)))
|
||||||
|
execRootSync("dnf", ["-y", "install", ...dnfArgs])
|
||||||
|
|
||||||
return { binDir: "/usr/bin/" }
|
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"),
|
setupPacmanPack("pkg-config"),
|
||||||
])
|
])
|
||||||
} else if (hasDnf()) {
|
} else if (hasDnf()) {
|
||||||
setupDnfPack("curl")
|
await setupDnfPack([
|
||||||
setupDnfPack("zip")
|
{ name: "curl" },
|
||||||
setupDnfPack("unzip")
|
{ name: "zip" },
|
||||||
setupDnfPack("tar")
|
{ name: "unzip" },
|
||||||
setupDnfPack("git")
|
{ name: "tar" },
|
||||||
setupDnfPack("pkg-config")
|
{ name: "git" },
|
||||||
|
{ name: "pkg-config" },
|
||||||
|
])
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
await setupAptPack([
|
await setupAptPack([
|
||||||
{ name: "curl" },
|
{ name: "curl" },
|
||||||
|
|
Loading…
Reference in New Issue