Async cleanup and improved logging (#21)

* Avoid unnecessary async-await

Since this is basically a linear script, we don't *really* need all this
async fluff, despite Node.js having a predisposition for async calls.
For one, it does not make much sense to immediately await an async call.
There is a synchronous version of exec -- execSync -- for that.

Suggested-by: Amin Yahyaabadi <aminyahyaabadi74@gmail.com>

* Make logging more verbose

Provide more insight in what paths are tried and where we have found
Visual Studio. Use info level so that it's visible without Actions
debugging being enabled. That way the users get to see a bit more
of the decision making process.
This commit is contained in:
Alexei Lozovsky
2020-12-13 15:03:03 +09:00
committed by GitHub
parent d9df5e2567
commit 87f7e3e8ba
+15 -8
View File
@@ -1,6 +1,5 @@
const core = require('@actions/core') const core = require('@actions/core')
const child_process = require('child_process') const child_process = require('child_process')
const exec = require('util').promisify(child_process.exec)
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const process = require('process') const process = require('process')
@@ -39,33 +38,37 @@ function findVcvarsall() {
// If vswhere is available, ask it about the location of the latest Visual Studio. // If vswhere is available, ask it about the location of the latest Visual Studio.
let path = findWithVswhere('VC\\Auxiliary\\Build\\vcvarsall.bat') let path = findWithVswhere('VC\\Auxiliary\\Build\\vcvarsall.bat')
if (path && fs.existsSync(path)) { if (path && fs.existsSync(path)) {
core.debug(`found with vswhere: ${path}`) core.info(`Found with vswhere: ${path}`)
return path return path
} }
core.info("Not found with vswhere")
// If that does not work, try the standard installation locations, // If that does not work, try the standard installation locations,
// starting with the latest and moving to the oldest. // starting with the latest and moving to the oldest.
for (const ver of VERSIONS) { for (const ver of VERSIONS) {
for (const ed of EDITIONS) { for (const ed of EDITIONS) {
path = `${PROGRAM_FILES_X86}\\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)) { if (fs.existsSync(path)) {
core.debug(`found standard location: ${path}`) core.info(`Found standard location: ${path}`)
return path return path
} }
} }
} }
core.info("Not found in standard locations")
// Special case for Visual Studio 2015 (and maybe earlier), try it out too. // Special case for Visual Studio 2015 (and maybe earlier), try it out too.
path = `${PROGRAM_FILES_X86}\\Microsoft Visual C++ Build Tools\\vcbuildtools.bat` path = `${PROGRAM_FILES_X86}\\Microsoft Visual C++ Build Tools\\vcbuildtools.bat`
if (fs.existsSync(path)) { if (fs.existsSync(path)) {
core.debug(`found VS 2015: ${path}`) core.info(`Found VS 2015: ${path}`)
return path return path
} }
core.info(`Not found in VS 2015 location: ${path}`)
throw new Error('Microsoft Visual Studio not found') throw new Error('Microsoft Visual Studio not found')
} }
async function main() { 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
@@ -99,8 +102,7 @@ async function main() {
const command = `"${findVcvarsall()}" ${args.join(' ')} && set` const command = `"${findVcvarsall()}" ${args.join(' ')} && set`
core.debug(`Running: ${command}`) core.debug(`Running: ${command}`)
const { stdout } = await exec(command, {shell: "cmd"}) const environment = child_process.execSync(command, {shell: "cmd"}).toString().split('\r\n')
const environment = stdout.split('\r\n')
for (let string of environment) { for (let string of environment) {
const [name, value] = string.split('=') const [name, value] = string.split('=')
@@ -115,4 +117,9 @@ async function main() {
core.info(`Configured Developer Command Prompt`) 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)
}