mirror of https://github.com/aminya/setup-cpp
fix: memoize ubuntuVersion and use it everywhere
This commit is contained in:
parent
cfa0cc5326
commit
f708497511
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
|
@ -16,6 +16,7 @@ import { setupDnfPack } from "../utils/setup/setupDnfPack"
|
||||||
import { isUbuntu } from "../utils/env/isUbuntu"
|
import { isUbuntu } from "../utils/env/isUbuntu"
|
||||||
import { pathExists } from "path-exists"
|
import { pathExists } from "path-exists"
|
||||||
import retry from "retry-as-promised"
|
import retry from "retry-as-promised"
|
||||||
|
import { ubuntuVersion } from "../utils/env/ubuntu_version"
|
||||||
|
|
||||||
/** Get the platform data for cmake */
|
/** Get the platform data for cmake */
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
@ -90,7 +91,7 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Unsupported linux distributions`)
|
throw new Error(`Unsupported linux distributions`)
|
||||||
}
|
}
|
||||||
await setupGraphviz(getVersion("graphviz", undefined), "", arch)
|
await setupGraphviz(getVersion("graphviz", undefined, await ubuntuVersion()), "", arch)
|
||||||
return installationInfo
|
return installationInfo
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { setupGraphviz } from "../graphviz"
|
||||||
import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers"
|
import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers"
|
||||||
import { InstallationInfo } from "../../utils/setup/setupBin"
|
import { InstallationInfo } from "../../utils/setup/setupBin"
|
||||||
import { getVersion } from "../../versions/versions"
|
import { getVersion } from "../../versions/versions"
|
||||||
|
import { ubuntuVersion } from "../../utils/env/ubuntu_version"
|
||||||
|
|
||||||
jest.setTimeout(300000)
|
jest.setTimeout(300000)
|
||||||
describe("setup-graphviz", () => {
|
describe("setup-graphviz", () => {
|
||||||
|
@ -11,7 +12,11 @@ describe("setup-graphviz", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should setup graphviz", async () => {
|
it("should setup graphviz", async () => {
|
||||||
const installInfo = await setupGraphviz(getVersion("graphviz", undefined), directory, process.arch)
|
const installInfo = await setupGraphviz(
|
||||||
|
getVersion("graphviz", undefined, await ubuntuVersion()),
|
||||||
|
directory,
|
||||||
|
process.arch
|
||||||
|
)
|
||||||
|
|
||||||
await testBin("dot", ["-V"], (installInfo as InstallationInfo | undefined)?.binDir)
|
await testBin("dot", ["-V"], (installInfo as InstallationInfo | undefined)?.binDir)
|
||||||
})
|
})
|
||||||
|
|
|
@ -15,6 +15,7 @@ import { addVPrefix, removeVPrefix } from "../utils/setup/version"
|
||||||
import { info } from "ci-log"
|
import { info } from "ci-log"
|
||||||
import { untildifyUser } from "untildify-user"
|
import { untildifyUser } from "untildify-user"
|
||||||
import { setupNinja } from "../ninja/ninja"
|
import { setupNinja } from "../ninja/ninja"
|
||||||
|
import { ubuntuVersion } from "../utils/env/ubuntu_version"
|
||||||
|
|
||||||
function getDownloadKcovPackageInfo(version: string): PackageInfo {
|
function getDownloadKcovPackageInfo(version: string): PackageInfo {
|
||||||
return {
|
return {
|
||||||
|
@ -79,12 +80,16 @@ async function buildKcov(file: string, dest: string) {
|
||||||
async function getCmake() {
|
async function getCmake() {
|
||||||
let cmake = which.sync("cmake", { nothrow: true })
|
let cmake = which.sync("cmake", { nothrow: true })
|
||||||
if (cmake === null) {
|
if (cmake === null) {
|
||||||
const { binDir } = await setupCmake(getVersion("cmake", undefined), join(untildifyUser(""), "cmake"), "")
|
const { binDir } = await setupCmake(
|
||||||
|
getVersion("cmake", undefined, await ubuntuVersion()),
|
||||||
|
join(untildifyUser(""), "cmake"),
|
||||||
|
""
|
||||||
|
)
|
||||||
cmake = join(binDir, "cmake")
|
cmake = join(binDir, "cmake")
|
||||||
}
|
}
|
||||||
const ninja = which.sync("ninja", { nothrow: true })
|
const ninja = which.sync("ninja", { nothrow: true })
|
||||||
if (ninja === null) {
|
if (ninja === null) {
|
||||||
await setupNinja(getVersion("ninja", undefined), join(untildifyUser(""), "ninja"), "")
|
await setupNinja(getVersion("ninja", undefined, await ubuntuVersion()), join(untildifyUser(""), "ninja"), "")
|
||||||
}
|
}
|
||||||
return cmake
|
return cmake
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,8 +46,7 @@ async function setupLLVMWithoutActivation(version: string, setupDir: string, arc
|
||||||
async function setupLLVMDeps(arch: string, version: string) {
|
async function setupLLVMDeps(arch: string, version: string) {
|
||||||
if (process.platform === "linux") {
|
if (process.platform === "linux") {
|
||||||
// install llvm build dependencies
|
// install llvm build dependencies
|
||||||
const osVersion = await ubuntuVersion()
|
await setupGcc(getVersion("gcc", undefined, await ubuntuVersion()), "", arch) // using llvm requires ld, an up to date libstdc++, etc. So, install gcc first
|
||||||
await setupGcc(getVersion("gcc", undefined, osVersion), "", arch) // using llvm requires ld, an up to date libstdc++, etc. So, install gcc first
|
|
||||||
|
|
||||||
if (isUbuntu()) {
|
if (isUbuntu()) {
|
||||||
const majorVersion = parseInt(version.split(".")[0], 10)
|
const majorVersion = parseInt(version.split(".")[0], 10)
|
||||||
|
|
|
@ -4,8 +4,9 @@ import which from "which"
|
||||||
import { setupAptPack } from "../setup/setupAptPack"
|
import { setupAptPack } from "../setup/setupAptPack"
|
||||||
import { isUbuntu } from "./isUbuntu"
|
import { isUbuntu } from "./isUbuntu"
|
||||||
import os from "os"
|
import os from "os"
|
||||||
|
import memoize from "micro-memoize"
|
||||||
|
|
||||||
export async function ubuntuVersion(): Promise<number[] | null> {
|
async function ubuntuVersion_raw(): Promise<number[] | null> {
|
||||||
try {
|
try {
|
||||||
if (isUbuntu()) {
|
if (isUbuntu()) {
|
||||||
try {
|
try {
|
||||||
|
@ -31,6 +32,10 @@ export async function ubuntuVersion(): Promise<number[] | null> {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Detect Ubuntu version */
|
||||||
|
export const ubuntuVersion = memoize(ubuntuVersion_raw)
|
||||||
|
|
||||||
/** Detect Ubuntu version using os.version() for Ubuntu based distros */
|
/** Detect Ubuntu version using os.version() for Ubuntu based distros */
|
||||||
function detectUsingOsVersion() {
|
function detectUsingOsVersion() {
|
||||||
// #46~22.04.1-Ubuntu SMP ...
|
// #46~22.04.1-Ubuntu SMP ...
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { addPythonBaseExecPrefix, setupPython } from "../../python/python"
|
||||||
import { addPath } from "../env/addEnv"
|
import { addPath } from "../env/addEnv"
|
||||||
import { InstallationInfo } from "./setupBin"
|
import { InstallationInfo } from "./setupBin"
|
||||||
import { getVersion } from "../../versions/versions"
|
import { getVersion } from "../../versions/versions"
|
||||||
|
import { ubuntuVersion } from "../env/ubuntu_version"
|
||||||
|
|
||||||
/* eslint-disable require-atomic-updates */
|
/* eslint-disable require-atomic-updates */
|
||||||
let python: string | undefined
|
let python: string | undefined
|
||||||
|
@ -16,7 +17,7 @@ export async function setupPipPack(name: string, version?: string): Promise<Inst
|
||||||
info(`Installing ${name} ${version ?? ""} via pip`)
|
info(`Installing ${name} ${version ?? ""} via pip`)
|
||||||
|
|
||||||
if (python === undefined) {
|
if (python === undefined) {
|
||||||
python = (await setupPython(getVersion("python", undefined), "", process.arch)).bin!
|
python = (await setupPython(getVersion("python", undefined, await ubuntuVersion()), "", process.arch)).bin!
|
||||||
}
|
}
|
||||||
|
|
||||||
execaSync(python, ["-m", "pip", "install", version !== undefined && version !== "" ? `${name}==${version}` : name], {
|
execaSync(python, ["-m", "pip", "install", version !== undefined && version !== "" ? `${name}==${version}` : name], {
|
||||||
|
|
Loading…
Reference in New Issue