|
1 | 1 | import { setupChocoPack } from "../utils/setup/setupChocoPack"
|
2 |
| -import { error } from "@actions/core" |
| 2 | +import { error, info } from "@actions/core" |
3 | 3 | import { setupVCVarsall } from "../vcvarsall/vcvarsall"
|
4 | 4 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
5 | 5 | // @ts-ignore
|
6 | 6 | import { vsversion_to_versionnumber, findVcvarsall } from "msvc-dev-cmd/lib.js"
|
7 | 7 |
|
8 | 8 | type MSVCVersion = "2022" | "17.0" | "2019" | "16.0" | "2017" | "15.0" | "2015" | "14.0" | "2013" | "12.0" | string
|
9 | 9 |
|
10 |
| -export async function setupMSVC( |
| 10 | +export function setupMSVC( |
11 | 11 | versionGiven: MSVCVersion,
|
12 | 12 | _setupDir: string,
|
13 | 13 | arch: string,
|
14 | 14 | sdk?: string,
|
15 | 15 | uwp?: boolean,
|
16 | 16 | spectre?: boolean
|
17 |
| -): Promise<void> { |
| 17 | +) { |
18 | 18 | if (process.platform !== "win32") {
|
19 | 19 | return
|
20 | 20 | }
|
21 | 21 | const version = vsversion_to_versionnumber(versionGiven) as string
|
22 | 22 |
|
23 | 23 | // check if the given version is already installed
|
| 24 | + info(`Checking if MSVC ${version} is already installed`) |
24 | 25 | let installed = false
|
25 | 26 | try {
|
26 |
| - findVcvarsall(version) |
| 27 | + const path = findVcvarsall(version) as string |
27 | 28 | installed = true
|
| 29 | + info(`Found the pre-installed version of MSVC at ${path}`) |
28 | 30 | } catch {
|
29 | 31 | // not installed, try installing
|
30 | 32 | }
|
31 | 33 |
|
32 | 34 | let toolset: string | undefined
|
33 | 35 | let VCTargetsPath: string | undefined
|
34 | 36 | // https://github.com/aminya/setup-cpp/issues/1
|
35 |
| - try { |
36 |
| - if (version === "14.0") { |
37 |
| - toolset = "14.0" |
38 |
| - if (!installed) { |
39 |
| - await setupChocoPack("visualcpp-build-tools", "14.0.25420.1", ["--ignore-dependencies"]) |
40 |
| - } |
41 |
| - VCTargetsPath = "C:/Program Files (x86)/MSBuild/Microsoft.Cpp/v4.0/v140" |
42 |
| - } else if (version === "15.0") { |
43 |
| - toolset = "14.16" |
44 |
| - if (!installed) { |
45 |
| - await setupChocoPack("visualstudio2017buildtools", "15.9.41.0", []) |
46 |
| - } |
47 |
| - VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16" // TODO verify path |
48 |
| - } else if (version === "16.0") { |
49 |
| - toolset = "14.29" |
50 |
| - if (!installed) { |
51 |
| - await setupChocoPack("visualstudio2019buildtools", "16.11.7.0", []) |
52 |
| - } |
53 |
| - VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133" |
54 |
| - } else if (version === "17.0") { |
55 |
| - toolset = undefined |
56 |
| - if (!installed) { |
57 |
| - await setupChocoPack("visualstudio2022buildtools", "117.0.5.0", []) |
| 37 | + if (!installed) { |
| 38 | + try { |
| 39 | + if (version === "14.0") { |
| 40 | + toolset = "14.0" |
| 41 | + setupChocoPack("visualcpp-build-tools", "14.0.25420.1", ["--ignore-dependencies"]) |
| 42 | + VCTargetsPath = "C:/Program Files (x86)/MSBuild/Microsoft.Cpp/v4.0/v140" |
| 43 | + } else if (version === "15.0") { |
| 44 | + toolset = "14.16" |
| 45 | + setupChocoPack("visualstudio2017buildtools", "15.9.41.0", []) |
| 46 | + VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16" // TODO verify path |
| 47 | + } else if (version === "16.0") { |
| 48 | + toolset = "14.29" |
| 49 | + setupChocoPack("visualstudio2019buildtools", "16.11.7.0", []) |
| 50 | + VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133" |
| 51 | + } else if (version === "17.0") { |
| 52 | + toolset = undefined |
| 53 | + setupChocoPack("visualstudio2022buildtools", "117.0.5.0", []) |
| 54 | + VCTargetsPath = undefined |
| 55 | + } else { |
| 56 | + error(`The given MSVC versions ${versionGiven} is not supported yet.`) |
58 | 57 | }
|
59 |
| - VCTargetsPath = undefined |
60 |
| - } else { |
61 |
| - error(`The given MSVC versions ${versionGiven} is not supported yet.`) |
| 58 | + } catch (e) { |
| 59 | + error(e as string | Error) |
62 | 60 | }
|
63 |
| - } catch (e) { |
64 |
| - error(e as string | Error) |
65 | 61 | }
|
66 | 62 | // run vcvarsall.bat environment variables
|
67 | 63 | setupVCVarsall(version, VCTargetsPath, arch, toolset, sdk, uwp, spectre)
|
|
0 commit comments