Skip to content

Commit

Permalink
Merge pull request #333 from aminya/gcc [skip ci]
Browse files Browse the repository at this point in the history
fix: do not fallback to latest apt package by default + fix: install both libtinfo5 and libtinfo6 for clang
  • Loading branch information
aminya authored Jan 29, 2025
2 parents 12e62a1 + 0dee00a commit c08b751
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 36 deletions.
2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.mjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/setup-apt/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 5 additions & 0 deletions packages/setup-apt/src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
8 changes: 5 additions & 3 deletions packages/setup-apt/src/qualify-install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -78,15 +78,17 @@ 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:
return `${name}-${version}`
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
Expand Down
58 changes: 30 additions & 28 deletions src/llvm/llvm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}
}
}
Expand All @@ -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) {
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

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 {
for (const dep of ["libtinfo5", "libtinfo6"]) {
/* eslint-disable no-await-in-loop */
try {
await installAptPack([{ name: "libtinfo6" }])
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)])
}
}
} 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
Expand Down

0 comments on commit c08b751

Please sign in to comment.