Compare commits

...

3 Commits

Author SHA1 Message Date
ilammy 6bcb337df2 msvc-dev-cmd v1.3.0 2020-06-14 20:57:29 +03:00
Alexei Lozovsky be0a358ece Look for vcbuildtools.bat of VS 2015 as well (#9)
"Visual C++" has its build tool batch files in a different place.
Let's look there as well if we have not found 2017 or 2019 stuff.

Thanks to ReactOS project for figuring this out.

Co-authored-by: Victor Perevertkin <victor.perevertkin@reactos.org>
2020-06-14 20:55:01 +03:00
Oleh Prypin 5a6b51d5ac Refactor to not use the helper script (#6)
Choose vcvarsall.bat within JS code, call CMD directly with a command instead of writing a temporary file.
2020-05-09 21:24:12 +03:00
3 changed files with 30 additions and 69 deletions
+28 -67
View File
@@ -1,8 +1,6 @@
const core = require('@actions/core') const core = require('@actions/core')
const execFile = require('util').promisify(require('child_process').execFile) const exec = require('util').promisify(require('child_process').exec)
const fs = require('fs').promises const fs = require('fs')
const os = require('os')
const path = require('path')
const process = require('process') const process = require('process')
const EDITIONS = ['Enterprise', 'Professional', 'Community'] const EDITIONS = ['Enterprise', 'Professional', 'Community']
@@ -20,32 +18,33 @@ const InterestingVariables = [
/^WindowsSDK/i, /^WindowsSDK/i,
] ]
function findVcvarsall() {
const programFiles = process.env['ProgramFiles(x86)']
// Given the order of each list it should check
// for the more recent versions first and the
// highest grade edition first.
for (const ver of VERSIONS) {
for (const ed of EDITIONS) {
const path = `${programFiles}\\Microsoft Visual Studio\\${ver}\\${ed}\\VC\\Auxiliary\\Build\\vcvarsall.bat`
if (fs.existsSync(path)) {
return path
}
}
}
// Special case for Visual Studio 2015 (and maybe earlier), try it out too.
const path = `${programFiles}\\Microsoft Visual C++ Build Tools\\vcbuildtools.bat`
if (fs.existsSync(path)) {
return path
}
throw new Error('Microsoft Visual Studio not found')
}
async function main() { async function main() {
if (process.platform != 'win32') { if (process.platform != 'win32') {
core.info('This is not a Windows virtual environment, bye!') core.info('This is not a Windows virtual environment, bye!')
return return
} }
// this should generate an array like
// [
// ['P2017', 'path\to\2017\Professional...'],
// ['C2017', 'path\to\2017\Entreprise...'],
// etc...
// [
// Given the order of each list it should check
// for the more recent versions first and the
// highest grade edition first.
var search_map = []
VERSIONS.forEach(ver => {
EDITIONS.forEach(ed => {
let label = ed.charAt(0) + ver
let path = `%ProgramFiles(x86)%\\Microsoft Visual Studio\\${ver}\\${ed}\\VC\\Auxiliary\\Build\\vcvarsall.bat`
search_map.push([label, path])
})
})
const arch = core.getInput('arch') const arch = core.getInput('arch')
const sdk = core.getInput('sdk') const sdk = core.getInput('sdk')
const toolset = core.getInput('toolset') const toolset = core.getInput('toolset')
@@ -53,10 +52,7 @@ async function main() {
const spectre = core.getInput('spectre') const spectre = core.getInput('spectre')
// Due to the way Microsoft Visual C++ is configured, we have to resort to the following hack: // Due to the way Microsoft Visual C++ is configured, we have to resort to the following hack:
// write a helper batch file which calls the configuration batch file and then outputs the // Call the configuration batch file and then output *all* the environment variables.
// configured environment variables, which we then pass to GitHub Actions.
const helper = path.join(os.homedir(), 'msvc-dev-cmd.bat')
var args = [arch] var args = [arch]
if (uwp == 'true') { if (uwp == 'true') {
@@ -71,46 +67,11 @@ async function main() {
if (spectre == 'true') { if (spectre == 'true') {
args.push('-vcvars_spectre_libs=spectre') args.push('-vcvars_spectre_libs=spectre')
} }
core.debug(`Arguments: ${args.join(' ')}`)
var script = ''; const command = `"${findVcvarsall()}" ${args.join(' ')} && set`
core.debug(`Running: ${command}`)
search_map.forEach(pair => { const { stdout } = await exec(command, {shell: "cmd"})
script += `@IF EXIST "${pair[1]}" GOTO :${pair[0]}\n` const environment = stdout.split('\r\n')
})
script += `@ECHO "Microsoft Visual Studio not found"\n
@EXIT 1\n`
search_map.forEach(pair => {
script += `:${pair[0]}\n
@CALL "${pair[1]}" ${args.join(' ')}\n
@GOTO ENV\n`
})
script += `:ENV\n
@IF ERRORLEVEL 1 EXIT\n
@SET`
core.debug(script)
core.debug(`Writing helper file: ${helper}`)
await fs.writeFile(helper, script)
var environment
try {
core.debug('Executing helper')
const { stdout } = await execFile('cmd.exe', ['/q', '/c', helper])
environment = stdout.split('\r\n')
}
catch (error) {
core.debug(`Helper failed: ${error.message}`)
throw error
}
finally {
core.debug('Removing helper')
await fs.unlink(helper)
}
for (let string of environment) { for (let string of environment) {
const [name, value] = string.split('=') const [name, value] = string.split('=')
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "msvc-dev-cmd", "name": "msvc-dev-cmd",
"version": "1.2.0", "version": "1.3.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "msvc-dev-cmd", "name": "msvc-dev-cmd",
"version": "1.2.0", "version": "1.3.0",
"description": "GitHub Action to setup Developer Command Prompt for Microsoft Visual C++", "description": "GitHub Action to setup Developer Command Prompt for Microsoft Visual C++",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {