From 87f7e3e8baed978b9a915c61dc327491aca9e255 Mon Sep 17 00:00:00 2001 From: Alexei Lozovsky Date: Sun, 13 Dec 2020 15:03:03 +0900 Subject: [PATCH] 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 * 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. --- index.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 1711ae1..fec3981 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,5 @@ 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') @@ -39,33 +38,37 @@ 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. for (const ver of VERSIONS) { for (const ed of EDITIONS) { 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 = `${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 @@ -99,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('=') @@ -115,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) +}