mirror of https://github.com/aminya/setup-cpp
feat: parallelize the apt package installation chunks
This commit is contained in:
parent
eea16aa8c7
commit
dac72316df
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
|
@ -36,7 +36,7 @@ export async function setupBazel(version: string, _setupDir: string, _arch: stri
|
||||||
"-c",
|
"-c",
|
||||||
`echo "deb [arch=amd64 signed-by=${keyFileName}] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list`,
|
`echo "deb [arch=amd64 signed-by=${keyFileName}] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list`,
|
||||||
])
|
])
|
||||||
return setupAptPack("bazel", version, [], true)
|
return setupAptPack([{ name: "bazel", version }], true)
|
||||||
}
|
}
|
||||||
throw new Error(`Unsupported linux distribution`)
|
throw new Error(`Unsupported linux distribution`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ export function setupCcache(version: string, _setupDir: string, _arch: string) {
|
||||||
} else if (hasDnf()) {
|
} else if (hasDnf()) {
|
||||||
return setupDnfPack("ccache", version)
|
return setupDnfPack("ccache", version)
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
return setupAptPack("ccache", version)
|
return setupAptPack([{ name: "ccache", version }])
|
||||||
}
|
}
|
||||||
throw new Error(`Unsupported linux distribution`)
|
throw new Error(`Unsupported linux distribution`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ export async function setupCppcheck(version: string | undefined, _setupDir: stri
|
||||||
} else if (hasDnf()) {
|
} else if (hasDnf()) {
|
||||||
return setupDnfPack("ccache", version)
|
return setupDnfPack("ccache", version)
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
return setupAptPack("cppcheck", version)
|
return setupAptPack([{ name: "cppcheck", version }])
|
||||||
}
|
}
|
||||||
throw new Error(`Unsupported linux distribution`)
|
throw new Error(`Unsupported linux distribution`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
|
||||||
} else if (hasDnf()) {
|
} else if (hasDnf()) {
|
||||||
return setupDnfPack("doxygen", version)
|
return setupDnfPack("doxygen", version)
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
installationInfo = await setupAptPack("doxygen", version)
|
installationInfo = await setupAptPack([{ name: "doxygen", version }])
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Unsupported linux distributions`)
|
throw new Error(`Unsupported linux distributions`)
|
||||||
}
|
}
|
||||||
|
@ -75,10 +75,10 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
|
||||||
try {
|
try {
|
||||||
// doxygen on stable Ubuntu repositories is very old. So, we use get the binary from the website itself
|
// doxygen on stable Ubuntu repositories is very old. So, we use get the binary from the website itself
|
||||||
installationInfo = await setupBin("doxygen", version, getDoxygenPackageInfo, setupDir, arch)
|
installationInfo = await setupBin("doxygen", version, getDoxygenPackageInfo, setupDir, arch)
|
||||||
await setupAptPack("libclang-cpp9")
|
await setupAptPack([{ name: "libclang-cpp9" }])
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
notice(`Failed to download doxygen binary. ${err}. Falling back to apt-get.`)
|
notice(`Failed to download doxygen binary. ${err}. Falling back to apt-get.`)
|
||||||
installationInfo = await setupAptPack("doxygen", undefined)
|
installationInfo = await setupAptPack([{ name: "doxygen" }])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Unsupported linux distributions`)
|
throw new Error(`Unsupported linux distributions`)
|
||||||
|
|
|
@ -96,15 +96,17 @@ export async function setupGcc(version: string, setupDir: string, arch: string)
|
||||||
setupDnfPack("gcc-c++", version)
|
setupDnfPack("gcc-c++", version)
|
||||||
setupDnfPack("libstdc++-devel", undefined)
|
setupDnfPack("libstdc++-devel", undefined)
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
await setupAptPack("gcc", version, ["ppa:ubuntu-toolchain-r/test"])
|
installationInfo = await setupAptPack([
|
||||||
installationInfo = await setupAptPack("g++", version, [])
|
{ name: "gcc", version, repositories: ["ppa:ubuntu-toolchain-r/test"] },
|
||||||
|
{ name: "g++", version, repositories: ["ppa:ubuntu-toolchain-r/test"] },
|
||||||
|
])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
info(`Install g++-multilib because gcc for ${arch} was requested`)
|
info(`Install g++-multilib because gcc for ${arch} was requested`)
|
||||||
if (isArch()) {
|
if (isArch()) {
|
||||||
setupPacmanPack("gcc-multilib", version)
|
setupPacmanPack("gcc-multilib", version)
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
await setupAptPack("gcc-multilib", version, ["ppa:ubuntu-toolchain-r/test"])
|
await setupAptPack([{ name: "gcc-multilib", version, repositories: ["ppa:ubuntu-toolchain-r/test"] }])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
|
@ -25,7 +25,7 @@ export async function setupGraphviz(version: string, _setupDir: string, _arch: s
|
||||||
} else if (hasDnf()) {
|
} else if (hasDnf()) {
|
||||||
return setupDnfPack("graphviz", version)
|
return setupDnfPack("graphviz", version)
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
return setupAptPack("graphviz", version)
|
return setupAptPack([{ name: "graphviz", version }])
|
||||||
}
|
}
|
||||||
throw new Error(`Unsupported linux distribution`)
|
throw new Error(`Unsupported linux distribution`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,8 +50,7 @@ async function buildKcov(file: string, dest: string) {
|
||||||
setupDnfPack("libdwarf-devel")
|
setupDnfPack("libdwarf-devel")
|
||||||
setupDnfPack("libcurl-devel")
|
setupDnfPack("libcurl-devel")
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
await setupAptPack("libdw-dev")
|
await setupAptPack([{ name: "libdw-dev" }, { name: "libcurl4-openssl-dev" }])
|
||||||
await setupAptPack("libcurl4-openssl-dev")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const buildDir = join(out, "build")
|
const buildDir = join(out, "build")
|
||||||
|
@ -102,7 +101,7 @@ export async function setupKcov(versionGiven: string, setupDir: string, arch: st
|
||||||
} else if (hasDnf()) {
|
} else if (hasDnf()) {
|
||||||
setupDnfPack("binutils")
|
setupDnfPack("binutils")
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
await setupAptPack("libbinutils")
|
await setupAptPack([{ name: "libbinutils" }])
|
||||||
}
|
}
|
||||||
return installationInfo
|
return installationInfo
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -52,9 +52,9 @@ async function setupLLVMDeps(arch: string, version: string) {
|
||||||
if (isUbuntu()) {
|
if (isUbuntu()) {
|
||||||
const majorVersion = parseInt(version.split(".")[0], 10)
|
const majorVersion = parseInt(version.split(".")[0], 10)
|
||||||
if (majorVersion <= 10) {
|
if (majorVersion <= 10) {
|
||||||
await setupAptPack("libtinfo5")
|
await setupAptPack([{ name: "libtinfo5" }])
|
||||||
} else {
|
} else {
|
||||||
await setupAptPack("libtinfo-dev")
|
await setupAptPack([{ name: "libtinfo-dev" }])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: install libtinfo on other distros
|
// TODO: install libtinfo on other distros
|
||||||
|
|
|
@ -25,7 +25,7 @@ export async function setupMake(version: string, _setupDir: string, _arch: strin
|
||||||
} else if (hasDnf()) {
|
} else if (hasDnf()) {
|
||||||
return setupDnfPack("make", version)
|
return setupDnfPack("make", version)
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
return setupAptPack("make", version)
|
return setupAptPack([{ name: "make", version }])
|
||||||
}
|
}
|
||||||
throw new Error(`Unsupported linux distribution`)
|
throw new Error(`Unsupported linux distribution`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,12 +33,12 @@ export async function setupNala(version: string, _setupDir: string, _arch: strin
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (version !== "legacy") {
|
if (version !== "legacy") {
|
||||||
await setupAptPack("nala", undefined, [], true)
|
await setupAptPack([{ name: "nala" }], true)
|
||||||
} else {
|
} else {
|
||||||
await setupAptPack("nala-legacy", undefined, [], true)
|
await setupAptPack([{ name: "nala-legacy" }], true)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await setupAptPack("nala-legacy", undefined, [], true)
|
await setupAptPack([{ name: "nala-legacy" }], true)
|
||||||
}
|
}
|
||||||
|
|
||||||
binDir = "/usr/bin" // eslint-disable-line require-atomic-updates
|
binDir = "/usr/bin" // eslint-disable-line require-atomic-updates
|
||||||
|
|
|
@ -33,7 +33,7 @@ export async function setupPowershell(version: string | undefined, _setupDir: st
|
||||||
])
|
])
|
||||||
return setupDnfPack("powershell", version)
|
return setupDnfPack("powershell", version)
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
await setupAptPack("curl")
|
await setupAptPack([{ name: "curl" }])
|
||||||
const ubuntuVerSplitted = (await ubuntuVersion())!
|
const ubuntuVerSplitted = (await ubuntuVersion())!
|
||||||
const ubuntuVersionString = `${ubuntuVerSplitted[0]}.0${ubuntuVerSplitted[1]}`
|
const ubuntuVersionString = `${ubuntuVerSplitted[0]}.0${ubuntuVerSplitted[1]}`
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ export async function setupPowershell(version: string | undefined, _setupDir: st
|
||||||
// `echo "deb [arch=amd64 signed-by=${keyFileName}] https://packages.microsoft.com/repos/microsoft-debian-bullseye-prod bullseye main" > /etc/apt/sources.list.d/microsoft.list`,
|
// `echo "deb [arch=amd64 signed-by=${keyFileName}] https://packages.microsoft.com/repos/microsoft-debian-bullseye-prod bullseye main" > /etc/apt/sources.list.d/microsoft.list`,
|
||||||
// ])
|
// ])
|
||||||
|
|
||||||
return setupAptPack("powershell", version, [], true)
|
return setupAptPack([{ name: "powershell", version }], true)
|
||||||
}
|
}
|
||||||
throw new Error(`Unsupported linux distribution`)
|
throw new Error(`Unsupported linux distribution`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,8 +69,7 @@ export async function setupPythonViaSystem(
|
||||||
installInfo = setupDnfPack("python3", version)
|
installInfo = setupDnfPack("python3", version)
|
||||||
setupDnfPack("python3-pip")
|
setupDnfPack("python3-pip")
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
installInfo = await setupAptPack("python3", version)
|
installInfo = await setupAptPack([{ name: "python3", version }, { name: "python3-pip" }])
|
||||||
await setupAptPack("python3-pip")
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Unsupported linux distributions`)
|
throw new Error(`Unsupported linux distributions`)
|
||||||
}
|
}
|
||||||
|
@ -118,7 +117,7 @@ export async function setupPythonAndPip(): Promise<string> {
|
||||||
} else if (hasDnf()) {
|
} else if (hasDnf()) {
|
||||||
setupDnfPack("python3-pip")
|
setupDnfPack("python3-pip")
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
await setupAptPack("python3-pip")
|
await setupAptPack([{ name: "python3-pip" }])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ export function setupSevenZip(version: string, _setupDir: string, _arch: string)
|
||||||
setupDnfPack("p7zip", version)
|
setupDnfPack("p7zip", version)
|
||||||
return setupDnfPack("p7zip-plugins", version)
|
return setupDnfPack("p7zip-plugins", version)
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
return setupAptPack("p7zip-full", version)
|
return setupAptPack([{ name: "p7zip-full", version }])
|
||||||
}
|
}
|
||||||
throw new Error(`Unsupported linux distribution`)
|
throw new Error(`Unsupported linux distribution`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ export async function ubuntuVersion(): Promise<number[] | null> {
|
||||||
try {
|
try {
|
||||||
if (isUbuntu()) {
|
if (isUbuntu()) {
|
||||||
if (which.sync("lsb_release", { nothrow: true }) === null) {
|
if (which.sync("lsb_release", { nothrow: true }) === null) {
|
||||||
await setupAptPack("lsb-release")
|
await setupAptPack([{ name: "lsb-release" }])
|
||||||
}
|
}
|
||||||
const versionSplitted = await getUbuntuVersion()
|
const versionSplitted = await getUbuntuVersion()
|
||||||
|
|
||||||
|
|
|
@ -8,20 +8,24 @@ import which from "which"
|
||||||
import pathExists from "path-exists"
|
import pathExists from "path-exists"
|
||||||
import { promises as fsPromises } from "fs"
|
import { promises as fsPromises } from "fs"
|
||||||
const { appendFile } = fsPromises
|
const { appendFile } = fsPromises
|
||||||
|
import execa from "execa"
|
||||||
|
|
||||||
let didUpdate: boolean = false
|
let didUpdate: boolean = false
|
||||||
let didInit: boolean = false
|
let didInit: boolean = false
|
||||||
|
|
||||||
|
export type AptPackage = {
|
||||||
|
name: string
|
||||||
|
version?: string
|
||||||
|
repositories?: string[]
|
||||||
|
}
|
||||||
|
|
||||||
/** A function that installs a package using apt */
|
/** A function that installs a package using apt */
|
||||||
export async function setupAptPack(
|
export async function setupAptPack(packages: AptPackage[], update = false): Promise<InstallationInfo> {
|
||||||
name: string,
|
|
||||||
version?: string,
|
|
||||||
repositories: string[] = [],
|
|
||||||
update = false
|
|
||||||
): Promise<InstallationInfo> {
|
|
||||||
const apt: string = getApt()
|
const apt: string = getApt()
|
||||||
|
|
||||||
info(`Installing ${name} ${version ?? ""} via ${apt}`)
|
for (const { name, version } of packages) {
|
||||||
|
info(`Installing ${name} ${version ?? ""} via ${apt}`)
|
||||||
|
}
|
||||||
|
|
||||||
process.env.DEBIAN_FRONTEND = "noninteractive"
|
process.env.DEBIAN_FRONTEND = "noninteractive"
|
||||||
|
|
||||||
|
@ -35,27 +39,36 @@ export async function setupAptPack(
|
||||||
didInit = true
|
didInit = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(repositories) && repositories.length !== 0) {
|
const allRepositories = [...new Set(packages.flatMap((pack) => pack.repositories ?? []))]
|
||||||
for (const repo of repositories) {
|
|
||||||
|
if (allRepositories.length !== 0) {
|
||||||
|
for (const repo of allRepositories) {
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
execRootSync("add-apt-repository", ["--update", "-y", repo])
|
execRootSync("add-apt-repository", ["-y", repo])
|
||||||
}
|
}
|
||||||
|
|
||||||
updateRepos(apt)
|
updateRepos(apt)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version !== undefined && version !== "") {
|
const aptArgs = await Promise.all(packages.map((pack) => getAptArg(pack.name, pack.version)))
|
||||||
try {
|
execRootSync(apt, ["install", "--fix-broken", "-y", ...aptArgs])
|
||||||
execRootSync(apt, ["install", "--fix-broken", "-y", `${name}=${version}`])
|
|
||||||
} catch {
|
|
||||||
execRootSync(apt, ["install", "--fix-broken", "-y", `${name}-${version}`])
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
execRootSync(apt, ["install", "--fix-broken", "-y", name])
|
|
||||||
}
|
|
||||||
|
|
||||||
return { binDir: "/usr/bin/" }
|
return { binDir: "/usr/bin/" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getAptArg(name: string, version: string | undefined) {
|
||||||
|
if (version !== undefined && version !== "") {
|
||||||
|
const { stdout } = await execa("apt-cache", ["search", "--names-only", `^${name}-${version}$`])
|
||||||
|
if (stdout.trim() !== "") {
|
||||||
|
return `${name}-${version}`
|
||||||
|
} else {
|
||||||
|
return `${name}=${version}`
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getApt() {
|
function getApt() {
|
||||||
let apt: string
|
let apt: string
|
||||||
if (which.sync("nala", { nothrow: true }) !== null) {
|
if (which.sync("nala", { nothrow: true }) !== null) {
|
||||||
|
@ -118,7 +131,7 @@ export async function addAptKeyViaDownload(name: string, url: string) {
|
||||||
const fileName = `/etc/apt/trusted.gpg.d/${name}`
|
const fileName = `/etc/apt/trusted.gpg.d/${name}`
|
||||||
if (!(await pathExists(fileName))) {
|
if (!(await pathExists(fileName))) {
|
||||||
initGpg()
|
initGpg()
|
||||||
await setupAptPack("curl", undefined)
|
await setupAptPack([{ name: "curl" }], undefined)
|
||||||
execRootSync("bash", ["-c", `curl -s ${url} | gpg --no-default-keyring --keyring gnupg-ring:${fileName} --import`])
|
execRootSync("bash", ["-c", `curl -s ${url} | gpg --no-default-keyring --keyring gnupg-ring:${fileName} --import`])
|
||||||
execRootSync("chmod", ["644", fileName])
|
execRootSync("chmod", ["644", fileName])
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,9 +103,7 @@ export async function setupBin(
|
||||||
setupDnfPack("tar")
|
setupDnfPack("tar")
|
||||||
setupDnfPack("xz")
|
setupDnfPack("xz")
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
await setupAptPack("unzip")
|
await setupAptPack([{ name: "unzip" }, { name: "tar" }, { name: "xz-utils" }])
|
||||||
await setupAptPack("tar")
|
|
||||||
await setupAptPack("xz-utils")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line require-atomic-updates
|
// eslint-disable-next-line require-atomic-updates
|
||||||
|
|
|
@ -36,12 +36,14 @@ export async function setupVcpkg(_version: string, setupDir: string, _arch: stri
|
||||||
setupDnfPack("git")
|
setupDnfPack("git")
|
||||||
setupDnfPack("pkg-config")
|
setupDnfPack("pkg-config")
|
||||||
} else if (isUbuntu()) {
|
} else if (isUbuntu()) {
|
||||||
await setupAptPack("curl")
|
await setupAptPack([
|
||||||
await setupAptPack("zip")
|
{ name: "curl" },
|
||||||
await setupAptPack("unzip")
|
{ name: "zip" },
|
||||||
await setupAptPack("tar")
|
{ name: "unzip" },
|
||||||
await setupAptPack("git")
|
{ name: "tar" },
|
||||||
await setupAptPack("pkg-config")
|
{ name: "git" },
|
||||||
|
{ name: "pkg-config" },
|
||||||
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue