mirror of https://github.com/aminya/setup-cpp
feat: add the cached isArch function
This commit is contained in:
parent
df27d7c079
commit
7caf0ddff8
|
@ -2,7 +2,7 @@ import { setupAptPack } from "../utils/setup/setupAptPack"
|
|||
import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
|
||||
import { setupBrewPack } from "../utils/setup/setupBrewPack"
|
||||
import { setupChocoPack } from "../utils/setup/setupChocoPack"
|
||||
import which from "which"
|
||||
import { isArch } from "../utils/env/isArch"
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function setupCcache(version: string, _setupDir: string, _arch: string) {
|
||||
|
@ -14,7 +14,7 @@ export function setupCcache(version: string, _setupDir: string, _arch: string) {
|
|||
return setupBrewPack("ccache", version)
|
||||
}
|
||||
case "linux": {
|
||||
if (which.sync("pacman", { nothrow: true })) {
|
||||
if (isArch()) {
|
||||
return setupPacmanPack("ccache", version)
|
||||
}
|
||||
return setupAptPack("ccache", version)
|
||||
|
|
|
@ -3,7 +3,7 @@ import { setupAptPack } from "../utils/setup/setupAptPack"
|
|||
import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
|
||||
import { setupBrewPack } from "../utils/setup/setupBrewPack"
|
||||
import { setupChocoPack } from "../utils/setup/setupChocoPack"
|
||||
import which from "which"
|
||||
import { isArch } from "../utils/env/isArch"
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export async function setupCppcheck(version: string | undefined, _setupDir: string, _arch: string) {
|
||||
|
@ -17,7 +17,7 @@ export async function setupCppcheck(version: string | undefined, _setupDir: stri
|
|||
return setupBrewPack("cppcheck", version)
|
||||
}
|
||||
case "linux": {
|
||||
if (which.sync("pacman", { nothrow: true })) {
|
||||
if (isArch()) {
|
||||
return setupPacmanPack("cppcheck", version)
|
||||
}
|
||||
return setupAptPack("cppcheck", version)
|
||||
|
|
|
@ -11,7 +11,7 @@ import { setupGraphviz } from "../graphviz/graphviz"
|
|||
import { getVersion } from "../default_versions"
|
||||
import { existsSync } from "fs"
|
||||
import { join } from "path"
|
||||
import which from "which"
|
||||
import { isArch } from "../utils/env/isArch"
|
||||
|
||||
/** Get the platform data for cmake */
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
|
@ -59,13 +59,13 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
|
|||
case "linux": {
|
||||
let installationInfo: InstallationInfo
|
||||
if (version === "") {
|
||||
if (which.sync("pacman", { nothrow: true })) {
|
||||
if (isArch()) {
|
||||
installationInfo = setupPacmanPack("doxygen", undefined)
|
||||
} else {
|
||||
installationInfo = setupAptPack("doxygen", undefined)
|
||||
}
|
||||
} else {
|
||||
if (which.sync("pacman", { nothrow: true })) {
|
||||
if (isArch()) {
|
||||
installationInfo = setupPacmanPack("doxygen", version)
|
||||
} else {
|
||||
try {
|
||||
|
|
|
@ -13,7 +13,7 @@ import { isGitHubCI } from "../utils/env/isci"
|
|||
import { addBinExtension } from "../utils/extension/extension"
|
||||
import { InstallationInfo, PackageInfo, setupBin } from "../utils/setup/setupBin"
|
||||
import { extract7Zip } from "../utils/setup/extract"
|
||||
import which from "which"
|
||||
import { isArch } from "../utils/env/isArch"
|
||||
|
||||
interface MingwInfo {
|
||||
releaseName: string
|
||||
|
@ -81,7 +81,7 @@ export async function setupGcc(version: string, setupDir: string, arch: string)
|
|||
}
|
||||
case "linux": {
|
||||
if (arch === "x64") {
|
||||
if (which.sync("pacman", { nothrow: true })) {
|
||||
if (isArch()) {
|
||||
installationInfo = setupPacmanPack("gcc", version)
|
||||
} else {
|
||||
setupAptPack("gcc", version, ["ppa:ubuntu-toolchain-r/test"])
|
||||
|
@ -89,7 +89,7 @@ export async function setupGcc(version: string, setupDir: string, arch: string)
|
|||
}
|
||||
} else {
|
||||
info(`Install g++-multilib because gcc for ${arch} was requested`)
|
||||
if (which.sync("pacman", { nothrow: true })) {
|
||||
if (isArch()) {
|
||||
setupPacmanPack("gcc-multilib", version)
|
||||
} else {
|
||||
setupAptPack("gcc-multilib", version, ["ppa:ubuntu-toolchain-r/test"])
|
||||
|
|
|
@ -4,7 +4,7 @@ import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
|
|||
import { InstallationInfo } from "../utils/setup/setupBin"
|
||||
import { setupBrewPack } from "../utils/setup/setupBrewPack"
|
||||
import { setupChocoPack } from "../utils/setup/setupChocoPack"
|
||||
import which from "which"
|
||||
import { isArch } from "../utils/env/isArch"
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export async function setupGraphviz(version: string, _setupDir: string, _arch: string) {
|
||||
|
@ -17,7 +17,7 @@ export async function setupGraphviz(version: string, _setupDir: string, _arch: s
|
|||
return setupBrewPack("graphviz", version)
|
||||
}
|
||||
case "linux": {
|
||||
if (which.sync("pacman", { nothrow: true })) {
|
||||
if (isArch()) {
|
||||
return setupPacmanPack("graphviz", version)
|
||||
}
|
||||
return setupAptPack("graphviz", version)
|
||||
|
|
|
@ -10,6 +10,7 @@ import { extractTarByExe } from "../utils/setup/extract"
|
|||
import { setupAptPack } from "../utils/setup/setupAptPack"
|
||||
import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
|
||||
import { PackageInfo, setupBin } from "../utils/setup/setupBin"
|
||||
import { isArch } from "../utils/env/isArch"
|
||||
|
||||
function getKcovPackageInfo(version: string): PackageInfo {
|
||||
const version_number = parseInt(version.replace(/^v/, ""), 10)
|
||||
|
@ -43,7 +44,7 @@ async function buildKcov(file: string, dest: string) {
|
|||
await setupCmake(getVersion("cmake", undefined), join(untildify(""), "cmake"), "")
|
||||
}
|
||||
if (process.platform === "linux") {
|
||||
if (which.sync("pacman", { nothrow: true })) {
|
||||
if (isArch()) {
|
||||
setupPacmanPack("libdwarf")
|
||||
setupPacmanPack("libcurl-openssl")
|
||||
} else {
|
||||
|
@ -60,7 +61,7 @@ async function buildKcov(file: string, dest: string) {
|
|||
export async function setupKcov(version: string, setupDir: string, arch: string) {
|
||||
switch (process.platform) {
|
||||
case "linux": {
|
||||
if (which.sync("pacman", { nothrow: true })) {
|
||||
if (isArch()) {
|
||||
// TODO install kcov ? setupPacmanPack("kcov")
|
||||
const installationInfo = await setupBin("kcov", version, getKcovPackageInfo, setupDir, arch)
|
||||
setupPacmanPack("binutils")
|
||||
|
|
|
@ -20,7 +20,7 @@ import { existsSync } from "fs"
|
|||
import { isGitHubCI } from "../utils/env/isci"
|
||||
import { setupGcc } from "../gcc/gcc"
|
||||
import { getVersion } from "../default_versions"
|
||||
import which from "which"
|
||||
import { isArch } from "../utils/env/isArch"
|
||||
|
||||
//================================================
|
||||
// Version
|
||||
|
@ -286,7 +286,7 @@ async function _setupLLVM(version: string, setupDir: string, arch: string) {
|
|||
if (process.platform === "linux") {
|
||||
// install llvm build dependencies
|
||||
await setupGcc(getVersion("gcc", undefined), "", arch) // using llvm requires ld, an up to date libstdc++, etc. So, install gcc first
|
||||
if (which.sync("pacman", { nothrow: true })) {
|
||||
if (isArch()) {
|
||||
// setupPacmanPack("ncurses")
|
||||
// TODO: install libtinfo ?
|
||||
} else {
|
||||
|
|
|
@ -3,7 +3,7 @@ import { setupAptPack } from "../utils/setup/setupAptPack"
|
|||
import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
|
||||
import { setupBrewPack } from "../utils/setup/setupBrewPack"
|
||||
import { setupChocoPack } from "../utils/setup/setupChocoPack"
|
||||
import which from "which"
|
||||
import { isArch } from "../utils/env/isArch"
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export async function setupMake(version: string, _setupDir: string, _arch: string) {
|
||||
|
@ -17,7 +17,7 @@ export async function setupMake(version: string, _setupDir: string, _arch: strin
|
|||
return { binDir: "/usr/local/opt/make/libexec/gnubin" }
|
||||
}
|
||||
case "linux": {
|
||||
if (which.sync("pacman", { nothrow: true })) {
|
||||
if (isArch()) {
|
||||
return setupPacmanPack("make", version)
|
||||
}
|
||||
return setupAptPack("make", version)
|
||||
|
|
|
@ -5,7 +5,7 @@ import { setupBrewPack } from "../utils/setup/setupBrewPack"
|
|||
import { setupChocoPack } from "../utils/setup/setupChocoPack"
|
||||
import { isGitHubCI } from "../utils/env/isci"
|
||||
import { warning, info } from "../utils/io/io"
|
||||
import which from "which"
|
||||
import { isArch } from "../utils/env/isArch"
|
||||
|
||||
export async function setupPython(version: string, setupDir: string, arch: string) {
|
||||
if (!isGitHubCI()) {
|
||||
|
@ -40,7 +40,7 @@ export async function setupPythonViaSystem(version: string, setupDir: string, _a
|
|||
return setupBrewPack("python3", version)
|
||||
}
|
||||
case "linux": {
|
||||
if (which.sync("pacman", { nothrow: true })) {
|
||||
if (isArch()) {
|
||||
const installInfo = setupPacmanPack("python", version)
|
||||
setupPacmanPack("python-pip")
|
||||
return installInfo
|
||||
|
|
|
@ -2,7 +2,7 @@ import { setupAptPack } from "../utils/setup/setupAptPack"
|
|||
import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
|
||||
import { setupBrewPack } from "../utils/setup/setupBrewPack"
|
||||
import { setupChocoPack } from "../utils/setup/setupChocoPack"
|
||||
import which from "which"
|
||||
import { isArch } from "../utils/env/isArch"
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function setupSevenZip(version: string, _setupDir: string, _arch: string) {
|
||||
|
@ -14,7 +14,7 @@ export function setupSevenZip(version: string, _setupDir: string, _arch: string)
|
|||
return setupBrewPack("p7zip", version)
|
||||
}
|
||||
case "linux": {
|
||||
if (which.sync("pacman", { nothrow: true })) {
|
||||
if (isArch()) {
|
||||
return setupPacmanPack("p7zip", version)
|
||||
}
|
||||
return setupAptPack("p7zip-full", version)
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
import which from "which"
|
||||
|
||||
let isArchCache: undefined | boolean = undefined
|
||||
|
||||
export function isArch(): boolean {
|
||||
if (isArchCache === undefined) {
|
||||
// detect arch by checking if pacman exists
|
||||
isArchCache = which.sync("pacman", { nothrow: true }) !== null
|
||||
}
|
||||
|
||||
return isArchCache
|
||||
}
|
|
@ -7,7 +7,7 @@ import { tmpdir } from "os"
|
|||
import { isGitHubCI } from "../env/isci"
|
||||
import { setupAptPack } from "./setupAptPack"
|
||||
import { setupPacmanPack } from "./setupPacmanPack"
|
||||
import which from "which"
|
||||
import { isArch } from "../env/isArch"
|
||||
|
||||
/** A type that describes a package */
|
||||
export type PackageInfo = {
|
||||
|
@ -90,7 +90,7 @@ export async function setupBin(
|
|||
if (!didInit) {
|
||||
if (process.platform === "linux") {
|
||||
// extraction dependencies
|
||||
if (which.sync("pacman", { nothrow: true })) {
|
||||
if (isArch()) {
|
||||
setupPacmanPack("unzip")
|
||||
setupPacmanPack("tar")
|
||||
setupPacmanPack("xz")
|
||||
|
|
|
@ -11,6 +11,7 @@ import { getVersion } from "../../default_versions"
|
|||
import { InstallationInfo } from "./setupBin"
|
||||
import { setupAptPack } from "./setupAptPack"
|
||||
import { setupPacmanPack } from "./setupPacmanPack"
|
||||
import { isArch } from "../env/isArch"
|
||||
|
||||
let python: string | undefined
|
||||
let binDir: string | undefined
|
||||
|
@ -43,7 +44,7 @@ export async function setupPipPack(name: string, version?: string): Promise<Inst
|
|||
execa.sync(python, ["-m", "pip", "install", "-U", "pip==21.3.1"], { stdio: "inherit" })
|
||||
} else if (process.platform === "linux") {
|
||||
// ensure that pip is installed on Linux (happens when python is found but pip not installed)
|
||||
if (which.sync("pacman", { nothrow: true })) {
|
||||
if (isArch()) {
|
||||
setupPacmanPack("python-pip")
|
||||
} else {
|
||||
setupAptPack("python3-pip")
|
||||
|
|
|
@ -10,6 +10,7 @@ import { notice } from "../utils/io/io"
|
|||
import { setupAptPack } from "../utils/setup/setupAptPack"
|
||||
import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
|
||||
import { InstallationInfo } from "../utils/setup/setupBin"
|
||||
import { isArch } from "../utils/env/isArch"
|
||||
|
||||
let hasVCPKG = false
|
||||
|
||||
|
@ -18,7 +19,7 @@ export async function setupVcpkg(_version: string, setupDir: string, _arch: stri
|
|||
if (!hasVCPKG || which.sync("vcpkg", { nothrow: true }) === null) {
|
||||
if (process.platform === "linux") {
|
||||
// vcpkg download and extraction dependencies
|
||||
if (which.sync("pacman", { nothrow: true })) {
|
||||
if (isArch()) {
|
||||
setupPacmanPack("curl")
|
||||
setupPacmanPack("zip")
|
||||
setupPacmanPack("unzip")
|
||||
|
|
Loading…
Reference in New Issue