Skip to content

Commit

Permalink
msvc-dev-cmd v1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ilammy committed Dec 13, 2020
2 parents ed94116 + 87f7e3e commit 3765150
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
39 changes: 27 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
const core = require('@actions/core')
const child_process = require('child_process')
const exec = require('util').promisify(child_process.exec)
const fs = require('fs')
const path = require('path')
const process = require('process')

const PROGRAM_FILES_X86 = process.env['ProgramFiles(x86)']

const EDITIONS = ['Enterprise', 'Professional', 'Community']
const VERSIONS = ['2019', '2017']

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

const InterestingVariables = [
'INCLUDE',
'LIB',
'LIBPATH',
'VCINSTALLDIR',
'Path',
'Platform',
'VisualStudioVersion',
Expand All @@ -24,7 +29,7 @@ function findWithVswhere(pattern) {
let installationPath = child_process.execSync(`vswhere -products * -latest -prerelease -property installationPath`).toString().trim()
return installationPath + '\\' + pattern
} catch (e) {
core.warn(`vswhere failed: ${e}`)
core.warning(`vswhere failed: ${e}`)
}
return null
}
Expand All @@ -33,39 +38,45 @@ function findVcvarsall() {
// If vswhere is available, ask it about the location of the latest Visual Studio.
let path = findWithVswhere('VC\\Auxiliary\\Build\\vcvarsall.bat')
if (path && fs.existsSync(path)) {
core.debug(`found with vswhere: ${path}`)
core.info(`Found with vswhere: ${path}`)
return path
}
core.info("Not found with vswhere")

// If that does not work, try the standard installation locations,
// starting with the latest and moving to the oldest.
const programFiles = process.env['ProgramFiles(x86)']
for (const ver of VERSIONS) {
for (const ed of EDITIONS) {
path = `${programFiles}\\Microsoft Visual Studio\\${ver}\\${ed}\\VC\\Auxiliary\\Build\\vcvarsall.bat`
path = `${PROGRAM_FILES_X86}\\Microsoft Visual Studio\\${ver}\\${ed}\\VC\\Auxiliary\\Build\\vcvarsall.bat`
core.info(`Trying standard location: ${path}`)
if (fs.existsSync(path)) {
core.debug(`found standard location: ${path}`)
core.info(`Found standard location: ${path}`)
return path
}
}
}
core.info("Not found in standard locations")

// Special case for Visual Studio 2015 (and maybe earlier), try it out too.
path = `${programFiles}\\Microsoft Visual C++ Build Tools\\vcbuildtools.bat`
path = `${PROGRAM_FILES_X86}\\Microsoft Visual C++ Build Tools\\vcbuildtools.bat`
if (fs.existsSync(path)) {
core.debug(`found VS 2015: ${path}`)
core.info(`Found VS 2015: ${path}`)
return path
}
core.info(`Not found in VS 2015 location: ${path}`)

throw new Error('Microsoft Visual Studio not found')
}

async function main() {
function main() {
if (process.platform != 'win32') {
core.info('This is not a Windows virtual environment, bye!')
return
}

// Add standard location of "vswhere" to PATH, in case it's not there.
process.env.PATH += path.delimiter + VSWHERE_PATH

const arch = core.getInput('arch')
const sdk = core.getInput('sdk')
const toolset = core.getInput('toolset')
Expand All @@ -91,8 +102,7 @@ async function main() {

const command = `"${findVcvarsall()}" ${args.join(' ')} && set`
core.debug(`Running: ${command}`)
const { stdout } = await exec(command, {shell: "cmd"})
const environment = stdout.split('\r\n')
const environment = child_process.execSync(command, {shell: "cmd"}).toString().split('\r\n')

for (let string of environment) {
const [name, value] = string.split('=')
Expand All @@ -107,4 +117,9 @@ async function main() {
core.info(`Configured Developer Command Prompt`)
}

main().catch((e) => core.setFailed('Could not setup Developer Command Prompt: ' + e.message))
try {
main()
}
catch (e) {
core.setFailed('Could not setup Developer Command Prompt: ' + e.message)
}
4 changes: 2 additions & 2 deletions node_modules/@actions/core/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "msvc-dev-cmd",
"version": "1.3.0",
"version": "1.5.0",
"description": "GitHub Action to setup Developer Command Prompt for Microsoft Visual C++",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 3765150

Please sign in to comment.