mirror of https://github.com/aminya/setup-cpp
Merge pull request #158 from StevenvdSchoot/v1 [skip ci]
This commit is contained in:
commit
14fa6823d4
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
|
@ -29,9 +29,22 @@ describe("syncVersion", () => {
|
|||
expect(syncVersions(parseArgs(["--llvm", "13.0.0", "--clangtidy", "true"]), llvmTools)).toBe(true)
|
||||
expect(syncVersions(parseArgs(["--llvm", "13.0.0", "--clangtidy", "12.0.0"]), llvmTools)).toBe(false)
|
||||
|
||||
const opts = parseArgs(["--llvm", "14.0.0", "--clangtidy", "true"])
|
||||
expect(syncVersions(opts, llvmTools)).toBe(true)
|
||||
expect(opts.llvm).toBe(opts.clangtidy)
|
||||
const opts1 = parseArgs(["--llvm", "14.0.0", "--clangtidy", "true"])
|
||||
expect(syncVersions(opts1, llvmTools)).toBe(true)
|
||||
expect(opts1.llvm).toBe(opts1.clangtidy)
|
||||
expect(opts1.clangformat).toBe(undefined)
|
||||
|
||||
const opts2 = parseArgs(["--clangtidy", "15.0.0", "--clangformat", "true"])
|
||||
expect(syncVersions(opts2, llvmTools)).toBe(true)
|
||||
expect(opts2.llvm).toBe(undefined)
|
||||
expect(opts2.clangtidy).toBe("15.0.0")
|
||||
expect(opts2.clangformat).toBe("15.0.0")
|
||||
|
||||
const opts3 = parseArgs(["--llvm", "true", "--clangformat", "true"])
|
||||
expect(syncVersions(opts3, llvmTools)).toBe(true)
|
||||
expect(opts3.llvm).toBe("true")
|
||||
expect(opts3.clangtidy).toBe(undefined)
|
||||
expect(opts3.clangformat).toBe("true")
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -29,26 +29,25 @@ export function isDefault(version: string | undefined, name: string) {
|
|||
return version === "true" || (version === undefined && name in DefaultVersions)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync the versions for the given inputs
|
||||
*
|
||||
* If the return is false, it means that versions don't match the target version
|
||||
*/
|
||||
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 toolsInUse = tools.filter((tool) => opts[tool] !== undefined)
|
||||
const toolsNonDefaultVersion = toolsInUse.filter((tool) => !isDefault(opts[tool], tool))
|
||||
|
||||
const tool = tools[i]
|
||||
const targetVersion = toolsNonDefaultVersion.length >= 1 ? opts[toolsNonDefaultVersion[0]] : "true"
|
||||
|
||||
if (!isDefault(opts[tool], tool)) {
|
||||
for (let i_other = 0; i_other < otherTools.length; i_other++) {
|
||||
const otherTool = otherTools[i_other]
|
||||
const useDefaultOtherTool = isDefault(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
|
||||
}
|
||||
}
|
||||
}
|
||||
if (toolsNonDefaultVersion.some((tool) => opts[tool] !== targetVersion)) {
|
||||
// error if any explicit versions don't match the target version
|
||||
return false
|
||||
}
|
||||
|
||||
toolsInUse.forEach((tool) => {
|
||||
opts[tool] = targetVersion
|
||||
})
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue