mirror of
https://github.com/ilammy/msvc-dev-cmd.git
synced 2026-09-07 06:07:19 +08:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b44b596ee5 | |||
| 4b3ec49c71 | |||
| 8a8bb270fb | |||
| 6bcb337df2 | |||
| be0a358ece | |||
| 5a6b51d5ac |
@@ -1,8 +1,7 @@
|
||||
const core = require('@actions/core')
|
||||
const execFile = require('util').promisify(require('child_process').execFile)
|
||||
const fs = require('fs').promises
|
||||
const os = require('os')
|
||||
const path = require('path')
|
||||
const child_process = require('child_process')
|
||||
const exec = require('util').promisify(child_process.exec)
|
||||
const fs = require('fs')
|
||||
const process = require('process')
|
||||
|
||||
const EDITIONS = ['Enterprise', 'Professional', 'Community']
|
||||
@@ -20,32 +19,54 @@ const InterestingVariables = [
|
||||
/^WindowsSDK/i,
|
||||
]
|
||||
|
||||
function findWithVswhere(pattern) {
|
||||
let path = null;
|
||||
try {
|
||||
path = child_process.execSync(`vswhere -products * -latest -prerelease -find ${pattern}`).toString().trim()
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
function findVcvarsall() {
|
||||
// use vswhere
|
||||
let path = findWithVswhere('**/Auxiliary/Build/vcvarsall.bat')
|
||||
if (path && fs.existsSync(path)) {
|
||||
return path
|
||||
}
|
||||
|
||||
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) {
|
||||
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.
|
||||
// us vswhere
|
||||
path = findWithVswhere('**/vcbuildtools.bat')
|
||||
if (path && fs.existsSync(path)) {
|
||||
return path
|
||||
}
|
||||
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() {
|
||||
if (process.platform != 'win32') {
|
||||
core.info('This is not a Windows virtual environment, bye!')
|
||||
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 sdk = core.getInput('sdk')
|
||||
const toolset = core.getInput('toolset')
|
||||
@@ -53,10 +74,7 @@ async function main() {
|
||||
const spectre = core.getInput('spectre')
|
||||
|
||||
// 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
|
||||
// configured environment variables, which we then pass to GitHub Actions.
|
||||
|
||||
const helper = path.join(os.homedir(), 'msvc-dev-cmd.bat')
|
||||
// Call the configuration batch file and then output *all* the environment variables.
|
||||
|
||||
var args = [arch]
|
||||
if (uwp == 'true') {
|
||||
@@ -71,46 +89,11 @@ async function main() {
|
||||
if (spectre == 'true') {
|
||||
args.push('-vcvars_spectre_libs=spectre')
|
||||
}
|
||||
core.debug(`Arguments: ${args.join(' ')}`)
|
||||
|
||||
var script = '';
|
||||
|
||||
search_map.forEach(pair => {
|
||||
script += `@IF EXIST "${pair[1]}" GOTO :${pair[0]}\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)
|
||||
}
|
||||
const command = `"${findVcvarsall()}" ${args.join(' ')} && set`
|
||||
core.debug(`Running: ${command}`)
|
||||
const { stdout } = await exec(command, {shell: "cmd"})
|
||||
const environment = stdout.split('\r\n')
|
||||
|
||||
for (let string of environment) {
|
||||
const [name, value] = string.split('=')
|
||||
|
||||
Generated
+4
-4
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "msvc-dev-cmd",
|
||||
"version": "1.2.0",
|
||||
"version": "1.3.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@@ -678,9 +678,9 @@
|
||||
}
|
||||
},
|
||||
"lodash": {
|
||||
"version": "4.17.15",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
|
||||
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==",
|
||||
"version": "4.17.19",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz",
|
||||
"integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==",
|
||||
"dev": true
|
||||
},
|
||||
"mimic-fn": {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "msvc-dev-cmd",
|
||||
"version": "1.2.0",
|
||||
"version": "1.3.0",
|
||||
"description": "GitHub Action to setup Developer Command Prompt for Microsoft Visual C++",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user