@@ -18,12 +18,14 @@ import untildify from "untildify"
18
18
import { isCI } from "./utils/env/isci"
19
19
20
20
import semverValid from "semver/functions/valid"
21
+ // import semverCoerce from "semver/functions/coerce"
21
22
import { getVersion } from "./default_versions"
22
23
import { setupGcc } from "./gcc/gcc"
23
24
import { InstallationInfo } from "./utils/setup/setupBin"
24
25
import { error , success } from "./utils/io/io"
25
26
import { setupVcpkg } from "./vcpkg/vcpkg"
26
27
import { join } from "path"
28
+ import { warning } from "@actions/core"
27
29
28
30
/** The setup functions */
29
31
const setups = {
@@ -135,18 +137,7 @@ export async function main(args: string[]): Promise<number> {
135
137
const maybeCompiler = opts . compiler
136
138
try {
137
139
if ( maybeCompiler !== undefined ) {
138
- // detecting the compiler version. Divide the given string by `-` and use the second element as the version
139
- const compilerAndMaybeVersion = maybeCompiler . split ( "-" )
140
- const compiler = compilerAndMaybeVersion [ 0 ]
141
- let version : string | undefined
142
- if ( 1 in compilerAndMaybeVersion ) {
143
- const maybeVersion = compilerAndMaybeVersion [ 1 ]
144
- if ( semverValid ( maybeVersion ) !== null ) {
145
- version = maybeVersion
146
- } else {
147
- error ( `Invalid version ${ maybeVersion } used for the compiler. Using the default version...` )
148
- }
149
- }
140
+ const { compiler, version } = getCompilerInfo ( maybeCompiler )
150
141
151
142
// install the compiler. We allow some aliases for the compiler name
152
143
switch ( compiler ) {
@@ -219,6 +210,32 @@ main(process.argv)
219
210
process . exitCode = 1
220
211
} )
221
212
213
+ /** Detecting the compiler version. Divide the given string by `-` and use the second element as the version */
214
+ export function getCompilerInfo ( maybeCompiler : string ) {
215
+ const compilerAndMaybeVersion = maybeCompiler . split ( "-" )
216
+ const compiler = compilerAndMaybeVersion [ 0 ]
217
+ if ( 1 in compilerAndMaybeVersion ) {
218
+ const maybeVersion = compilerAndMaybeVersion [ 1 ]
219
+ if ( semverValid ( maybeVersion ) !== null ) {
220
+ return { compiler, version : maybeVersion }
221
+ } else {
222
+ // version coercion
223
+ // try {
224
+ // // find the semver version of an integer
225
+ // const coercedVersion = semverCoerce(maybeVersion)
226
+ // if (coercedVersion !== null) {
227
+ // return { compiler, version: coercedVersion.version }
228
+ // }
229
+ // } catch (err) {
230
+ // // handled in the end
231
+ // }
232
+ warning ( `Invalid semver version ${ maybeVersion } used for the compiler.` )
233
+ return { compiler, version : maybeVersion }
234
+ }
235
+ }
236
+ return { compiler, version : undefined }
237
+ }
238
+
222
239
function printHelp ( ) {
223
240
core . info ( `
224
241
setup_cpp [options]
@@ -228,7 +245,7 @@ Install all the tools required for building and testing C++/C projects.
228
245
229
246
--architecture\t the cpu architecture to install the tools for. By default it uses the current CPU architecture.
230
247
--compiler\t the <compiler> to install.
231
- \t You can specify the version instead of specifying just the name e.g: --compiler 'llvm-11 '
248
+ \t You can specify the version instead of specifying just the name e.g: --compiler 'llvm-13.0.0 '
232
249
233
250
--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"
234
251
0 commit comments