Merge pull request #158 from StevenvdSchoot/v1 [skip ci]

This commit is contained in:
Amin Yahyaabadi 2023-01-17 21:28:08 -08:00 committed by GitHub
commit 14fa6823d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 24 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

@ -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", "true"]), llvmTools)).toBe(true)
expect(syncVersions(parseArgs(["--llvm", "13.0.0", "--clangtidy", "12.0.0"]), llvmTools)).toBe(false) expect(syncVersions(parseArgs(["--llvm", "13.0.0", "--clangtidy", "12.0.0"]), llvmTools)).toBe(false)
const opts = parseArgs(["--llvm", "14.0.0", "--clangtidy", "true"]) const opts1 = parseArgs(["--llvm", "14.0.0", "--clangtidy", "true"])
expect(syncVersions(opts, llvmTools)).toBe(true) expect(syncVersions(opts1, llvmTools)).toBe(true)
expect(opts.llvm).toBe(opts.clangtidy) 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")
}) })
}) })

View File

@ -29,26 +29,25 @@ export function isDefault(version: string | undefined, name: string) {
return version === "true" || (version === undefined && name in DefaultVersions) 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 { export function syncVersions(opts: Opts, tools: Inputs[]): boolean {
for (let i = 0; i < tools.length; i++) { const toolsInUse = tools.filter((tool) => opts[tool] !== undefined)
// tools excluding i_tool const toolsNonDefaultVersion = toolsInUse.filter((tool) => !isDefault(opts[tool], tool))
const otherTools = tools.slice(0, i).concat(tools.slice(i + 1))
const tool = tools[i] const targetVersion = toolsNonDefaultVersion.length >= 1 ? opts[toolsNonDefaultVersion[0]] : "true"
if (!isDefault(opts[tool], tool)) { if (toolsNonDefaultVersion.some((tool) => opts[tool] !== targetVersion)) {
for (let i_other = 0; i_other < otherTools.length; i_other++) { // error if any explicit versions don't match the target version
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 return false
} }
}
} toolsInUse.forEach((tool) => {
} opts[tool] = targetVersion
})
return true return true
} }