Skip to content

Commit e4f89db

Browse files
committed
fix: check of compiler should be synced
1 parent 3a86553 commit e4f89db

File tree

6 files changed

+25
-9
lines changed

6 files changed

+25
-9
lines changed

dist/legacy/setup-cpp.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.mjs

+1-1
Large diffs are not rendered by default.

dist/modern/setup-cpp.mjs.map

+1-1
Large diffs are not rendered by default.

src/__tests__/main.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ describe("syncVersion", () => {
7777
expect(opts4.compiler).toBe("llvm-13.0.0")
7878
expect(opts4.clangtidy).toBe("13.0.0")
7979
expect(opts4.clangformat).toBe(undefined)
80+
81+
const opts5 = parseArgs(["--compiler", "gcc-13", "--clangtidy", "true"])
82+
expect(syncVersions(opts5, [...llvmTools, "compiler"] as Inputs[], getCompilerInfo("gcc-13"))).toBe(true)
83+
expect(opts5.compiler).toBe("gcc-13")
84+
expect(opts5.clangtidy).toBe("true")
85+
expect(opts5.clangformat).toBe(undefined)
8086
})
8187
})
8288

src/versions/versions.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,39 @@ function getDefaultLinuxVersion(osVersion: number[], toolLinuxVersions: Record<n
4141
* @param tools - The tools to sync the versions for (it can include `compiler`)
4242
* @param compilerInfo - The compiler info to sync the versions for (if any)
4343
*/
44-
export function syncVersions(opts: Opts, tools: Inputs[], compilerInfo: CompilerInfo | undefined = undefined): boolean {
44+
export function syncVersions(
45+
opts: Opts,
46+
toolsGiven: Inputs[],
47+
compilerInfo: CompilerInfo | undefined = undefined,
48+
): boolean {
49+
// check if compiler version should be synced
50+
const syncCompiler = compilerInfo === undefined ? false : toolsGiven.includes(compilerInfo.compiler as Inputs)
51+
52+
// remove the compiler from the tools if it should not be synced
53+
const tools = syncCompiler ? toolsGiven : toolsGiven.filter((tool) => tool !== "compiler")
54+
4555
// filter out the tools that are in use in the options
4656
const toolsInUse = tools.filter((tool) => opts[tool] !== undefined)
4757

4858
// filter out the tools that are not default
4959
const toolsNonDefaultVersion = toolsInUse.filter((tool) => {
50-
const version = (tool === "compiler" && compilerInfo !== undefined)
60+
const version = (syncCompiler && tool === "compiler" && compilerInfo !== undefined)
5161
? compilerInfo.version
5262
: opts[tool]
5363
return !isVersionDefault(version)
5464
})
5565

5666
// find the target version to sync to
5767
const targetVersion: string = (toolsNonDefaultVersion.length !== 0)
58-
? (toolsNonDefaultVersion[0] === "compiler" && compilerInfo !== undefined)
68+
? (syncCompiler && toolsNonDefaultVersion[0] === "compiler" && compilerInfo !== undefined)
5969
? compilerInfo.version ?? "true"
6070
: opts[toolsNonDefaultVersion[0]] ?? "true"
6171
: "true"
6272

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

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

7686
// update the version of all the tools to the target version
7787
for (const tool of toolsInUse) {
78-
opts[tool] = (tool === "compiler" && compilerInfo !== undefined)
88+
opts[tool] = (syncCompiler && tool === "compiler" && compilerInfo !== undefined)
7989
? `${compilerInfo.compiler}-${targetVersion}`
8090
: targetVersion
8191
}

0 commit comments

Comments
 (0)