fix: check of compiler should be synced

This commit is contained in:
Amin Yahyaabadi 2024-09-19 15:00:10 -07:00
parent 3a86553eb1
commit e4f89db091
No known key found for this signature in database
GPG Key ID: F52AF77F636088F0
6 changed files with 25 additions and 9 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

View File

@ -77,6 +77,12 @@ describe("syncVersion", () => {
expect(opts4.compiler).toBe("llvm-13.0.0") expect(opts4.compiler).toBe("llvm-13.0.0")
expect(opts4.clangtidy).toBe("13.0.0") expect(opts4.clangtidy).toBe("13.0.0")
expect(opts4.clangformat).toBe(undefined) expect(opts4.clangformat).toBe(undefined)
const opts5 = parseArgs(["--compiler", "gcc-13", "--clangtidy", "true"])
expect(syncVersions(opts5, [...llvmTools, "compiler"] as Inputs[], getCompilerInfo("gcc-13"))).toBe(true)
expect(opts5.compiler).toBe("gcc-13")
expect(opts5.clangtidy).toBe("true")
expect(opts5.clangformat).toBe(undefined)
}) })
}) })

View File

@ -41,13 +41,23 @@ function getDefaultLinuxVersion(osVersion: number[], toolLinuxVersions: Record<n
* @param tools - The tools to sync the versions for (it can include `compiler`) * @param tools - The tools to sync the versions for (it can include `compiler`)
* @param compilerInfo - The compiler info to sync the versions for (if any) * @param compilerInfo - The compiler info to sync the versions for (if any)
*/ */
export function syncVersions(opts: Opts, tools: Inputs[], compilerInfo: CompilerInfo | undefined = undefined): boolean { export function syncVersions(
opts: Opts,
toolsGiven: Inputs[],
compilerInfo: CompilerInfo | undefined = undefined,
): boolean {
// check if compiler version should be synced
const syncCompiler = compilerInfo === undefined ? false : toolsGiven.includes(compilerInfo.compiler as Inputs)
// remove the compiler from the tools if it should not be synced
const tools = syncCompiler ? toolsGiven : toolsGiven.filter((tool) => tool !== "compiler")
// filter out the tools that are in use in the options // filter out the tools that are in use in the options
const toolsInUse = tools.filter((tool) => opts[tool] !== undefined) const toolsInUse = tools.filter((tool) => opts[tool] !== undefined)
// filter out the tools that are not default // filter out the tools that are not default
const toolsNonDefaultVersion = toolsInUse.filter((tool) => { const toolsNonDefaultVersion = toolsInUse.filter((tool) => {
const version = (tool === "compiler" && compilerInfo !== undefined) const version = (syncCompiler && tool === "compiler" && compilerInfo !== undefined)
? compilerInfo.version ? compilerInfo.version
: opts[tool] : opts[tool]
return !isVersionDefault(version) return !isVersionDefault(version)
@ -55,7 +65,7 @@ export function syncVersions(opts: Opts, tools: Inputs[], compilerInfo: Compiler
// find the target version to sync to // find the target version to sync to
const targetVersion: string = (toolsNonDefaultVersion.length !== 0) const targetVersion: string = (toolsNonDefaultVersion.length !== 0)
? (toolsNonDefaultVersion[0] === "compiler" && compilerInfo !== undefined) ? (syncCompiler && toolsNonDefaultVersion[0] === "compiler" && compilerInfo !== undefined)
? compilerInfo.version ?? "true" ? compilerInfo.version ?? "true"
: opts[toolsNonDefaultVersion[0]] ?? "true" : opts[toolsNonDefaultVersion[0]] ?? "true"
: "true" : "true"
@ -63,7 +73,7 @@ export function syncVersions(opts: Opts, tools: Inputs[], compilerInfo: Compiler
// error if any explicit versions don't match the target version // error if any explicit versions don't match the target version
if ( if (
toolsNonDefaultVersion.some((tool) => { toolsNonDefaultVersion.some((tool) => {
if (tool === "compiler" && compilerInfo !== undefined) { if (syncCompiler && tool === "compiler" && compilerInfo !== undefined) {
return opts.compiler !== `${compilerInfo.compiler}-${targetVersion}` return opts.compiler !== `${compilerInfo.compiler}-${targetVersion}`
} }
@ -75,7 +85,7 @@ export function syncVersions(opts: Opts, tools: Inputs[], compilerInfo: Compiler
// update the version of all the tools to the target version // update the version of all the tools to the target version
for (const tool of toolsInUse) { for (const tool of toolsInUse) {
opts[tool] = (tool === "compiler" && compilerInfo !== undefined) opts[tool] = (syncCompiler && tool === "compiler" && compilerInfo !== undefined)
? `${compilerInfo.compiler}-${targetVersion}` ? `${compilerInfo.compiler}-${targetVersion}`
: targetVersion : targetVersion
} }