mirror of
https://github.com/ilammy/msvc-dev-cmd.git
synced 2026-09-06 21:57:19 +08:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user