Skip to content

Commit f708497

Browse files
committed
fix: memoize ubuntuVersion and use it everywhere
1 parent cfa0cc5 commit f708497

File tree

10 files changed

+32
-16
lines changed

10 files changed

+32
-16
lines changed

dist/node12/setup-cpp.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/node12/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/node16/setup-cpp.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/node16/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.

src/doxygen/doxygen.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { setupDnfPack } from "../utils/setup/setupDnfPack"
1616
import { isUbuntu } from "../utils/env/isUbuntu"
1717
import { pathExists } from "path-exists"
1818
import retry from "retry-as-promised"
19+
import { ubuntuVersion } from "../utils/env/ubuntu_version"
1920

2021
/** Get the platform data for cmake */
2122
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -90,7 +91,7 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
9091
} else {
9192
throw new Error(`Unsupported linux distributions`)
9293
}
93-
await setupGraphviz(getVersion("graphviz", undefined), "", arch)
94+
await setupGraphviz(getVersion("graphviz", undefined, await ubuntuVersion()), "", arch)
9495
return installationInfo
9596
}
9697
default: {

src/graphviz/__tests__/graphviz.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { setupGraphviz } from "../graphviz"
22
import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers"
33
import { InstallationInfo } from "../../utils/setup/setupBin"
44
import { getVersion } from "../../versions/versions"
5+
import { ubuntuVersion } from "../../utils/env/ubuntu_version"
56

67
jest.setTimeout(300000)
78
describe("setup-graphviz", () => {
@@ -11,7 +12,11 @@ describe("setup-graphviz", () => {
1112
})
1213

1314
it("should setup graphviz", async () => {
14-
const installInfo = await setupGraphviz(getVersion("graphviz", undefined), directory, process.arch)
15+
const installInfo = await setupGraphviz(
16+
getVersion("graphviz", undefined, await ubuntuVersion()),
17+
directory,
18+
process.arch
19+
)
1520

1621
await testBin("dot", ["-V"], (installInfo as InstallationInfo | undefined)?.binDir)
1722
})

src/kcov/kcov.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { addVPrefix, removeVPrefix } from "../utils/setup/version"
1515
import { info } from "ci-log"
1616
import { untildifyUser } from "untildify-user"
1717
import { setupNinja } from "../ninja/ninja"
18+
import { ubuntuVersion } from "../utils/env/ubuntu_version"
1819

1920
function getDownloadKcovPackageInfo(version: string): PackageInfo {
2021
return {
@@ -79,12 +80,16 @@ async function buildKcov(file: string, dest: string) {
7980
async function getCmake() {
8081
let cmake = which.sync("cmake", { nothrow: true })
8182
if (cmake === null) {
82-
const { binDir } = await setupCmake(getVersion("cmake", undefined), join(untildifyUser(""), "cmake"), "")
83+
const { binDir } = await setupCmake(
84+
getVersion("cmake", undefined, await ubuntuVersion()),
85+
join(untildifyUser(""), "cmake"),
86+
""
87+
)
8388
cmake = join(binDir, "cmake")
8489
}
8590
const ninja = which.sync("ninja", { nothrow: true })
8691
if (ninja === null) {
87-
await setupNinja(getVersion("ninja", undefined), join(untildifyUser(""), "ninja"), "")
92+
await setupNinja(getVersion("ninja", undefined, await ubuntuVersion()), join(untildifyUser(""), "ninja"), "")
8893
}
8994
return cmake
9095
}

src/llvm/llvm.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ async function setupLLVMWithoutActivation(version: string, setupDir: string, arc
4646
async function setupLLVMDeps(arch: string, version: string) {
4747
if (process.platform === "linux") {
4848
// install llvm build dependencies
49-
const osVersion = await ubuntuVersion()
50-
await setupGcc(getVersion("gcc", undefined, osVersion), "", arch) // using llvm requires ld, an up to date libstdc++, etc. So, install gcc first
49+
await setupGcc(getVersion("gcc", undefined, await ubuntuVersion()), "", arch) // using llvm requires ld, an up to date libstdc++, etc. So, install gcc first
5150

5251
if (isUbuntu()) {
5352
const majorVersion = parseInt(version.split(".")[0], 10)

src/utils/env/ubuntu_version.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import which from "which"
44
import { setupAptPack } from "../setup/setupAptPack"
55
import { isUbuntu } from "./isUbuntu"
66
import os from "os"
7+
import memoize from "micro-memoize"
78

8-
export async function ubuntuVersion(): Promise<number[] | null> {
9+
async function ubuntuVersion_raw(): Promise<number[] | null> {
910
try {
1011
if (isUbuntu()) {
1112
try {
@@ -31,6 +32,10 @@ export async function ubuntuVersion(): Promise<number[] | null> {
3132
return null
3233
}
3334
}
35+
36+
/** Detect Ubuntu version */
37+
export const ubuntuVersion = memoize(ubuntuVersion_raw)
38+
3439
/** Detect Ubuntu version using os.version() for Ubuntu based distros */
3540
function detectUsingOsVersion() {
3641
// #46~22.04.1-Ubuntu SMP ...

src/utils/setup/setupPipPack.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { addPythonBaseExecPrefix, setupPython } from "../../python/python"
77
import { addPath } from "../env/addEnv"
88
import { InstallationInfo } from "./setupBin"
99
import { getVersion } from "../../versions/versions"
10+
import { ubuntuVersion } from "../env/ubuntu_version"
1011

1112
/* eslint-disable require-atomic-updates */
1213
let python: string | undefined
@@ -16,7 +17,7 @@ export async function setupPipPack(name: string, version?: string): Promise<Inst
1617
info(`Installing ${name} ${version ?? ""} via pip`)
1718

1819
if (python === undefined) {
19-
python = (await setupPython(getVersion("python", undefined), "", process.arch)).bin!
20+
python = (await setupPython(getVersion("python", undefined, await ubuntuVersion()), "", process.arch)).bin!
2021
}
2122

2223
execaSync(python, ["-m", "pip", "install", version !== undefined && version !== "" ? `${name}==${version}` : name], {

0 commit comments

Comments
 (0)