Skip to content

Commit c08b751

Browse files
authored
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
2 parents 12e62a1 + 0dee00a commit c08b751

File tree

8 files changed

+45
-36
lines changed

8 files changed

+45
-36
lines changed

dist/legacy/setup-cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/modern/setup-cpp.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/setup-apt/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "setup-apt",
3-
"version": "2.1.0",
3+
"version": "3.0.0",
44
"description": "Setup apt packages and repositories in Debian/Ubuntu-based distributions",
55
"repository": "https://github.com/aminya/setup-cpp",
66
"homepage": "https://github.com/aminya/setup-cpp/tree/master/packages/setup-apt",

packages/setup-apt/src/install.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ export type AptPackage = {
3434
repository?: string
3535
/** The key to add before installing the package (optional) */
3636
key?: AddAptKeyOptions
37+
/**
38+
* If the given version is not available, fall back to the latest version
39+
* @default false
40+
*/
41+
fallBackToLatest?: boolean
3742
}
3843

3944
const retryErrors = [

packages/setup-apt/src/qualify-install.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export async function filterAndQualifyAptPackages(packages: AptPackage[], apt: s
3232
*/
3333
export async function qualifiedNeededAptPackage(pack: AptPackage, apt: string = getApt()) {
3434
// Qualify the package into full package name/version
35-
const qualified = await getAptArg(apt, pack.name, pack.version)
35+
const qualified = await getAptArg(apt, pack)
3636
// filter out the package that are already installed
3737
return (await isAptPackInstalled(qualified)) ? undefined : qualified
3838
}
@@ -78,15 +78,17 @@ async function aptPackageType(apt: string, name: string, version: string | undef
7878
return AptPackageType.None
7979
}
8080

81-
async function getAptArg(apt: string, name: string, version: string | undefined) {
81+
async function getAptArg(apt: string, pack: AptPackage) {
82+
const { name, version, fallBackToLatest = false } = pack
83+
8284
const package_type = await aptPackageType(apt, name, version)
8385
switch (package_type) {
8486
case AptPackageType.NameDashVersion:
8587
return `${name}-${version}`
8688
case AptPackageType.NameEqualsVersion:
8789
return `${name}=${version}`
8890
case AptPackageType.Name:
89-
if (version !== undefined && version !== "") {
91+
if (version !== undefined && version !== "" && fallBackToLatest) {
9092
warning(`Could not find package ${name} with version ${version}. Installing the latest version.`)
9193
}
9294
return name

src/llvm/llvm.ts

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ async function setupLLVMOnly(
7878
info(`Failed to install llvm via system package manager ${err}. Trying to remove the repository`)
7979
try {
8080
execRootSync(join(dirname, "llvm_repo_remove.bash"), [`${majorVersion}`])
81-
} catch (err) {
82-
info(`Failed to remove llvm repository ${err}`)
81+
} catch (removeErr) {
82+
info(`Failed to remove llvm repository ${removeErr}`)
8383
}
8484
}
8585
}
@@ -94,36 +94,38 @@ function majorLLVMVersion(version: string) {
9494
return Number.parseInt(coeredVersion.split(".")[0], 10)
9595
}
9696

97-
async function llvmBinaryDeps_(majorVersion: number) {
97+
async function llvmBinaryDeps_(_majorVersion: number) {
9898
if (isUbuntu()) {
99-
if (majorVersion <= 10) {
100-
try {
101-
await installAptPack([{ name: "libtinfo5" }])
102-
} catch (err) {
103-
// Manually install libtinfo5 if the package is not available
104-
info(`Failed to install libtinfo5 ${err}\nManually installing the package`)
105-
const arch = x86_64.includes(process.arch)
106-
? "amd64"
107-
: arm64.includes(process.arch)
108-
? "arm64"
109-
: process.arch
110-
111-
const fileName = `libtinfo5_6.3-2ubuntu0.1_${arch}.deb`
112-
const url = `http://launchpadlibrarian.net/666971015/${fileName}`
113-
const dl = new DownloaderHelper(url, tmpdir(), { fileName })
114-
dl.on("error", (dlErr) => {
115-
throw new Error(`Failed to download ${url}: ${dlErr}`)
116-
})
117-
await dl.start()
118-
// Install the downloaded package via dpkg
119-
execRootSync("dpkg", ["-i", join(tmpdir(), fileName)])
120-
}
121-
} else {
99+
for (const dep of ["libtinfo5", "libtinfo6"]) {
100+
/* eslint-disable no-await-in-loop */
122101
try {
123-
await installAptPack([{ name: "libtinfo6" }])
102+
try {
103+
await installAptPack([{ name: dep }])
104+
} catch (err) {
105+
if (dep === "libtinfo5") {
106+
// Manually install libtinfo5 if the package is not available
107+
info(`Failed to install ${dep} ${err}\nManually installing the package`)
108+
const arch = x86_64.includes(process.arch)
109+
? "amd64"
110+
: arm64.includes(process.arch)
111+
? "arm64"
112+
: process.arch
113+
114+
const fileName = `libtinfo5_6.3-2ubuntu0.1_${arch}.deb`
115+
const url = `http://launchpadlibrarian.net/666971015/${fileName}`
116+
const dl = new DownloaderHelper(url, tmpdir(), { fileName })
117+
dl.on("error", (dlErr) => {
118+
throw new Error(`Failed to download ${url}: ${dlErr}`)
119+
})
120+
await dl.start()
121+
// Install the downloaded package via dpkg
122+
execRootSync("dpkg", ["-i", join(tmpdir(), fileName)])
123+
}
124+
}
124125
} catch (err) {
125-
info(`Failed to install libtinfo6 ${err}\nSkipping the dependency`)
126+
info(`Failed to install ${dep}. Ignoring`)
126127
}
128+
/* eslint-enable no-await-in-loop */
127129
}
128130
} else if (isArch()) {
129131
// https://aur.archlinux.org/packages/ncurses5-compat-libs

0 commit comments

Comments
 (0)