Skip to content

Commit d1458aa

Browse files
committed
fix: use a map to set the default versions on ubuntu
1 parent 43b287e commit d1458aa

File tree

3 files changed

+40
-21
lines changed

3 files changed

+40
-21
lines changed

dist/setup_cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup_cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/default_versions.ts

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,51 @@ const DefaultVersions: Record<string, string> = {
1616
gcc: "11", // https://github.com/brechtsanders/winlibs_mingw/releases and // https://packages.ubuntu.com/search?suite=all&arch=any&searchon=names&keywords=gcc
1717
}
1818

19+
/// If an ubuntu versions is not in this map:
20+
// - the newer ubuntu versions use the first entry (e.g. v20),
21+
// - the older ones use ""
22+
const DefaultUbuntuVersion: Record<string, Record<number, string>> = {
23+
llvm: {
24+
20: "13.0.0-ubuntu-20.04",
25+
18: "13.0.1-ubuntu-18.04",
26+
16: "13.0.0-ubuntu-16.04",
27+
},
28+
clangtidy: {
29+
20: "13.0.0-ubuntu-20.04",
30+
18: "13.0.1-ubuntu-18.04",
31+
16: "13.0.0-ubuntu-16.04",
32+
},
33+
clangformat: {
34+
20: "13.0.0-ubuntu-20.04",
35+
18: "13.0.1-ubuntu-18.04",
36+
16: "13.0.0-ubuntu-16.04",
37+
},
38+
gcovr: {
39+
20: "5.1",
40+
18: "5.0",
41+
},
42+
meson: {
43+
20: "0.62.1",
44+
18: "0.61.4",
45+
},
46+
doxygen: {
47+
20: "1.9.4",
48+
},
49+
}
50+
1951
/** Get the default version if passed true or undefined, otherwise return the version itself */
2052
export function getVersion(name: string, version: string | undefined, osVersion: number[] | null = null) {
2153
if (useDefault(version, name)) {
2254
// choose the default linux version based on ubuntu version
23-
if (process.platform === "linux" && osVersion !== null) {
24-
if (["llvm", "clangtidy", "clangformat"].includes(name)) {
25-
if ([20, 18, 16].includes(osVersion[0]) && osVersion[1] === 4) {
26-
return `${osVersion[0] === 18 ? "13.0.1" : "13.0.0"}-ubuntu-${osVersion[0]}.0${osVersion[1]}`
27-
}
55+
if (process.platform === "linux" && osVersion !== null && name in DefaultUbuntuVersion) {
56+
const osVersionMaj = osVersion[0]
57+
const newest = parseInt(Object.keys(DefaultUbuntuVersion[name])[0], 10) // newest version with the default
58+
if (osVersionMaj >= newest) {
59+
return DefaultUbuntuVersion[name][osVersionMaj]
2860
} else {
29-
if (osVersion[0] < 20) {
30-
switch (name) {
31-
case "gcovr":
32-
return osVersion[0] === 18 ? "5.0" : "" /* pip default */
33-
case "meson":
34-
return osVersion[0] === 18 ? "0.61.4" : "" /* pip default */
35-
case "doxygen":
36-
return "" /* apt default */
37-
default: {
38-
// nothing
39-
}
40-
}
41-
}
61+
return ""
4262
}
4363
}
44-
4564
// anything else
4665
return DefaultVersions[name]
4766
} else {

0 commit comments

Comments
 (0)