Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: store default versions in a json version file #312

Merged
merged 5 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/legacy/versions.json
Original file line number Diff line number Diff line change
@@ -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":""},"else":""},"gcovr":{"linux":{"ubuntu":{"20":"","18":"5.0","else":"5.0"},"else":""},"else":""},"nala":{"linux":{"ubuntu":{"22":"","21":"legacy","else":"legacy"},"else":""},"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"}}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.mjs.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/modern/versions.json
Original file line number Diff line number Diff line change
@@ -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":""},"else":""},"gcovr":{"linux":{"ubuntu":{"20":"","18":"5.0","else":"5.0"},"else":""},"else":""},"nala":{"linux":{"ubuntu":{"22":"","21":"legacy","else":"legacy"},"else":""},"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"}}
12 changes: 3 additions & 9 deletions src/__tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { parseArgs } from "../cli-options.js"
import { getCompilerInfo } from "../compilers.js"
import { type Inputs, llvmTools } from "../tool.js"
import { DefaultUbuntuVersion, DefaultVersions } from "../versions/default_versions.js"
import { getVersion, syncVersions } from "../versions/versions.js"

jest.setTimeout(300000)
Expand Down Expand Up @@ -90,18 +89,13 @@ describe("getVersion", () => {
it("gcovr", () => {
expect(getVersion("gcovr", "5.0")).toBe("5.0")
if (process.platform === "linux") {
expect(getVersion("gcovr", "true", [22, 4])).toBe(DefaultUbuntuVersion.gcovr![22])
expect(getVersion("gcovr", "true", [20, 4])).toBe(DefaultUbuntuVersion.gcovr![20])
expect(getVersion("gcovr", "true", [18, 4])).toBe(DefaultUbuntuVersion.gcovr![18])
expect(getVersion("gcovr", "true", [22, 4])).toBe("")
expect(getVersion("gcovr", "true", [20, 4])).toBe("")
expect(getVersion("gcovr", "true", [18, 4])).toBe("5.0")
}
})

it("llvm", () => {
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)
}
})
})
17 changes: 12 additions & 5 deletions src/python/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { setupPacmanPack } from "../utils/setup/setupPacmanPack.js"
import { hasPipx, setupPipPackSystem, setupPipPackWithPython } from "../utils/setup/setupPipPack.js"
import { isBinUptoDate } from "../utils/setup/version.js"
import { unique } from "../utils/std/index.js"
import { MinVersions } from "../versions/default_versions.js"
import { getVersionDefault, isMinVersion } from "../versions/versions.js"

export async function setupPython(
version: string,
Expand Down Expand Up @@ -89,7 +89,10 @@ async function setupWheel(foundPython: string) {
}
}

async function findOrSetupPython(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
async function findOrSetupPython(givenVersion: string, setupDir: string, arch: string): Promise<InstallationInfo> {
// if a version range specified, use the default version, and later check the range
const version = isMinVersion(givenVersion) ? "" : givenVersion

let installInfo: InstallationInfo | undefined
let foundPython = await findPython(setupDir)

Expand Down Expand Up @@ -214,17 +217,19 @@ async function findPython(binDir?: string) {

async function isPythonUpToDate(candidate: string, binDir?: string) {
try {
const targetVersion = getVersionDefault("python")

if (binDir !== undefined) {
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
}
}
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const pythonBinPaths = (await which(candidate, { nothrow: true, all: true })) ?? []
for (const pythonBinPath of pythonBinPaths) {
// eslint-disable-next-line no-await-in-loop
if (await isBinUptoDate(pythonBinPath, MinVersions.python!)) {
if (await isBinUptoDate(pythonBinPath, targetVersion!)) {
return pythonBinPath
}
}
Expand Down Expand Up @@ -260,11 +265,13 @@ async function findPip() {

async function isPipUptoDate(pip: string) {
try {
const targetVersion = getVersionDefault("pip")

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const pipPaths = (await which(pip, { nothrow: true, all: true })) ?? []
for (const pipPath of pipPaths) {
// eslint-disable-next-line no-await-in-loop
if (await isBinUptoDate(pipPath, MinVersions.pip!)) {
if (await isBinUptoDate(pipPath, targetVersion!)) {
return pipPath
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/utils/setup/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { info } from "ci-log"
import { isUrlOnline } from "is-url-online"
import semverCoerce from "semver/functions/coerce"
import semverCompare from "semver/functions/compare"
import semverSatisfies from "semver/functions/satisfies"
import semverValid from "semver/functions/valid"

/**
Expand Down Expand Up @@ -112,7 +113,15 @@ export async function isBinUptoDate(
) {
const givenVersion = await getBinVersion(givenFile, versionRegex)
if (givenVersion !== undefined && targetVersion !== "") {
return semverCompare(givenVersion, targetVersion) !== -1
try {
// if -1, it means the given version is newer than the target version
// this requires the target version to be a valid semver range
return semverCompare(givenVersion, targetVersion) !== -1
} catch {
// check if the given version satisfies the target version
// this works even if the target version is not a valid semver range (e.g. >=1.2.3)
return semverSatisfies(givenVersion, targetVersion)
}
} else {
// assume given version is old
return false
Expand Down
83 changes: 0 additions & 83 deletions src/versions/default_versions.ts

This file was deleted.

158 changes: 158 additions & 0 deletions src/versions/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"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": ""
},
"else": ""
},
"gcovr": {
"linux": {
"ubuntu": {
"20": "",
"18": "5.0",
"else": "5.0"
},
"else": ""
},
"else": ""
},
"nala": {
"linux": {
"ubuntu": {
"22": "",
"21": "legacy",
"else": "legacy"
},
"else": ""
},
"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"
}
}
Loading
Loading