Skip to content

Commit c56c0d9

Browse files
authored
Merge pull request #25 from aminya/vs2022 [skip ci]
2 parents 61a3c6c + bb2e50e commit c56c0d9

File tree

9 files changed

+78
-57
lines changed

9 files changed

+78
-57
lines changed

.github/workflows/CI.yml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
os:
18+
- windows-2022
1819
- windows-2019
1920
- ubuntu-20.04
2021
- macos-10.15

dist/setup_cpp.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup_cpp.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/default_versions.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
const DefaultVersions: Record<string, string> = {
2-
msvc: "2019",
3-
vcvarsall: "2019",
42
llvm: "13.0.0",
53
clangtidy: "13.0.0",
64
clangformat: "13.0.0",

src/main.ts

+3-11
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,15 @@ export async function main(args: string[]): Promise<number> {
160160
case "llvm":
161161
case "clang":
162162
case "clang++": {
163-
const installationInfo = await setupLLVM(
164-
getVersion("llvm", version) as string,
165-
join(setupCppDir, "llvm"),
166-
arch
167-
)
163+
const installationInfo = await setupLLVM(getVersion("llvm", version), join(setupCppDir, "llvm"), arch)
168164
successMessages.push(getSuccessMessage("llvm", installationInfo))
169165
break
170166
}
171167
case "gcc":
172168
case "mingw":
173169
case "cygwin":
174170
case "msys": {
175-
const installationInfo = await setupGcc(getVersion("gcc", version) as string, join(setupCppDir, "gcc"), arch)
171+
const installationInfo = await setupGcc(getVersion("gcc", version), join(setupCppDir, "gcc"), arch)
176172
successMessages.push(getSuccessMessage("gcc", installationInfo))
177173
break
178174
}
@@ -183,11 +179,7 @@ export async function main(args: string[]): Promise<number> {
183179
case "visualstudio":
184180
case "visualcpp":
185181
case "visualc++": {
186-
const installationInfo = await setupMSVC(
187-
getVersion("msvc", version) as string,
188-
join(setupCppDir, "msvc"),
189-
arch
190-
)
182+
const installationInfo = setupMSVC(getVersion("msvc", version), join(setupCppDir, "msvc"), arch)
191183
successMessages.push(getSuccessMessage("msvc", installationInfo))
192184
break
193185
}

src/msvc/__tests__/msvc.test.ts

+35-13
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,67 @@
11
import which from "which"
2-
import { testBin } from "../../utils/tests/test-helpers"
32
import { setupMSVC } from "../msvc"
43

54
jest.setTimeout(300000)
65
describe("setup-msvc", () => {
7-
it("should setup msvc 2019", async () => {
6+
it("should setup the pre-installed msvc", () => {
87
try {
98
if (process.platform !== "win32") {
109
return
1110
}
12-
await setupMSVC("2019", "", process.arch)
13-
await testBin("cl", [])
14-
console.log(which("cl"))
11+
setupMSVC("", "", process.arch)
12+
console.log(which.sync("cl"))
1513
} catch (e) {
1614
// TODO
1715
console.error(e)
1816
}
1917
})
2018

21-
it("should setup msvc 2017", async () => {
19+
it("should setup msvc 2022", () => {
2220
try {
2321
if (process.platform !== "win32") {
2422
return
2523
}
26-
await setupMSVC("2017", "", process.arch)
27-
await testBin("cl", [])
28-
console.log(which("cl"))
24+
setupMSVC("2022", "", process.arch)
25+
console.log(which.sync("cl"))
2926
} catch (e) {
3027
// TODO
3128
console.error(e)
3229
}
3330
})
3431

35-
it("should setup msvc 2015", async () => {
32+
it("should setup msvc 2019", () => {
3633
try {
3734
if (process.platform !== "win32") {
3835
return
3936
}
40-
await setupMSVC("2015", "", process.arch)
41-
await testBin("cl", [])
42-
console.log(which("cl"))
37+
setupMSVC("2019", "", process.arch)
38+
console.log(which.sync("cl"))
39+
} catch (e) {
40+
// TODO
41+
console.error(e)
42+
}
43+
})
44+
45+
it("should setup msvc 2017", () => {
46+
try {
47+
if (process.platform !== "win32") {
48+
return
49+
}
50+
setupMSVC("2017", "", process.arch)
51+
console.log(which.sync("cl"))
52+
} catch (e) {
53+
// TODO
54+
console.error(e)
55+
}
56+
})
57+
58+
it("should setup msvc 2015", () => {
59+
try {
60+
if (process.platform !== "win32") {
61+
return
62+
}
63+
setupMSVC("2015", "", process.arch)
64+
console.log(which.sync("cl"))
4365
} catch (e) {
4466
// TODO
4567
console.error(e)

src/msvc/msvc.ts

+28-26
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,63 @@
11
import { setupChocoPack } from "../utils/setup/setupChocoPack"
2-
import { error } from "@actions/core"
2+
import { error, info } from "@actions/core"
33
import { setupVCVarsall } from "../vcvarsall/vcvarsall"
44
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
55
// @ts-ignore
66
import { vsversion_to_versionnumber, findVcvarsall } from "msvc-dev-cmd/lib.js"
77

88
type MSVCVersion = "2022" | "17.0" | "2019" | "16.0" | "2017" | "15.0" | "2015" | "14.0" | "2013" | "12.0" | string
99

10-
export async function setupMSVC(
10+
export function setupMSVC(
1111
versionGiven: MSVCVersion,
1212
_setupDir: string,
1313
arch: string,
1414
sdk?: string,
1515
uwp?: boolean,
1616
spectre?: boolean
17-
): Promise<void> {
17+
) {
1818
if (process.platform !== "win32") {
1919
return
2020
}
2121
const version = vsversion_to_versionnumber(versionGiven) as string
2222

2323
// check if the given version is already installed
24+
info(`Checking if MSVC ${version} is already installed`)
2425
let installed = false
2526
try {
26-
findVcvarsall(version)
27+
const path = findVcvarsall(version) as string
2728
installed = true
29+
info(`Found the pre-installed version of MSVC at ${path}`)
2830
} catch {
2931
// not installed, try installing
3032
}
3133

3234
let toolset: string | undefined
3335
let VCTargetsPath: string | undefined
3436
// 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", [])
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.`)
5257
}
53-
VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133"
54-
} else {
55-
error(`The given MSVC versions ${versionGiven} is not supported yet.`)
58+
} catch (e) {
59+
error(e as string | Error)
5660
}
57-
} catch (e) {
58-
error(e as string | Error)
5961
}
6062
// run vcvarsall.bat environment variables
6163
setupVCVarsall(version, VCTargetsPath, arch, toolset, sdk, uwp, spectre)

src/utils/setup/setupChocoPack.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ export function setupChocoPack(name: string, version?: string, args: string[] =
2323
env.PATH = PATH
2424

2525
if (version !== undefined && version !== "") {
26-
execa.sync("choco", ["install", "-y", name, `--version=${version}`, ...args], { env, extendEnv: false })
26+
execa.sync("choco", ["install", "-y", name, `--version=${version}`, ...args], {
27+
env,
28+
extendEnv: false,
29+
stdio: "inherit",
30+
})
2731
} else {
28-
execa.sync("choco", ["install", "-y", name, ...args], { env, extendEnv: false })
32+
execa.sync("choco", ["install", "-y", name, ...args], { env, extendEnv: false, stdio: "inherit" })
2933
}
3034

3135
const binDir = `${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin`

src/utils/setup/setupPipPack.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export async function setupPipPack(name: string, version?: string) {
2626
}
2727
}
2828

29-
execa.sync(pip, ["install", version !== undefined && version !== "" ? `${name}==${version}` : name])
29+
execa.sync(pip, ["install", version !== undefined && version !== "" ? `${name}==${version}` : name], {
30+
stdio: "inherit",
31+
})
3032

3133
if (binDir === undefined) {
3234
if (process.platform === "linux") {

0 commit comments

Comments
 (0)