mirror of https://github.com/aminya/setup-cpp
fix: get ubuntu version inside the main file
This commit is contained in:
parent
6edc7f9498
commit
6251144095
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -15,7 +15,7 @@
|
|||
"build": "shx rm -rf dist/ && shx mkdir ./dist && run-p test.tsc build.parcel copy.matchers",
|
||||
"build.docker": "pnpm build && docker build -f ./dev/docker/ubuntu_node.dockerfile -t setup_cpp .",
|
||||
"build.parcel": "cross-env NODE_ENV=production parcel build --detailed-report",
|
||||
"bump": "ncu -u -x execa,make-synchronous,numerous && pnpm update",
|
||||
"bump": "ncu -u -x execa,numerous && pnpm update",
|
||||
"clean": "shx rm -rf .parcel-cache dist exe",
|
||||
"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/ ",
|
||||
"dev": "cross-env NODE_ENV=development parcel watch",
|
||||
|
@ -38,7 +38,6 @@
|
|||
"@actions/io": "^1.1.2",
|
||||
"@actions/tool-cache": "^1.7.2",
|
||||
"execa": "^5.1.1",
|
||||
"make-synchronous": "^0.1.1",
|
||||
"mri": "^1.2.0",
|
||||
"msvc-dev-cmd": "github:aminya/msvc-dev-cmd#9f672c1",
|
||||
"numerous": "1.0.3",
|
||||
|
|
|
@ -28,7 +28,6 @@ specifiers:
|
|||
execa: ^5.1.1
|
||||
jest: ^28.0.3
|
||||
loose-ts-check: ^1.2.0
|
||||
make-synchronous: ^0.1.1
|
||||
mri: ^1.2.0
|
||||
msvc-dev-cmd: github:aminya/msvc-dev-cmd#9f672c1
|
||||
npm-check-updates: ^12.5.11
|
||||
|
@ -54,7 +53,6 @@ dependencies:
|
|||
'@actions/io': 1.1.2
|
||||
'@actions/tool-cache': 1.7.2
|
||||
execa: 5.1.1
|
||||
make-synchronous: 0.1.1
|
||||
mri: 1.2.0
|
||||
msvc-dev-cmd: github.com/aminya/msvc-dev-cmd/9f672c1
|
||||
numerous: 1.0.3
|
||||
|
@ -3145,6 +3143,7 @@ packages:
|
|||
/crypto-random-string/2.0.0:
|
||||
resolution: {integrity: sha512-v1plID3y9r/lPhviJ1wrXpLeyUIGAZ2SHNYTEapm7/8A9nLPoyvVp3RK/EPFqn5kEznyWgYZNsRtYYIWbuG8KA==}
|
||||
engines: {node: '>=8'}
|
||||
dev: true
|
||||
|
||||
/crypto-random-string/3.3.1:
|
||||
resolution: {integrity: sha512-5j88ECEn6h17UePrLi6pn1JcLtAiANa3KExyr9y9Z5vo2mv56Gh3I4Aja/B9P9uyMwyxNHAHWv+nE72f30T5Dg==}
|
||||
|
@ -3597,6 +3596,7 @@ packages:
|
|||
/escape-string-regexp/2.0.0:
|
||||
resolution: {integrity: sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==}
|
||||
engines: {node: '>=8'}
|
||||
dev: true
|
||||
|
||||
/escape-string-regexp/4.0.0:
|
||||
resolution: {integrity: sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==}
|
||||
|
@ -5728,14 +5728,6 @@ packages:
|
|||
- supports-color
|
||||
dev: true
|
||||
|
||||
/make-synchronous/0.1.1:
|
||||
resolution: {integrity: sha512-Y4SxxqhaoyMDokJQ0AZz0E+bLhRkOSR7Z/IQoTKPdS6HYi3aobal2kMHoHHoqBadPWjf07P4K1FQLXOx3wf9Yw==}
|
||||
engines: {node: '>=12'}
|
||||
dependencies:
|
||||
subsume: 3.0.0
|
||||
type-fest: 0.16.0
|
||||
dev: false
|
||||
|
||||
/makeerror/1.0.12:
|
||||
resolution: {integrity: sha512-JmqCvUhmt43madlpFzG4BQzG2Z3m6tvQDNKdClZnO3VbIudJYmxsT0FNJMeiB2+JTSlTQTSbU8QdesVmwJcmLg==}
|
||||
dependencies:
|
||||
|
@ -7457,14 +7449,6 @@ packages:
|
|||
engines: {node: '>=8'}
|
||||
dev: true
|
||||
|
||||
/subsume/3.0.0:
|
||||
resolution: {integrity: sha512-6n/UfV8UWKwJNO8OAOiKntwEMihuBeeoJfzpL542C+OuvT4iWG9SwjrXkOmsxjb4SteHUsos9SvrdqZ9+ICwTQ==}
|
||||
engines: {node: '>=8'}
|
||||
dependencies:
|
||||
escape-string-regexp: 2.0.0
|
||||
unique-string: 2.0.0
|
||||
dev: false
|
||||
|
||||
/supports-color/5.5.0:
|
||||
resolution: {integrity: sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==}
|
||||
engines: {node: '>=4'}
|
||||
|
@ -7710,11 +7694,6 @@ packages:
|
|||
engines: {node: '>=4'}
|
||||
dev: true
|
||||
|
||||
/type-fest/0.16.0:
|
||||
resolution: {integrity: sha512-eaBzG6MxNzEn9kiwvtre90cXaNLkmadMWa1zQMs3XORCXNbsH/OewwbxC5ia9dCxIxnTAsSxXJaa/p5y8DlvJg==}
|
||||
engines: {node: '>=10'}
|
||||
dev: false
|
||||
|
||||
/type-fest/0.20.2:
|
||||
resolution: {integrity: sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==}
|
||||
engines: {node: '>=10'}
|
||||
|
@ -7777,6 +7756,7 @@ packages:
|
|||
engines: {node: '>=8'}
|
||||
dependencies:
|
||||
crypto-random-string: 2.0.0
|
||||
dev: true
|
||||
|
||||
/unist-util-stringify-position/3.0.2:
|
||||
resolution: {integrity: sha512-7A6eiDCs9UtjcwZOcCpM4aPII3bAAGv13E96IkawkOAW0OhH+yRxtY0lzo8KiHpzEMfH7Q+FizUmwp8Iqy5EWg==}
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
import { warning } from "./utils/io/io"
|
||||
import { ubuntuVersion } from "./utils/env/ubuntu_version"
|
||||
|
||||
const DefaultVersions: Record<string, string> = {
|
||||
llvm: "13.0.0", // https://github.com/llvm/llvm-project/releases
|
||||
clangtidy: "13.0.0",
|
||||
|
@ -17,24 +14,15 @@ const DefaultVersions: Record<string, string> = {
|
|||
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
|
||||
}
|
||||
|
||||
let ubuntuVersionCached: number[] | null = null
|
||||
|
||||
/** Get the default version if passed true or undefined, otherwise return the version itself */
|
||||
export function getVersion(name: string, version: string | undefined) {
|
||||
export function getVersion(name: string, version: string | undefined, osVersion: number[] | null = null) {
|
||||
if (version === "true" || (version === undefined && name in DefaultVersions)) {
|
||||
// llvm on linux
|
||||
if (process.platform === "linux" && ["llvm", "clangtidy", "clangformat"].includes(name)) {
|
||||
try {
|
||||
// get the version if not already done
|
||||
ubuntuVersionCached = ubuntuVersionCached ?? ubuntuVersion()
|
||||
} catch (err) {
|
||||
warning((err as Error).toString())
|
||||
return DefaultVersions[name]
|
||||
}
|
||||
// choose the default version for llvm based on ubuntu
|
||||
if (ubuntuVersionCached !== null) {
|
||||
if ([20, 18, 16].includes(ubuntuVersionCached[0]) && ubuntuVersionCached[1] === 4) {
|
||||
return `-13.0.0-x86_64-linux-gnu-ubuntu-${ubuntuVersionCached[0]}.0${ubuntuVersionCached[1]}`
|
||||
if (osVersion !== null) {
|
||||
if ([20, 18, 16].includes(osVersion[0]) && osVersion[1] === 4) {
|
||||
return `-13.0.0-x86_64-linux-gnu-ubuntu-${osVersion[0]}.0${osVersion[1]}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import path from "path"
|
|||
import { addBinExtension } from "../../utils/extension/extension"
|
||||
import { chmodSync } from "fs"
|
||||
import { getVersion } from "../../default_versions"
|
||||
import { ubuntuVersion } from "../../utils/env/ubuntu_version"
|
||||
|
||||
jest.setTimeout(400000)
|
||||
async function testUrl(version: string) {
|
||||
|
@ -51,7 +52,7 @@ describe("setup-llvm", () => {
|
|||
})
|
||||
|
||||
it("should setup LLVM", async () => {
|
||||
const { binDir } = await setupLLVM(getVersion("llvm", "true"), directory, process.arch)
|
||||
const { binDir } = await setupLLVM(getVersion("llvm", "true", await ubuntuVersion()), directory, process.arch)
|
||||
await testBin("clang++", ["--version"], binDir)
|
||||
|
||||
expect(process.env.CC?.includes("clang")).toBeTruthy()
|
||||
|
|
23
src/main.ts
23
src/main.ts
|
@ -28,6 +28,7 @@ import * as numerous from "numerous"
|
|||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
import numerousLocale from "numerous/locales/en.js"
|
||||
import { ubuntuVersion } from "./utils/env/ubuntu_version"
|
||||
|
||||
import semverValid from "semver/functions/valid"
|
||||
import { getVersion } from "./default_versions"
|
||||
|
@ -141,6 +142,14 @@ export async function main(args: string[]): Promise<number> {
|
|||
|
||||
// installing the specified tools
|
||||
|
||||
let osVersion: number[] | null = null
|
||||
try {
|
||||
// get the version if not already done
|
||||
osVersion = await ubuntuVersion()
|
||||
} catch (err) {
|
||||
warning((err as Error).toString())
|
||||
}
|
||||
|
||||
// loop over the tools and run their setup function
|
||||
for (const tool of tools) {
|
||||
// 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> {
|
|||
let installationInfo: InstallationInfo | undefined | void
|
||||
if (tool === "vcvarsall") {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
setupVCVarsall(getVersion(tool, version), undefined, arch, undefined, undefined, false, false)
|
||||
setupVCVarsall(getVersion(tool, version, osVersion), undefined, arch, undefined, undefined, false, false)
|
||||
} else {
|
||||
// get the setup function
|
||||
const setupFunction = setups[tool]
|
||||
|
@ -164,7 +173,7 @@ export async function main(args: string[]): Promise<number> {
|
|||
const setupDir = join(setupCppDir, ["llvm", "clangformat", "clangtidy"].includes(tool) ? "llvm" : tool)
|
||||
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
installationInfo = await setupFunction(getVersion(tool, version), setupDir, arch)
|
||||
installationInfo = await setupFunction(getVersion(tool, version, osVersion), setupDir, arch)
|
||||
}
|
||||
// preparing a report string
|
||||
successMessages.push(getSuccessMessage(tool, installationInfo))
|
||||
|
@ -192,7 +201,11 @@ export async function main(args: string[]): Promise<number> {
|
|||
case "llvm":
|
||||
case "clang":
|
||||
case "clang++": {
|
||||
const installationInfo = await setupLLVM(getVersion("llvm", version), join(setupCppDir, "llvm"), arch)
|
||||
const installationInfo = await setupLLVM(
|
||||
getVersion("llvm", version, osVersion),
|
||||
join(setupCppDir, "llvm"),
|
||||
arch
|
||||
)
|
||||
successMessages.push(getSuccessMessage("llvm", installationInfo))
|
||||
break
|
||||
}
|
||||
|
@ -200,7 +213,7 @@ export async function main(args: string[]): Promise<number> {
|
|||
case "mingw":
|
||||
case "cygwin":
|
||||
case "msys": {
|
||||
const installationInfo = await setupGcc(getVersion("gcc", version), join(setupCppDir, "gcc"), arch)
|
||||
const installationInfo = await setupGcc(getVersion("gcc", version, osVersion), join(setupCppDir, "gcc"), arch)
|
||||
successMessages.push(getSuccessMessage("gcc", installationInfo))
|
||||
break
|
||||
}
|
||||
|
@ -211,7 +224,7 @@ export async function main(args: string[]): Promise<number> {
|
|||
case "visualstudio":
|
||||
case "visualcpp":
|
||||
case "visualc++": {
|
||||
const installationInfo = setupMSVC(getVersion("msvc", version), join(setupCppDir, "msvc"), arch)
|
||||
const installationInfo = setupMSVC(getVersion("msvc", version, osVersion), join(setupCppDir, "msvc"), arch)
|
||||
successMessages.push(getSuccessMessage("msvc", installationInfo))
|
||||
break
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import { getUbuntuVersion } from "ubuntu-version"
|
||||
import makeSynchronous from "make-synchronous"
|
||||
|
||||
export function ubuntuVersion(): number[] | null {
|
||||
export async function ubuntuVersion(): Promise<number[] | null> {
|
||||
if (process.platform === "linux") {
|
||||
const versionSplitted = makeSynchronous(getUbuntuVersion)()
|
||||
const versionSplitted = await getUbuntuVersion()
|
||||
|
||||
if (versionSplitted.length === 0) {
|
||||
throw new Error("Failed to get the ubuntu major version.")
|
||||
|
|
Loading…
Reference in New Issue