Skip to content

Commit

Permalink
fix: check of compiler should be synced
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Sep 19, 2024
1 parent 3a86553 commit e4f89db
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.mjs.map

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/__tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ describe("syncVersion", () => {
expect(opts4.compiler).toBe("llvm-13.0.0")
expect(opts4.clangtidy).toBe("13.0.0")
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)
})
})

Expand Down
20 changes: 15 additions & 5 deletions src/versions/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,39 @@ function getDefaultLinuxVersion(osVersion: number[], toolLinuxVersions: Record<n
* @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)
*/
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
const toolsInUse = tools.filter((tool) => opts[tool] !== undefined)

// filter out the tools that are not default
const toolsNonDefaultVersion = toolsInUse.filter((tool) => {
const version = (tool === "compiler" && compilerInfo !== undefined)
const version = (syncCompiler && tool === "compiler" && compilerInfo !== undefined)
? compilerInfo.version
: opts[tool]
return !isVersionDefault(version)
})

// find the target version to sync to
const targetVersion: string = (toolsNonDefaultVersion.length !== 0)
? (toolsNonDefaultVersion[0] === "compiler" && compilerInfo !== undefined)
? (syncCompiler && toolsNonDefaultVersion[0] === "compiler" && compilerInfo !== undefined)
? compilerInfo.version ?? "true"
: opts[toolsNonDefaultVersion[0]] ?? "true"
: "true"

// error if any explicit versions don't match the target version
if (
toolsNonDefaultVersion.some((tool) => {
if (tool === "compiler" && compilerInfo !== undefined) {
if (syncCompiler && tool === "compiler" && compilerInfo !== undefined) {
return opts.compiler !== `${compilerInfo.compiler}-${targetVersion}`
}

Expand All @@ -75,7 +85,7 @@ export function syncVersions(opts: Opts, tools: Inputs[], compilerInfo: Compiler

// update the version of all the tools to the target version
for (const tool of toolsInUse) {
opts[tool] = (tool === "compiler" && compilerInfo !== undefined)
opts[tool] = (syncCompiler && tool === "compiler" && compilerInfo !== undefined)
? `${compilerInfo.compiler}-${targetVersion}`
: targetVersion
}
Expand Down

0 comments on commit e4f89db

Please sign in to comment.