Skip to content

Commit 8166564

Browse files
committed
feat: skip msvc installation if already installed
1 parent 19e8171 commit 8166564

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

dist/setup_cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup_cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/msvc/msvc.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { error } from "@actions/core"
33
import { setupVCVarsall } from "../vcvarsall/vcvarsall"
44
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
55
// @ts-ignore
6-
import { vsversion_to_versionnumber } from "msvc-dev-cmd/lib.js"
6+
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

@@ -20,21 +20,36 @@ export async function setupMSVC(
2020
}
2121
const version = vsversion_to_versionnumber(versionGiven) as string
2222

23+
// check if the given version is already installed
24+
let installed = false
25+
try {
26+
findVcvarsall(version)
27+
installed = true
28+
} catch {
29+
// not installed, try installing
30+
}
31+
2332
let toolset: string | undefined
2433
let VCTargetsPath: string | undefined
2534
// https://github.com/aminya/setup-cpp/issues/1
2635
try {
2736
if (version === "14.0") {
2837
toolset = "14.0"
29-
await setupChocoPack("visualcpp-build-tools", "14.0.25420.1", ["--ignore-dependencies"])
38+
if (!installed) {
39+
await setupChocoPack("visualcpp-build-tools", "14.0.25420.1", ["--ignore-dependencies"])
40+
}
3041
VCTargetsPath = "C:/Program Files (x86)/MSBuild/Microsoft.Cpp/v4.0/v140"
3142
} else if (version === "15.0") {
3243
toolset = "14.16"
33-
await setupChocoPack("visualstudio2017buildtools", "15.9.41.0", [])
44+
if (!installed) {
45+
await setupChocoPack("visualstudio2017buildtools", "15.9.41.0", [])
46+
}
3447
VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16" // TODO verify path
3548
} else if (version === "16.0") {
3649
toolset = "14.29"
37-
await setupChocoPack("visualstudio2019buildtools", "16.11.7.0", [])
50+
if (!installed) {
51+
await setupChocoPack("visualstudio2019buildtools", "16.11.7.0", [])
52+
}
3853
VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133"
3954
} else {
4055
error(`The given MSVC versions ${versionGiven} is not supported yet.`)

0 commit comments

Comments
 (0)