mirror of https://github.com/aminya/setup-cpp
fix: sync the llvm tools versions (compiler, clangtidy, etc)
This commit is contained in:
parent
6251144095
commit
5cd5225bee
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,3 +1,5 @@
|
||||||
|
import { Inputs, Opts } from "./main"
|
||||||
|
|
||||||
const DefaultVersions: Record<string, string> = {
|
const DefaultVersions: Record<string, string> = {
|
||||||
llvm: "13.0.0", // https://github.com/llvm/llvm-project/releases
|
llvm: "13.0.0", // https://github.com/llvm/llvm-project/releases
|
||||||
clangtidy: "13.0.0",
|
clangtidy: "13.0.0",
|
||||||
|
@ -16,7 +18,7 @@ const DefaultVersions: Record<string, string> = {
|
||||||
|
|
||||||
/** 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 (version === "true" || (version === undefined && name in DefaultVersions)) {
|
if (useDefault(version, name)) {
|
||||||
// llvm on linux
|
// llvm on linux
|
||||||
if (process.platform === "linux" && ["llvm", "clangtidy", "clangformat"].includes(name)) {
|
if (process.platform === "linux" && ["llvm", "clangtidy", "clangformat"].includes(name)) {
|
||||||
// choose the default version for llvm based on ubuntu
|
// choose the default version for llvm based on ubuntu
|
||||||
|
@ -32,3 +34,31 @@ export function getVersion(name: string, version: string | undefined, osVersion:
|
||||||
return version ?? ""
|
return version ?? ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function useDefault(version: string | undefined, name: string) {
|
||||||
|
return version === "true" || (version === undefined && name in DefaultVersions)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function syncVersions(opts: Opts, tools: Inputs[]): boolean {
|
||||||
|
for (let i = 0; i < tools.length; i++) {
|
||||||
|
// tools excluding i_tool
|
||||||
|
const otherTools = tools.slice(0, i).concat(tools.slice(i + 1))
|
||||||
|
|
||||||
|
const tool = tools[i]
|
||||||
|
|
||||||
|
if (!useDefault(opts[tool], tool)) {
|
||||||
|
for (let i_other = 0; i_other < otherTools.length; i_other++) {
|
||||||
|
const otherTool = otherTools[i_other]
|
||||||
|
const useDefaultOtherTool = useDefault(opts[otherTool], otherTools[i_other])
|
||||||
|
if (useDefaultOtherTool) {
|
||||||
|
// use the same version if the other tool was requested with the default
|
||||||
|
opts[otherTool] = opts[tool]
|
||||||
|
} else if (opts[tool] !== opts[otherTools[i_other]]) {
|
||||||
|
// error if different from the other given versions
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
33
src/main.ts
33
src/main.ts
|
@ -31,7 +31,7 @@ import numerousLocale from "numerous/locales/en.js"
|
||||||
import { ubuntuVersion } from "./utils/env/ubuntu_version"
|
import { ubuntuVersion } from "./utils/env/ubuntu_version"
|
||||||
|
|
||||||
import semverValid from "semver/functions/valid"
|
import semverValid from "semver/functions/valid"
|
||||||
import { getVersion } from "./default_versions"
|
import { getVersion, syncVersions } from "./default_versions"
|
||||||
import { setupGcc } from "./gcc/gcc"
|
import { setupGcc } from "./gcc/gcc"
|
||||||
import { InstallationInfo } from "./utils/setup/setupBin"
|
import { InstallationInfo } from "./utils/setup/setupBin"
|
||||||
import { error, info, success, warning } from "./utils/io/io"
|
import { error, info, success, warning } from "./utils/io/io"
|
||||||
|
@ -100,7 +100,7 @@ const tools: Array<keyof typeof setups> = [
|
||||||
]
|
]
|
||||||
|
|
||||||
/** The possible inputs to the program */
|
/** The possible inputs to the program */
|
||||||
type Inputs = keyof typeof setups | "compiler" | "architecture"
|
export type Inputs = keyof typeof setups | "compiler" | "architecture"
|
||||||
|
|
||||||
// an array of possible inputs
|
// an array of possible inputs
|
||||||
const inputs: Array<Inputs> = ["compiler", "architecture", ...tools]
|
const inputs: Array<Inputs> = ["compiler", "architecture", ...tools]
|
||||||
|
@ -112,12 +112,7 @@ export async function main(args: string[]): Promise<number> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse options using mri or github actions
|
// parse options using mri or github actions
|
||||||
const opts = mri<Record<Inputs, string | undefined> & { help: boolean }>(args, {
|
const opts = parseArgs(args)
|
||||||
string: inputs,
|
|
||||||
default: Object.fromEntries(inputs.map((inp) => [inp, maybeGetInput(inp)])),
|
|
||||||
alias: { h: "help" },
|
|
||||||
boolean: "help",
|
|
||||||
})
|
|
||||||
|
|
||||||
// print help
|
// print help
|
||||||
if (opts.help) {
|
if (opts.help) {
|
||||||
|
@ -150,6 +145,12 @@ export async function main(args: string[]): Promise<number> {
|
||||||
warning((err as Error).toString())
|
warning((err as Error).toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sync the version for the llvm tools
|
||||||
|
if (!syncVersions(opts, ["llvm", "clangtidy", "clangformat"])) {
|
||||||
|
error("The same version must be used for llvm, clangformat and clangtidy")
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
// loop over the tools and run their setup function
|
// loop over the tools and run their setup function
|
||||||
for (const tool of tools) {
|
for (const tool of tools) {
|
||||||
// get the version or "true" or undefined for this tool from the options
|
// get the version or "true" or undefined for this tool from the options
|
||||||
|
@ -163,7 +164,6 @@ export async function main(args: string[]): Promise<number> {
|
||||||
try {
|
try {
|
||||||
let installationInfo: InstallationInfo | undefined | void
|
let installationInfo: InstallationInfo | undefined | void
|
||||||
if (tool === "vcvarsall") {
|
if (tool === "vcvarsall") {
|
||||||
// eslint-disable-next-line no-await-in-loop
|
|
||||||
setupVCVarsall(getVersion(tool, version, osVersion), undefined, arch, undefined, undefined, false, false)
|
setupVCVarsall(getVersion(tool, version, osVersion), undefined, arch, undefined, undefined, false, false)
|
||||||
} else {
|
} else {
|
||||||
// get the setup function
|
// get the setup function
|
||||||
|
@ -293,6 +293,21 @@ main(process.argv)
|
||||||
process.exitCode = 1
|
process.exitCode = 1
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export type Opts = mri.Argv<
|
||||||
|
Record<Inputs, string | undefined> & {
|
||||||
|
help: boolean
|
||||||
|
}
|
||||||
|
>
|
||||||
|
|
||||||
|
export function parseArgs(args: string[]): Opts {
|
||||||
|
return mri<Record<Inputs, string | undefined> & { help: boolean }>(args, {
|
||||||
|
string: inputs,
|
||||||
|
default: Object.fromEntries(inputs.map((inp) => [inp, maybeGetInput(inp)])),
|
||||||
|
alias: { h: "help" },
|
||||||
|
boolean: "help",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/** Detecting the compiler version. Divide the given string by `-` and use the second element as the version */
|
/** Detecting the compiler version. Divide the given string by `-` and use the second element as the version */
|
||||||
export function getCompilerInfo(maybeCompiler: string) {
|
export function getCompilerInfo(maybeCompiler: string) {
|
||||||
const compilerAndMaybeVersion = maybeCompiler.split("-")
|
const compilerAndMaybeVersion = maybeCompiler.split("-")
|
||||||
|
|
Loading…
Reference in New Issue