Skip to content

Commit 14fa682

Browse files
authored
Merge pull request #158 from StevenvdSchoot/v1 [skip ci]
2 parents 77554aa + b0d6527 commit 14fa682

File tree

6 files changed

+38
-26
lines changed

6 files changed

+38
-26
lines changed

dist/node12/setup_cpp.js

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

dist/node12/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/node16/setup_cpp.js

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

dist/node16/setup_cpp.js.map

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

src/__tests__/main.test.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,22 @@ describe("syncVersion", () => {
2929
expect(syncVersions(parseArgs(["--llvm", "13.0.0", "--clangtidy", "true"]), llvmTools)).toBe(true)
3030
expect(syncVersions(parseArgs(["--llvm", "13.0.0", "--clangtidy", "12.0.0"]), llvmTools)).toBe(false)
3131

32-
const opts = parseArgs(["--llvm", "14.0.0", "--clangtidy", "true"])
33-
expect(syncVersions(opts, llvmTools)).toBe(true)
34-
expect(opts.llvm).toBe(opts.clangtidy)
32+
const opts1 = parseArgs(["--llvm", "14.0.0", "--clangtidy", "true"])
33+
expect(syncVersions(opts1, llvmTools)).toBe(true)
34+
expect(opts1.llvm).toBe(opts1.clangtidy)
35+
expect(opts1.clangformat).toBe(undefined)
36+
37+
const opts2 = parseArgs(["--clangtidy", "15.0.0", "--clangformat", "true"])
38+
expect(syncVersions(opts2, llvmTools)).toBe(true)
39+
expect(opts2.llvm).toBe(undefined)
40+
expect(opts2.clangtidy).toBe("15.0.0")
41+
expect(opts2.clangformat).toBe("15.0.0")
42+
43+
const opts3 = parseArgs(["--llvm", "true", "--clangformat", "true"])
44+
expect(syncVersions(opts3, llvmTools)).toBe(true)
45+
expect(opts3.llvm).toBe("true")
46+
expect(opts3.clangtidy).toBe(undefined)
47+
expect(opts3.clangformat).toBe("true")
3548
})
3649
})
3750

src/versions/versions.ts

+18-19
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,25 @@ export function isDefault(version: string | undefined, name: string) {
2929
return version === "true" || (version === undefined && name in DefaultVersions)
3030
}
3131

32+
/**
33+
* Sync the versions for the given inputs
34+
*
35+
* If the return is false, it means that versions don't match the target version
36+
*/
3237
export function syncVersions(opts: Opts, tools: Inputs[]): boolean {
33-
for (let i = 0; i < tools.length; i++) {
34-
// tools excluding i_tool
35-
const otherTools = tools.slice(0, i).concat(tools.slice(i + 1))
36-
37-
const tool = tools[i]
38-
39-
if (!isDefault(opts[tool], tool)) {
40-
for (let i_other = 0; i_other < otherTools.length; i_other++) {
41-
const otherTool = otherTools[i_other]
42-
const useDefaultOtherTool = isDefault(opts[otherTool], otherTools[i_other])
43-
if (useDefaultOtherTool) {
44-
// use the same version if the other tool was requested with the default
45-
opts[otherTool] = opts[tool]
46-
} else if (opts[tool] !== opts[otherTools[i_other]]) {
47-
// error if different from the other given versions
48-
return false
49-
}
50-
}
51-
}
38+
const toolsInUse = tools.filter((tool) => opts[tool] !== undefined)
39+
const toolsNonDefaultVersion = toolsInUse.filter((tool) => !isDefault(opts[tool], tool))
40+
41+
const targetVersion = toolsNonDefaultVersion.length >= 1 ? opts[toolsNonDefaultVersion[0]] : "true"
42+
43+
if (toolsNonDefaultVersion.some((tool) => opts[tool] !== targetVersion)) {
44+
// error if any explicit versions don't match the target version
45+
return false
5246
}
47+
48+
toolsInUse.forEach((tool) => {
49+
opts[tool] = targetVersion
50+
})
51+
5352
return true
5453
}

0 commit comments

Comments
 (0)