Skip to content

Commit 5c330b4

Browse files
committed
msvc-dev-cmd v1.11.0
2 parents d8610e2 + fe44a12 commit 5c330b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+6556
-60
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ jobs:
7171
- `uwp` – set `true` to build for Universal Windows Platform (i.e., for Windows Store)
7272
- `spectre` – set `true` to use Visual Studio libraries with [Spectre](https://meltdownattack.com) mitigations
7373

74+
- `vsversion` - The Visual Studio version to use. This can be the version number (e.g. 16.0 for 2019) or the year (e.g. "2019").
75+
7476
## Caveats
7577

7678
### Name conflicts with `shell: bash`

action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ inputs:
1212
description: VC++ compiler toolset version
1313
uwp:
1414
description: Build for Universal Windows Platform
15+
vsversion:
16+
description: The Visual Studio version to use. This can be the version number (e.g. 16.0 for 2019) or the year (e.g. "2019").
1517
runs:
1618
using: node12
1719
main: index.js

index.js

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,67 @@ const PROGRAM_FILES = [process.env['ProgramFiles(x86)'], process.env['ProgramFil
99

1010

1111
const EDITIONS = ['Enterprise', 'Professional', 'Community']
12-
const VERSIONS = ['2022', '2019', '2017']
12+
const YEARS = ['2022', '2019', '2017']
13+
14+
const VsYearVersion = {
15+
'2022': '17.0',
16+
'2019': '16.0',
17+
'2017': '15.0',
18+
'2015': '14.0',
19+
'2013': '12.0',
20+
}
21+
22+
function vsversion_to_versionnumber(vsversion) {
23+
if (Object.values(VsYearVersion).includes(vsversion)) {
24+
return vsversion
25+
} else {
26+
if (vsversion in VsYearVersion) {
27+
return VsYearVersion[vsversion]
28+
}
29+
}
30+
return vsversion
31+
}
32+
exports.vsversion_to_versionnumber = vsversion_to_versionnumber
33+
34+
function vsversion_to_year(vsversion) {
35+
if (Object.keys(VsYearVersion).includes(vsversion)) {
36+
return vsversion
37+
} else {
38+
for (const [year, ver] of Object.entries(VsYearVersion)) {
39+
if (ver === vsversion) {
40+
return year
41+
}
42+
}
43+
}
44+
return vsversion
45+
}
46+
exports.vsversion_to_year = vsversion_to_year
1347

1448
const VSWHERE_PATH = `${PROGRAM_FILES_X86}\\Microsoft Visual Studio\\Installer`
1549

16-
function findWithVswhere(pattern) {
50+
function findWithVswhere(pattern, version_pattern) {
1751
try {
18-
let installationPath = child_process.execSync(`vswhere -products * -latest -prerelease -property installationPath`).toString().trim()
52+
let installationPath = child_process.execSync(`vswhere -products * ${version_pattern} -prerelease -property installationPath`).toString().trim()
1953
return installationPath + '\\' + pattern
2054
} catch (e) {
2155
core.warning(`vswhere failed: ${e}`)
2256
}
2357
return null
2458
}
59+
exports.findWithVswhere = findWithVswhere
60+
61+
function findVcvarsall(vsversion) {
62+
const vsversion_number = vsversion_to_versionnumber(vsversion)
63+
let version_pattern
64+
if (vsversion_number) {
65+
const upper_bound = vsversion_number.split('.')[0] + '.9'
66+
version_pattern = `-version "${vsversion_number},${upper_bound}"`
67+
} else {
68+
version_pattern = "-latest"
69+
}
2570

26-
function findVcvarsall() {
2771
// If vswhere is available, ask it about the location of the latest Visual Studio.
28-
let path = findWithVswhere('VC\\Auxiliary\\Build\\vcvarsall.bat')
72+
let path = findWithVswhere('VC\\Auxiliary\\Build\\vcvarsall.bat', version_pattern)
2973
if (path && fs.existsSync(path)) {
3074
core.info(`Found with vswhere: ${path}`)
3175
return path
@@ -34,8 +78,9 @@ function findVcvarsall() {
3478

3579
// If that does not work, try the standard installation locations,
3680
// starting with the latest and moving to the oldest.
81+
const years = vsversion ? [vsversion_to_year(vsversion)] : YEARS
3782
for (const prog_files of PROGRAM_FILES) {
38-
for (const ver of VERSIONS) {
83+
for (const ver of years) {
3984
for (const ed of EDITIONS) {
4085
path = `${prog_files}\\Microsoft Visual Studio\\${ver}\\${ed}\\VC\\Auxiliary\\Build\\vcvarsall.bat`
4186
core.info(`Trying standard location: ${path}`)
@@ -58,6 +103,7 @@ function findVcvarsall() {
58103

59104
throw new Error('Microsoft Visual Studio not found')
60105
}
106+
exports.findVcvarsall = findVcvarsall
61107

62108
function isPathVariable(name) {
63109
const pathLikeVariables = ['PATH', 'INCLUDE', 'LIB', 'LIBPATH']
@@ -75,7 +121,7 @@ function filterPathValue(path) {
75121
}
76122

77123
/** See https://github.com/ilammy/msvc-dev-cmd#inputs */
78-
function setupMSVCDevCmd(arch, sdk, toolset, uwp, spectre) {
124+
function setupMSVCDevCmd(arch, sdk, toolset, uwp, spectre, vsversion) {
79125
if (process.platform != 'win32') {
80126
core.info('This is not a Windows virtual environment, bye!')
81127
return
@@ -114,7 +160,7 @@ function setupMSVCDevCmd(arch, sdk, toolset, uwp, spectre) {
114160
args.push('-vcvars_spectre_libs=spectre')
115161
}
116162

117-
const vcvars = `"${findVcvarsall()}" ${args.join(' ')}`
163+
const vcvars = `"${findVcvarsall(vsversion)}" ${args.join(' ')}`
118164
core.debug(`vcvars command-line: ${vcvars}`)
119165

120166
const cmd_output_string = child_process.execSync(`set && cls && ${vcvars} && cls && set`, {shell: "cmd"}).toString()
@@ -184,8 +230,9 @@ function main() {
184230
const toolset = core.getInput('toolset')
185231
const uwp = core.getInput('uwp')
186232
const spectre = core.getInput('spectre')
233+
const vsversion = core.getInput('vsversion')
187234

188-
setupMSVCDevCmd(arch, sdk, toolset, uwp, spectre)
235+
setupMSVCDevCmd(arch, sdk, toolset, uwp, spectre, vsversion)
189236
}
190237

191238
try {

node_modules/.bin/uuid

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

node_modules/.package-lock.json

Lines changed: 32 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)