feat: store default versions in a json version file

This commit is contained in:
Amin Yahyaabadi 2024-10-25 01:49:11 -07:00
parent e0e749b984
commit 819d82997a
13 changed files with 278 additions and 126 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1
dist/legacy/versions.json vendored Normal file
View File

@ -0,0 +1 @@
{"ninja":"1.12.1","cmake":"3.30.4","task":"3.39.2","powershell":"7.4.5","pip":"22.2.0","python":"3.7.9","meson":{"linux":{"ubuntu":{"20":"1.5.2","18":"0.61.4","else":"0.61.4"},"else":"1.5.2"},"else":"1.5.2"},"kcov":{"linux":{"ubuntu":{"22":"42-binary","20":"40-binary","14":"40","else":"42"},"else":"42"},"else":"42"},"doxygen":{"linux":{"archlinux":"1.12.0-2","ubuntu":{"22":"1.12.0","18":"1.10.0","else":"1.10.0"},"else":"1.12.0"},"else":"1.12.0"},"gcc":{"win32":"14.2.0posix-18.1.8-12.0.0-ucrt-r1","else":""},"mingw":{"win32":"14.2.0posix-18.1.8-12.0.0-ucrt-r1","linux":{"ubuntu":{"22":"8.0.0-1","20":"7.0.0-2","else":"7.0.0-2"}},"else":""},"gcovr":{"linux":{"ubuntu":{"20":"","18":"5.0","else":"5.0"}},"else":""},"nala":{"win32":"14.2.0posix-18.1.8-12.0.0-ucrt-r1","linux":{"ubuntu":{"22":"","21":"legacy","else":"legacy"}},"else":""},"llvm":{"darwin":{"else":{"else":{"x64":"15.0.7","else":"18.1.8"}}},"else":"18.1.8"},"clang":{"darwin":{"else":{"else":{"x64":"15.0.7","else":"18.1.8"}}},"else":"18.1.8"},"clang++":{"darwin":{"else":{"else":{"x64":"15.0.7","else":"18.1.8"}}},"else":"18.1.8"},"clang-tidy":{"darwin":{"else":{"else":{"x64":"15.0.7","else":"18.1.8"}}},"else":"18.1.8"},"clangtidy":{"darwin":{"else":{"else":{"x64":"15.0.7","else":"18.1.8"}}},"else":"18.1.8"},"clang-format":{"darwin":{"else":{"else":{"x64":"15.0.7","else":"18.1.8"}}},"else":"18.1.8"},"clangformat":{"darwin":{"else":{"else":{"x64":"15.0.7","else":"18.1.8"}}},"else":"18.1.8"}}

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

1
dist/modern/versions.json vendored Normal file
View File

@ -0,0 +1 @@
{"ninja":"1.12.1","cmake":"3.30.4","task":"3.39.2","powershell":"7.4.5","pip":"22.2.0","python":"3.7.9","meson":{"linux":{"ubuntu":{"20":"1.5.2","18":"0.61.4","else":"0.61.4"},"else":"1.5.2"},"else":"1.5.2"},"kcov":{"linux":{"ubuntu":{"22":"42-binary","20":"40-binary","14":"40","else":"42"},"else":"42"},"else":"42"},"doxygen":{"linux":{"archlinux":"1.12.0-2","ubuntu":{"22":"1.12.0","18":"1.10.0","else":"1.10.0"},"else":"1.12.0"},"else":"1.12.0"},"gcc":{"win32":"14.2.0posix-18.1.8-12.0.0-ucrt-r1","else":""},"mingw":{"win32":"14.2.0posix-18.1.8-12.0.0-ucrt-r1","linux":{"ubuntu":{"22":"8.0.0-1","20":"7.0.0-2","else":"7.0.0-2"}},"else":""},"gcovr":{"linux":{"ubuntu":{"20":"","18":"5.0","else":"5.0"}},"else":""},"nala":{"win32":"14.2.0posix-18.1.8-12.0.0-ucrt-r1","linux":{"ubuntu":{"22":"","21":"legacy","else":"legacy"}},"else":""},"llvm":{"darwin":{"else":{"else":{"x64":"15.0.7","else":"18.1.8"}}},"else":"18.1.8"},"clang":{"darwin":{"else":{"else":{"x64":"15.0.7","else":"18.1.8"}}},"else":"18.1.8"},"clang++":{"darwin":{"else":{"else":{"x64":"15.0.7","else":"18.1.8"}}},"else":"18.1.8"},"clang-tidy":{"darwin":{"else":{"else":{"x64":"15.0.7","else":"18.1.8"}}},"else":"18.1.8"},"clangtidy":{"darwin":{"else":{"else":{"x64":"15.0.7","else":"18.1.8"}}},"else":"18.1.8"},"clang-format":{"darwin":{"else":{"else":{"x64":"15.0.7","else":"18.1.8"}}},"else":"18.1.8"},"clangformat":{"darwin":{"else":{"else":{"x64":"15.0.7","else":"18.1.8"}}},"else":"18.1.8"}}

View File

@ -1,7 +1,6 @@
import { parseArgs } from "../cli-options.js" import { parseArgs } from "../cli-options.js"
import { getCompilerInfo } from "../compilers.js" import { getCompilerInfo } from "../compilers.js"
import { type Inputs, llvmTools } from "../tool.js" import { type Inputs, llvmTools } from "../tool.js"
import { DefaultUbuntuVersion, DefaultVersions } from "../versions/default_versions.js"
import { getVersion, syncVersions } from "../versions/versions.js" import { getVersion, syncVersions } from "../versions/versions.js"
jest.setTimeout(300000) jest.setTimeout(300000)
@ -90,18 +89,13 @@ describe("getVersion", () => {
it("gcovr", () => { it("gcovr", () => {
expect(getVersion("gcovr", "5.0")).toBe("5.0") expect(getVersion("gcovr", "5.0")).toBe("5.0")
if (process.platform === "linux") { if (process.platform === "linux") {
expect(getVersion("gcovr", "true", [22, 4])).toBe(DefaultUbuntuVersion.gcovr![22]) expect(getVersion("gcovr", "true", [22, 4])).toBe("")
expect(getVersion("gcovr", "true", [20, 4])).toBe(DefaultUbuntuVersion.gcovr![20]) expect(getVersion("gcovr", "true", [20, 4])).toBe("")
expect(getVersion("gcovr", "true", [18, 4])).toBe(DefaultUbuntuVersion.gcovr![18]) expect(getVersion("gcovr", "true", [18, 4])).toBe("5.0")
} }
}) })
it("llvm", () => { it("llvm", () => {
expect(getVersion("llvm", "13.0.0")).toBe("13.0.0") expect(getVersion("llvm", "13.0.0")).toBe("13.0.0")
if (process.platform === "linux") {
expect(getVersion("llvm", "true", [20, 4])).toBe(DefaultVersions.llvm)
expect(getVersion("llvm", "true", [18, 4])).toBe(DefaultVersions.llvm)
expect(getVersion("llvm", "true", [16, 4])).toBe(DefaultVersions.llvm)
}
}) })
}) })

View File

@ -25,7 +25,7 @@ import { setupPacmanPack } from "../utils/setup/setupPacmanPack.js"
import { hasPipx, setupPipPackSystem, setupPipPackWithPython } from "../utils/setup/setupPipPack.js" import { hasPipx, setupPipPackSystem, setupPipPackWithPython } from "../utils/setup/setupPipPack.js"
import { isBinUptoDate } from "../utils/setup/version.js" import { isBinUptoDate } from "../utils/setup/version.js"
import { unique } from "../utils/std/index.js" import { unique } from "../utils/std/index.js"
import { MinVersions } from "../versions/default_versions.js" import { getVersionDefault } from "../versions/versions.js"
export async function setupPython( export async function setupPython(
version: string, version: string,
@ -214,9 +214,11 @@ async function findPython(binDir?: string) {
async function isPythonUpToDate(candidate: string, binDir?: string) { async function isPythonUpToDate(candidate: string, binDir?: string) {
try { try {
const targetVersion = getVersionDefault("python")
if (binDir !== undefined) { if (binDir !== undefined) {
const pythonBinPath = join(binDir, addExeExt(candidate)) const pythonBinPath = join(binDir, addExeExt(candidate))
if (await pathExists(pythonBinPath) && await isBinUptoDate(pythonBinPath, MinVersions.python!)) { if (await pathExists(pythonBinPath) && await isBinUptoDate(pythonBinPath, targetVersion!)) {
return pythonBinPath return pythonBinPath
} }
} }
@ -224,7 +226,7 @@ async function isPythonUpToDate(candidate: string, binDir?: string) {
const pythonBinPaths = (await which(candidate, { nothrow: true, all: true })) ?? [] const pythonBinPaths = (await which(candidate, { nothrow: true, all: true })) ?? []
for (const pythonBinPath of pythonBinPaths) { for (const pythonBinPath of pythonBinPaths) {
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
if (await isBinUptoDate(pythonBinPath, MinVersions.python!)) { if (await isBinUptoDate(pythonBinPath, targetVersion!)) {
return pythonBinPath return pythonBinPath
} }
} }
@ -260,11 +262,13 @@ async function findPip() {
async function isPipUptoDate(pip: string) { async function isPipUptoDate(pip: string) {
try { try {
const targetVersion = getVersionDefault("pip")
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const pipPaths = (await which(pip, { nothrow: true, all: true })) ?? [] const pipPaths = (await which(pip, { nothrow: true, all: true })) ?? []
for (const pipPath of pipPaths) { for (const pipPath of pipPaths) {
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
if (await isBinUptoDate(pipPath, MinVersions.pip!)) { if (await isBinUptoDate(pipPath, targetVersion!)) {
return pipPath return pipPath
} }
} }

View File

@ -1,83 +0,0 @@
import { isArch } from "../utils/env/isArch.js"
const defaultLLVM = process.platform === "darwin" && process.arch === "x64"
? "15.0.7"
: "18.1.8"
/**
* Default versions for the tools
* DefaultUbuntuVersion overrides the default version for the tools on Ubuntu
*/
export const DefaultVersions: Record<string, string | undefined> = {
// https://github.com/llvm/llvm-project/releases
llvm: defaultLLVM,
clang: defaultLLVM,
"clang++": defaultLLVM,
"clang-tidy": defaultLLVM,
clangtidy: defaultLLVM,
"clang-format": defaultLLVM,
clangformat: defaultLLVM,
ninja: "1.12.1", // https://github.com/ninja-build/ninja/releases
cmake: "3.30.4", // https://github.com/Kitware/CMake/releases
meson: "1.5.2", // https://github.com/mesonbuild/meson/releases
kcov: "42", // https://github.com/SimonKagstrom/kcov/releases
task: "3.39.2", // https://github.com/go-task/task/releases
doxygen: isArch() ? "1.12.0-2" : "1.12.0", // https://www.doxygen.nl/download.html // https://packages.ubuntu.com/search?suite=all&arch=any&searchon=names&keywords=doxygen // https://formulae.brew.sh/formula/doxygen // https://archlinux.org/packages/extra/x86_64/doxygen/
gcc: process.platform === "win32"
? "14.2.0posix-18.1.8-12.0.0-ucrt-r1"
: "", // use the default version on Ubuntu, Fedora, Arch, macOS, etc.
// mingw: isArch() ? "12.2.0-1" : "8", // https://archlinux.org/packages/extra/x86_64/mingw-w64-gcc/
powershell: "7.4.5",
}
export const MinVersions: Record<string, string | undefined> = {
pip: "22.2.0",
python: "3.7.9",
}
/// If an ubuntu versions is not in this map:
// - the newer ubuntu versions use the first entry (e.g. v20),
// - the older ones use ""
export const DefaultUbuntuVersion: Record<string, Record<number, string> | undefined> = {
// https://packages.ubuntu.com/search?suite=all&arch=any&searchon=names&keywords=mingw-w64
mingw: {
24: "8.0.0-1",
22: "8.0.0-1",
20: "7.0.0-2",
},
gcovr: {
24: "6.0",
22: "6.0",
20: "6.0",
18: "5.0",
},
meson: {
24: "1.0.0",
22: "1.0.0",
20: "1.0.0",
18: "0.61.4",
},
nala: {
24: "",
22: "",
21: "legacy",
20: "legacy",
18: "legacy",
16: "legacy",
14: "legacy",
},
kcov: {
24: "42-binary",
22: "42-binary",
20: "40-binary", // https://github.com/SimonKagstrom/kcov/releases
18: "40",
16: "40",
14: "40",
},
doxygen: {
24: "1.11.0",
22: "1.11.0",
20: "1.10.0",
18: "1.10.0",
},
}

156
src/versions/versions.json Normal file
View File

@ -0,0 +1,156 @@
{
"ninja": "1.12.1",
"cmake": "3.30.4",
"task": "3.39.2",
"powershell": "7.4.5",
"pip": "22.2.0",
"python": "3.7.9",
"meson": {
"linux": {
"ubuntu": {
"20": "1.5.2",
"18": "0.61.4",
"else": "0.61.4"
},
"else": "1.5.2"
},
"else": "1.5.2"
},
"kcov": {
"linux": {
"ubuntu": {
"22": "42-binary",
"20": "40-binary",
"14": "40",
"else": "42"
},
"else": "42"
},
"else": "42"
},
"doxygen": {
"linux": {
"archlinux": "1.12.0-2",
"ubuntu": {
"22": "1.12.0",
"18": "1.10.0",
"else": "1.10.0"
},
"else": "1.12.0"
},
"else": "1.12.0"
},
"gcc": {
"win32": "14.2.0posix-18.1.8-12.0.0-ucrt-r1",
"else": ""
},
"mingw": {
"win32": "14.2.0posix-18.1.8-12.0.0-ucrt-r1",
"linux": {
"ubuntu": {
"22": "8.0.0-1",
"20": "7.0.0-2",
"else": "7.0.0-2"
}
},
"else": ""
},
"gcovr": {
"linux": {
"ubuntu": {
"20": "",
"18": "5.0",
"else": "5.0"
}
},
"else": ""
},
"nala": {
"win32": "14.2.0posix-18.1.8-12.0.0-ucrt-r1",
"linux": {
"ubuntu": {
"22": "",
"21": "legacy",
"else": "legacy"
}
},
"else": ""
},
"llvm": {
"darwin": {
"else": {
"else": {
"x64": "15.0.7",
"else": "18.1.8"
}
}
},
"else": "18.1.8"
},
"clang": {
"darwin": {
"else": {
"else": {
"x64": "15.0.7",
"else": "18.1.8"
}
}
},
"else": "18.1.8"
},
"clang++": {
"darwin": {
"else": {
"else": {
"x64": "15.0.7",
"else": "18.1.8"
}
}
},
"else": "18.1.8"
},
"clang-tidy": {
"darwin": {
"else": {
"else": {
"x64": "15.0.7",
"else": "18.1.8"
}
}
},
"else": "18.1.8"
},
"clangtidy": {
"darwin": {
"else": {
"else": {
"x64": "15.0.7",
"else": "18.1.8"
}
}
},
"else": "18.1.8"
},
"clang-format": {
"darwin": {
"else": {
"else": {
"x64": "15.0.7",
"else": "18.1.8"
}
}
},
"else": "18.1.8"
},
"clangformat": {
"darwin": {
"else": {
"else": {
"x64": "15.0.7",
"else": "18.1.8"
}
}
},
"else": "18.1.8"
}
}

View File

@ -1,37 +1,116 @@
import fs from "fs"
import path from "path"
import { fileURLToPath } from "url"
import memoize from "memoizee"
import type { Opts } from "../cli-options.js" import type { Opts } from "../cli-options.js"
import type { CompilerInfo } from "../compilers.js" import type { CompilerInfo } from "../compilers.js"
import type { Inputs } from "../tool.js" import type { Inputs, ToolName } from "../tool.js"
import { DefaultUbuntuVersion, DefaultVersions } from "./default_versions.js" import { isArch } from "../utils/env/isArch.js"
import { isUbuntu } from "../utils/env/isUbuntu.js"
export function getVersion(name: ToolName, version: string | undefined, distroVersion: number[] | null = null) {
if (isVersionDefault(version)) {
return getVersionDefault(name, distroVersion) ?? ""
}
return version
}
type ArchVersionMap = Record<NodeJS.Architecture | "else", string | undefined>
type DistroVersionMap = Record<
`${number}` | `${number}.${number}` | `${number}.${number}.${number}` | string | "else",
ArchVersionMap | string | undefined
>
type DistroMap = Record<"ubuntu" | "archlinux" | string | "else", DistroVersionMap | string | undefined>
type PlatformMap = Record<NodeJS.Platform | "else", DistroMap | string | undefined>
type Versions = Record<ToolName | "pip", PlatformMap | string | undefined>
function readVersions_(): Versions {
const dirname = typeof __dirname === "string" ? __dirname : path.dirname(fileURLToPath(import.meta.url))
const jsonPath = path.join(dirname, "versions.json")
return JSON.parse(fs.readFileSync(jsonPath, "utf-8")) as Versions
}
const readVersions = memoize(readVersions_)
/** Get the default version if passed true or undefined, otherwise return the version itself */ /** Get the default version if passed true or undefined, otherwise return the version itself */
export function getVersion(name: string, version: string | undefined, osVersion: number[] | null = null) { export function getVersionDefault(
if (isVersionDefault(version) && process.platform === "linux" && osVersion !== null && name in DefaultUbuntuVersion) { tool: ToolName | "pip",
return getDefaultLinuxVersion(osVersion, DefaultUbuntuVersion[name]!) distroVersion: number[] | null = null,
} else if (isVersionDefault(version) && name in DefaultVersions) { ): string | undefined {
return DefaultVersions[name] ?? "" // get the tool
} else if (version === "true") { const versions = readVersions()
return "" const platformMapOrVersion = versions[tool]
if (platformMapOrVersion === undefined) {
throw new Error(`Tool "${tool}" not found in versions data`)
} }
return version ?? "" // platform-independent versions
if (typeof platformMapOrVersion === "string") {
return platformMapOrVersion
}
const platformMap = platformMapOrVersion
// Check for platform-specific versions
const distroMapOrVersion = platformMap[process.platform] ?? platformMap.else
if (distroMapOrVersion === undefined) {
throw new Error(`Platform "${process.platform}" not found in versions data for tool "${tool}"`)
}
// distro-independent versions
if (typeof distroMapOrVersion === "string") {
return distroMapOrVersion
}
const distroMap = distroMapOrVersion
// check for distro-specific versions
const distro = isUbuntu() ? "ubuntu" : isArch() ? "archlinux" : "else"
const distroVersionMapOrVersion = distroMap[distro] ?? distroMap.else
if (distroVersionMapOrVersion === undefined) {
throw new Error(`Distro "${distro}" not found in versions data for tool "${tool}"`)
}
// distro version independent versions
if (typeof distroVersionMapOrVersion === "string") {
return distroVersionMapOrVersion
}
const distroVersionMap = distroVersionMapOrVersion
// check for the distro-specific version for the current architecture
const archVersionMapOrVersion = distroVersion !== null
? matchDistroVersion(distroVersion, distroVersionMap)
: distroVersionMap.else
if (archVersionMapOrVersion === undefined) {
throw new Error(`Architecture "${process.arch}" not found in versions data for tool "${tool}"`)
}
if (typeof archVersionMapOrVersion === "string") {
return archVersionMapOrVersion
}
const archVersionMap = archVersionMapOrVersion
// get the version for the current architecture
return archVersionMap[process.arch] ?? archVersionMap.else
}
/// choose the default linux version based on ubuntu version
function matchDistroVersion(distroVersion: number[], distroVersionMap: DistroVersionMap) {
const distroVersionMaj = distroVersion[0]
// find which version block the os version is in
const satisfyingVersion = Object.keys(distroVersionMap)
.map((v) => Number.parseInt(v, 10))
.filter((v) => !Number.isNaN(v))
.sort((a, b) => b - a) // sort in descending order
.find((v) => distroVersionMaj >= v)
return satisfyingVersion !== undefined
? distroVersionMap[satisfyingVersion]
?? distroVersionMap.else
: distroVersionMap.else
} }
function isVersionDefault(version: string | undefined) { function isVersionDefault(version: string | undefined) {
return version === "true" || version === undefined return version === "true" || version === undefined
} }
/// choose the default linux version based on ubuntu version
function getDefaultLinuxVersion(osVersion: number[], toolLinuxVersions: Record<number, string>) {
const osVersionMaj = osVersion[0]
// find which version block the os version is in
const satisfyingVersion = Object.keys(toolLinuxVersions)
.map((v) => Number.parseInt(v, 10))
.sort((a, b) => b - a) // sort in descending order
.find((v) => osVersionMaj >= v)
return satisfyingVersion === undefined ? "" : toolLinuxVersions[satisfyingVersion]
}
/** /**
* Sync the versions for the given inputs * Sync the versions for the given inputs
* *