Skip to content

Commit 6251144

Browse files
committed
fix: get ubuntu version inside the main file
1 parent 6edc7f9 commit 6251144

File tree

8 files changed

+32
-52
lines changed

8 files changed

+32
-52
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.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"build": "shx rm -rf dist/ && shx mkdir ./dist && run-p test.tsc build.parcel copy.matchers",
1616
"build.docker": "pnpm build && docker build -f ./dev/docker/ubuntu_node.dockerfile -t setup_cpp .",
1717
"build.parcel": "cross-env NODE_ENV=production parcel build --detailed-report",
18-
"bump": "ncu -u -x execa,make-synchronous,numerous && pnpm update",
18+
"bump": "ncu -u -x execa,numerous && pnpm update",
1919
"clean": "shx rm -rf .parcel-cache dist exe",
2020
"copy.matchers": "shx cp ./src/gcc/gcc_matcher.json ./dist/ && shx cp ./src/msvc/msvc_matcher.json ./dist && shx cp ./src/python/python_matcher.json ./dist/ && shx cp ./src/llvm/llvm_matcher.json ./dist/ ",
2121
"dev": "cross-env NODE_ENV=development parcel watch",
@@ -38,7 +38,6 @@
3838
"@actions/io": "^1.1.2",
3939
"@actions/tool-cache": "^1.7.2",
4040
"execa": "^5.1.1",
41-
"make-synchronous": "^0.1.1",
4241
"mri": "^1.2.0",
4342
"msvc-dev-cmd": "github:aminya/msvc-dev-cmd#9f672c1",
4443
"numerous": "1.0.3",

pnpm-lock.yaml

Lines changed: 3 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/default_versions.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import { warning } from "./utils/io/io"
2-
import { ubuntuVersion } from "./utils/env/ubuntu_version"
3-
41
const DefaultVersions: Record<string, string> = {
52
llvm: "13.0.0", // https://github.com/llvm/llvm-project/releases
63
clangtidy: "13.0.0",
@@ -17,24 +14,15 @@ const DefaultVersions: Record<string, string> = {
1714
gcc: process.platform === "win32" ? "11.2.0.07112021" : "11", // https://community.chocolatey.org/packages/mingw#versionhistory and // https://packages.ubuntu.com/search?suite=all&arch=any&searchon=names&keywords=gcc
1815
}
1916

20-
let ubuntuVersionCached: number[] | null = null
21-
2217
/** Get the default version if passed true or undefined, otherwise return the version itself */
23-
export function getVersion(name: string, version: string | undefined) {
18+
export function getVersion(name: string, version: string | undefined, osVersion: number[] | null = null) {
2419
if (version === "true" || (version === undefined && name in DefaultVersions)) {
2520
// llvm on linux
2621
if (process.platform === "linux" && ["llvm", "clangtidy", "clangformat"].includes(name)) {
27-
try {
28-
// get the version if not already done
29-
ubuntuVersionCached = ubuntuVersionCached ?? ubuntuVersion()
30-
} catch (err) {
31-
warning((err as Error).toString())
32-
return DefaultVersions[name]
33-
}
3422
// choose the default version for llvm based on ubuntu
35-
if (ubuntuVersionCached !== null) {
36-
if ([20, 18, 16].includes(ubuntuVersionCached[0]) && ubuntuVersionCached[1] === 4) {
37-
return `-13.0.0-x86_64-linux-gnu-ubuntu-${ubuntuVersionCached[0]}.0${ubuntuVersionCached[1]}`
23+
if (osVersion !== null) {
24+
if ([20, 18, 16].includes(osVersion[0]) && osVersion[1] === 4) {
25+
return `-13.0.0-x86_64-linux-gnu-ubuntu-${osVersion[0]}.0${osVersion[1]}`
3826
}
3927
}
4028
}

src/llvm/__tests__/llvm.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import path from "path"
88
import { addBinExtension } from "../../utils/extension/extension"
99
import { chmodSync } from "fs"
1010
import { getVersion } from "../../default_versions"
11+
import { ubuntuVersion } from "../../utils/env/ubuntu_version"
1112

1213
jest.setTimeout(400000)
1314
async function testUrl(version: string) {
@@ -51,7 +52,7 @@ describe("setup-llvm", () => {
5152
})
5253

5354
it("should setup LLVM", async () => {
54-
const { binDir } = await setupLLVM(getVersion("llvm", "true"), directory, process.arch)
55+
const { binDir } = await setupLLVM(getVersion("llvm", "true", await ubuntuVersion()), directory, process.arch)
5556
await testBin("clang++", ["--version"], binDir)
5657

5758
expect(process.env.CC?.includes("clang")).toBeTruthy()

src/main.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import * as numerous from "numerous"
2828
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2929
// @ts-ignore
3030
import numerousLocale from "numerous/locales/en.js"
31+
import { ubuntuVersion } from "./utils/env/ubuntu_version"
3132

3233
import semverValid from "semver/functions/valid"
3334
import { getVersion } from "./default_versions"
@@ -141,6 +142,14 @@ export async function main(args: string[]): Promise<number> {
141142

142143
// installing the specified tools
143144

145+
let osVersion: number[] | null = null
146+
try {
147+
// get the version if not already done
148+
osVersion = await ubuntuVersion()
149+
} catch (err) {
150+
warning((err as Error).toString())
151+
}
152+
144153
// loop over the tools and run their setup function
145154
for (const tool of tools) {
146155
// get the version or "true" or undefined for this tool from the options
@@ -155,7 +164,7 @@ export async function main(args: string[]): Promise<number> {
155164
let installationInfo: InstallationInfo | undefined | void
156165
if (tool === "vcvarsall") {
157166
// eslint-disable-next-line no-await-in-loop
158-
setupVCVarsall(getVersion(tool, version), undefined, arch, undefined, undefined, false, false)
167+
setupVCVarsall(getVersion(tool, version, osVersion), undefined, arch, undefined, undefined, false, false)
159168
} else {
160169
// get the setup function
161170
const setupFunction = setups[tool]
@@ -164,7 +173,7 @@ export async function main(args: string[]): Promise<number> {
164173
const setupDir = join(setupCppDir, ["llvm", "clangformat", "clangtidy"].includes(tool) ? "llvm" : tool)
165174

166175
// eslint-disable-next-line no-await-in-loop
167-
installationInfo = await setupFunction(getVersion(tool, version), setupDir, arch)
176+
installationInfo = await setupFunction(getVersion(tool, version, osVersion), setupDir, arch)
168177
}
169178
// preparing a report string
170179
successMessages.push(getSuccessMessage(tool, installationInfo))
@@ -192,15 +201,19 @@ export async function main(args: string[]): Promise<number> {
192201
case "llvm":
193202
case "clang":
194203
case "clang++": {
195-
const installationInfo = await setupLLVM(getVersion("llvm", version), join(setupCppDir, "llvm"), arch)
204+
const installationInfo = await setupLLVM(
205+
getVersion("llvm", version, osVersion),
206+
join(setupCppDir, "llvm"),
207+
arch
208+
)
196209
successMessages.push(getSuccessMessage("llvm", installationInfo))
197210
break
198211
}
199212
case "gcc":
200213
case "mingw":
201214
case "cygwin":
202215
case "msys": {
203-
const installationInfo = await setupGcc(getVersion("gcc", version), join(setupCppDir, "gcc"), arch)
216+
const installationInfo = await setupGcc(getVersion("gcc", version, osVersion), join(setupCppDir, "gcc"), arch)
204217
successMessages.push(getSuccessMessage("gcc", installationInfo))
205218
break
206219
}
@@ -211,7 +224,7 @@ export async function main(args: string[]): Promise<number> {
211224
case "visualstudio":
212225
case "visualcpp":
213226
case "visualc++": {
214-
const installationInfo = setupMSVC(getVersion("msvc", version), join(setupCppDir, "msvc"), arch)
227+
const installationInfo = setupMSVC(getVersion("msvc", version, osVersion), join(setupCppDir, "msvc"), arch)
215228
successMessages.push(getSuccessMessage("msvc", installationInfo))
216229
break
217230
}

src/utils/env/ubuntu_version.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { getUbuntuVersion } from "ubuntu-version"
2-
import makeSynchronous from "make-synchronous"
32

4-
export function ubuntuVersion(): number[] | null {
3+
export async function ubuntuVersion(): Promise<number[] | null> {
54
if (process.platform === "linux") {
6-
const versionSplitted = makeSynchronous(getUbuntuVersion)()
5+
const versionSplitted = await getUbuntuVersion()
76

87
if (versionSplitted.length === 0) {
98
throw new Error("Failed to get the ubuntu major version.")

0 commit comments

Comments
 (0)