mirror of https://github.com/aminya/setup-cpp
feat: fallback to version-less package on arch if not found
This commit is contained in:
parent
a0488f7712
commit
36a5b861ce
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
|
@ -70,7 +70,7 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
|
|||
let installationInfo: InstallationInfo
|
||||
if (version === "" || isArch() || hasDnf()) {
|
||||
if (isArch()) {
|
||||
installationInfo = setupPacmanPack("doxygen", version)
|
||||
installationInfo = await setupPacmanPack("doxygen", version)
|
||||
} else if (hasDnf()) {
|
||||
return setupDnfPack("doxygen", version)
|
||||
} else if (isUbuntu()) {
|
||||
|
|
|
@ -95,7 +95,7 @@ export async function setupGcc(version: string, setupDir: string, arch: string)
|
|||
case "linux": {
|
||||
if (arch === "x64") {
|
||||
if (isArch()) {
|
||||
installationInfo = setupPacmanPack("gcc", version)
|
||||
installationInfo = await setupPacmanPack("gcc", version)
|
||||
} else if (hasDnf()) {
|
||||
installationInfo = setupDnfPack("gcc", version)
|
||||
setupDnfPack("gcc-c++", version)
|
||||
|
|
|
@ -63,7 +63,7 @@ export async function setupPythonViaSystem(
|
|||
case "linux": {
|
||||
let installInfo: InstallationInfo
|
||||
if (isArch()) {
|
||||
installInfo = setupPacmanPack("python", version)
|
||||
installInfo = await setupPacmanPack("python", version)
|
||||
setupPacmanPack("python-pip")
|
||||
} else if (hasDnf()) {
|
||||
installInfo = setupDnfPack("python3", version)
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
/* eslint-disable require-atomic-updates */
|
||||
import { InstallationInfo } from "./setupBin"
|
||||
import { execRootSync } from "admina"
|
||||
import { info } from "ci-log"
|
||||
import { info, warning } from "ci-log"
|
||||
import { execa } from "execa"
|
||||
|
||||
/* eslint-disable require-atomic-updates */
|
||||
let didUpdate: boolean = false
|
||||
let didInit: boolean = false
|
||||
|
||||
/** A function that installs a package using pacman */
|
||||
export function setupPacmanPack(name: string, version?: string, aur?: string): InstallationInfo {
|
||||
export async function setupPacmanPack(name: string, version?: string, aur?: string): Promise<InstallationInfo> {
|
||||
info(`Installing ${name} ${version ?? ""} via pacman`)
|
||||
|
||||
const pacman = "pacman"
|
||||
|
@ -18,21 +19,52 @@ export function setupPacmanPack(name: string, version?: string, aur?: string): I
|
|||
didUpdate = true
|
||||
}
|
||||
|
||||
if (!didInit) {
|
||||
// install base-devel
|
||||
if (!didInit) {
|
||||
execRootSync(pacman, ["-S", "--noconfirm", "base-devel"])
|
||||
didInit = true
|
||||
}
|
||||
|
||||
const runInstall = (arg: string) => {
|
||||
return execRootSync(aur ?? pacman, ["-S", "--noconfirm", arg])
|
||||
}
|
||||
|
||||
if (version !== undefined && version !== "") {
|
||||
// check if version is available
|
||||
const availableVersions = await availablePacmanVersions(pacman, name)
|
||||
if (availableVersions.includes(version)) {
|
||||
// try different version formats
|
||||
try {
|
||||
execRootSync(aur ?? pacman, ["-S", "--noconfirm", `${name}=${version}`])
|
||||
runInstall(`${name}=${version}`)
|
||||
} catch {
|
||||
execRootSync(aur ?? pacman, ["-S", "--noconfirm", `${name}${version}`])
|
||||
runInstall(`${name}${version}`)
|
||||
}
|
||||
} else {
|
||||
execRootSync(aur ?? pacman, ["-S", "--noconfirm", name])
|
||||
// try without version
|
||||
info(`Failed to install ${name} ${version} via pacman, trying without version`)
|
||||
runInstall(name)
|
||||
}
|
||||
} else {
|
||||
// version not specified, install latest
|
||||
runInstall(name)
|
||||
}
|
||||
|
||||
return { binDir: "/usr/bin/" }
|
||||
}
|
||||
|
||||
const pacmanSiVersionRegex = /Version\s*:\s*(.*)/g
|
||||
|
||||
/** Query pacman for available versions */
|
||||
async function availablePacmanVersions(pacman: string, name: string) {
|
||||
const availableVersions = []
|
||||
try {
|
||||
const { stdout } = await execa(pacman, ["-Si", name])
|
||||
|
||||
for (const match of stdout.matchAll(pacmanSiVersionRegex)) {
|
||||
availableVersions.push(match[1])
|
||||
}
|
||||
} catch (err) {
|
||||
warning(`Failed to get available versions for ${name}: ${err}`)
|
||||
}
|
||||
return availableVersions
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue