Merge pull request #333 from aminya/gcc [skip ci]

fix: do not fallback to latest apt package by default + fix: install both libtinfo5 and libtinfo6 for clang
This commit is contained in:
Amin Ya 2025-01-29 02:24:28 -08:00 committed by GitHub
commit c08b751296
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 44 additions and 35 deletions

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

View File

@ -1,6 +1,6 @@
{
"name": "setup-apt",
"version": "2.1.0",
"version": "3.0.0",
"description": "Setup apt packages and repositories in Debian/Ubuntu-based distributions",
"repository": "https://github.com/aminya/setup-cpp",
"homepage": "https://github.com/aminya/setup-cpp/tree/master/packages/setup-apt",

View File

@ -34,6 +34,11 @@ export type AptPackage = {
repository?: string
/** The key to add before installing the package (optional) */
key?: AddAptKeyOptions
/**
* If the given version is not available, fall back to the latest version
* @default false
*/
fallBackToLatest?: boolean
}
const retryErrors = [

View File

@ -32,7 +32,7 @@ export async function filterAndQualifyAptPackages(packages: AptPackage[], apt: s
*/
export async function qualifiedNeededAptPackage(pack: AptPackage, apt: string = getApt()) {
// Qualify the package into full package name/version
const qualified = await getAptArg(apt, pack.name, pack.version)
const qualified = await getAptArg(apt, pack)
// filter out the package that are already installed
return (await isAptPackInstalled(qualified)) ? undefined : qualified
}
@ -78,7 +78,9 @@ async function aptPackageType(apt: string, name: string, version: string | undef
return AptPackageType.None
}
async function getAptArg(apt: string, name: string, version: string | undefined) {
async function getAptArg(apt: string, pack: AptPackage) {
const { name, version, fallBackToLatest = false } = pack
const package_type = await aptPackageType(apt, name, version)
switch (package_type) {
case AptPackageType.NameDashVersion:
@ -86,7 +88,7 @@ async function getAptArg(apt: string, name: string, version: string | undefined)
case AptPackageType.NameEqualsVersion:
return `${name}=${version}`
case AptPackageType.Name:
if (version !== undefined && version !== "") {
if (version !== undefined && version !== "" && fallBackToLatest) {
warning(`Could not find package ${name} with version ${version}. Installing the latest version.`)
}
return name

View File

@ -78,8 +78,8 @@ async function setupLLVMOnly(
info(`Failed to install llvm via system package manager ${err}. Trying to remove the repository`)
try {
execRootSync(join(dirname, "llvm_repo_remove.bash"), [`${majorVersion}`])
} catch (err) {
info(`Failed to remove llvm repository ${err}`)
} catch (removeErr) {
info(`Failed to remove llvm repository ${removeErr}`)
}
}
}
@ -94,36 +94,38 @@ function majorLLVMVersion(version: string) {
return Number.parseInt(coeredVersion.split(".")[0], 10)
}
async function llvmBinaryDeps_(majorVersion: number) {
async function llvmBinaryDeps_(_majorVersion: number) {
if (isUbuntu()) {
if (majorVersion <= 10) {
for (const dep of ["libtinfo5", "libtinfo6"]) {
/* eslint-disable no-await-in-loop */
try {
await installAptPack([{ name: "libtinfo5" }])
} catch (err) {
// Manually install libtinfo5 if the package is not available
info(`Failed to install libtinfo5 ${err}\nManually installing the package`)
const arch = x86_64.includes(process.arch)
? "amd64"
: arm64.includes(process.arch)
? "arm64"
: process.arch
try {
await installAptPack([{ name: dep }])
} catch (err) {
if (dep === "libtinfo5") {
// Manually install libtinfo5 if the package is not available
info(`Failed to install ${dep} ${err}\nManually installing the package`)
const arch = x86_64.includes(process.arch)
? "amd64"
: arm64.includes(process.arch)
? "arm64"
: process.arch
const fileName = `libtinfo5_6.3-2ubuntu0.1_${arch}.deb`
const url = `http://launchpadlibrarian.net/666971015/${fileName}`
const dl = new DownloaderHelper(url, tmpdir(), { fileName })
dl.on("error", (dlErr) => {
throw new Error(`Failed to download ${url}: ${dlErr}`)
})
await dl.start()
// Install the downloaded package via dpkg
execRootSync("dpkg", ["-i", join(tmpdir(), fileName)])
}
} else {
try {
await installAptPack([{ name: "libtinfo6" }])
const fileName = `libtinfo5_6.3-2ubuntu0.1_${arch}.deb`
const url = `http://launchpadlibrarian.net/666971015/${fileName}`
const dl = new DownloaderHelper(url, tmpdir(), { fileName })
dl.on("error", (dlErr) => {
throw new Error(`Failed to download ${url}: ${dlErr}`)
})
await dl.start()
// Install the downloaded package via dpkg
execRootSync("dpkg", ["-i", join(tmpdir(), fileName)])
}
}
} catch (err) {
info(`Failed to install libtinfo6 ${err}\nSkipping the dependency`)
info(`Failed to install ${dep}. Ignoring`)
}
/* eslint-enable no-await-in-loop */
}
} else if (isArch()) {
// https://aur.archlinux.org/packages/ncurses5-compat-libs