Compare commits

..

10 Commits

Author SHA1 Message Date
Alexei Lozovsky 24b406e1cf msvc-dev-cmd v1.6.0 2021-03-07 15:29:22 +09:00
Alexei Lozovsky 6f493f9a67 Architecture aliases: Win32 & Win64 (#29)
By a public request, let's support aliases for architecture parameters.
Treat "arch: Win32" as "x86" and "Win64" as "x64".

Test this on CI just in case x86 breaks or something.
2021-03-07 08:23:48 +02:00
Alexei Lozovsky 754fb4dc40 Detect and report vcvarsall.bat errors (#28)
If the parameters passed to the script are incorrect -- for example,
architecture is set to something the script does not understand --
then the script will print an error message *and* exit successfully
without doing anything useful.

Detect the error messages, forward them to the user, and fail the
action. Hopefully, the information from the script will be enough
to pinpoint the source of the issue.

For example, if the action is run

    with:
      arch: Win32

then the output will be

    Found with vswhere: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat
    Error: [ERROR:vcvarsall.bat] Invalid argument found : Win32
    Error: Could not setup Developer Command Prompt: invalid parameters

which is close enough.
2021-03-07 08:16:28 +02:00
Ewout ter Hoeven aa2e60900e CI: Cleanup, checkout v2 (#24)
- Remove the fail-fast: tag, it's non-functional since a matrix isn't used anymore
- Update to the faster checkout v2
2021-02-01 14:01:31 +02:00
Alexei Lozovsky 376515093d msvc-dev-cmd v1.5.0 2020-12-13 15:07:07 +09:00
Alexei Lozovsky 87f7e3e8ba 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.
2020-12-13 08:03:03 +02:00
Alexei Lozovsky d9df5e2567 Add default vswhere location to PATH (#20)
Instead of checking "vswhere" in PATH and then in the default location
explicitly, just add the default locatio to PATH. That makes a single
attempt sufficient.
2020-12-13 07:49:04 +02:00
Alexei Lozovsky ccb28adcc4 Add node_modules on master with up-to-date deps
GitHub Actions tutorials suggest that you should not commit Node.js crap
onto your master branch, but it's not like this action has a lot of
dependencies, and not being able to test "ilammy/msvc-dev-cmd@master" is
so annoying... Therefore, do

    npm install --only production

and commit the results.
2020-12-11 20:05:07 +09:00
Serge Camille 3c1ec87255 Add VCINSTALLDIR to list of exported variables (#23)
This should allow windeployqt to pick up the exported environment variable.
2020-12-11 14:27:22 +09:00
Nicolas Jarnoux 75fbadd7d3 Check default vswhere location too (#19)
On some self-hosted runners "vswhere" is not available in the PATH.
Add another check in the findWithVswhere() function. It checks the
default installation of vswhere as stated by Microsoft, just in case
it is there but just not in the PATH.

Furthermore, the check refers to non-existent method core.warn()
instead of core.warning(). Use the correct method for reporting.
2020-10-18 13:38:45 +03:00
7 changed files with 85 additions and 26 deletions
+19 -4
View File
@@ -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
+2 -4
View File
@@ -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
+3 -1
View File
@@ -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
+57 -13
View File
@@ -1,16 +1,21 @@
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',
@@ -24,7 +29,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 +38,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 +113,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 +146,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
View File
@@ -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"
},
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "msvc-dev-cmd",
"version": "1.3.0",
"version": "1.6.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
+1 -1
View File
@@ -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": {