mirror of
https://github.com/ilammy/msvc-dev-cmd.git
synced 2026-09-06 21:57:19 +08:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d39d8f7626 | |||
| 38903dd110 | |||
| 24b406e1cf | |||
| 6f493f9a67 | |||
| 754fb4dc40 | |||
| aa2e60900e | |||
| 376515093d | |||
| 87f7e3e8ba | |||
| d9df5e2567 | |||
| ccb28adcc4 | |||
| 3c1ec87255 | |||
| 75fbadd7d3 |
@@ -13,11 +13,9 @@ jobs:
|
||||
test:
|
||||
name: default
|
||||
runs-on: windows-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
steps:
|
||||
- name: Check out source code
|
||||
uses: actions/checkout@v1
|
||||
uses: actions/checkout@v2
|
||||
- name: Download Internet
|
||||
run: npm install
|
||||
- name: Enable Developer Command Prompt
|
||||
@@ -32,6 +30,23 @@ jobs:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: Check out source code
|
||||
uses: actions/checkout@v1
|
||||
uses: actions/checkout@v2
|
||||
- run: npm install
|
||||
- run: npm audit --audit-level=moderate
|
||||
alias-arch:
|
||||
name: arch aliases
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: Check out source code
|
||||
uses: actions/checkout@v2
|
||||
- name: Download Internet
|
||||
run: npm install
|
||||
- name: Enable Developer Command Prompt
|
||||
uses: ./
|
||||
with:
|
||||
arch: Win32
|
||||
- name: Compile and run some C code
|
||||
shell: cmd
|
||||
run: |
|
||||
cl.exe hello.c
|
||||
hello.exe
|
||||
|
||||
@@ -11,13 +11,11 @@ jobs:
|
||||
test:
|
||||
name: release
|
||||
runs-on: windows-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
steps:
|
||||
- name: Setup Developer Command Prompt
|
||||
uses: ilammy/msvc-dev-cmd@v1
|
||||
- name: Check out source code
|
||||
uses: actions/checkout@v1
|
||||
uses: actions/checkout@v2
|
||||
- name: Compile and run some C code
|
||||
shell: cmd
|
||||
run: |
|
||||
@@ -28,5 +26,5 @@ jobs:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: Check out source code
|
||||
uses: actions/checkout@v1
|
||||
uses: actions/checkout@v2
|
||||
- run: npm audit --audit-level=moderate
|
||||
|
||||
@@ -11,7 +11,9 @@ Supports Windows. Does nothing on Linux and macOS.
|
||||
## Inputs
|
||||
|
||||
- `arch` – target architecture
|
||||
- native compilation: `x86`, `x64` (default), `amd64` (synonym for x64)
|
||||
- native compilation:
|
||||
- `x64` (default) or its synonyms: `amd64`, `win64`
|
||||
- `x86` or its synonyms: `win32`
|
||||
- cross-compilation: `x86_amd64`, `x86_arm`, `x86_arm64`,
|
||||
`amd64_x86`, `amd64_arm`, `amd64_arm64`
|
||||
- `sdk` – Windows SDK to use
|
||||
|
||||
@@ -1,19 +1,26 @@
|
||||
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')
|
||||
|
||||
const PROGRAM_FILES_X86 = process.env['ProgramFiles(x86)']
|
||||
|
||||
const EDITIONS = ['Enterprise', 'Professional', 'Community']
|
||||
const VERSIONS = ['2019', '2017']
|
||||
|
||||
const VSWHERE_PATH = `${PROGRAM_FILES_X86}\\Microsoft Visual Studio\\Installer`
|
||||
|
||||
const InterestingVariables = [
|
||||
'INCLUDE',
|
||||
'LIB',
|
||||
'LIBPATH',
|
||||
'VCINSTALLDIR',
|
||||
'Path',
|
||||
'Platform',
|
||||
'VisualStudioVersion',
|
||||
'UCRTVersion',
|
||||
'UniversalCRTSdkDir',
|
||||
/^VCTools/,
|
||||
/^VSCMD_/,
|
||||
/^WindowsSDK/i,
|
||||
@@ -24,7 +31,7 @@ function findWithVswhere(pattern) {
|
||||
let installationPath = child_process.execSync(`vswhere -products * -latest -prerelease -property installationPath`).toString().trim()
|
||||
return installationPath + '\\' + pattern
|
||||
} catch (e) {
|
||||
core.warn(`vswhere failed: ${e}`)
|
||||
core.warning(`vswhere failed: ${e}`)
|
||||
}
|
||||
return null
|
||||
}
|
||||
@@ -33,45 +40,62 @@ 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.
|
||||
const programFiles = process.env['ProgramFiles(x86)']
|
||||
for (const ver of VERSIONS) {
|
||||
for (const ed of EDITIONS) {
|
||||
path = `${programFiles}\\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)) {
|
||||
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 = `${programFiles}\\Microsoft Visual C++ Build Tools\\vcbuildtools.bat`
|
||||
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
|
||||
}
|
||||
|
||||
const arch = core.getInput('arch')
|
||||
// Add standard location of "vswhere" to PATH, in case it's not there.
|
||||
process.env.PATH += path.delimiter + VSWHERE_PATH
|
||||
|
||||
var arch = core.getInput('arch')
|
||||
const sdk = core.getInput('sdk')
|
||||
const toolset = core.getInput('toolset')
|
||||
const uwp = core.getInput('uwp')
|
||||
const spectre = core.getInput('spectre')
|
||||
|
||||
// There are all sorts of way the architectures are called. In addition to
|
||||
// values supported by Microsoft Visual C++, recognize some common aliases.
|
||||
let arch_aliases = {
|
||||
"win32": "x86",
|
||||
"win64": "x64",
|
||||
}
|
||||
// Ignore case when matching as that's what humans expect.
|
||||
if (arch.toLowerCase() in arch_aliases) {
|
||||
arch = arch_aliases[arch.toLowerCase()]
|
||||
}
|
||||
|
||||
// Due to the way Microsoft Visual C++ is configured, we have to resort to the following hack:
|
||||
// Call the configuration batch file and then output *all* the environment variables.
|
||||
|
||||
@@ -91,8 +115,25 @@ 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')
|
||||
|
||||
// If vsvars.bat is given an incorrect command line, it will print out
|
||||
// an error and *still* exit successfully. Parse out errors from output
|
||||
// which don't look like environment variables, and fail if appropriate.
|
||||
var failed = false
|
||||
for (let line of environment) {
|
||||
if (line.match(/^\[ERROR.*\]/)) {
|
||||
failed = true
|
||||
// Don't print this particular line which will be confusing in output.
|
||||
if (line.match(/Error in script usage. The correct usage is:$/)) {
|
||||
continue
|
||||
}
|
||||
core.error(line)
|
||||
}
|
||||
}
|
||||
if (failed) {
|
||||
throw new Error('invalid parameters')
|
||||
}
|
||||
|
||||
for (let string of environment) {
|
||||
const [name, value] = string.split('=')
|
||||
@@ -107,4 +148,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)
|
||||
}
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
"_args": [
|
||||
[
|
||||
"@actions/core@1.2.6",
|
||||
"/home/ilammy/Documents/dev/ilammy/msvc-dev-cmd"
|
||||
"/Users/ilammy/Documents/dev/ilammy/msvc-dev-cmd"
|
||||
]
|
||||
],
|
||||
"_from": "@actions/core@1.2.6",
|
||||
@@ -27,7 +27,7 @@
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz",
|
||||
"_spec": "1.2.6",
|
||||
"_where": "/home/ilammy/Documents/dev/ilammy/msvc-dev-cmd",
|
||||
"_where": "/Users/ilammy/Documents/dev/ilammy/msvc-dev-cmd",
|
||||
"bugs": {
|
||||
"url": "https://github.com/actions/toolkit/issues"
|
||||
},
|
||||
|
||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "msvc-dev-cmd",
|
||||
"version": "1.3.0",
|
||||
"version": "1.6.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "msvc-dev-cmd",
|
||||
"version": "1.3.0",
|
||||
"version": "1.6.0",
|
||||
"description": "GitHub Action to setup Developer Command Prompt for Microsoft Visual C++",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user