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 llvm: getLLVMDefault(), // https://github.com/llvm/llvm-project/releases
clangtidy: getLLVMDefault(), clangtidy: getLLVMDefault(),
clangformat: getLLVMDefault(), clangformat: getLLVMDefault(),
@ -33,7 +33,7 @@ export const DefaultVersions: Record<string, string> = {
/// If an ubuntu versions is not in this map: /// If an ubuntu versions is not in this map:
// - the newer ubuntu versions use the first entry (e.g. v20), // - the newer ubuntu versions use the first entry (e.g. v20),
// - the older ones use "" // - the older ones use ""
export const DefaultLinuxVersion: Record<string, Record<number, string>> = { export const DefaultLinuxVersion: Record<string, Record<number, string> | undefined> = {
gcc: { gcc: {
22: "13", 22: "13",
20: "11", 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 */ /** 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 getVersion(name: string, version: string | undefined, osVersion: number[] | null = null) {
if (isDefault(version, name)) { console.log("isDefault", version, name, isVersionDefault(version))
if (process.platform === "linux" && osVersion !== null && name in DefaultLinuxVersion) { if (isVersionDefault(version) && process.platform === "linux" && osVersion !== null && name in DefaultLinuxVersion) {
return getDefaultLinuxVersion(name, osVersion) return getDefaultLinuxVersion(osVersion, DefaultLinuxVersion[name]!)
} else if (isVersionDefault(version) && name in DefaultVersions) {
return DefaultVersions[name]!
} else if (version === "true") {
return ""
} }
// anything else
return DefaultVersions[name]
} else {
return version ?? "" return version ?? ""
} }
function isVersionDefault(version: string | undefined) {
return version === "true" || version === undefined
} }
/// choose the default linux version based on ubuntu version /// 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 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) { // find which version block the os version is in
return version === "true" || (version === undefined && name in DefaultVersions) 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 { export function syncVersions(opts: Opts, tools: Inputs[]): boolean {
const toolsInUse = tools.filter((tool) => opts[tool] !== undefined) 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" const targetVersion = toolsNonDefaultVersion.length >= 1 ? opts[toolsNonDefaultVersion[0]] : "true"