mirror of https://github.com/aminya/setup-cpp
fix: fix version extraction from the compiler input
This commit is contained in:
parent
2d4c04a0f7
commit
bd2585f331
|
@ -115,7 +115,7 @@ jobs:
|
||||||
compiler:
|
compiler:
|
||||||
- llvm
|
- llvm
|
||||||
- gcc
|
- gcc
|
||||||
# you can specify the version after `-` like `llvm-11`.
|
# you can specify the version after `-` like `llvm-13.0.0`.
|
||||||
steps:
|
steps:
|
||||||
- name: Setup Cpp
|
- name: Setup Cpp
|
||||||
uses: aminya/setup-cpp@v1
|
uses: aminya/setup-cpp@v1
|
||||||
|
|
|
@ -4,7 +4,7 @@ author: "Amin Yahyaabadi"
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
compiler:
|
compiler:
|
||||||
description: "The compiler to use and its optinal version separated by - e.g. llvm-11"
|
description: "The compiler to use and its optional version separated by - e.g. llvm-13.0.0"
|
||||||
required: false
|
required: false
|
||||||
architecture:
|
architecture:
|
||||||
description: "The CPU architecture"
|
description: "The CPU architecture"
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,22 @@
|
||||||
|
import { getCompilerInfo } from "../main"
|
||||||
|
|
||||||
|
jest.setTimeout(300000)
|
||||||
|
describe("getCompilerInfo", () => {
|
||||||
|
it("version will be undefined if not provided", () => {
|
||||||
|
const { compiler, version } = getCompilerInfo("llvm")
|
||||||
|
expect(compiler).toBe("llvm")
|
||||||
|
expect(version).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("extracts version", () => {
|
||||||
|
const { compiler, version } = getCompilerInfo("llvm-12.0.0")
|
||||||
|
expect(compiler).toBe("llvm")
|
||||||
|
expect(version).toBe("12.0.0")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("finds a version even if not semver", () => {
|
||||||
|
const { compiler, version } = getCompilerInfo("llvm-12")
|
||||||
|
expect(compiler).toBe("llvm")
|
||||||
|
expect(version).toBe("12")
|
||||||
|
})
|
||||||
|
})
|
43
src/main.ts
43
src/main.ts
|
@ -18,12 +18,14 @@ import untildify from "untildify"
|
||||||
import { isCI } from "./utils/env/isci"
|
import { isCI } from "./utils/env/isci"
|
||||||
|
|
||||||
import semverValid from "semver/functions/valid"
|
import semverValid from "semver/functions/valid"
|
||||||
|
// import semverCoerce from "semver/functions/coerce"
|
||||||
import { getVersion } from "./default_versions"
|
import { getVersion } from "./default_versions"
|
||||||
import { setupGcc } from "./gcc/gcc"
|
import { setupGcc } from "./gcc/gcc"
|
||||||
import { InstallationInfo } from "./utils/setup/setupBin"
|
import { InstallationInfo } from "./utils/setup/setupBin"
|
||||||
import { error, success } from "./utils/io/io"
|
import { error, success } from "./utils/io/io"
|
||||||
import { setupVcpkg } from "./vcpkg/vcpkg"
|
import { setupVcpkg } from "./vcpkg/vcpkg"
|
||||||
import { join } from "path"
|
import { join } from "path"
|
||||||
|
import { warning } from "@actions/core"
|
||||||
|
|
||||||
/** The setup functions */
|
/** The setup functions */
|
||||||
const setups = {
|
const setups = {
|
||||||
|
@ -135,18 +137,7 @@ export async function main(args: string[]): Promise<number> {
|
||||||
const maybeCompiler = opts.compiler
|
const maybeCompiler = opts.compiler
|
||||||
try {
|
try {
|
||||||
if (maybeCompiler !== undefined) {
|
if (maybeCompiler !== undefined) {
|
||||||
// detecting the compiler version. Divide the given string by `-` and use the second element as the version
|
const { compiler, version } = getCompilerInfo(maybeCompiler)
|
||||||
const compilerAndMaybeVersion = maybeCompiler.split("-")
|
|
||||||
const compiler = compilerAndMaybeVersion[0]
|
|
||||||
let version: string | undefined
|
|
||||||
if (1 in compilerAndMaybeVersion) {
|
|
||||||
const maybeVersion = compilerAndMaybeVersion[1]
|
|
||||||
if (semverValid(maybeVersion) !== null) {
|
|
||||||
version = maybeVersion
|
|
||||||
} else {
|
|
||||||
error(`Invalid version ${maybeVersion} used for the compiler. Using the default version...`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// install the compiler. We allow some aliases for the compiler name
|
// install the compiler. We allow some aliases for the compiler name
|
||||||
switch (compiler) {
|
switch (compiler) {
|
||||||
|
@ -219,6 +210,32 @@ main(process.argv)
|
||||||
process.exitCode = 1
|
process.exitCode = 1
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/** Detecting the compiler version. Divide the given string by `-` and use the second element as the version */
|
||||||
|
export function getCompilerInfo(maybeCompiler: string) {
|
||||||
|
const compilerAndMaybeVersion = maybeCompiler.split("-")
|
||||||
|
const compiler = compilerAndMaybeVersion[0]
|
||||||
|
if (1 in compilerAndMaybeVersion) {
|
||||||
|
const maybeVersion = compilerAndMaybeVersion[1]
|
||||||
|
if (semverValid(maybeVersion) !== null) {
|
||||||
|
return { compiler, version: maybeVersion }
|
||||||
|
} else {
|
||||||
|
// version coercion
|
||||||
|
// try {
|
||||||
|
// // find the semver version of an integer
|
||||||
|
// const coercedVersion = semverCoerce(maybeVersion)
|
||||||
|
// if (coercedVersion !== null) {
|
||||||
|
// return { compiler, version: coercedVersion.version }
|
||||||
|
// }
|
||||||
|
// } catch (err) {
|
||||||
|
// // handled in the end
|
||||||
|
// }
|
||||||
|
warning(`Invalid semver version ${maybeVersion} used for the compiler.`)
|
||||||
|
return { compiler, version: maybeVersion }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { compiler, version: undefined }
|
||||||
|
}
|
||||||
|
|
||||||
function printHelp() {
|
function printHelp() {
|
||||||
core.info(`
|
core.info(`
|
||||||
setup_cpp [options]
|
setup_cpp [options]
|
||||||
|
@ -228,7 +245,7 @@ Install all the tools required for building and testing C++/C projects.
|
||||||
|
|
||||||
--architecture\t the cpu architecture to install the tools for. By default it uses the current CPU architecture.
|
--architecture\t the cpu architecture to install the tools for. By default it uses the current CPU architecture.
|
||||||
--compiler\t the <compiler> to install.
|
--compiler\t the <compiler> to install.
|
||||||
\t You can specify the version instead of specifying just the name e.g: --compiler 'llvm-11'
|
\t You can specify the version instead of specifying just the name e.g: --compiler 'llvm-13.0.0'
|
||||||
|
|
||||||
--tool_name\t pass "true" or pass the <version> you would like to install for this tool. e.g. --conan true or --conan "1.42.1"
|
--tool_name\t pass "true" or pass the <version> you would like to install for this tool. e.g. --conan true or --conan "1.42.1"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue