mirror of https://github.com/aminya/setup-cpp
Merge pull request #176 from aminya/version-handling
This commit is contained in:
commit
63d7251996
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
|
@ -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",
|
||||
|
|
|
@ -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)
|
||||
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 ""
|
||||
}
|
||||
// anything else
|
||||
return DefaultVersions[name]
|
||||
} else {
|
||||
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"
|
||||
|
||||
|
|
Loading…
Reference in New Issue