2019-10-01 22:13:57 +03:00
|
|
|
const core = require('@actions/core')
|
2020-09-23 05:20:24 -05:00
|
|
|
const child_process = require('child_process')
|
2020-05-09 11:24:12 -07:00
|
|
|
const fs = require('fs')
|
2020-12-13 14:49:04 +09:00
|
|
|
const path = require('path')
|
2019-10-01 22:51:02 +03:00
|
|
|
const process = require('process')
|
|
|
|
|
|
2020-10-18 11:38:45 +01:00
|
|
|
const PROGRAM_FILES_X86 = process.env['ProgramFiles(x86)']
|
|
|
|
|
|
2020-04-26 21:54:04 +01:00
|
|
|
const EDITIONS = ['Enterprise', 'Professional', 'Community']
|
|
|
|
|
const VERSIONS = ['2019', '2017']
|
2019-10-01 22:51:02 +03:00
|
|
|
|
2020-12-13 14:49:04 +09:00
|
|
|
const VSWHERE_PATH = `${PROGRAM_FILES_X86}\\Microsoft Visual Studio\\Installer`
|
2020-10-18 11:38:45 +01:00
|
|
|
|
2019-10-01 22:51:02 +03:00
|
|
|
const InterestingVariables = [
|
|
|
|
|
'INCLUDE',
|
|
|
|
|
'LIB',
|
|
|
|
|
'LIBPATH',
|
2020-12-11 06:27:22 +01:00
|
|
|
'VCINSTALLDIR',
|
2019-10-01 22:51:02 +03:00
|
|
|
'Path',
|
|
|
|
|
'Platform',
|
2020-03-19 02:24:49 -04:00
|
|
|
'VisualStudioVersion',
|
2019-10-01 22:51:02 +03:00
|
|
|
/^VCTools/,
|
|
|
|
|
/^VSCMD_/,
|
|
|
|
|
/^WindowsSDK/i,
|
|
|
|
|
]
|
2019-10-01 22:13:57 +03:00
|
|
|
|
2020-09-23 05:20:24 -05:00
|
|
|
function findWithVswhere(pattern) {
|
|
|
|
|
try {
|
2020-10-03 17:51:55 +03:00
|
|
|
let installationPath = child_process.execSync(`vswhere -products * -latest -prerelease -property installationPath`).toString().trim()
|
|
|
|
|
return installationPath + '\\' + pattern
|
2020-09-23 05:20:24 -05:00
|
|
|
} catch (e) {
|
2020-10-18 11:38:45 +01:00
|
|
|
core.warning(`vswhere failed: ${e}`)
|
|
|
|
|
}
|
2020-10-03 17:51:55 +03:00
|
|
|
return null
|
2020-09-23 05:20:24 -05:00
|
|
|
}
|
|
|
|
|
|
2020-05-09 11:24:12 -07:00
|
|
|
function findVcvarsall() {
|
2020-10-03 17:51:55 +03:00
|
|
|
// If vswhere is available, ask it about the location of the latest Visual Studio.
|
|
|
|
|
let path = findWithVswhere('VC\\Auxiliary\\Build\\vcvarsall.bat')
|
2020-09-23 05:20:24 -05:00
|
|
|
if (path && fs.existsSync(path)) {
|
2020-12-13 15:03:03 +09:00
|
|
|
core.info(`Found with vswhere: ${path}`)
|
2020-09-23 05:20:24 -05:00
|
|
|
return path
|
|
|
|
|
}
|
2020-12-13 15:03:03 +09:00
|
|
|
core.info("Not found with vswhere")
|
2020-09-23 05:20:24 -05:00
|
|
|
|
2020-10-03 17:51:55 +03:00
|
|
|
// If that does not work, try the standard installation locations,
|
|
|
|
|
// starting with the latest and moving to the oldest.
|
2020-05-09 11:24:12 -07:00
|
|
|
for (const ver of VERSIONS) {
|
|
|
|
|
for (const ed of EDITIONS) {
|
2020-10-18 11:38:45 +01:00
|
|
|
path = `${PROGRAM_FILES_X86}\\Microsoft Visual Studio\\${ver}\\${ed}\\VC\\Auxiliary\\Build\\vcvarsall.bat`
|
2020-12-13 15:03:03 +09:00
|
|
|
core.info(`Trying standard location: ${path}`)
|
2020-05-09 11:24:12 -07:00
|
|
|
if (fs.existsSync(path)) {
|
2020-12-13 15:03:03 +09:00
|
|
|
core.info(`Found standard location: ${path}`)
|
2020-05-09 11:24:12 -07:00
|
|
|
return path
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-13 15:03:03 +09:00
|
|
|
core.info("Not found in standard locations")
|
2020-10-03 17:51:55 +03:00
|
|
|
|
2020-06-14 20:55:01 +03:00
|
|
|
// Special case for Visual Studio 2015 (and maybe earlier), try it out too.
|
2020-10-18 11:38:45 +01:00
|
|
|
path = `${PROGRAM_FILES_X86}\\Microsoft Visual C++ Build Tools\\vcbuildtools.bat`
|
2020-06-14 20:55:01 +03:00
|
|
|
if (fs.existsSync(path)) {
|
2020-12-13 15:03:03 +09:00
|
|
|
core.info(`Found VS 2015: ${path}`)
|
2020-06-14 20:55:01 +03:00
|
|
|
return path
|
|
|
|
|
}
|
2020-12-13 15:03:03 +09:00
|
|
|
core.info(`Not found in VS 2015 location: ${path}`)
|
2020-10-03 17:51:55 +03:00
|
|
|
|
2020-05-09 11:24:12 -07:00
|
|
|
throw new Error('Microsoft Visual Studio not found')
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-13 15:03:03 +09:00
|
|
|
function main() {
|
2019-10-01 22:51:02 +03:00
|
|
|
if (process.platform != 'win32') {
|
|
|
|
|
core.info('This is not a Windows virtual environment, bye!')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-13 14:49:04 +09:00
|
|
|
// Add standard location of "vswhere" to PATH, in case it's not there.
|
|
|
|
|
process.env.PATH += path.delimiter + VSWHERE_PATH
|
|
|
|
|
|
2019-10-01 22:51:02 +03:00
|
|
|
const arch = core.getInput('arch')
|
|
|
|
|
const sdk = core.getInput('sdk')
|
|
|
|
|
const toolset = core.getInput('toolset')
|
|
|
|
|
const uwp = core.getInput('uwp')
|
|
|
|
|
const spectre = core.getInput('spectre')
|
|
|
|
|
|
|
|
|
|
// Due to the way Microsoft Visual C++ is configured, we have to resort to the following hack:
|
2020-05-09 11:24:12 -07:00
|
|
|
// Call the configuration batch file and then output *all* the environment variables.
|
2019-10-01 22:51:02 +03:00
|
|
|
|
|
|
|
|
var args = [arch]
|
|
|
|
|
if (uwp == 'true') {
|
|
|
|
|
args.push('uwp')
|
|
|
|
|
}
|
|
|
|
|
if (sdk) {
|
|
|
|
|
args.push(sdk)
|
|
|
|
|
}
|
|
|
|
|
if (toolset) {
|
|
|
|
|
args.push(`-vcvars_ver=${toolset}`)
|
|
|
|
|
}
|
|
|
|
|
if (spectre == 'true') {
|
|
|
|
|
args.push('-vcvars_spectre_libs=spectre')
|
|
|
|
|
}
|
2020-04-26 21:54:04 +01:00
|
|
|
|
2020-05-09 11:24:12 -07:00
|
|
|
const command = `"${findVcvarsall()}" ${args.join(' ')} && set`
|
|
|
|
|
core.debug(`Running: ${command}`)
|
2020-12-13 15:03:03 +09:00
|
|
|
const environment = child_process.execSync(command, {shell: "cmd"}).toString().split('\r\n')
|
2019-10-01 22:51:02 +03:00
|
|
|
|
2019-10-02 01:09:14 +03:00
|
|
|
for (let string of environment) {
|
2019-10-01 22:51:02 +03:00
|
|
|
const [name, value] = string.split('=')
|
2019-10-02 01:09:14 +03:00
|
|
|
for (let pattern of InterestingVariables) {
|
2019-10-01 22:51:02 +03:00
|
|
|
if (name.match(pattern)) {
|
|
|
|
|
core.exportVariable(name, value)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
core.info(`Configured Developer Command Prompt`)
|
2019-10-01 22:13:57 +03:00
|
|
|
}
|
|
|
|
|
|
2020-12-13 15:03:03 +09:00
|
|
|
try {
|
|
|
|
|
main()
|
|
|
|
|
}
|
|
|
|
|
catch (e) {
|
|
|
|
|
core.setFailed('Could not setup Developer Command Prompt: ' + e.message)
|
|
|
|
|
}
|