1
1
import { join } from "path"
2
- import { endGroup , notice , startGroup } from "@actions/core"
2
+ import { endGroup , startGroup } from "@actions/core"
3
3
import { error , info } from "ci-log"
4
- import { addEnv } from "envosman"
5
4
import semverValid from "semver/functions/valid"
6
- import { getSuccessMessage , rcOptions } from "./cli-options.js"
5
+ import { getSuccessMessage } from "./cli-options.js"
7
6
import { setupGcc , setupMingw } from "./gcc/gcc.js"
8
7
import { activateGcovGCC , activateGcovLLVM } from "./gcovr/gcovr.js"
8
+ import { setupAppleClang } from "./llvm/apple-clang.js"
9
9
import { setupLLVM } from "./llvm/llvm.js"
10
10
import { setupMSVC } from "./msvc/msvc.js"
11
+ import { appleClangSetups , gccSetups , llvmSetups , mingwSetups , msvcSetups } from "./tool.js"
12
+ import type { InstallationInfo } from "./utils/setup/setupBin.js"
11
13
import { getVersion } from "./versions/versions.js"
12
14
13
- /** Detecting the compiler version. Divide the given string by `-` and use the second element as the version */
15
+ /**
16
+ * Detecting the compiler version. Divide the given string by `-` and use the second element as the version
17
+ *
18
+ * @param compilerAndVersion - The compiler and version string
19
+ * @returns The compiler and version
20
+ *
21
+ * @nothrow It doesn't throw any error, but it logs the error if it fails to parse the compiler info
22
+ */
14
23
export function getCompilerInfo ( compilerAndVersion : string ) {
15
- const compilerAndMaybeVersion = compilerAndVersion . split ( "-" )
16
- const compiler = compilerAndMaybeVersion [ 0 ]
17
- if ( 1 in compilerAndMaybeVersion ) {
18
- const maybeVersion = compilerAndMaybeVersion [ 1 ]
19
- if ( semverValid ( maybeVersion ) !== null ) {
20
- return { compiler , version : maybeVersion }
21
- } else {
22
- info ( `Invalid semver version ${ maybeVersion } used for the compiler.` )
24
+ try {
25
+ const compilerAndMaybeVersion = compilerAndVersion . split ( "-" )
26
+ const compiler = compilerAndMaybeVersion [ 0 ]
27
+ if ( 1 in compilerAndMaybeVersion ) {
28
+ const maybeVersion = compilerAndMaybeVersion [ 1 ]
29
+ if ( semverValid ( maybeVersion ) === null ) {
30
+ info ( `Invalid semver version ${ maybeVersion } used for the compiler.` )
31
+ }
23
32
return { compiler, version : maybeVersion }
24
33
}
34
+ return { compiler, version : undefined }
35
+ } catch ( err ) {
36
+ error ( `Failed to parse the compiler info ${ compilerAndVersion } : ${ err } ` )
37
+ return { compiler : compilerAndVersion , version : undefined }
25
38
}
26
- return { compiler, version : undefined }
27
39
}
28
40
29
41
/** Installing the specified compiler */
@@ -35,73 +47,47 @@ export async function installCompiler(
35
47
successMessages : string [ ] ,
36
48
errorMessages : string [ ] ,
37
49
) {
38
- try {
39
- const { compiler, version } = getCompilerInfo ( compilerAndVersion )
50
+ const { compiler, version } = getCompilerInfo ( compilerAndVersion )
40
51
52
+ let installationInfo : InstallationInfo | undefined | void | null // null means the compiler is not supported
53
+ try {
41
54
// install the compiler. We allow some aliases for the compiler name
42
55
startGroup ( `Installing ${ compiler } ${ version ?? "" } ` )
43
- switch ( compiler ) {
44
- case "llvm" :
45
- case "clang" :
46
- case "clang++" : {
47
- const installationInfo = await setupLLVM (
48
- getVersion ( "llvm" , version , osVersion ) ,
49
- join ( setupCppDir , "llvm" ) ,
50
- arch ,
51
- )
52
-
53
- await activateGcovLLVM ( )
54
-
55
- successMessages . push ( getSuccessMessage ( "llvm" , installationInfo ) )
56
- break
57
- }
58
- case "gcc" :
59
- case "mingw" :
60
- case "cygwin" :
61
- case "msys" : {
62
- const gccVersion = compiler === "mingw"
63
- ? getVersion ( "mingw" , version , osVersion )
64
- : getVersion ( "gcc" , version , osVersion )
65
- const installationInfo = compiler === "mingw"
66
- ? await setupMingw ( gccVersion , join ( setupCppDir , "gcc" ) , arch )
67
- : await setupGcc ( gccVersion , join ( setupCppDir , "gcc" ) , arch )
68
-
69
- await activateGcovGCC ( gccVersion )
70
-
71
- successMessages . push ( getSuccessMessage ( "gcc" , installationInfo ) )
72
- break
73
- }
74
- case "cl" :
75
- case "msvc" :
76
- case "msbuild" :
77
- case "vs" :
78
- case "visualstudio" :
79
- case "visualcpp" :
80
- case "visualc++" : {
81
- const installationInfo = await setupMSVC (
82
- getVersion ( "msvc" , version , osVersion ) ,
83
- join ( setupCppDir , "msvc" ) ,
84
- arch ,
85
- )
86
-
87
- successMessages . push ( getSuccessMessage ( "msvc" , installationInfo ) )
88
- break
89
- }
90
- case "appleclang" :
91
- case "applellvm" : {
92
- notice ( "Assuming apple-clang is already installed" )
93
- await Promise . all ( [ addEnv ( "CC" , "clang" , rcOptions ) , addEnv ( "CXX" , "clang++" , rcOptions ) ] )
94
- successMessages . push ( getSuccessMessage ( "apple-clang" , undefined ) )
95
- break
96
- }
97
- default : {
98
- errorMessages . push ( `Unsupported compiler ${ compiler } ` )
99
- }
56
+ if ( compiler in llvmSetups ) {
57
+ installationInfo = await setupLLVM (
58
+ getVersion ( "llvm" , version , osVersion ) ,
59
+ join ( setupCppDir , "llvm" ) ,
60
+ arch ,
61
+ )
62
+ await activateGcovLLVM ( )
63
+ } else if ( compiler in gccSetups ) {
64
+ const gccVersion = getVersion ( "gcc" , version , osVersion )
65
+ installationInfo = await setupGcc ( gccVersion , join ( setupCppDir , "gcc" ) , arch )
66
+ await activateGcovGCC ( gccVersion )
67
+ } else if ( compiler in mingwSetups ) {
68
+ const gccVersion = getVersion ( "mingw" , version , osVersion )
69
+ installationInfo = await setupMingw ( gccVersion , join ( setupCppDir , "gcc" ) , arch )
70
+ await activateGcovGCC ( gccVersion )
71
+ } else if ( compiler in msvcSetups ) {
72
+ installationInfo = await setupMSVC (
73
+ getVersion ( "msvc" , version , osVersion ) ,
74
+ join ( setupCppDir , "msvc" ) ,
75
+ arch ,
76
+ )
77
+ } else if ( compiler in appleClangSetups ) {
78
+ await setupAppleClang ( )
79
+ } else {
80
+ installationInfo = null
81
+ errorMessages . push ( `Unsupported compiler ${ compiler } ` )
100
82
}
101
83
} catch ( err ) {
102
84
error ( err as string | Error )
103
85
errorMessages . push ( `Failed to install the ${ compilerAndVersion } ` )
104
86
}
105
87
88
+ if ( installationInfo !== null ) {
89
+ successMessages . push ( getSuccessMessage ( compiler , installationInfo ) )
90
+ }
91
+
106
92
endGroup ( )
107
93
}
0 commit comments