fix: handle the promises in setupAptPack

This commit is contained in:
Amin Yahyaabadi 2022-07-27 19:07:30 -07:00
parent a9e484f19f
commit c8cec57d18
16 changed files with 45 additions and 45 deletions

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

@ -67,7 +67,7 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
} else if (hasDnf()) {
return setupDnfPack("doxygen", version)
} else if (isUbuntu()) {
installationInfo = setupAptPack("doxygen", version)
installationInfo = await setupAptPack("doxygen", version)
} else {
throw new Error(`Unsupported linux distributions`)
}
@ -75,10 +75,10 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
try {
// 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)
setupAptPack("libclang-cpp9")
await setupAptPack("libclang-cpp9")
} catch (err) {
notice(`Failed to download doxygen binary. ${err}. Falling back to apt-get.`)
installationInfo = setupAptPack("doxygen", undefined)
installationInfo = await setupAptPack("doxygen", undefined)
}
} else {
throw new Error(`Unsupported linux distributions`)

View File

@ -91,15 +91,15 @@ export async function setupGcc(version: string, setupDir: string, arch: string)
setupDnfPack("gcc-c++", version)
setupDnfPack("libstdc++-devel", undefined)
} else if (isUbuntu()) {
setupAptPack("gcc", version, ["ppa:ubuntu-toolchain-r/test"])
installationInfo = setupAptPack("g++", version, [])
await setupAptPack("gcc", version, ["ppa:ubuntu-toolchain-r/test"])
installationInfo = await setupAptPack("g++", version, [])
}
} else {
info(`Install g++-multilib because gcc for ${arch} was requested`)
if (isArch()) {
setupPacmanPack("gcc-multilib", version)
} else if (isUbuntu()) {
setupAptPack("gcc-multilib", version, ["ppa:ubuntu-toolchain-r/test"])
await setupAptPack("gcc-multilib", version, ["ppa:ubuntu-toolchain-r/test"])
}
}
break

View File

@ -41,7 +41,7 @@ async function buildKcov(file: string, dest: string) {
const out = await extractTarByExe(file, dest, ["--strip-components=1"])
// build after extraction using CMake
let cmake = await getCmake()
const cmake = await getCmake()
if (process.platform === "linux") {
if (isArch()) {
@ -51,8 +51,8 @@ async function buildKcov(file: string, dest: string) {
setupDnfPack("libdwarf-devel")
setupDnfPack("libcurl-devel")
} else if (isUbuntu()) {
setupAptPack("libdw-dev")
setupAptPack("libcurl4-openssl-dev")
await setupAptPack("libdw-dev")
await setupAptPack("libcurl4-openssl-dev")
}
}
const buildDir = join(out, "build")
@ -72,7 +72,7 @@ async function getCmake() {
const { binDir } = await setupCmake(getVersion("cmake", undefined), join(untildify_user(""), "cmake"), "")
cmake = join(binDir, "cmake")
}
let ninja = which.sync("ninja", { nothrow: true })
const ninja = which.sync("ninja", { nothrow: true })
if (ninja === null) {
await setupNinja(getVersion("ninja", undefined), join(untildify_user(""), "ninja"), "")
}
@ -103,7 +103,7 @@ export async function setupKcov(versionGiven: string, setupDir: string, arch: st
} else if (hasDnf()) {
setupDnfPack("binutils")
} else if (isUbuntu()) {
setupAptPack("libbinutils")
await setupAptPack("libbinutils")
}
return installationInfo
} else {

View File

@ -294,7 +294,7 @@ async function _setupLLVM(version: string, setupDir: string, arch: string) {
// setupPacmanPack("ncurses")
// TODO: install libtinfo ?
} else if (isUbuntu()) {
setupAptPack("libtinfo-dev")
await setupAptPack("libtinfo-dev")
}
}
// eslint-disable-next-line require-atomic-updates

View File

@ -8,7 +8,7 @@ describe("setup-nala", () => {
if (!isUbuntu()) {
return
}
const installInfo = setupNala("", "", process.arch)
const installInfo = await setupNala("", "", process.arch)
await testBin("nala", ["--version"], installInfo?.binDir)
})
})

View File

@ -7,7 +7,7 @@ import { setupAptPack } from "../utils/setup/setupAptPack"
let binDir: string | undefined
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function setupNala(version: string, _setupDir: string, _arch: string) {
export async function setupNala(version: string, _setupDir: string, _arch: string) {
if (!isUbuntu()) {
return undefined
}
@ -22,7 +22,7 @@ export function setupNala(version: string, _setupDir: string, _arch: string) {
}
// https://github.com/volitank/nala#-installation
setupAptPack("wget")
await setupAptPack("wget")
execSudo("/bin/bash", [
"-c",
`wget -qO - https://deb.volian.org/volian/scar.key | tee /etc/apt/trusted.gpg.d/volian-archive-scar-unstable.gpg > /dev/null`,
@ -34,15 +34,15 @@ export function setupNala(version: string, _setupDir: string, _arch: string) {
try {
if (version !== "legacy") {
setupAptPack("nala", undefined, [], true)
await setupAptPack("nala", undefined, [], true)
} else {
setupAptPack("nala-legacy", undefined, [], true)
await setupAptPack("nala-legacy", undefined, [], true)
}
} catch (err) {
setupAptPack("nala-legacy", undefined, [], true)
await setupAptPack("nala-legacy", undefined, [], true)
}
binDir = "/usr/bin"
binDir = "/usr/bin" // eslint-disable-line require-atomic-updates
return { binDir }
}

View File

@ -63,8 +63,8 @@ export async function setupPythonViaSystem(
installInfo = setupDnfPack("python3", version)
setupDnfPack("python3-pip")
} else if (isUbuntu()) {
installInfo = setupAptPack("python3", version)
setupAptPack("python3-pip")
installInfo = await setupAptPack("python3", version)
await setupAptPack("python3-pip")
} else {
throw new Error(`Unsupported linux distributions`)
}

View File

@ -6,7 +6,7 @@ import { isUbuntu } from "./isUbuntu"
export async function ubuntuVersion(): Promise<number[] | null> {
if (isUbuntu()) {
if (which.sync("lsb_release", { nothrow: true }) === null) {
setupAptPack("lsb-release")
await setupAptPack("lsb-release")
}
const versionSplitted = await getUbuntuVersion()

View File

@ -12,15 +12,15 @@ let didUpdate: boolean = false
let didInit: boolean = false
/** A function that installs a package using apt */
export function setupAptPack(
export async function setupAptPack(
name: string,
version?: string,
repositories: string[] = [],
update = false
): InstallationInfo {
): Promise<InstallationInfo> {
info(`Installing ${name} ${version ?? ""} via apt`)
let apt: string = getApt()
const apt: string = getApt()
process.env.DEBIAN_FRONTEND = "noninteractive"
@ -30,7 +30,7 @@ export function setupAptPack(
}
if (!didInit) {
initApt(apt)
await initApt(apt)
didInit = true
}
@ -70,7 +70,7 @@ function updateRepos(apt: string) {
}
/** Install apt utils and certificates (usually missing from docker containers) */
function initApt(apt: string) {
async function initApt(apt: string) {
execSudo(apt, [
"install",
"--fix-broken",
@ -84,8 +84,8 @@ function initApt(apt: string) {
addAptKey(["1E9377A2BA9EF27F"], "setup-cpp-launchpad-toolchain.gpg")
if (apt === "nala") {
// enable utf8 otherwise it fails because of the usage of ASCII encoding
addEnv("LANG", "C.UTF-8")
addEnv("LC_ALL", "C.UTF-8")
await addEnv("LANG", "C.UTF-8")
await addEnv("LC_ALL", "C.UTF-8")
}
}

View File

@ -82,8 +82,8 @@ export async function setupBin(
}
}
let installDir = join(setupDir, extractedFolderName)
let binDir = join(installDir, binRelativeDir)
const installDir = join(setupDir, extractedFolderName)
const binDir = join(installDir, binRelativeDir)
const binFile = join(binDir, binFileName)
// download ane extract the package into the installation directory.
@ -102,9 +102,9 @@ export async function setupBin(
setupDnfPack("tar")
setupDnfPack("xz")
} else if (isUbuntu()) {
setupAptPack("unzip")
setupAptPack("tar")
setupAptPack("xz-utils")
await setupAptPack("unzip")
await setupAptPack("tar")
await setupAptPack("xz-utils")
}
}
// eslint-disable-next-line require-atomic-updates

View File

@ -52,7 +52,7 @@ export async function setupPipPack(name: string, version?: string): Promise<Inst
} else if (hasDnf()) {
setupDnfPack("python3-pip")
} else if (isUbuntu()) {
setupAptPack("python3-pip")
await setupAptPack("python3-pip")
}
}

View File

@ -36,12 +36,12 @@ export async function setupVcpkg(_version: string, setupDir: string, _arch: stri
setupDnfPack("git")
setupDnfPack("pkg-config")
} else if (isUbuntu()) {
setupAptPack("curl")
setupAptPack("zip")
setupAptPack("unzip")
setupAptPack("tar")
setupAptPack("git")
setupAptPack("pkg-config")
await setupAptPack("curl")
await setupAptPack("zip")
await setupAptPack("unzip")
await setupAptPack("tar")
await setupAptPack("git")
await setupAptPack("pkg-config")
}
}