Merge pull request #176 from aminya/version-handling

This commit is contained in:
Amin Yahyaabadi 2023-06-27 15:35:39 -07:00 committed by GitHub
commit 63d7251996
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 37 additions and 35 deletions

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

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

View File

@ -15,7 +15,7 @@ function getLLVMDefault() {
}
}
export const DefaultVersions: Record<string, string> = {
export const DefaultVersions: Record<string, string | undefined> = {
llvm: getLLVMDefault(), // https://github.com/llvm/llvm-project/releases
clangtidy: getLLVMDefault(),
clangformat: getLLVMDefault(),
@ -33,7 +33,7 @@ export const DefaultVersions: Record<string, string> = {
/// 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 DefaultLinuxVersion: Record<string, Record<number, string>> = {
export const DefaultLinuxVersion: Record<string, Record<number, string> | undefined> = {
gcc: {
22: "13",
20: "11",

View File

@ -4,30 +4,32 @@ import { DefaultLinuxVersion, DefaultVersions } from "./default_versions"
/** 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) {
if (isDefault(version, name)) {
if (process.platform === "linux" && osVersion !== null && name in DefaultLinuxVersion) {
return getDefaultLinuxVersion(name, osVersion)
}
// anything else
return DefaultVersions[name]
} else {
return version ?? ""
console.log("isDefault", version, name, isVersionDefault(version))
if (isVersionDefault(version) && process.platform === "linux" && osVersion !== null && name in DefaultLinuxVersion) {
return getDefaultLinuxVersion(osVersion, DefaultLinuxVersion[name]!)
} else if (isVersionDefault(version) && name in DefaultVersions) {
return DefaultVersions[name]!
} else if (version === "true") {
return ""
}
return version ?? ""
}
function isVersionDefault(version: string | undefined) {
return version === "true" || version === undefined
}
/// choose the default linux version based on ubuntu version
function getDefaultLinuxVersion(name: string, osVersion: number[]) {
function getDefaultLinuxVersion(osVersion: number[], toolLinuxVersions: Record<number, string>) {
const osVersionMaj = osVersion[0]
const newest = parseInt(Object.keys(DefaultLinuxVersion[name])[0], 10) // newest version with the default
if (osVersionMaj >= newest) {
return DefaultLinuxVersion[name][osVersionMaj]
} else {
return ""
}
}
export function isDefault(version: string | undefined, name: string) {
return version === "true" || (version === undefined && name in DefaultVersions)
// find which version block the os version is in
const satisfyingVersion = Object.keys(toolLinuxVersions)
.map((v) => parseInt(v, 10))
.sort((a, b) => b - a) // sort in descending order
.find((v) => osVersionMaj >= v)
return satisfyingVersion === undefined ? "" : toolLinuxVersions[satisfyingVersion]
}
/**
@ -37,7 +39,7 @@ export function isDefault(version: string | undefined, name: string) {
*/
export function syncVersions(opts: Opts, tools: Inputs[]): boolean {
const toolsInUse = tools.filter((tool) => opts[tool] !== undefined)
const toolsNonDefaultVersion = toolsInUse.filter((tool) => !isDefault(opts[tool], tool))
const toolsNonDefaultVersion = toolsInUse.filter((tool) => !isVersionDefault(opts[tool]))
const targetVersion = toolsNonDefaultVersion.length >= 1 ? opts[toolsNonDefaultVersion[0]] : "true"